|
|
|
@ -1,15 +1,5 @@
|
|
|
|
|
package com.ms.api.biz;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.ProductGetCatePropertyV2Request;
|
|
|
|
@ -20,24 +10,53 @@ import com.doudian.open.api.product_getProductUpdateRule.data.NormalRule;
|
|
|
|
|
import com.doudian.open.api.product_getProductUpdateRule.data.ProductGetProductUpdateRuleData;
|
|
|
|
|
import com.doudian.open.api.product_getProductUpdateRule.param.ProductGetProductUpdateRuleParam;
|
|
|
|
|
import com.doudian.open.core.AccessToken;
|
|
|
|
|
import com.ms.api.bo.AttributeBO;
|
|
|
|
|
import com.ms.api.bo.CateAttributeResultBO;
|
|
|
|
|
import com.ms.api.bo.MoveProductPublishQueueBO;
|
|
|
|
|
import com.ms.api.bo.MoveShopSettingBO;
|
|
|
|
|
import com.ms.api.common.ApiResult;
|
|
|
|
|
import com.ms.api.common.MSException;
|
|
|
|
|
import com.ms.api.common.Ret;
|
|
|
|
|
import com.ms.api.common.StrObjMap;
|
|
|
|
|
import com.ms.api.consts.MoveConst;
|
|
|
|
|
import com.ms.api.consts.StatusConst;
|
|
|
|
|
import com.ms.api.service.MoveCollectTaskDetailService;
|
|
|
|
|
import com.ms.api.tool.CommonTool;
|
|
|
|
|
import com.ms.api.util.DdRequestUtil;
|
|
|
|
|
import com.ms.dal.bo.CollectTaskDetailBO;
|
|
|
|
|
import com.ms.dal.entity.MoveCollectTask;
|
|
|
|
|
import com.ms.dal.entity.MoveCollectTaskDetail;
|
|
|
|
|
import com.ms.dal.entity.MoveProductPublishBuffer;
|
|
|
|
|
import com.ms.dal.entity.MoveShopSetting;
|
|
|
|
|
import com.ms.dal.mapper.MoveCollectTaskDetailMapper;
|
|
|
|
|
import com.ms.dal.mapper.MoveCollectTaskMapper;
|
|
|
|
|
import com.ms.dal.mapper.MoveProductPublishBufferMapper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component
|
|
|
|
|
public class MoveService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PlatformTransactionManager transactionManager;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SaveBatchMoveTaskBizService saveBatchMoveTaskBizService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveCollectTaskDetailService moveCollectTaskDetailService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveCollectTaskDetailMapper moveCollectTaskDetailMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveProductPublishBufferMapper moveProductPublishBufferMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveCollectTaskMapper moveCollectTaskMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据搬家配置,修改数据
|
|
|
|
|
*
|
|
|
|
@ -345,6 +364,155 @@ public class MoveService {
|
|
|
|
|
return uniqueUrls.stream().filter(url -> url != null && !url.isEmpty()).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Long moveAgainDetailsByDetailId(Long shopId, Long detailId) {
|
|
|
|
|
MoveCollectTaskDetail moveDetail = moveCollectTaskDetailService.getMoveCollectTaskDetail(shopId, detailId);
|
|
|
|
|
if (moveDetail == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int needAddCnt = 1;
|
|
|
|
|
|
|
|
|
|
Ret checkAndGetConfigIdRet = saveBatchMoveTaskBizService.checkAvailableCopyAndGetMoveConfigId(shopId, needAddCnt);
|
|
|
|
|
if (CommonTool.isFailRet(checkAndGetConfigIdRet)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
Integer moveShopConfigId = null;
|
|
|
|
|
if (checkAndGetConfigIdRet.getData().containsKey("moveShopConfigId")) {
|
|
|
|
|
moveShopConfigId = Integer.valueOf(checkAndGetConfigIdRet.getData().get("moveShopConfigId").toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo: MoveAgainDetailsForDsApi相关判断逻辑 用不上,跳过
|
|
|
|
|
|
|
|
|
|
MoveCollectTaskDetail taskDetailData = new MoveCollectTaskDetail();
|
|
|
|
|
taskDetailData.setShopId(shopId);
|
|
|
|
|
taskDetailData.setMoveCollectTaskId(moveDetail.getMoveCollectTaskId());
|
|
|
|
|
taskDetailData.setIsFastMode(moveDetail.getIsFastMode());
|
|
|
|
|
taskDetailData.setMoveShopConfigId(moveShopConfigId);
|
|
|
|
|
taskDetailData.setSource(moveDetail.getSource());
|
|
|
|
|
taskDetailData.setSite(moveDetail.getSource());
|
|
|
|
|
taskDetailData.setSourceItemId(moveDetail.getSourceItemId());
|
|
|
|
|
taskDetailData.setSourceTitle(moveDetail.getSourceTitle());
|
|
|
|
|
taskDetailData.setSourceImgUrl(moveDetail.getSourceImgUrl());
|
|
|
|
|
taskDetailData.setSourceShopName(moveDetail.getSourceShopName());
|
|
|
|
|
taskDetailData.setCid(moveDetail.getCid());
|
|
|
|
|
taskDetailData.setStatus(StatusConst.processing);
|
|
|
|
|
taskDetailData.setGmtCreate(new Date());
|
|
|
|
|
taskDetailData.setGmtModified(new Date());
|
|
|
|
|
|
|
|
|
|
// todo: 构建 MoveCollectTaskDetailExt,这个版本不用
|
|
|
|
|
|
|
|
|
|
Integer priority = saveBatchMoveTaskBizService.getTaskPriority(shopId, 1);
|
|
|
|
|
|
|
|
|
|
MoveProductPublishBuffer insertPublishBuffer = new MoveProductPublishBuffer();
|
|
|
|
|
insertPublishBuffer.setShopId(shopId);
|
|
|
|
|
insertPublishBuffer.setMoveCollectTaskId(moveDetail.getMoveCollectTaskId().intValue());
|
|
|
|
|
insertPublishBuffer.setTryTimes(0);
|
|
|
|
|
insertPublishBuffer.setPriority(priority);
|
|
|
|
|
insertPublishBuffer.setGmtCreate(new Date());
|
|
|
|
|
insertPublishBuffer.setGmtModified(new Date());
|
|
|
|
|
|
|
|
|
|
Long newDetailId = addMoveTaskDetail(shopId, taskDetailData, insertPublishBuffer, moveShopConfigId, detailId);
|
|
|
|
|
if (newDetailId == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newDetailId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Long addMoveTaskDetail(Long shopId, MoveCollectTaskDetail taskDetailData, MoveProductPublishBuffer insertPublishBuffer, Integer moveShopConfigId, Long detailId) {
|
|
|
|
|
|
|
|
|
|
CollectTaskDetailBO taskDetail = getCollectTaskDetail(detailId);
|
|
|
|
|
|
|
|
|
|
if (shopId == null || moveShopConfigId == null || ObjectUtil.isEmpty(taskDetailData) || ObjectUtil.isEmpty(insertPublishBuffer)) {
|
|
|
|
|
log.error("商品添加是,参数有误");
|
|
|
|
|
return null;
|
|
|
|
|
// return Ret.fail("商品添加是,参数有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StatusConst.wait.equals(taskDetail.getStatus()) || StatusConst.process.equals(taskDetail.getStatus()) || taskDetail.getShopId() != shopId) {
|
|
|
|
|
log.error("重试失败,任务状态错误");
|
|
|
|
|
return null;
|
|
|
|
|
// return Ret.fail("重试失败,任务状态错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int needAddCnt = 1;
|
|
|
|
|
|
|
|
|
|
Ret checkAndGetConfigIdRet = saveBatchMoveTaskBizService.checkAvailableCopyAndGetMoveConfigId(shopId, needAddCnt);
|
|
|
|
|
if (CommonTool.isFailRet(checkAndGetConfigIdRet)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
|
|
|
|
TransactionStatus status = transactionManager.getTransaction(def);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (needAddCnt > 0) {
|
|
|
|
|
Ret deductRet = saveBatchMoveTaskBizService.deductMoveCopyCount(shopId, needAddCnt, moveShopConfigId);
|
|
|
|
|
if (CommonTool.isFailRet(deductRet)) {
|
|
|
|
|
throw new MSException("扣除额度失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taskDetailData.setMoveShopConfigId(moveShopConfigId);
|
|
|
|
|
|
|
|
|
|
moveCollectTaskDetailMapper.insertSelective(taskDetailData);
|
|
|
|
|
|
|
|
|
|
detailId = taskDetailData.getMoveCollectTaskDetailId();
|
|
|
|
|
insertPublishBuffer.setMoveCollectTaskDetailId(detailId);
|
|
|
|
|
|
|
|
|
|
moveProductPublishBufferMapper.insertSelective(insertPublishBuffer);
|
|
|
|
|
|
|
|
|
|
log.info(String.format("addMoveTaskDetail shopId[%s] detailId[%s] success", shopId, detailId));
|
|
|
|
|
|
|
|
|
|
if (taskDetail.getCondition().getSkipCopied() != 0) {
|
|
|
|
|
MoveShopSetting newCondition = getMoveCollectTaskCondition(Long.valueOf(taskDetail.getMoveCollectTaskId()));
|
|
|
|
|
String jsonStr = JSONObject.toJSONString(newCondition);
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
|
|
jsonObject.remove("skipCopied");
|
|
|
|
|
|
|
|
|
|
MoveCollectTask updateData = new MoveCollectTask();
|
|
|
|
|
updateData.setMoveCollectTaskId(taskDetail.getMoveCollectTaskId().intValue());
|
|
|
|
|
updateData.setCondition(jsonObject.toJSONString());
|
|
|
|
|
updateData.setGmtModified(new Date());
|
|
|
|
|
moveCollectTaskMapper.updateByPrimaryKeySelective(updateData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transactionManager.commit(status);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(String.format("addMoveTaskDetail, shopId[%s] ,detailId[%s] error", shopId, detailId), e);
|
|
|
|
|
transactionManager.rollback(status);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return detailId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MoveShopSetting getMoveCollectTaskCondition(Long moveCollectTaskId) {
|
|
|
|
|
MoveShopSetting condition = null;
|
|
|
|
|
try {
|
|
|
|
|
MoveCollectTask moveCollectTask = moveCollectTaskMapper.selectByPrimaryKey(moveCollectTaskId);
|
|
|
|
|
MoveShopSetting moveShopSetting = JSONObject.parseObject(moveCollectTask.getCondition(), MoveShopSetting.class);
|
|
|
|
|
// PHPSerializer p = new PHPSerializer();
|
|
|
|
|
// condition = (MoveShopSetting) p.unserialize(moveCollectTask.getCondition().getBytes(), MoveShopSetting.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("getMoveCollectTaskCondition unserialize failed", e);
|
|
|
|
|
}
|
|
|
|
|
return condition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CollectTaskDetailBO getCollectTaskDetail(Long collectTaskDetailId) {
|
|
|
|
|
CollectTaskDetailBO ret = moveCollectTaskDetailMapper.getCollectTaskDetail(collectTaskDetailId);
|
|
|
|
|
try {
|
|
|
|
|
MoveShopSetting moveShopSetting = JSONObject.parseObject(ret.getConditionStr(), MoveShopSetting.class);
|
|
|
|
|
// PHPSerializer p = new PHPSerializer();
|
|
|
|
|
// MoveShopSetting moveShopSetting = (MoveShopSetting) p.unserialize(ret.getConditionStr().getBytes(), MoveShopSetting.class);
|
|
|
|
|
ret.setCondition(moveShopSetting);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("getCollectTaskDetail condition unserialize failed", e);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Ret getCategoryAttrV2FromDd(String cid, AccessToken accessToken) {
|
|
|
|
|
if (StringUtils.isBlank(cid)) {
|
|
|
|
|
return CommonTool.failResult("参数错误");
|
|
|
|
|