完善开始搬家接口

20230922-ljl-fixBug
qiushengjie 1 year ago
parent 71fd49ead1
commit c0ae832ace

@ -11,4 +11,6 @@ import java.util.List;
public class GetProductInfoRequestDTO { public class GetProductInfoRequestDTO {
// sourceItemUrls array 来源商品连接 是 // sourceItemUrls array 来源商品连接 是
} }

@ -6,6 +6,8 @@ import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.dto.ItemDTO; import com.ms.api.dto.ItemDTO;
import com.ms.api.tool.DsFormRequestTemplate; import com.ms.api.tool.DsFormRequestTemplate;
import com.ms.api.tool.SecurityTool;
import com.ms.api.util.UniqueKeyMultiValueMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -21,13 +23,14 @@ public class DsRequestService implements ExtensionServiceHandler<ItemDTO, Intege
@Override @Override
public BaseResponse<Integer> handle(BaseRequest<ItemDTO> req) { public BaseResponse<Integer> handle(BaseRequest<ItemDTO> req) {
Map params = new HashMap(); UniqueKeyMultiValueMap<String,String> params = new UniqueKeyMultiValueMap<>();
params.put("platform", "ddMicroApp"); params.add("platform", "ddMicroApp");
params.add("platformOrderId", "2332");
params.put("platformOrderId", "2332"); String shopId = SecurityTool.encodeByAES(String.valueOf(78327));
params.put("shopId", "78327"); log.info(shopId);
params.put("operateInfo", "{\"userId\":\"2332\", \"ip\": \"123.21.123.123\"}"); params.add("shopId", shopId);
params.put("platformSkuId", "123232"); params.add("operateInfo", "{\"userId\":\"2332\", \"ip\": \"123.21.123.123\"}");
params.add("platformSkuId", "123232");
try { try {
String res = dsFormRequestTemplate.execute("/order/cancelPurchaseOrderRelate", params); String res = dsFormRequestTemplate.execute("/order/cancelPurchaseOrderRelate", params);
log.info(res); log.info(res);

@ -0,0 +1,8 @@
package com.ms.api.bo;
import lombok.Data;
@Data
public class ConditionBO {
}

@ -8,6 +8,7 @@ import com.ms.api.common.R;
import com.ms.api.common.SPIBaseService; import com.ms.api.common.SPIBaseService;
import com.ms.api.dto.order.GetPlatformAuthUrlRequestDTO; import com.ms.api.dto.order.GetPlatformAuthUrlRequestDTO;
import com.ms.api.tool.DsFormRequestTemplate; import com.ms.api.tool.DsFormRequestTemplate;
import com.ms.api.tool.SecurityTool;
import com.ms.api.util.UniqueKeyMultiValueMap; import com.ms.api.util.UniqueKeyMultiValueMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -33,10 +34,10 @@ public class GetPlatformAuthUrlService extends SPIBaseService implements Extensi
// ----业务处理---- // ----业务处理----
MultiValueMap<String, String> params = new UniqueKeyMultiValueMap<>(); MultiValueMap<String, String> params = new UniqueKeyMultiValueMap<>();
params.add("userId",fields.getUserId()); // TODO 需要加密发送 params.add("userId", SecurityTool.encodeByAES(fields.getUserId()));
params.add("redirectUrl",fields.getRedirectUrl()); //params.add("redirectUrl",fields.getRedirectUrl());
params.add("platform","ddMicroApp"); params.add("platform","ddMicroApp");
params.add("appName",fields.getAppName()); //params.add("appName",fields.getAppName());
String res = null; String res = null;
try { try {
res = dsFormRequestTemplate.execute("/platform_shop/checkDsAppAuthExpire", params); res = dsFormRequestTemplate.execute("/platform_shop/checkDsAppAuthExpire", params);

@ -4,6 +4,7 @@ import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.bo.ConditionBO;
import com.ms.api.bo.ProductBO; import com.ms.api.bo.ProductBO;
import com.ms.api.common.R; import com.ms.api.common.R;
import com.ms.api.common.SPIBaseService; import com.ms.api.common.SPIBaseService;
@ -49,7 +50,7 @@ public class SaveBatchMoveTaskService extends SPIBaseService implements Extensio
long shopId = 0L; //TODO 要从session中取 long shopId = 0L; //TODO 要从session中取
log.info("shopId "+shopId+" start saveTask"); log.info("shopId "+shopId+" start saveTask");
addCollectTask(shopId, "copyType", "name",null); // addCollectTask(shopId, "copyType", "name",null);
// ----结果返回---- // ----结果返回----
return R.ok(); return R.ok();
@ -59,22 +60,80 @@ public class SaveBatchMoveTaskService extends SPIBaseService implements Extensio
} }
private void addShopCollectTask(long shopId, List<ProductBO> shopProductsList, String name, String copyType){ // private Map<String, Object> saveTaskByAuthShop(int shopId, String copyType, Map<String, Object> shopMoveConditionMap, Map<String, Object> shopMoveSettingOperateLogMap, Map<String, Object> shopConditions, Map<String, Object> shopProducts, Map<String, Object> shopPreviewCateAttr, String hostname, String operateSource, int isFromLtaoRank) {
// TODO 开启事务 // log.info("shopId " + shopId + " start saveMoveSetting");
//
// Pair<List<Integer>, List<Integer>> result = saveMoveSetting(shopMoveConditionMap, shopMoveSettingOperateLogMap);
// List<Integer> updateErrorShopIds = result.getFirst();
// List<Integer> moveShopSettingIds = result.getSecond();
//
// zc.G("shopId " + shopId + " end saveMoveSetting");
//
// if (!updateErrorShopIds.isEmpty()) {
// Map<String, Object> ret = CommonTool.failResult("店铺Id:" + String.join(" ", updateErrorShopIds) + ",保存搬家配置失败,请稍后再尝试");
// ret.put("hostname", hostname);
// return ret;
// }
//
// String name;
// if (copyType.equals(MoveConst.COLLECT_LINKS_COPY)) { // Assuming you have a MoveConst class
// name = ZcDateHelper.now() + " 批量抓取"; // Assuming you have a ZcDateHelper class
// } else {
// name = ZcDateHelper.now().toString();
// }
//
// zc.G("shopId " + shopId + " start replaceShopConditionsBigField");
// shopConditions = moveService.replaceShopConditionsBigField(shopConditions, moveShopSettingIds);
// zc.G("shopId " + shopId + " end replaceShopConditionsBigField");
//
// shopConditions = attachMoveSettingIdToMoveTaskCondition(moveShopSettingIds, shopConditions);
// moveBatchSaveTaskLog.info("shopId " + shopId + " start addShopCollectTask");
//
// Map<String, Object> addRet = moveService.addShopCollectTask(shopId, shopProducts, name, copyType, shopConditions, shopPreviewCateAttr, operateSource, isFromLtaoRank);
//
// if (CommonTool.isFailRet(addRet)) { // Assuming you have a CommonTool class
// moveBatchSaveTaskLog.info("shopId " + shopId + " saveTask addRet fail" + zc.G().toString());
// addRet.put("hostname", hostname);
// }
//
// return addRet;
// }
//
// private Pair<List<Integer>,List<Integer>> saveMoveSetting(Map<String, Object> shopMoveConditionMap, Map<String, Object> shopMoveSettingOperateLogMap) {
// }
private Map<String, String> addShopCollectTask(long shopId, Map<Long,Map<Integer, ProductBO>> shopProductsList, String name, String copyType, Map<Long, ConditionBO> shopConditions) {
// TODO 添加事务
// int oldErrorMode = db.setErrorMode(ZcDb.ERROR_MODE_EXCEPTION);
// boolean transStatus = db.startTransaction();
int taskId = 0;
String cnaliDsDetailMap = null;
try { try {
for (ProductBO product: shopProductsList) { for (Map.Entry<Long, Map<Integer, ProductBO>> entry : shopProductsList.entrySet()) {
// this.addCollectTask(shopId,shopProductsList,copyType,name,); long authShopId = entry.getKey();
Map<String, String> addRet = this.addCollectTask(authShopId, shopId, copyType, name, shopConditions.get(authShopId), shopProductsList.get(authShopId));
if (CommonTool.isSuccessRet(addRet) && authShopId == shopId) {
taskId = Integer.parseInt(addRet.get("taskId"));
cnaliDsDetailMap = addRet.get("cnaliDsDetailMap");
} }
}
}catch (Exception e){ // db.commit(transStatus);
// db.setErrorMode(oldErrorMode);
} catch (Exception ex) {
// moveLog.error(ex.getMessage());
// db.rollback(transStatus);
// db.setErrorMode(oldErrorMode);
return CommonTool.failResult("添加任务数据失败");
} }
// TODO 关闭事务 HashMap<String, String> ret = new HashMap<>();
ret.put("taskId", String.valueOf(taskId));
ret.put("cnaliDsDetailMap", cnaliDsDetailMap);
return CommonTool.successResult(ret);
} }
private Map<String, String> addCollectTask(long shopId, long operatorShopId, String copyType, String name, List<ProductBO> products){ private Map<String, String> addCollectTask(long shopId, long operatorShopId, String copyType, String name, ConditionBO condition, Map<Integer, ProductBO> products){
int productTotal = products.size(); // TODO 这边计算还有点内容 int productTotal = products.size(); // TODO 这边计算还有点内容
Map<String, String> checkAndGetConfigIdRet = this.checkAvailableCopyAndGetMoveConfigId(shopId,productTotal); Map<String, String> checkAndGetConfigIdRet = this.checkAvailableCopyAndGetMoveConfigId(shopId,productTotal);
if(CommonTool.isFailRet(checkAndGetConfigIdRet)){ if(CommonTool.isFailRet(checkAndGetConfigIdRet)){
@ -98,7 +157,8 @@ public class SaveBatchMoveTaskService extends SPIBaseService implements Extensio
log.info("INSERT move_collect task SQL:" + moveCollectTask.toString()); log.info("INSERT move_collect task SQL:" + moveCollectTask.toString());
for (ProductBO product: products) { for (Map.Entry<Integer,ProductBO> entry : products.entrySet()) {
ProductBO product = entry.getValue();
MoveCollectTaskDetail moveCollectTaskDetail = new MoveCollectTaskDetail(); MoveCollectTaskDetail moveCollectTaskDetail = new MoveCollectTaskDetail();
moveCollectTaskDetail.setShopId(shopId); moveCollectTaskDetail.setShopId(shopId);
// moveCollectTaskDetail.setAuthShopId // moveCollectTaskDetail.setAuthShopId
@ -130,12 +190,10 @@ public class SaveBatchMoveTaskService extends SPIBaseService implements Extensio
log.info("INSERT move_product_publish_buffer SQL"); log.info("INSERT move_product_publish_buffer SQL");
} }
return CommonTool.successResult( HashMap<String, String> ret = new HashMap<>();
new HashMap<String, String>() {{ ret.put("taskId", String.valueOf(moveCollectTaskId));
put("taskId", String.valueOf(moveCollectTaskId)); ret.put("cnaliDsDetailMap", "");
put("cnaliDsDetailMap", ""); return CommonTool.successResult(ret);
}}
);
} }

@ -0,0 +1,45 @@
package com.ms.api.tool;
import com.ms.api.tool.security.AES;
import org.springframework.beans.factory.annotation.Value;
import java.util.Base64;
public class SecurityTool {
public static String key = "D2E31857FB4C4C9439EDED69F5A85775";
/**
* AES
*/
public static String encodeByAES(String context){
byte[] aesByte;
try {
AES aes = new AES(key);
aesByte = aes.encode(context);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 将ase_encode的结果base64_encode处理
Base64.Encoder encode = Base64.getEncoder();
return encode.encodeToString(aesByte);
}
/**
* AES
*/
public static String decodeByAES(String aesString){
Base64.Decoder decoder = Base64.getDecoder();
//将加密后的字符串先base64_decode处理
byte[] aesByte = decoder.decode(aesString);
//解密
String desString;
try {
AES aes = new AES(key);
desString = aes.decode(aesByte);
} catch (Exception e) {
throw new RuntimeException(e);
}
return desString;
}
}

@ -0,0 +1,61 @@
package com.ms.api.tool.security;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
/**
* AES
*
* https://www.jianshu.com/p/13b7fd018f7c
*/
public class AES {
private String key;
public AES(String key)
{
this.key = key;
}
/**
*
*
* @param context
* @return
* @throws Exception
*/
public byte[] encode(String context) throws Exception
{
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(key.getBytes());
kgen.init(128, secureRandom);
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
return cipher.doFinal(context.getBytes(StandardCharsets.UTF_8));
}
/**
*
*
* @param encryptBytes
* @return
* @throws Exception
*/
public String decode(byte[] encryptBytes) throws Exception
{
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(key.getBytes());
kgen.init(128, secureRandom);
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
byte[] decryptBytes = cipher.doFinal(encryptBytes);
return new String(decryptBytes, "UTF-8");
}
}

@ -17,3 +17,4 @@ jx.ds.host-prod=https://acn-ds.chengji-inc.com/open
jx.ds.host-test=https://acn-ds-test.chengji-inc.com/open jx.ds.host-test=https://acn-ds-test.chengji-inc.com/open
jx.ds.token-prod=dighgfghf^&)l3sedi&(.D@BC jx.ds.token-prod=dighgfghf^&)l3sedi&(.D@BC
jx.ds.token-test=dighgfghf^&)l3sedi&(.D@BC jx.ds.token-test=dighgfghf^&)l3sedi&(.D@BC

@ -0,0 +1,13 @@
package com.ms.test;
import com.ms.api.tool.SecurityTool;
public class SecurityTest {
public static void main(String[] args) {
String word = SecurityTool.encodeByAES("hello world!");
System.out.println(word);
String ss = SecurityTool.decodeByAES(word);
System.out.println(ss);
}
}
Loading…
Cancel
Save