From 8e7d294945af49e2bdd4dedea92daa35519cda5c Mon Sep 17 00:00:00 2001 From: wujingtao Date: Wed, 20 Oct 2021 17:33:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=B7=E6=B1=82=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=20=E5=B0=86feign=E8=BD=AC=E4=B8=BAhttp=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hchbox/api/RequestCore.java | 68 +++++++++++++++++++ .../controller/AccountInfoController.java | 40 ++++++----- .../com/hchbox/module/feign/AliPayClient.java | 28 -------- .../security/config/SecurityConfig.java | 1 + .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application.yml | 5 +- .../controller/SellerAccountController.java | 2 +- .../src/main/resources/application.yml | 2 +- .../impl/SellerAccountServiceImpl.java | 4 +- .../java/com/hchbox/vo/AccountSearchVo.java | 2 +- 10 files changed, 102 insertions(+), 51 deletions(-) create mode 100644 service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/api/RequestCore.java diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/api/RequestCore.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/api/RequestCore.java new file mode 100644 index 0000000..214f291 --- /dev/null +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/api/RequestCore.java @@ -0,0 +1,68 @@ +package com.hchbox.api; + +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.hchbox.model.param.CommonResult; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author wujingtao + * @date 2021/10/20 + */ +@Component +public class RequestCore { + private final String API_PREFIX = "/source"; + @Value("${trade.service.source.url}") + private String url; + + /** + * 分页查询主账号的列表 + * + * @param sellerNick + * @param pageable + * @return + */ + public CommonResult getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable) { + String reqUrl = url + API_PREFIX + "/account/parentAccounts" + "?" + "sellerNick=" + sellerNick + "&pageNumber=" + pageable.getPageNumber() + "&pageSize=" + pageable.getPageSize(); + return requestApi(reqUrl); + } + + /** + * 查询套餐 + * + * @return + */ + public CommonResult getPayTemplate() { + String reqUrl = url + API_PREFIX + "/pay/template"; + return requestApi(reqUrl); + } + + + /** + * 子账号授权 + * + * @param childrenAccountId + * @param payTemplateId + * @return + */ + CommonResult authorizeChildrenAccount(@RequestParam(value = "childrenAccountId") Long childrenAccountId, @RequestParam(value = "payTemplateId") Long payTemplateId) { + String reqUrl = url + API_PREFIX + "/account/authorize" + "?" + "childrenAccountId=" + childrenAccountId + "&payTemplateId=" + payTemplateId; + return requestApi(reqUrl); + } + + private CommonResult requestApi(String url) { + JSONObject results; + String getResult = HttpUtil + .createGet(url) + .execute() + .charset("utf-8") + .body(); + JSONObject o = JSONUtil.parseObj(getResult); + results = o.getJSONObject("data"); + return new CommonResult<>().success(results); + } +} diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/AccountInfoController.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/AccountInfoController.java index 5ab9d36..9852470 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/AccountInfoController.java +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/AccountInfoController.java @@ -1,7 +1,9 @@ package com.hchbox.module.controller; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import com.hchbox.api.RequestCore; import com.hchbox.constant.AuthConstants; import com.hchbox.constant.DefaultNumberConstants; import com.hchbox.module.entity.SellerAccount; @@ -27,6 +29,8 @@ import org.springframework.web.bind.annotation.*; public class AccountInfoController { private final AliPayClient aliPayClient; private final AccountInfoService accountInfoService; + @Resource + private RequestCore requestCore; @GetMapping("/list") @ApiOperation("查询主账号下的子账号") @@ -42,24 +46,24 @@ public class AccountInfoController { } @GetMapping("/parent/accounts") - @ApiOperation("查询主账号下的子账号") - public CommonResult> getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable) { - return aliPayClient.getParentAccount(sellerNick, pageable); - } - - @GetMapping("/pay/template") - @ApiOperation("查询套餐") - public CommonResult getPayTemplate() { - return aliPayClient.getPayTemplate(); - } - - @GetMapping("/account/authorize") - @ApiOperation("对子账号授权") - public CommonResult authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) { - if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) { - return new CommonResult<>().validateFailed("参数错误"); - } - return aliPayClient.authorizeChildrenAccount(childrenAccountId, payTemplateId); + @ApiOperation("查询主账号") + public CommonResult getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable) { + return requestCore.getParentAccount(sellerNick, pageable); } +// +// @GetMapping("/pay/template") +// @ApiOperation("查询套餐") +// public CommonResult getPayTemplate() { +// return aliPayClient.getPayTemplate(); +// } +// +// @GetMapping("/account/authorize") +// @ApiOperation("对子账号授权") +// public CommonResult authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) { +// if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) { +// return new CommonResult<>().validateFailed("参数错误"); +// } +// return aliPayClient.authorizeChildrenAccount(childrenAccountId, payTemplateId); +// } } diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/feign/AliPayClient.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/feign/AliPayClient.java index dfc9a9a..2b1bf73 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/feign/AliPayClient.java +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/feign/AliPayClient.java @@ -25,32 +25,4 @@ public interface AliPayClient { */ @GetMapping(API_PREFIX + "/account/checkAccount") Long checkSellAccountByPurchaser(@RequestParam(value = "token") String token); - - /** - * 分页查询主账号的列表 - * - * @param sellerNick - * @param pageable - * @return - */ - @GetMapping(API_PREFIX + "/account/parentAccounts") - CommonResult> getParentAccount(@RequestParam(value = "sellerNick") String sellerNick, Pageable pageable); - - /** - * 查询套餐 - * - * @return - */ - @GetMapping(API_PREFIX + "/pay/template") - CommonResult getPayTemplate(); - - /** - * 子账号授权 - * - * @param childrenAccountId - * @param payTemplateId - * @return - */ - @GetMapping("/account/authorize") - CommonResult authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId); } diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/security/config/SecurityConfig.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/security/config/SecurityConfig.java index 7ffbe3d..7ed38a7 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/security/config/SecurityConfig.java +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/security/config/SecurityConfig.java @@ -125,6 +125,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() // 放开生成一级分类链接 .antMatchers(HttpMethod.POST, "/api/remoteRecord/createRemoteRecord").permitAll() + .antMatchers(HttpMethod.GET, "/account/parent/accounts").permitAll() // 自定义匿名访问所有url放行:允许匿名和带Token访问,细腻化到每个 Request 类型 // GET .antMatchers(HttpMethod.GET, anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0])).permitAll() diff --git a/service/trade-service-others/trade-service-others-account/src/main/resources/application-dev.yml b/service/trade-service-others/trade-service-others-account/src/main/resources/application-dev.yml index ba385ed..f518de4 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/resources/application-dev.yml +++ b/service/trade-service-others/trade-service-others-account/src/main/resources/application-dev.yml @@ -3,6 +3,7 @@ spring: nacos: discovery: server-addr: ${NACOS_HOST:118.178.137.129}:${NACOS_PORT:8848} + # server-addr: ${NACOS_HOST:172.26.244.159}:${NACOS_PORT:8848} redis: database: 2 host: 118.178.137.129 diff --git a/service/trade-service-others/trade-service-others-account/src/main/resources/application.yml b/service/trade-service-others/trade-service-others-account/src/main/resources/application.yml index c27093d..f9322fd 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/resources/application.yml +++ b/service/trade-service-others/trade-service-others-account/src/main/resources/application.yml @@ -55,6 +55,9 @@ jwt: # 续期时间范围,默认1小时,单位毫秒 renew: 3600000 - +trade: + service: + source: + url: http://39.100.226.133:80 diff --git a/service/trade-service-source/trade-service-source-core/src/main/java/com/hchbox/controller/SellerAccountController.java b/service/trade-service-source/trade-service-source-core/src/main/java/com/hchbox/controller/SellerAccountController.java index e5bf281..8b68551 100644 --- a/service/trade-service-source/trade-service-source-core/src/main/java/com/hchbox/controller/SellerAccountController.java +++ b/service/trade-service-source/trade-service-source-core/src/main/java/com/hchbox/controller/SellerAccountController.java @@ -87,7 +87,7 @@ public class SellerAccountController { @GetMapping("/authorize") @ApiOperation("子账号授权") - public CommonResult authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) { + public CommonResult authorizeChildrenAccount(@RequestParam("childrenAccountId")Long childrenAccountId,@RequestParam("payTemplateId") Long payTemplateId) { if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) { return new CommonResult<>().validateFailed("参数错误"); } diff --git a/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml b/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml index ca3795b..0be7779 100644 --- a/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml +++ b/service/trade-service-source/trade-service-source-core/src/main/resources/application.yml @@ -3,7 +3,7 @@ server: spring: profiles: - active: dev + active: prod servlet: multipart: max-file-size: 200MB #单个文件上传大小 diff --git a/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/service/impl/SellerAccountServiceImpl.java b/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/service/impl/SellerAccountServiceImpl.java index 7256b27..c33d690 100644 --- a/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/service/impl/SellerAccountServiceImpl.java +++ b/service/trade-service-source/trade-service-source-taobao/src/main/java/com/hchbox/service/impl/SellerAccountServiceImpl.java @@ -342,7 +342,9 @@ public class SellerAccountServiceImpl implements SellerAccountService { @Override public CommonResult> getParentAccount(String sellerNick, Pageable pageable) { AccountSearchVo accountSearchVo = new AccountSearchVo(); - accountSearchVo.setSellerNick(sellerNick); + if (StrUtil.isNotEmpty(sellerNick)) { + accountSearchVo.setNickname(sellerNick); + } accountSearchVo.setParentId((long) DefaultNumberConstants.ZERO_NUMBER); Page sellerAccounts = sellerAccountRepository.findAll( ((root, criteriaQuery, cb) -> diff --git a/trade-common/src/main/java/com/hchbox/vo/AccountSearchVo.java b/trade-common/src/main/java/com/hchbox/vo/AccountSearchVo.java index 66366a7..e14477e 100644 --- a/trade-common/src/main/java/com/hchbox/vo/AccountSearchVo.java +++ b/trade-common/src/main/java/com/hchbox/vo/AccountSearchVo.java @@ -12,7 +12,7 @@ import lombok.Data; public class AccountSearchVo { @Query(type = Query.Type.INNER_LIKE, propName = "sellerNick") @ApiModelProperty("sellerNick") - private String sellerNick; + private String nickname; @Query(type = Query.Type.EQUAL, propName = "parentId") @ApiModelProperty("parentId")