wangchaoxu 1 year ago
commit c9ab5909d0

@ -10,4 +10,7 @@ import lombok.Data;
public class ItemDTO {
private String title;
private Integer price;
private Integer start;
private Integer end;
private Integer length;
}

@ -35,11 +35,11 @@ public class TestRedisService extends SPIBaseService implements ExtensionService
initHandle(req);
ItemDTO itemDTO = req.getData();
if(itemDTO.getTitle().equals("initProcess")){
for (long i = 0; i < 50; i++) {
for (long i = 0; i < itemDTO.getLength(); i++) {
redisService.pop(RedisKeyConst.MOVE_PRODUCT_PUBLISH_QUEUE);
}
for (long i = 149; i < 200; i++) {
for (long i = itemDTO.getStart(); i < itemDTO.getEnd(); i++) {
MoveProductPublishQueue data = moveProductPublishQueueService.selectByPrimaryKey(i);
if(data != null && data.getLocked() == 0){
redisService.push(RedisKeyConst.MOVE_PRODUCT_PUBLISH_QUEUE, String.valueOf(data.getMoveCollectTaskDetailId()));
@ -49,11 +49,11 @@ public class TestRedisService extends SPIBaseService implements ExtensionService
//to pic
if(itemDTO.getTitle().equals("initToPic")){
for (long i = 0; i < 30; i++) {
for (long i = 0; i < itemDTO.getLength(); i++) {
redisService.pop(RedisKeyConst.MOVE_PRODUCT_PUBLISH_TO_PIC_QUEUE);
}
for (long i = 190; i < 250; i++) {
for (long i = itemDTO.getStart(); i < itemDTO.getEnd(); i++) {
MoveProductPublishToPicQueue data = moveProductPublishToPicQueueService.selectByPrimaryKey(i);
if (data != null && data.getLocked() == 0) {
redisService.push(RedisKeyConst.MOVE_PRODUCT_PUBLISH_TO_PIC_QUEUE, String.valueOf(data.getMoveProductPublishToPicQueueId()));

@ -16,6 +16,8 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
@ -58,41 +60,21 @@ import com.ms.api.common.MSException;
import com.ms.api.common.Ret;
import com.ms.api.common.StrObjMap;
import com.ms.api.common.StrStrMap;
import com.ms.api.consts.AppConst;
import com.ms.api.consts.MaterialConst;
import com.ms.api.consts.MoveConst;
import com.ms.api.consts.StatusConst;
import com.ms.api.consts.*;
import com.ms.api.paas.RedisService;
import com.ms.api.paas.StorageService;
import com.ms.api.service.CategorySizeTemplateSubTypeService;
import com.ms.api.service.DsRelateProductAnalysisOpOrderQueueService;
import com.ms.api.service.MaterialAuditStatusBufferService;
import com.ms.api.service.MaterialBizAuditStatusLogService;
import com.ms.api.service.MoveCollectTaskDetailService;
import com.ms.api.service.MoveShopConfigService;
import com.ms.api.service.ProductToDsItemService;
import com.ms.api.service.Shop1688DsAuthService;
import com.ms.api.service.ShopService;
import com.ms.api.service.*;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.DsJsonRequestTemplate;
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.CategorySizeTemplateSubType;
import com.ms.dal.entity.DsRelateProductAnalysisOpOrderQueue;
import com.ms.dal.entity.MaterialAuditStatusBuffer;
import com.ms.dal.entity.MaterialBizAuditStatusLog;
import com.ms.dal.entity.MoveCollectTask;
import com.ms.dal.entity.MoveCollectTaskDetail;
import com.ms.dal.entity.MoveProductPublishBuffer;
import com.ms.dal.entity.MoveShopConfig;
import com.ms.dal.entity.MoveShopSetting;
import com.ms.dal.entity.ProductToDsItem;
import com.ms.dal.entity.Shop;
import com.ms.dal.entity.Shop1688DsAuth;
import com.ms.dal.entity.*;
import com.ms.dal.mapper.MoveCollectTaskDetailMapper;
import com.ms.dal.mapper.MoveCollectTaskMapper;
import com.ms.dal.mapper.MoveProductPublishBufferMapper;
import com.ms.dal.mapper.QueueMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -112,6 +94,10 @@ public class MoveService {
@Autowired
private MoveCollectTaskDetailService moveCollectTaskDetailService;
@Autowired
private MoveProductPublishToPicQueueService moveProductPublishToPicQueueService;
@Autowired
private MoveProductPublishQueueService moveProductPublishQueueService;
@Autowired
private ShopService shopService;
@Autowired
private MoveCollectTaskDetailMapper moveCollectTaskDetailMapper;
@ -146,6 +132,12 @@ public class MoveService {
@Autowired
MaterialBizAuditStatusLogService materialBizAuditStatusLogService;
@Autowired
private QueueMapper queueMapper;
@Autowired
RedisService redisService;
/**
*
*
@ -270,10 +262,10 @@ public class MoveService {
if (price <= 0) {
return 99999;
}
double pricePercent = condition.getPricePercent().doubleValue();
double priceAdd = condition.getPriceAdd().doubleValue();
double priceSub = condition.getPriceSub().doubleValue();
int priceTail = condition.getPriceTail();
double pricePercent = ObjectUtil.isNotEmpty(condition.getPricePercent())? condition.getPricePercent().doubleValue():0;
double priceAdd = ObjectUtil.isNotEmpty(condition.getPriceAdd())?condition.getPriceAdd().doubleValue():0;
double priceSub = ObjectUtil.isNotEmpty(condition.getPriceSub())?condition.getPriceSub().doubleValue():0;
int priceTail = ObjectUtil.isNotEmpty(condition.getPriceTail())?condition.getPriceTail():0;
String priceDecimal = condition.getPriceDecimal();
double priceDecimalDiyValue = !ObjectUtil.isEmpty(condition.getPriceDecimalDiyValue()) ? Double.valueOf(condition.getPriceDecimalDiyValue()) : 0.00;
return getConditionDdPrice(price, pricePercent, priceAdd, priceSub, priceTail, priceDecimal, priceDecimalDiyValue);
@ -375,8 +367,8 @@ public class MoveService {
allowOptions.put(value, value);
}
return allOptions.entrySet().stream()
.filter(entry -> allowOptions.containsKey(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.filter(entry -> allowOptions.containsKey(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
public String buildProductName(String title, String shopId) {
@ -388,7 +380,7 @@ public class MoveService {
}
public String rebuildTitleByConfig(String title, String shopId) {
int maxTitleLen = shopId.equals(AppConst.TEST_SHOP_ID)? MoveConst.MOVE_TITLE_LEN_TEST:MoveConst.MOVE_TITLE_LEN;
int maxTitleLen = shopId.equals(AppConst.TEST_SHOP_ID) ? MoveConst.MOVE_TITLE_LEN_TEST : MoveConst.MOVE_TITLE_LEN;
int newTitleLen = CommonTool.countStrLen(title);
if (newTitleLen > maxTitleLen) {
title = CommonTool.substringByLen(title, maxTitleLen);
@ -1191,7 +1183,7 @@ public class MoveService {
public Ret saveMaterialAuditStatusBuffer(long shopId, List<String> materialIds, StrStrMap materialIdAndOriginUrlMap) {
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
try{
try {
StrObjMap filter = new StrObjMap();
filter.put("materialIds", materialIds);
Map<String, MaterialBizAuditStatusLog> materialIdMap = materialBizAuditStatusLogService.getShopMaterialBizAuditStatusLogMap(shopId, filter);
@ -1199,7 +1191,7 @@ public class MoveService {
addMaterialAuditStatusBuffer(shopId, materialIds);
addMaterialBizAuditStatusLog(shopId, materialIds, materialIdAndOriginUrlMap);
transactionManager.commit(status);
}catch (Throwable e){
} catch (Throwable e) {
e.printStackTrace();
transactionManager.rollback(status);
log.info("任务执行失败 数据回滚: ", e);
@ -1366,46 +1358,126 @@ public class MoveService {
return ret;
}
// TODO
//dd 返回字段首字母大写,全部转成小写处理。
// JSONObject product = (JSONObject)ret.getData().get("data");
return CommonTool.successResult("product", ret.getData());
}
// $productFormatNew = json_decode($ret['data']['product_format_new'], true);
// $productFormat = [];
// foreach ($productFormatNew as &$attrs) {
// foreach ($attrs as $index => $attr) {
// foreach ($attr as $key => $value) {
// unset($attr[$key]);
// $attr[lcfirst($key)] = $value;
// }
//
// $propertyName = $attr['propertyName'];
// $productFormat[$propertyName] = $productFormat[$propertyName] ? $productFormat[$propertyName] . ' ' . $attr['name'] : $attr['name'];
// $attrs[$index] = $attr;
// }
// }
// $ret['data']['product_format_new'] = json_encode($productFormatNew, true);
// $ret['data']['product_format'] = $ret['data']['product_format'] ? $ret['data']['product_format'] : json_encode($productFormat, true);
//
// $specOrder = [];
// foreach ($ret['data']['specs'][0]['values'] as $index => $spec) {
// $specOrder[$spec['id']] = $index;
// }
// usort($ret['data']['spec_pics'], function ($specA, $specB) use ($specOrder) {
// return $specOrder[$specA['spec_detail_id']] - $specOrder[$specB['spec_detail_id']];
// });
//
// if(empty($ret['data']['quality_list'])) {
// if(!empty($ret['data']['extra'])) {
// $extra = json_decode($ret['data']['extra'], true);
// $ret['data']['quality_list'] = !empty($extra['quality_list']) ? $extra['quality_list'] : [];
// }
// }
//
// if ($ret['data']['name_prefix'] && (stripos($ret['data']['name'], $ret['data']['name_prefix']) === 0)) {
// $ret['data']['name'] = mb_substr($ret['data']['name'], mb_strlen($ret['data']['name_prefix']));
// }
public int unlockMoveProductPublishQueue() {
String tableName = "move_product_publish_queue";
int lockSec = 5 * 60;
DateTime deadTime = DateUtil.offsetSecond(new Date(), -lockSec);
String where = String.format(" WHERE locked > 0 AND gmt_locked < '%s' ", DateUtil.formatDateTime(deadTime));
List<Map<String, Object>> queueList = queueMapper.select(tableName, where);
if (ObjectUtil.isEmpty(queueList)) {
return 0;
}
String queueIdColumnName = QueueConst.getQueueIdColumnName(tableName);
for (Map<String, Object> queue : queueList) {
String queueIdStr = "";
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
try {
queueIdStr = queue.get(queueIdColumnName).toString();
Long queueId = Long.parseLong(queueIdStr);
String detailIdStr = queue.get("move_collect_task_detail_id").toString();
Long detailId = Long.parseLong(detailIdStr);
if (ObjectUtil.isNotNull(queueId)) {
MoveCollectTaskDetail moveCollectTaskDetail = moveCollectTaskDetailService.selectByPrimaryKey(detailId);
if (ObjectUtil.isNotEmpty(moveCollectTaskDetail)) {
// 如果重试次数超过3次就把任务标记为失败
int try_times = (int) queue.get("try_times");
if (try_times > 3) {
int publishCostSeconds = lockSec;
moveProductPublishQueueService.deleteByPrimaryKey(queueId);
// 更新任务状态
moveCollectTaskDetail.setStatus(StatusConst.fail);
moveCollectTaskDetail.setReason("重试3次依旧失败自动关闭此任务");
moveCollectTaskDetail.setPublishCostSeconds(publishCostSeconds);
moveCollectTaskDetailService.updateByPrimaryKeySelective(moveCollectTaskDetail);
// TODO 搬家数量需要更新
// $this->updateMoveShopPublishCount($queue['shop_id'], 'error', $queue['priority'], $publishCostSeconds);
continue;
}
return CommonTool.successResult("product", ret.getData());
// 更新重试次数
MoveProductPublishQueue moveProductPublishQueue = moveProductPublishQueueService.selectByPrimaryKey(queueId);
moveProductPublishQueue.setTryTimes(try_times + 1);
moveProductPublishQueueService.updateByPrimaryKeySelective(moveProductPublishQueue);
// 解锁和redis
queueMapper.updateLocked(tableName, queueIdColumnName, queueId, 0, DateUtil.now());
redisService.push(RedisKeyConst.MOVE_PRODUCT_PUBLISH_QUEUE, detailIdStr);
}
}
transactionManager.commit(status);
} catch (Exception e) {
e.printStackTrace();
log.info("unlock process publish exception : " + queueIdStr);
transactionManager.rollback(status);
}
}
return queueList.size();
}
public int unlockMoveProductPublishToPicQueue() {
String tableName = "move_product_publish_to_pic_queue";
int lockSec = 5 * 60;
DateTime deadTime = DateUtil.offsetSecond(new Date(), -lockSec);
String where = String.format(" WHERE locked > 0 AND gmt_locked < '%s' ", DateUtil.formatDateTime(deadTime));
List<Map<String, Object>> queueList = queueMapper.select(tableName, where);
if (ObjectUtil.isEmpty(queueList)) {
return 0;
}
String queueIdColumnName = QueueConst.getQueueIdColumnName(tableName);
for (Map<String, Object> queue : queueList) {
String queueIdStr = "";
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
try {
queueIdStr = queue.get(queueIdColumnName).toString();
Long queueId = Long.parseLong(queueIdStr);
String detailIdStr = queue.get("move_collect_task_detail_id").toString();
Long detailId = Long.parseLong(detailIdStr);
if (ObjectUtil.isNotNull(queueId)) {
MoveCollectTaskDetail moveCollectTaskDetail = moveCollectTaskDetailService.selectByPrimaryKey(detailId);
if (ObjectUtil.isNotEmpty(moveCollectTaskDetail)) {
// 如果重试次数超过3次就把任务标记为失败
int try_times = (int) queue.get("try_times");
if (try_times > 3) {
int publishCostSeconds = lockSec;
moveProductPublishToPicQueueService.deleteByPrimaryKey(queueId);
// 更新任务状态
moveCollectTaskDetail.setStatus(StatusConst.fail);
moveCollectTaskDetail.setReason("重试3次依旧失败自动关闭此任务");
moveCollectTaskDetail.setPublishCostSeconds(publishCostSeconds);
moveCollectTaskDetailService.updateByPrimaryKeySelective(moveCollectTaskDetail);
// TODO 搬家数量需要更新
// $this->updateMoveShopPublishCount($queue['shop_id'], 'error', $queue['priority'], $publishCostSeconds);
continue;
}
// 更新重试次数
MoveProductPublishToPicQueue moveProductPublishToPicQueue = moveProductPublishToPicQueueService.selectByPrimaryKey(queueId);
moveProductPublishToPicQueue.setTryTimes(try_times + 1);
moveProductPublishToPicQueueService.updateByPrimaryKeySelective(moveProductPublishToPicQueue);
// 解锁和redis
queueMapper.updateLocked(tableName, queueIdColumnName, queueId, 0, DateUtil.now());
redisService.push(RedisKeyConst.MOVE_PRODUCT_PUBLISH_TO_PIC_QUEUE, queueIdStr);
}
}
transactionManager.commit(status);
} catch (Exception e) {
e.printStackTrace();
log.info("unlock process publish exception : " + queueIdStr);
transactionManager.rollback(status);
}
}
return queueList.size();
}
}

@ -112,34 +112,34 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
product.put("ddCategoryList", "");
}
// 处理价格
// Double price = product.getDoubleValue("jd_price");
// JSONObject skuMap = product.getJSONObject("skuMap");
// Double consignPrice = 0D;
// for (String key : skuMap.keySet()) {
// JSONObject item = JSONObject.parseObject(skuMap.get(key).toString());
// Double cPrice = item.getDoubleValue("consignPrice");
// if (cPrice > consignPrice) {
// consignPrice = cPrice;
// }
// }
// if (Objects.isNull(consignPrice)) {
// consignPrice = 0D;
// }
// MoveShopSetting moveShopSetting = moveShopSettingService.getDetailByShopId(shopId);
// ModelMapper modelMapper = new ModelMapper();
// modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
// MoveShopSettingBO condition = modelMapper.map(moveShopSetting, MoveShopSettingBO.class);
// if (condition.getAliPriceType().equals(MoveConst.ALI_PRICE_TYPE_CONSIGN) && consignPrice > 0) {
// price = consignPrice;
// }
// double mPrice = moveService.processConditionPrice(condition, price);
// product.put("price", mPrice);
Double price = product.getDoubleValue("jd_price");
JSONObject skuMap = product.getJSONObject("skuMap");
Double consignPrice = 0D;
for (String key : skuMap.keySet()) {
JSONObject item = JSONObject.parseObject(skuMap.get(key).toString());
Double cPrice = item.getDoubleValue("consignPrice");
if (cPrice > consignPrice) {
consignPrice = cPrice;
}
}
if (Objects.isNull(consignPrice)) {
consignPrice = 0D;
}
MoveShopSetting moveShopSetting = moveShopSettingService.getDetailByShopId(shopId);
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
MoveShopSettingBO condition = modelMapper.map(moveShopSetting, MoveShopSettingBO.class);
if (condition.getAliPriceType().equals(MoveConst.ALI_PRICE_TYPE_CONSIGN) && consignPrice > 0) {
price = consignPrice;
}
double mPrice = moveService.processConditionPrice(condition, price);
product.put("price", mPrice);
productInfo.add(resObj.getJSONObject("productInfo"));
log.info(res);
} catch (Exception e) {
fetchFailIds.add(productIds.get(i));
e.printStackTrace();
log.error(e.getMessage());
log.error(e.toString());
}
}

@ -0,0 +1,28 @@
package com.ms.api.spi.timer;
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.Ret;
import com.ms.api.common.TimerBaseService;
import com.ms.api.dto.ItemDTO;
import com.ms.api.task.MoveUnlockTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ExtensionService("moveUnlockTimer")
@Slf4j
public class MoveUnlockTimerService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
@Autowired
MoveUnlockTaskService moveUnlockTaskService;
@Override
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
moveUnlockTaskService.runTask();
return R.ok(Ret.success());
}
}

@ -0,0 +1,103 @@
package com.ms.api.task;
import com.ms.api.biz.MoveService;
import com.ms.api.bo.RedisKeyBO;
import com.ms.api.common.TaskBaseService;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.service.QueueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.concurrent.Executor;
/**
*
*/
@Configuration
@Component
@Slf4j
public class MoveUnlockTaskService extends TaskBaseService {
@Autowired
MoveService moveService;
@Autowired
QueueService unlockTimeoutQueue;
/**
*
*/
public int getCorePoolSiz() {
return 3;
}
/**
*
*/
public String getTaskExecutorName() {
return "moveUnlockTaskPool";
}
@Bean(name = "moveUnlockTaskPool")
@Override
public Executor getAsyncExecutor() {
return super.getAsyncExecutor();
}
@Resource(name = "moveUnlockTaskPool")
protected Executor taskPool;
@Override
protected Executor getTaskPool() {
return taskPool;
}
@Async("moveUnlockTaskPool")
@Scheduled(fixedRate = 10000)
@Override
public void runTask() {
super.runTask();
}
/**
*
*/
@Override
public Object getTask(RedisKeyBO redisKeyBO) {
return null;
}
/**
*
*
* @param params
* @return
*/
@Override
public Object processTask(Object params) {
log.info("start move unlock service");
moveService.unlockMoveProductPublishToPicQueue();
moveService.unlockMoveProductPublishQueue();
int heartBeatSec = 2 * 60;
unlockTimeoutQueue.unlockTimeoutQueue("material_audit_status_queue",heartBeatSec,"");
unlockTimeoutQueue.unlockTimeoutQueue("material_biz_queue",heartBeatSec,"");
log.info("end move unlock service");
return null;
}
/**
*
*
* @param params
*/
@Override
public void clearTask(Object params) {
}
}

@ -1,22 +1,5 @@
package com.ms.api.task;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
@ -36,44 +19,17 @@ import com.ms.api.bo.MoveProductPublishQueueBO;
import com.ms.api.bo.MoveProductPublishToPicQueueBO;
import com.ms.api.bo.MoveShopSettingBO;
import com.ms.api.bo.RedisKeyBO;
import com.ms.api.common.E;
import com.ms.api.common.Ret;
import com.ms.api.common.StrObjMap;
import com.ms.api.common.StrStrMap;
import com.ms.api.common.TaskBaseService;
import com.ms.api.consts.AppConst;
import com.ms.api.consts.CommonConst;
import com.ms.api.consts.MoveConst;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.consts.StatusConst;
import com.ms.api.common.*;
import com.ms.api.consts.*;
import com.ms.api.paas.RedisService;
import com.ms.api.paas.StorageService;
import com.ms.api.service.DsRelateProductAnalysisOpOrderQueueService;
import com.ms.api.service.MaterialBizAuditStatusLogService;
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.MoveProductLogService;
import com.ms.api.service.MoveProductPublishQueueService;
import com.ms.api.service.MoveProductPublishToPicQueueService;
import com.ms.api.service.ProductService;
import com.ms.api.service.ProductToDsItemService;
import com.ms.api.service.Shop1688DsAuthService;
import com.ms.api.service.ShopService;
import com.ms.api.service.*;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.tool.SecurityTool;
import com.ms.api.tool.TailorImgTool;
import com.ms.api.util.MoveUtil;
import com.ms.dal.entity.MaterialBizAuditStatusLog;
import com.ms.dal.entity.MaterialBizQueue;
import com.ms.dal.entity.MaterialBizToMaterial;
import com.ms.dal.entity.MoveCollectTask;
import com.ms.dal.entity.MoveCollectTaskDetail;
import com.ms.dal.entity.MoveProductLog;
import com.ms.dal.entity.MoveProductPublishToPicQueue;
import com.ms.dal.entity.Shop;
import com.ms.dal.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -86,6 +42,13 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
*
*/
@ -220,7 +183,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
@Override
protected void rollbackRedisKey(RedisKeyBO redisKeyBO) {
redisService.push(redisKeyBO.getKey(), String.valueOf(redisKeyBO.getValue()));
//redisService.push(redisKeyBO.getKey(), String.valueOf(redisKeyBO.getValue()));
}
private MoveProductPublishToPicQueue lockSolidRedisQueue(RedisKeyBO redisKeyBO) {
@ -839,8 +802,8 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
Long shopId = queueMsg.getShopId();
String folderId = moveService.getUploadImgFolderId(shopId, accessToken, false);
List<String> batchUploadPics = Arrays.stream(mainImgUrls)
.filter(pic -> !pic.contains(CommonConst.ddImgUrlNeedle))
.collect(Collectors.toList());
.filter(pic -> !pic.contains(CommonConst.ddImgUrlNeedle))
.collect(Collectors.toList());
if (!batchUploadPics.isEmpty()) {
moveService.uploadMoveProductImgToDd(shopId, batchUploadPics, folderId, "false", accessToken);
@ -970,8 +933,8 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
productDetailBase.put("newSizeNameAndOldSizeNameMap", specResult.get("newSizeNameAndOldSizeNameMap"));
productDetailBase.put("publishTips", specResult.get("publishTips"));
JSONArray specPrices = moveService.buildSpecPrice(productDetailBase,
condition, (List<String>) specResult.get("colorSpecArr"), (List<String>) specResult.get("sizeSpecArr"),
BeanUtil.toBean(queueMsg, MoveProductPublishQueueBO.class), (StrObjMap) specResult.get("newColorNameAndOldColorNameMap"), true, foundBanWordList);
condition, (List<String>) specResult.get("colorSpecArr"), (List<String>) specResult.get("sizeSpecArr"),
BeanUtil.toBean(queueMsg, MoveProductPublishQueueBO.class), (StrObjMap) specResult.get("newColorNameAndOldColorNameMap"), true, foundBanWordList);
productDetailBase.put("specPrices", specPrices);
productDetailBase = moveService.processSpuPriceMaybeOutRange(productDetailBase);
@ -998,8 +961,8 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
for (String specStr : specArr) {
String[] specItems = specStr.split("|");
String[] uniqueSpecItems = Arrays.stream(specItems)
.distinct()
.toArray(String[]::new);
.distinct()
.toArray(String[]::new);
if (uniqueSpecItems.length != specItems.length) {
hasRepeatSpec = true;
break;
@ -1216,7 +1179,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
private StrObjMap processProductDeliveryDelayDayError(JSONObject productDetailBase, Boolean dataIsChange, String reason) {
if (reason.indexOf("承诺发货时间不在合理范围内") != -1
|| reason.indexOf("校验预售发货信息失败发货时间配置不满足要求") != -1) {
|| reason.indexOf("校验预售发货信息失败发货时间配置不满足要求") != -1) {
productDetailBase.put("deliveryDelayDay", MoveConst.deliveryDelayOneDay);
dataIsChange = true;
log.info("processProductDeliveryDelayDayError : " + productDetailBase.getString("deliveryDelayDay"));
@ -1229,9 +1192,9 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
private StrObjMap processOuterProductIdError(JSONObject productDetailBase, Boolean dataIsChange, String reason) {
if (reason.indexOf("out_product_id需为数字字符串") != -1
|| reason.indexOf("该out_product_id无法被添加, 已存在") != -1
|| reason.indexOf("OutProductId已存在请检查") != -1
|| reason.indexOf("outerProductId已经存在") != -1) {
|| reason.indexOf("该out_product_id无法被添加, 已存在") != -1
|| reason.indexOf("OutProductId已存在请检查") != -1
|| reason.indexOf("outerProductId已经存在") != -1) {
Integer randNum = new Random().nextInt(100000000 - 1000000) + 1000000;
productDetailBase.put("outProductId", randNum);
dataIsChange = true;
@ -1269,7 +1232,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
if (!Objects.isNull(startSaleType)) {
param.setStartSaleType(startSaleType);
}
Long outProductId = productData.getLong("outProductId");
if (!Objects.isNull(outProductId)) {
param.setOutProductId(outProductId);
@ -1505,8 +1468,8 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
private Ret processPicQueueCreateProductException(Integer code, String message, JSONObject data, long shopId, MoveProductPublishToPicQueueBO queueMsg) {
if (Arrays.asList(MoveConst.MovePublishToPicQueueAgainWaitSpecPicAuditPass,
MoveConst.MovePublishToPicQueueAgainWaitMainImgPicAuditPass,
MoveConst.MovePublishToPicQueueAgainWaitNoteImgPicAuditPass).contains(code)) {
MoveConst.MovePublishToPicQueueAgainWaitMainImgPicAuditPass,
MoveConst.MovePublishToPicQueueAgainWaitNoteImgPicAuditPass).contains(code)) {
boolean isChange = false;
JSONObject productDetailBase = data.getJSONObject("productDetailBase");
if (Objects.equals(code, MoveConst.MovePublishToPicQueueAgainWaitSpecPicAuditPass)) {

@ -1,34 +1,5 @@
package com.ms.api.task;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
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;
@ -49,61 +20,16 @@ import com.doudian.open.api.product_getCatePropertyV2.data.ProductGetCatePropert
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.MoveShopSettingBO;
import com.ms.api.bo.RedisKeyBO;
import com.ms.api.bo.SkuDetailBO;
import com.ms.api.bo.SkuInfoBO;
import com.ms.api.common.ApiResult;
import com.ms.api.common.E;
import com.ms.api.common.Ret;
import com.ms.api.common.StrObjMap;
import com.ms.api.common.StrStrMap;
import com.ms.api.common.TaskBaseService;
import com.ms.api.consts.CommonConst;
import com.ms.api.consts.MaterialConst;
import com.ms.api.consts.MoveConst;
import com.ms.api.consts.RedisKeyConst;
import com.ms.api.consts.StatusConst;
import com.ms.api.bo.*;
import com.ms.api.common.*;
import com.ms.api.consts.*;
import com.ms.api.paas.RedisService;
import com.ms.api.paas.StorageService;
import com.ms.api.service.CategoryShopService;
import com.ms.api.service.MaterialBizAuditStatusLogService;
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;
import com.ms.api.service.ShopService;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.tool.ImageTool;
import com.ms.api.tool.MoveTool;
import com.ms.api.tool.SecurityTool;
import com.ms.api.tool.TailorImgTool;
import com.ms.api.service.*;
import com.ms.api.tool.*;
import com.ms.api.util.DdRequestUtil;
import com.ms.api.util.MoveUtil;
import com.ms.dal.entity.Category;
import com.ms.dal.entity.CategoryShop;
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.RsyncCategoryQueue;
import com.ms.dal.entity.Shop;
import com.ms.dal.entity.Shop1688DsAuth;
import com.ms.dal.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -118,6 +44,21 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* move_product_publish_queue
*/
@ -602,8 +543,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
productDetailBase.put("newColorNameAndOldColorNameMap", data.get("newColorNameAndOldColorNameMap"));
productDetailBase.put("newSizeNameAndOldSizeNameMap", data.get("newSizeNameAndOldSizeNameMap"));
ArrayList publishTips = (ArrayList) data.get("publishTips");
productDetailBase.put("specPrices", moveService.buildSpecPrice(productDetailBase, condition,
colorSpecArrCalc, sizeSpecArrCalc, queueMsg, skuPresellChildSkuDetail, false, new ArrayList<>()));
productDetailBase.put("specPrices", moveService.buildSpecPrice(productDetailBase, condition, colorSpecArrCalc, sizeSpecArrCalc, queueMsg, skuPresellChildSkuDetail, false, new ArrayList<>()));
List<String> repeatSpecArr = checkHasRepeatSpec(colorSpecArrCalc, sizeSpecArrCalc);
if (ObjectUtil.isNotEmpty(repeatSpecArr)) {
@ -676,11 +616,9 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
}
private String getSkuSpecStr(MoveProductPublishQueueBO queueMsg, Integer deliveryDelayDay) {
Map<String, Object> presellTimeSkuSpecNameAndStockPercentMap = queueMsg.getPresellTimeSkuSpecNameAndStockPercentMap() != null ?
queueMsg.getPresellTimeSkuSpecNameAndStockPercentMap() : queueMsg.getCondition().getPresellTimeSkuSpecNameAndStockPercentMap();
Map<String, Object> presellTimeSkuSpecNameAndStockPercentMap = queueMsg.getPresellTimeSkuSpecNameAndStockPercentMap() != null ? queueMsg.getPresellTimeSkuSpecNameAndStockPercentMap() : queueMsg.getCondition().getPresellTimeSkuSpecNameAndStockPercentMap();
if (queueMsg.getIsFastMode() != 0 && queueMsg.getSizeAndPresellMap() != null &&
queueMsg.getSizeAndPresellMap().get("presellMap") != null && queueMsg.getCondition().getUseSourcePresell()) {
if (queueMsg.getIsFastMode() != 0 && queueMsg.getSizeAndPresellMap() != null && queueMsg.getSizeAndPresellMap().get("presellMap") != null && queueMsg.getCondition().getUseSourcePresell()) {
presellTimeSkuSpecNameAndStockPercentMap = (Map<String, Object>) queueMsg.getSizeAndPresellMap().get("presellMap");
}
@ -1643,12 +1581,10 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
}
private String buildSkuListKey(JSONObject firstAttr, JSONObject secondAttr, List<String> filterWordArray) {
String firstName = firstAttr.getString("newName") != null ? firstAttr.getString("newName") :
(firstAttr.getString("calName") != null ? firstAttr.getString("calName") : firstAttr.getString("name"));
String firstName = firstAttr.getString("newName") != null ? firstAttr.getString("newName") : (firstAttr.getString("calName") != null ? firstAttr.getString("calName") : firstAttr.getString("name"));
firstName = filterBanWordsList(filterWordArray, firstName, true);
String secondName = secondAttr.getString("newName") != null ? secondAttr.getString("newName") :
(secondAttr.getString("calName") != null ? secondAttr.getString("calName") : secondAttr.getString("name"));
String secondName = secondAttr.getString("newName") != null ? secondAttr.getString("newName") : (secondAttr.getString("calName") != null ? secondAttr.getString("calName") : secondAttr.getString("name"));
secondName = filterBanWordsList(filterWordArray, secondName, true);
if (ObjectUtil.isNotEmpty(secondAttr) && ObjectUtil.isNull(secondName)) {
@ -1789,8 +1725,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
boolean checkBuidSkuCondition = checkBuildSkuCondition(skuPropStr, cAv, sAv);
if (checkBuidSkuCondition) {
String sourceSkuCode = skuInfo.containsKey("skuCode") ? skuInfo.getString("skuCode") : "";
skuCode = skuInfo.containsKey("newSkuCode") ? skuInfo.getString("newSkuCode") :
(skuInfo.containsKey("calSkuCode") ? skuInfo.getString("calSkuCode") : sourceSkuCode);
skuCode = skuInfo.containsKey("newSkuCode") ? skuInfo.getString("newSkuCode") : (skuInfo.containsKey("calSkuCode") ? skuInfo.getString("calSkuCode") : sourceSkuCode);
break;
}
}
@ -2994,7 +2929,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
@Override
protected void rollbackRedisKey(RedisKeyBO redisKeyBO) {
redisService.push(redisKeyBO.getKey(), String.valueOf(redisKeyBO.getValue()));
//redisService.push(redisKeyBO.getKey(), String.valueOf(redisKeyBO.getValue()));
}
private MoveProductPublishQueueBO lockProductPublishQueue(RedisKeyBO redisKeyBO) {
@ -3010,6 +2945,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
MoveProductPublishQueue moveProductPublishQueue = new MoveProductPublishQueue();
moveProductPublishQueue.setMoveCollectTaskDetailId(taskDetailId);
moveProductPublishQueue.setLocked(1);
moveProductPublishQueue.setGmtLastHeartbeat(new Date());
moveProductPublishQueue.setGmtLocked(new Date());
moveProductPublishQueue.setGmtModified(new Date());
int affectRows = moveProductPublishQueueService.updateByMoveCollectTaskDetailIdForUnlock(moveProductPublishQueue);

@ -1,13 +1,13 @@
#本地端口
server.port=9090
#server.port=9090
#开发库
spring.datasource.url=jdbc:mysql://rm-2ze492h01b2j0i718mo.mysql.rds.aliyuncs.com:3306/dd_light_ds_dev2?characterEncoding=utf-8&useSSL=false
spring.redis.database=10
#spring.datasource.url=jdbc:mysql://rm-2ze492h01b2j0i718mo.mysql.rds.aliyuncs.com:3306/dd_light_ds_dev2?characterEncoding=utf-8&useSSL=false
#spring.redis.database=10
#测试库
#spring.datasource.url=jdbc:mysql://rm-2ze492h01b2j0i718mo.mysql.rds.aliyuncs.com:3306/dd_light_ds_dev?characterEncoding=utf-8&useSSL=false
#spring.redis.database=0
spring.datasource.url=jdbc:mysql://rm-2ze492h01b2j0i718mo.mysql.rds.aliyuncs.com:3306/dd_light_ds_dev?characterEncoding=utf-8&useSSL=false
spring.redis.database=0
#=================测试环境
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -9,7 +9,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(scanBasePackages = {"com.ms","com.jinritemai"})
@MapperScan("com.ms.dal.mapper")
@EnableAsync
//@EnableScheduling
@EnableScheduling
public class MsApplication {
public static void main(String[] args) {

Loading…
Cancel
Save