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