From ef00082e7ca4643ac1be4501254ec0dc51a935a8 Mon Sep 17 00:00:00 2001 From: qiushengjie Date: Tue, 29 Aug 2023 23:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ms/api/DsRequestService.java | 44 ----------- .../com/ms/api/DsTestJavaRequestService.java | 5 -- .../src/main/java/com/ms/api/TaskService.java | 28 ------- .../main/java/com/ms/api/TestSignService.java | 76 +++++++++++++++++++ .../com/ms/api/common/SPIBaseService.java | 59 +++++++------- .../auth/GetAuthShopMemberInfosService.java | 2 +- .../spi/auth/GetPlatformAuthUrlService.java | 8 +- .../com/ms/api/tool/CloudRequestTemplate.java | 3 +- .../ms/api/tool/DsFormRequestTemplate.java | 3 +- .../ms/api/tool/DsJsonRequestTemplate.java | 3 +- .../main/java/com/ms/api/tool/SystemTool.java | 37 +++++++++ 11 files changed, 150 insertions(+), 118 deletions(-) delete mode 100644 ms-biz/src/main/java/com/ms/api/DsRequestService.java delete mode 100644 ms-biz/src/main/java/com/ms/api/TaskService.java create mode 100644 ms-biz/src/main/java/com/ms/api/TestSignService.java create mode 100644 ms-biz/src/main/java/com/ms/api/tool/SystemTool.java diff --git a/ms-biz/src/main/java/com/ms/api/DsRequestService.java b/ms-biz/src/main/java/com/ms/api/DsRequestService.java deleted file mode 100644 index 19ac725a..00000000 --- a/ms-biz/src/main/java/com/ms/api/DsRequestService.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ms.api; - -import com.jinritemai.cloud.base.api.BaseRequest; -import com.jinritemai.cloud.base.api.BaseResponse; -import com.jinritemai.cloud.base.api.ExtensionService; -import com.jinritemai.cloud.base.api.ExtensionServiceHandler; -import com.ms.api.dto.ItemDTO; -import com.ms.api.tool.DsFormRequestTemplate; -import com.ms.api.tool.SecurityTool; -import com.ms.api.common.UniqueKeyMultiValueMap; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; - -@ExtensionService("dsRequest") -@Slf4j -public class DsRequestService implements ExtensionServiceHandler { - - @Autowired - private DsFormRequestTemplate dsFormRequestTemplate; - - @Override - public BaseResponse handle(BaseRequest req) { - UniqueKeyMultiValueMap params = new UniqueKeyMultiValueMap<>(); - params.add("platform", "ddMicroApp"); - params.add("platformOrderId", "2332"); - String shopId = SecurityTool.encodeByAES(String.valueOf(78327)); - log.info(shopId); - params.add("shopId", shopId); - params.add("operateInfo", "{\"userId\":\"2332\", \"ip\": \"123.21.123.123\"}"); - params.add("platformSkuId", "123232"); - try { - String res = dsFormRequestTemplate.execute("/order/cancelPurchaseOrderRelate", params); - log.info(res); - } catch (Exception e) { - log.error(e.getMessage()); - } - return BaseResponse.builder() - .success(true) - .message("success") - .data(123) - .code("10000") - .build(); - } -} diff --git a/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java b/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java index 49c25ed1..f107e0f4 100644 --- a/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java +++ b/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java @@ -1,22 +1,17 @@ package com.ms.api; -import com.alibaba.fastjson.JSON; import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.ms.api.common.R; import com.ms.api.dto.ItemDTO; -import com.ms.api.dto.move.GetChoicenessSourceItemTagRequestDTO; import com.ms.api.dto.move.GetCurrentShopMoveSettingRequestDTO; import com.ms.api.dto.move.GetMoveHistoryProductListRequestDTO; import com.ms.api.dto.move.SaveBatchMoveTaskRequestDTO; -import com.ms.api.tool.DsFormRequestTemplate; -import com.ms.api.common.UniqueKeyMultiValueMap; import com.ms.api.tool.DsJsonRequestTemplate; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.MultiValueMap; import java.util.*; diff --git a/ms-biz/src/main/java/com/ms/api/TaskService.java b/ms-biz/src/main/java/com/ms/api/TaskService.java deleted file mode 100644 index 410caa21..00000000 --- a/ms-biz/src/main/java/com/ms/api/TaskService.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ms.api; - -import com.jinritemai.cloud.base.api.BaseRequest; -import com.jinritemai.cloud.base.api.BaseResponse; -import com.jinritemai.cloud.base.api.ExtensionService; -import com.jinritemai.cloud.base.api.ExtensionServiceHandler; -import com.ms.api.dto.ItemDTO; -import lombok.extern.slf4j.Slf4j; - -/** - * @Author: laixw - * @Date: 2023/8/23 - */ -@ExtensionService("TaskRun") -@Slf4j -public class TaskService implements ExtensionServiceHandler { - @Override - public BaseResponse handle(BaseRequest req) { - - // 业务逻辑处理 - // do something... - // db.save(itemDTO); - log.info("TaskService..."); - - return BaseResponse.builder() - .build(); - } -} diff --git a/ms-biz/src/main/java/com/ms/api/TestSignService.java b/ms-biz/src/main/java/com/ms/api/TestSignService.java new file mode 100644 index 00000000..2d540b06 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/TestSignService.java @@ -0,0 +1,76 @@ +package com.ms.api; + +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.common.R; +import com.ms.api.dto.ItemDTO; +import com.ms.api.dto.move.GetCurrentShopMoveSettingRequestDTO; +import com.ms.api.dto.move.GetMoveHistoryProductListRequestDTO; +import com.ms.api.dto.move.SaveBatchMoveTaskRequestDTO; +import com.ms.api.tool.DsJsonRequestTemplate; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +@ExtensionService("testSign") +@Slf4j +public class TestSignService implements ExtensionServiceHandler { + + @Autowired + private DsJsonRequestTemplate dsJsonRequestTemplate; + + @Override + public BaseResponse handle(BaseRequest req) { + log.info(""); + + HashMap params = new HashMap<>(); + +// List arrayString = new ArrayList<>(); +// arrayString.add("arrayString1"); +// arrayString.add("arrayString2"); +// params.put("arrayString", arrayString); +// +// HashMap mapStringString = new HashMap<>(); +// mapStringString.put("A","mapStringString1"); +// mapStringString.put("B","mapStringString2"); +// params.put("mapStringString", mapStringString); +// +// List arrayInt64 = new ArrayList<>(); +// arrayInt64.add(10000); +// arrayInt64.add(10000); +// params.put("arrayInt64", arrayInt64); +// +// params.put("int16", 10000); +// params.put("int32", 10000); +// params.put("int64", 10000); +// params.put("double", 10.1); + params.put("string", "test"); + +// params.put("struct", new GetCurrentShopMoveSettingRequestDTO()); +// +// List arrayStruct = new LinkedList<>(); +// arrayStruct.add(new GetCurrentShopMoveSettingRequestDTO()); +// arrayStruct.add(new GetMoveHistoryProductListRequestDTO()); +// arrayStruct.add(new SaveBatchMoveTaskRequestDTO()); +// params.put("arrayStruct", arrayStruct); +// +// Map mapStringStruct = new HashMap<>(); +// mapStringStruct.put("mapstruct1", new GetCurrentShopMoveSettingRequestDTO()); +// mapStringStruct.put("mapstruct2", new GetMoveHistoryProductListRequestDTO()); +// mapStringStruct.put("mapstruct3", new SaveBatchMoveTaskRequestDTO()); +// params.put("mapStringStruct", mapStringStruct); + + String res = null; + try { + res = dsJsonRequestTemplate.execute("/order/testJava", params); + log.info(res); + } catch (Exception e) { + e.printStackTrace(); + log.error(e.getMessage()); + } + return R.ok(res); + } +} diff --git a/ms-biz/src/main/java/com/ms/api/common/SPIBaseService.java b/ms-biz/src/main/java/com/ms/api/common/SPIBaseService.java index bf96976e..0475b247 100644 --- a/ms-biz/src/main/java/com/ms/api/common/SPIBaseService.java +++ b/ms-biz/src/main/java/com/ms/api/common/SPIBaseService.java @@ -12,10 +12,13 @@ import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.ms.api.bo.ShopBO; import com.ms.api.service.ShopService; import com.ms.api.tool.SecurityTool; +import com.ms.api.tool.SystemTool; import com.ms.dal.entity.Shop; import org.modelmapper.ModelMapper; import org.springframework.beans.factory.annotation.Autowired; +import java.util.Objects; + /** * SPI基础类 */ @@ -24,44 +27,44 @@ public class SPIBaseService implements ExtensionServiceHandler { @Autowired private ShopService shopService; - protected String shopId; + protected Long shopId = 4463798L; protected ShopBO shopInfo; @Override public BaseResponse handle(BaseRequest req) { - shopId = req.getAuthId(); - - // TODO 后面可以改为redis - // TODO 数据库查下shopId 有就注入到shopInfo中,没有要新增, - // TODO 并且调用抖店的查询店铺详情接口补充详情,可以是accesToken那个接口 + if(!SystemTool.isDevEnv()){ + shopId = Long.valueOf(req.getAuthId()); + } - TokenCreateRequest request = new TokenCreateRequest(); - TokenCreateParam param = request.getParam(); - param.setCode("df020f1c-37ed-41b5-8341-85d3d3b02250"); - param.setGrantType("authorization_code"); - TokenCreateResponse response = request.execute(); - TokenCreateData data = new TokenCreateData(); - data = response.getData(); - Long shopId = data.getShopId(); - String accessToken = data.getAccessToken(); - Long expiresIn = data.getExpiresIn(); - String shopName = data.getShopName(); - String refreshToken = data.getRefreshToken(); + // TODO 后面可以redis缓存,避免每次都查库 + // 获取店铺信息 Shop shop = shopService.getDetailById(shopId); - if (shop == null) { + if (Objects.isNull(shop)) { shop = new Shop(); shop.setShopId(shopId); - shop.setAccessToken(SecurityTool.encodeByAES(accessToken)); // 加密 - shop.setRefreshToken(SecurityTool.encodeByAES(refreshToken)); // 加密 - shop.setExpiresIn(expiresIn.toString()); - shop.setShopName(shopName); + + // 更多信息根据请求抖店接口的结果,可失败 + TokenCreateRequest request = new TokenCreateRequest(); + TokenCreateParam param = request.getParam(); + param.setCode("df020f1c-37ed-41b5-8341-85d3d3b02250"); + param.setGrantType("authorization_code"); + TokenCreateResponse response = request.execute(); + if(response.isSuccess()){ + TokenCreateData data = response.getData(); + Long shopId = data.getShopId(); + String accessToken = data.getAccessToken(); + Long expiresIn = data.getExpiresIn(); + String shopName = data.getShopName(); + String refreshToken = data.getRefreshToken(); + shop.setShopName(shopName); + shop.setAccessToken(SecurityTool.encodeByAES(accessToken)); // 加密 + shop.setRefreshToken(SecurityTool.encodeByAES(refreshToken)); // 加密 + shop.setExpiresIn(expiresIn.toString()); // TODO 这个可能是时间格式,转成时间 + } + + // 新建店铺 shopService.insert(shop); - } else { - shop.setAccessToken(SecurityTool.encodeByAES(accessToken)); // 加密 - shop.setRefreshToken(SecurityTool.encodeByAES(refreshToken)); // 加密 - shopService.updateByPrimaryKey(shop); } - ModelMapper modelMapper = new ModelMapper(); shopInfo = modelMapper.map(shop, ShopBO.class); diff --git a/ms-biz/src/main/java/com/ms/api/spi/auth/GetAuthShopMemberInfosService.java b/ms-biz/src/main/java/com/ms/api/spi/auth/GetAuthShopMemberInfosService.java index a510948b..01f16378 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/auth/GetAuthShopMemberInfosService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/auth/GetAuthShopMemberInfosService.java @@ -34,7 +34,7 @@ public class GetAuthShopMemberInfosService extends SPIBaseService params = new UniqueKeyMultiValueMap<>(); - params.add("shopId", SecurityTool.encodeByAES(fields.getShopId())); + params.add("shopId", SecurityTool.encodeByAES(String.valueOf(shopId))); params.add("platform","ddMicroApp"); String res = null; try { diff --git a/ms-biz/src/main/java/com/ms/api/spi/auth/GetPlatformAuthUrlService.java b/ms-biz/src/main/java/com/ms/api/spi/auth/GetPlatformAuthUrlService.java index 6c64a581..e522a7e2 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/auth/GetPlatformAuthUrlService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/auth/GetPlatformAuthUrlService.java @@ -3,17 +3,13 @@ package com.ms.api.spi.auth; import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; -import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.ms.api.common.R; import com.ms.api.common.SPIBaseService; import com.ms.api.dto.auth.GetPlatformAuthUrlRequestDTO; -import com.ms.api.tool.DsFormRequestTemplate; import com.ms.api.tool.DsJsonRequestTemplate; import com.ms.api.tool.SecurityTool; -import com.ms.api.common.UniqueKeyMultiValueMap; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.MultiValueMap; import java.util.HashMap; @@ -37,10 +33,10 @@ public class GetPlatformAuthUrlService extends SPIBaseService params = new HashMap<>(); - params.put("userId", SecurityTool.encodeByAES(shopId)); + params.put("userId", SecurityTool.encodeByAES(String.valueOf(shopId))); params.put("platform","ddMicroApp"); String res = null; try { diff --git a/ms-biz/src/main/java/com/ms/api/tool/CloudRequestTemplate.java b/ms-biz/src/main/java/com/ms/api/tool/CloudRequestTemplate.java index 9ce56a1e..3038b51a 100644 --- a/ms-biz/src/main/java/com/ms/api/tool/CloudRequestTemplate.java +++ b/ms-biz/src/main/java/com/ms/api/tool/CloudRequestTemplate.java @@ -111,8 +111,7 @@ public class CloudRequestTemplate { // 请求地址 String reqeustUrl = "http://openspi.doudian.ivolces.com/light/spi"; // 本地开发环境,就不去请求代理地址,直接请求接口 - String activeProfile = System.getenv("sys-deploy-env"); - if (StringUtils.isEmpty(activeProfile)) { + if(SystemTool.isDevEnv()){ reqeustUrl = url; } diff --git a/ms-biz/src/main/java/com/ms/api/tool/DsFormRequestTemplate.java b/ms-biz/src/main/java/com/ms/api/tool/DsFormRequestTemplate.java index 350d600c..cdf7867a 100644 --- a/ms-biz/src/main/java/com/ms/api/tool/DsFormRequestTemplate.java +++ b/ms-biz/src/main/java/com/ms/api/tool/DsFormRequestTemplate.java @@ -43,8 +43,7 @@ public class DsFormRequestTemplate { public String execute(String url, T body) throws Exception { // 选择环境 if (StringUtils.isEmpty(dsHost)) { - String activeProfile = System.getenv("sys-deploy-env"); - if ("Prod".equals(activeProfile)) { + if (SystemTool.isProdEnv()) { // 当前为生产环境 dsHost = dsHostProd; dsToken = dsTokenProd; diff --git a/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java b/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java index 1e290a73..54885c52 100644 --- a/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java +++ b/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java @@ -43,8 +43,7 @@ public class DsJsonRequestTemplate { public String execute(String url, T body) throws Exception { // 选择环境 if (StringUtils.isEmpty(dsHost)) { - String activeProfile = System.getenv("sys-deploy-env"); - if ("Prod".equals(activeProfile)) { + if (SystemTool.isProdEnv()) { // 当前为生产环境 dsHost = dsHostProd; dsToken = dsTokenProd; diff --git a/ms-biz/src/main/java/com/ms/api/tool/SystemTool.java b/ms-biz/src/main/java/com/ms/api/tool/SystemTool.java new file mode 100644 index 00000000..b5dc506c --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/tool/SystemTool.java @@ -0,0 +1,37 @@ +package com.ms.api.tool; + +import org.springframework.util.StringUtils; + +/** + * 系统工具 + */ +public class SystemTool { + + /** + * 是否生产环境 + * @return + */ + public static boolean isProdEnv(){ + String activeProfile = System.getenv("sys-deploy-env"); + return "Prod".equals(activeProfile); + } + + /** + * 是否测试环境 + * @return + */ + public static boolean isTestEnv(){ + String activeProfile = System.getenv("sys-deploy-env"); + return "Test".equals(activeProfile); + } + + /** + * 是否生产环境 + * @return + */ + public static boolean isDevEnv(){ + String activeProfile = System.getenv("sys-deploy-env"); + return StringUtils.isEmpty(activeProfile); + } + +}