整理代码

20230922-ljl-fixBug
qiushengjie 1 year ago
parent 6ad85cd00f
commit ef00082e7c

@ -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<ItemDTO, Integer> {
@Autowired
private DsFormRequestTemplate dsFormRequestTemplate;
@Override
public BaseResponse<Integer> handle(BaseRequest<ItemDTO> req) {
UniqueKeyMultiValueMap<String,String> 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.<Integer>builder()
.success(true)
.message("success")
.data(123)
.code("10000")
.build();
}
}

@ -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.*;

@ -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<ItemDTO, Void> {
@Override
public BaseResponse<Void> handle(BaseRequest<ItemDTO> req) {
// 业务逻辑处理
// do something...
// db.save(itemDTO);
log.info("TaskService...");
return BaseResponse.<Void>builder()
.build();
}
}

@ -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<ItemDTO, String> {
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
@Override
public BaseResponse<String> handle(BaseRequest<ItemDTO> req) {
log.info("");
HashMap<String, Object> params = new HashMap<>();
// List<String> arrayString = new ArrayList<>();
// arrayString.add("arrayString1");
// arrayString.add("arrayString2");
// params.put("arrayString", arrayString);
//
// HashMap<String, String> mapStringString = new HashMap<>();
// mapStringString.put("A","mapStringString1");
// mapStringString.put("B","mapStringString2");
// params.put("mapStringString", mapStringString);
//
// List<Integer> 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<Object> arrayStruct = new LinkedList<>();
// arrayStruct.add(new GetCurrentShopMoveSettingRequestDTO());
// arrayStruct.add(new GetMoveHistoryProductListRequestDTO());
// arrayStruct.add(new SaveBatchMoveTaskRequestDTO());
// params.put("arrayStruct", arrayStruct);
//
// Map<String,Object> 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);
}
}

@ -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<T,R> implements ExtensionServiceHandler<T, R> {
@Autowired
private ShopService shopService;
protected String shopId;
protected Long shopId = 4463798L;
protected ShopBO shopInfo;
@Override
public BaseResponse<R> handle(BaseRequest<T> 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);

@ -34,7 +34,7 @@ public class GetAuthShopMemberInfosService extends SPIBaseService<GetAuthShopMem
// ----业务处理----
MultiValueMap<String, String> 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 {

@ -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<GetPlatformAuthUrl
// ----逻辑校验----
// ----业务处理----
// TODO 群里讨论过说,先判断下获取授权信息列表,如果授权过,就不用再获取这个链接 open/platform_shop/get_platform_auth_url
// TODO 群里讨论过说,先判断下获取授权信息列表,如果授权过,就不用再获取这个链接
HashMap<String, String> 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 {

@ -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;
}

@ -43,8 +43,7 @@ public class DsFormRequestTemplate {
public <T> 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;

@ -43,8 +43,7 @@ public class DsJsonRequestTemplate {
public <T> 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;

@ -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);
}
}
Loading…
Cancel
Save