|
|
|
@ -28,6 +28,7 @@ import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
@ -51,18 +52,17 @@ import com.doudian.open.api.material_getFolderInfo.param.MaterialGetFolderInfoPa
|
|
|
|
|
import com.doudian.open.api.material_uploadImageSync.MaterialUploadImageSyncRequest;
|
|
|
|
|
import com.doudian.open.api.material_uploadImageSync.MaterialUploadImageSyncResponse;
|
|
|
|
|
import com.doudian.open.api.material_uploadImageSync.param.MaterialUploadImageSyncParam;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.ProductGetCatePropertyV2Request;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.ProductGetCatePropertyV2Response;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.data.DataItem;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.data.OptionsItem;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.data.ProductGetCatePropertyV2Data;
|
|
|
|
|
import com.doudian.open.api.product_getCatePropertyV2.param.ProductGetCatePropertyV2Param;
|
|
|
|
|
import com.doudian.open.core.AccessToken;
|
|
|
|
|
import com.ms.api.biz.MoveService;
|
|
|
|
|
import com.ms.api.biz.SaveBatchMoveTaskBizService;
|
|
|
|
|
import com.ms.api.bo.AttributeBO;
|
|
|
|
|
import com.ms.api.bo.CateAttributeResultBO;
|
|
|
|
|
import com.ms.api.bo.CategoryBO;
|
|
|
|
|
import com.ms.api.bo.MoveProductPublishQueueBO;
|
|
|
|
|
import com.ms.api.bo.MoveShopConfigBO;
|
|
|
|
|
import com.ms.api.bo.MoveShopSettingBO;
|
|
|
|
|
import com.ms.api.common.ApiResult;
|
|
|
|
|
import com.ms.api.common.E;
|
|
|
|
@ -84,8 +84,10 @@ import com.ms.api.service.MaterialBizQueueService;
|
|
|
|
|
import com.ms.api.service.MaterialBizToMaterialService;
|
|
|
|
|
import com.ms.api.service.MoveCollectTaskDetailService;
|
|
|
|
|
import com.ms.api.service.MoveCollectTaskService;
|
|
|
|
|
import com.ms.api.service.MoveProductPublishBufferService;
|
|
|
|
|
import com.ms.api.service.MoveProductPublishQueueService;
|
|
|
|
|
import com.ms.api.service.MoveProductPublishToPicQueueService;
|
|
|
|
|
import com.ms.api.service.MoveShopConfigService;
|
|
|
|
|
import com.ms.api.service.MoveShopSettingService;
|
|
|
|
|
import com.ms.api.service.RsyncCategoryQueueService;
|
|
|
|
|
import com.ms.api.service.Shop1688DsAuthService;
|
|
|
|
@ -97,6 +99,7 @@ import com.ms.api.tool.MoveTool;
|
|
|
|
|
import com.ms.api.tool.SecurityTool;
|
|
|
|
|
import com.ms.api.util.DdRequestUtil;
|
|
|
|
|
import com.ms.api.util.MoveUtil;
|
|
|
|
|
import com.ms.dal.bo.CollectTaskDetailBO;
|
|
|
|
|
import com.ms.dal.entity.Category;
|
|
|
|
|
import com.ms.dal.entity.CategoryShop;
|
|
|
|
|
import com.ms.dal.entity.MaterialAuditStatusBuffer;
|
|
|
|
@ -104,8 +107,10 @@ import com.ms.dal.entity.MaterialBizAuditStatusLog;
|
|
|
|
|
import com.ms.dal.entity.MaterialBizQueue;
|
|
|
|
|
import com.ms.dal.entity.MaterialBizToMaterial;
|
|
|
|
|
import com.ms.dal.entity.MoveCollectTaskDetail;
|
|
|
|
|
import com.ms.dal.entity.MoveProductPublishBuffer;
|
|
|
|
|
import com.ms.dal.entity.MoveProductPublishQueue;
|
|
|
|
|
import com.ms.dal.entity.MoveProductPublishToPicQueue;
|
|
|
|
|
import com.ms.dal.entity.MoveShopConfig;
|
|
|
|
|
import com.ms.dal.entity.RsyncCategoryQueue;
|
|
|
|
|
import com.ms.dal.entity.Shop;
|
|
|
|
|
import com.ms.dal.entity.Shop1688DsAuth;
|
|
|
|
@ -118,7 +123,6 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import sun.net.www.http.HttpClient;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理move_product_publish_queue中的数据
|
|
|
|
@ -179,6 +183,15 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveService moveService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveShopConfigService moveShopConfigService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MoveProductPublishBufferService moveProductPublishBufferService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SaveBatchMoveTaskBizService saveBatchMoveTaskBizService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
|
|
|
@ -416,7 +429,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return CommonTool.successResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getUploadImgSuccessMapAndFailUrls(Map<String,Object> data, List<String> uploadImgs) {
|
|
|
|
|
private List<String> getUploadImgSuccessMapAndFailUrls(Map<String, Object> data, List<String> uploadImgs) {
|
|
|
|
|
Map<String, String> sourceImgUrlToDdImgUrl = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Object> temp : data.entrySet()) {
|
|
|
|
@ -510,7 +523,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
|
|
|
|
|
byte[] imageData = convertToByteArray(imgUrl);
|
|
|
|
|
if (CommonTool.isAnimatedGif(imageData)) {
|
|
|
|
|
return CommonTool.failResult( "gif动图,不处理");
|
|
|
|
|
return CommonTool.failResult("gif动图,不处理");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: 2023/9/13 涉及到oss 暂时不处理
|
|
|
|
@ -524,7 +537,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
//
|
|
|
|
|
// return CommonTool.successResult("ossUrl", OssTool.getPubOssUrlByOssPath(ossPath));
|
|
|
|
|
StrStrMap strMap = new StrStrMap();
|
|
|
|
|
strMap.put("ossUrl","");
|
|
|
|
|
strMap.put("ossUrl", "");
|
|
|
|
|
return Ret.success(strMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -566,7 +579,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
}
|
|
|
|
|
param.setFolderId(filter.getOrDefault("folderId", "0"));
|
|
|
|
|
if (filter.containsKey("materialName")) {
|
|
|
|
|
param.setFolderId(filter.get("materialName"));
|
|
|
|
|
param.setMaterialName(filter.get("materialName"));
|
|
|
|
|
}
|
|
|
|
|
MaterialUploadImageSyncResponse response = request.execute(accessToken);
|
|
|
|
|
Ret checkRet = CommonTool.checkDdApiRetStatus(response);
|
|
|
|
@ -2859,16 +2872,24 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
}
|
|
|
|
|
Ret processRet = (Ret) params;
|
|
|
|
|
MoveProductPublishQueueBO queueMsg = (MoveProductPublishQueueBO) processRet.getQueueMsg();
|
|
|
|
|
Ret ret = processMovePublishQueueRet(processRet);
|
|
|
|
|
|
|
|
|
|
// TODO: 2023/9/13 这个不知道怎么翻译
|
|
|
|
|
// $publishCostSeconds = time() - $this->startTime;
|
|
|
|
|
|
|
|
|
|
Ret ret = processMovePublishQueueRet(processRet, 0);
|
|
|
|
|
log.info("processMovePublishQueueRet ret:{}", ret);
|
|
|
|
|
// 前面已经挂起,这边删除que
|
|
|
|
|
deleteQueueMsg(queueMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret processMovePublishQueueRet(Ret processRet) {
|
|
|
|
|
private Ret processMovePublishQueueRet(Ret processRet, Integer publishCostSeconds) {
|
|
|
|
|
MoveProductPublishQueueBO queueMsg = (MoveProductPublishQueueBO) processRet.getQueueMsg();
|
|
|
|
|
Long detailId = queueMsg.getMoveCollectTaskDetailId();
|
|
|
|
|
StrObjMap nextData = (StrObjMap) processRet.getData();
|
|
|
|
|
long shopId = queueMsg.getShopId();
|
|
|
|
|
String cnaliDsDetailId = queueMsg.getCnaliDsDetailId();
|
|
|
|
|
Integer taskId = queueMsg.getMoveCollectTaskId();
|
|
|
|
|
int tryTimes = queueMsg.getTryTimes() == 0 ? queueMsg.getTryTimes() : 0;
|
|
|
|
|
if (CommonTool.isSuccessRet(processRet)) {
|
|
|
|
|
JSONObject productDetailBase = (JSONObject) processRet.getData().get("productDetailBase");
|
|
|
|
|
// 要搬家的所有图片
|
|
|
|
@ -2876,60 +2897,143 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
|
|
|
|
|
// 图片素材相关
|
|
|
|
|
StrStrMap urlAndMaterialIdMap = getUrlAndMaterialIdMapBySourceUrl(shopId, imgUrls);
|
|
|
|
|
|
|
|
|
|
MoveCollectTaskDetail updateMoveCollectTaskDetailData = new MoveCollectTaskDetail();
|
|
|
|
|
// TODO
|
|
|
|
|
// $updateMoveCollectTaskDetailData = [
|
|
|
|
|
// 'reason' => '铺货数据组装完毕,等待抖店审核图片通过',
|
|
|
|
|
// 'publish_cost_seconds' => $publishCostSeconds
|
|
|
|
|
// ];
|
|
|
|
|
updateMoveCollectTaskDetailData.setReason("铺货数据组装完毕,等待抖店审核图片通过");
|
|
|
|
|
updateMoveCollectTaskDetailData.setPublishCostSeconds(publishCostSeconds);
|
|
|
|
|
|
|
|
|
|
// 移动到pic_queue 挂起
|
|
|
|
|
int queueId = createMoveProductPublishToPicQueue(queueMsg);
|
|
|
|
|
if (queueId > 0) {
|
|
|
|
|
// $updateMoveCollectTaskDetailData = [
|
|
|
|
|
// 'reason' => '写入图片处理队列失败,请重试任务',
|
|
|
|
|
// 'status' => StatusConst::fail
|
|
|
|
|
// ];
|
|
|
|
|
updateMoveCollectTaskDetailData = new MoveCollectTaskDetail();
|
|
|
|
|
updateMoveCollectTaskDetailData.setReason("写入图片处理队列失败,请重试任务");
|
|
|
|
|
updateMoveCollectTaskDetailData.setStatus(StatusConst.fail);
|
|
|
|
|
}
|
|
|
|
|
List<String> materialIds = Arrays.asList(urlAndMaterialIdMap.values().toArray(new String[0]));
|
|
|
|
|
// 保存素材业务信息
|
|
|
|
|
// 素材的task和detail就加入了
|
|
|
|
|
Ret saveMaterialBizRet = saveMaterialBiz(shopId, CommonConst.BIZ_MOVE, queueId, materialIds, new HashMap());
|
|
|
|
|
if (CommonTool.isFailRet(saveMaterialBizRet)) {
|
|
|
|
|
// $updateMoveCollectTaskDetailData = [
|
|
|
|
|
// 'reason' => '图片业务处理失败,请重试任务',
|
|
|
|
|
// 'status' => StatusConst::fail
|
|
|
|
|
// ];
|
|
|
|
|
updateMoveCollectTaskDetailData = new MoveCollectTaskDetail();
|
|
|
|
|
updateMoveCollectTaskDetailData.setReason("图片业务处理失败,请重试任务");
|
|
|
|
|
updateMoveCollectTaskDetailData.setStatus(StatusConst.fail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新搬家detail数据
|
|
|
|
|
// updateMoveCollectTaskDetail(updateMoveCollectTaskDetailData, shopId, detailId);
|
|
|
|
|
moveService.updateMoveCollectTaskDetail(updateMoveCollectTaskDetailData, shopId, detailId);
|
|
|
|
|
} else {
|
|
|
|
|
E.throwMSException(processRet.getReason());
|
|
|
|
|
// TODO
|
|
|
|
|
// // 限流等情况的处理
|
|
|
|
|
// checkIsFrequencyLimitReason();
|
|
|
|
|
//
|
|
|
|
|
// // 回滚次数
|
|
|
|
|
// revertMoveCopyCount();
|
|
|
|
|
if (CommonTool.checkIsFrequencyLimitReason(processRet.getReason()) && queueMsg.getTryTimes() < 3) {
|
|
|
|
|
addTaskBuffer(shopId, taskId, detailId, 1, queueMsg.getLimitSource(), tryTimes + 1, DateUtil.formatDateTime(DateUtil.offsetSecond(new Date(), new Random().nextInt(541) + 60)));
|
|
|
|
|
return Ret.success();
|
|
|
|
|
}
|
|
|
|
|
String publishStat = processRet.getCode();
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(cnaliDsDetailId)) {
|
|
|
|
|
revertMoveCopyCount(shopId, detailId, "processMovePublishQueueRet");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MoveCollectTaskDetail updateMoveCollectTaskDetailDto = new MoveCollectTaskDetail();
|
|
|
|
|
updateMoveCollectTaskDetailDto.setStatus(processRet.getCode());
|
|
|
|
|
updateMoveCollectTaskDetailDto.setReason(processRet.getReason());
|
|
|
|
|
updateMoveCollectTaskDetailDto.setPublishCostSeconds(publishCostSeconds);
|
|
|
|
|
//
|
|
|
|
|
// // 更新搬家detail数据
|
|
|
|
|
// updateMoveCollectTaskDetail(new StrObjMap(), shopId, queueMsg.getMoveCollectTaskDetailId());
|
|
|
|
|
updateMoveCollectTaskDetail(updateMoveCollectTaskDetailDto, shopId, detailId);
|
|
|
|
|
//
|
|
|
|
|
// processCreateProductRetCommonPart();
|
|
|
|
|
processCreateProductRetCommonPart(queueMsg, StatusConst.fail, processRet, publishCostSeconds, publishStat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return processRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void revertMoveCopyCount() {
|
|
|
|
|
//TODO
|
|
|
|
|
private void processCreateProductRetCommonPart(MoveProductPublishQueueBO queueMsg, String fail, Ret processRet, Integer publishCostSeconds, String publishStat) {
|
|
|
|
|
// TODO: 2023/9/13 进度
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processCreateProductRetCommonPart() {
|
|
|
|
|
//TODO
|
|
|
|
|
private void addTaskBuffer(long shopId, Integer moveCollectTaskId, Long moveCollectTaskDetailId, int productTotal, Integer limitSource, int tryTimes, String gmtExec) {
|
|
|
|
|
int priority = saveBatchMoveTaskBizService.getTaskPriority(shopId, productTotal);
|
|
|
|
|
|
|
|
|
|
MoveProductPublishBuffer dto = new MoveProductPublishBuffer();
|
|
|
|
|
dto.setMoveCollectTaskId(moveCollectTaskId);
|
|
|
|
|
dto.setMoveCollectTaskDetailId(moveCollectTaskDetailId);
|
|
|
|
|
dto.setShopId(shopId);
|
|
|
|
|
dto.setPriority(priority);
|
|
|
|
|
dto.setTryTimes(tryTimes);
|
|
|
|
|
dto.setGmtExec(DateUtil.parse(gmtExec));
|
|
|
|
|
dto.setGmtCreate(new Date());
|
|
|
|
|
dto.setGmtModified(new Date());
|
|
|
|
|
moveProductPublishBufferService.insert(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateMoveCollectTaskDetail(MoveCollectTaskDetail updateMoveCollectTaskDetailDto, long shopId, Long detailId) {
|
|
|
|
|
MoveCollectTaskDetail moveCollectTaskDetail = moveCollectTaskDetailService.selectByPrimaryKey(detailId);
|
|
|
|
|
if (ObjectUtil.isNull(moveCollectTaskDetail) || !moveCollectTaskDetail.getShopId().equals(shopId)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
updateMoveCollectTaskDetailDto.setMoveCollectTaskDetailId(detailId);
|
|
|
|
|
moveCollectTaskDetailService.updateByPrimaryKeySelective(updateMoveCollectTaskDetailDto);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void revertMoveCopyCount(Long shopId, Long detailId, String funcName) {
|
|
|
|
|
if (shopId <= 0 || ObjectUtil.isNull(detailId)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MoveCollectTaskDetail moveCollectTaskDetail = moveCollectTaskDetailService.selectByPrimaryKey(detailId);
|
|
|
|
|
if (ObjectUtil.isNull(moveCollectTaskDetail)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Integer deductMoveShopConfigId = moveCollectTaskDetail.getMoveShopConfigId();
|
|
|
|
|
MoveShopConfigBO currentMonthMoveConfig = moveService.getAvailableCopyCount(shopId);
|
|
|
|
|
Integer currentMoveShopConfigId = currentMonthMoveConfig.getMoveShopConfigId();
|
|
|
|
|
CollectTaskDetailBO detail = moveService.getCollectTaskDetail(detailId);
|
|
|
|
|
if (detail.getCopyType().equals(MoveConst.collectDsCopy)) {
|
|
|
|
|
// TODO: 2023/9/13 没 ds_revert_log表
|
|
|
|
|
// logRevertDsCopyMoveCnt(shopId, detailId, funcName);
|
|
|
|
|
if (ObjectUtil.isNotNull(detail.getCnaliDsDetailId())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUseRechargeNum(shopId, Long.valueOf(deductMoveShopConfigId))) {
|
|
|
|
|
MoveShopConfig moveShopConfig = moveShopConfigService.selectByPrimaryKey(Long.valueOf(deductMoveShopConfigId));
|
|
|
|
|
// TODO: 2023/9/13 没有这个 pre_paid_fail_total
|
|
|
|
|
// updateMoveShopConfig(shopId, currentMoveShopConfigId, Map.of("pre_paid_fail_total", new ZcDbEval("pre_paid_fail_total + 1")));
|
|
|
|
|
} else {
|
|
|
|
|
MoveShopConfig moveShopConfig = moveShopConfigService.selectByPrimaryKey(Long.valueOf(deductMoveShopConfigId));
|
|
|
|
|
updateMoveShopConfig(shopId, deductMoveShopConfigId, MoveShopConfig.builder().failTotal(moveShopConfig.getFailTotal() + 1).build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean updateMoveShopConfig(long shopId, Integer moveShopConfigId, MoveShopConfig updateData) {
|
|
|
|
|
if (ObjectUtil.isNull(moveShopConfigId)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
updateData.setMoveShopConfigId(moveShopConfigId);
|
|
|
|
|
moveShopConfigService.updateByPrimaryKeySelective(updateData);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isUseRechargeNum(Long shopId, Long moveShopConfigId) {
|
|
|
|
|
MoveShopConfig moveShopConfig = moveShopConfigService.selectByPrimaryKey(moveShopConfigId);
|
|
|
|
|
if (ObjectUtil.isNull(moveShopConfig)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
int presentNumSurplus = getPresentNumSurplus(moveShopConfig);
|
|
|
|
|
return presentNumSurplus <= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPresentNumSurplus(MoveShopConfig moveConfig) {
|
|
|
|
|
int monthTotal = moveConfig.getTotal() + moveConfig.getAttachTotal();
|
|
|
|
|
// TODO: 2023/9/13 没有这个 pre_paid_fail_total 取0
|
|
|
|
|
int moveSuccessTotal = moveConfig.getUsedTotal() - (moveConfig.getFailTotal() + 0);
|
|
|
|
|
return monthTotal - moveSuccessTotal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkIsFrequencyLimitReason() {
|
|
|
|
|
//TODO
|
|
|
|
|
}
|
|
|
|
|