Merge remote-tracking branch 'origin/master'

20230922-ljl-fixBug
daixiaogang 1 year ago
commit 7ae382201e

@ -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("参数错误");

@ -7,6 +7,7 @@ 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.biz.MoveService;
import com.ms.api.biz.SaveBatchMoveTaskBizService;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
@ -43,7 +44,8 @@ public class MoveAgainDetailService extends SPIBaseService implements ExtensionS
private MoveCollectTaskDetailService moveCollectTaskDetailService;
@Autowired
private ShopService shopService;
private MoveService moveService;
@Override
public BaseResponse<Ret> handle(BaseRequest<MoveAgainDetailRequestDTO> req) {
@ -56,7 +58,7 @@ public class MoveAgainDetailService extends SPIBaseService implements ExtensionS
int size = taskDetailIds.size();
if (size == 1) {
Long lastDetails = taskDetailIds.get(0);
Long newDetailId = this.moveAgainDetailsByDetailId(shopId, lastDetails, null);
Long newDetailId = moveService.moveAgainDetailsByDetailId(shopId, lastDetails);
if (newDetailId != null && newDetailId != 0) {
JSONObject retObj = new JSONObject();
retObj.put("processCount", 1);
@ -65,73 +67,10 @@ public class MoveAgainDetailService extends SPIBaseService implements ExtensionS
return R.ok(Ret.fail("当前商品数据已失效,暂不支持操作,如有疑问请联系客服"));
}
} else {
// todo:
// todo: 批量
}
// ----结果返回----
return R.fail("111");
return R.ok(Ret.success());
}
private Long moveAgainDetailsByDetailId(Long shopId, Long detailId, Long cnaliDetailId) {
MoveCollectTaskDetail moveDetail = moveCollectTaskDetailService.getMoveCollectTaskDetail(shopId, detailId);
if (moveDetail == null) {
return null;
}
int needAddCnt = 1;
if (cnaliDetailId != null) {
needAddCnt = 0;
}
Ret checkAndGetConfigIdRet = saveBatchMoveTaskBizService.checkAvailableCopyAndGetMoveConfigId(shopId, needAddCnt);
if (checkAndGetConfigIdRet.getResult().equals("fail")) {
return null;
}
Integer 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());
boolean addRet = addMoveTaskDetail(shopId, taskDetailData, insertPublishBuffer, moveShopConfigId, detailId);
if (!addRet) {
return null;
}
return detailId;
}
private boolean addMoveTaskDetail(Long shopId, MoveCollectTaskDetail taskDetailData, MoveProductPublishBuffer insertPublishBuffer, Integer moveShopConfigId, Long detailId) {
// todo:
return true;
}
}

@ -0,0 +1,30 @@
package com.ms.dal.bo;
import com.ms.dal.entity.MoveCollectTaskDetail;
import com.ms.dal.entity.MoveShopSetting;
import lombok.Data;
@Data
public class CollectTaskDetailBO extends MoveCollectTaskDetail {
// /**
// * move_collect_task_id
// */
// private Integer moveCollectTaskId;
/**
* name
*/
private String name;
/**
* copy_type
*/
private String copyType;
/**
* condition
*/
private String conditionStr;
private MoveShopSetting condition;
}

@ -1,5 +1,6 @@
package com.ms.dal.mapper;
import com.ms.dal.bo.CollectTaskDetailBO;
import com.ms.dal.entity.MoveCollectTaskDetail;
import org.apache.ibatis.annotations.Mapper;
@ -32,4 +33,6 @@ public interface MoveCollectTaskDetailMapper {
List<Long> getMoveDetailIdsByStatus(Long shopId, String status);
MoveCollectTaskDetail getMoveCollectTaskDetail(Long shopId,Long moveCollectTaskDetailId);
CollectTaskDetailBO getCollectTaskDetail(Long collectTaskDetailId);
}

@ -31,6 +31,13 @@
<result property="productId" column="product_id" jdbcType="BIGINT"/>
</resultMap>
<resultMap id="QOResultMap" type="com.ms.dal.bo.CollectTaskDetailBO" extends="BaseResultMap">
<result property="moveCollectTaskId" column="move_collect_task_id"/>
<result property="name" column="name"/>
<result property="conditionStr" column="condition_str"/>
<result property="copyType" column="copy_type"/>
</resultMap>
<sql id="Base_Column_List">
move_collect_task_detail_id,shop_id,move_collect_task_id,
is_fast_mode,move_shop_config_id,source,
@ -46,12 +53,12 @@
select
<include refid="Base_Column_List" />
from move_collect_task_detail
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from move_collect_task_detail
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
</delete>
<insert id="insert" keyColumn="move_collect_task_detail_id" keyProperty="moveCollectTaskDetailId" parameterType="com.ms.dal.entity.MoveCollectTaskDetail" useGeneratedKeys="true">
insert into move_collect_task_detail
@ -195,11 +202,11 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
</set>
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.MoveCollectTaskDetail">
update move_collect_task_detail
set
set
shop_id = #{shopId,jdbcType=BIGINT},
move_collect_task_id = #{moveCollectTaskId,jdbcType=BIGINT},
is_fast_mode = #{isFastMode,jdbcType=TINYINT},
@ -222,7 +229,7 @@
publish_wait_seconds = #{publishWaitSeconds,jdbcType=INTEGER},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT}
</update>
<select id="getMoveCollectTaskList" resultMap="BaseResultMap">
select a.*,b.product_id
@ -266,4 +273,9 @@
from move_collect_task_detail
where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} and shop_id = #{shopId,jdbcType=BIGINT}
</select>
<select id="getCollectTaskDetail" resultMap="QOResultMap">
SELECT ct.move_collect_task_id, ct.name, ct.condition as condition_str , ct.copy_type, ctd.*
FROM move_collect_task_detail ctd LEFT JOIN move_collect_task ct ON ct.move_collect_task_id = ctd.move_collect_task_id
WHERE ctd.move_collect_task_detail_id = #{collectTaskDetailId,jdbcType=BIGINT}
</select>
</mapper>

Loading…
Cancel
Save