From 968108c56fc54976b61ab04ac098f0b4a50fe987 Mon Sep 17 00:00:00 2001 From: daixiaogang <2510234660@qq.com> Date: Wed, 13 Sep 2023 14:06:18 +0800 Subject: [PATCH 1/4] rebuildAddRetReason --- .../main/java/com/ms/api/biz/MoveService.java | 28 +++ .../java/com/ms/api/consts/MoveConst.java | 2 +- .../ProcessMovePublishToPicTaskService.java | 180 ++++++++++++------ .../ProcessProductPublishTaskService.java | 27 +-- 4 files changed, 154 insertions(+), 83 deletions(-) diff --git a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java index 2703e1ba..c09370a0 100644 --- a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java +++ b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java @@ -12,6 +12,9 @@ import java.util.stream.Collectors; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.product_getCatePropertyV2.ProductGetCatePropertyV2Request; +import com.doudian.open.api.product_getCatePropertyV2.ProductGetCatePropertyV2Response; +import com.doudian.open.api.product_getCatePropertyV2.param.ProductGetCatePropertyV2Param; import com.doudian.open.api.product_getProductUpdateRule.data.FulfillmentRule; import com.doudian.open.api.product_getProductUpdateRule.data.NormalRule; import com.doudian.open.api.product_getProductUpdateRule.data.ProductGetProductUpdateRuleData; @@ -28,6 +31,7 @@ import com.ms.api.consts.MoveConst; import com.ms.api.tool.CommonTool; import com.ms.api.util.DdRequestUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @Slf4j @@ -341,4 +345,28 @@ public class MoveService { return uniqueUrls.stream().filter(url -> url != null && !url.isEmpty()).collect(Collectors.toList()); } + public Ret getCategoryAttrV2FromDd(String cid, AccessToken accessToken) { + if (StringUtils.isBlank(cid)) { + return CommonTool.failResult("参数错误"); + } + + // TODO存取添加缓存 +// $accessTokenSecret = md5($accessToken); +// if ($useCache && ($cache = $this->getCategoryAttrV2FromCache($cid, $accessTokenSecret))) { +// return CommonTool::successResult($cache); +// } + + ProductGetCatePropertyV2Request request = new ProductGetCatePropertyV2Request(); + ProductGetCatePropertyV2Param param = request.getParam(); + param.setCategoryLeafId(Long.valueOf(cid)); + ProductGetCatePropertyV2Response response = request.execute(accessToken); + Ret checkRet = CommonTool.checkDdApiRetStatus(response); + if (CommonTool.isFailRet(checkRet)) { + return checkRet; + } + +// $this->setCategoryAttrV2Cache($cid, $ret['data'], $accessTokenSecret); + + return CommonTool.successResult("data", response.getData()); + } } diff --git a/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java b/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java index 234b7202..2885ebbb 100644 --- a/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java +++ b/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java @@ -102,7 +102,7 @@ public class MoveConst { public static String aliPriceTypeConfig = "config"; public static String collectTaskSource1688 = "1688"; public static String proxyPlatformTypePicUrl = "picUrl"; - + public static String brandEmpty = "empty"; public static List getSpecialBanWordList() { List result = new ArrayList(); result.add("特价"); diff --git a/ms-biz/src/main/java/com/ms/api/task/ProcessMovePublishToPicTaskService.java b/ms-biz/src/main/java/com/ms/api/task/ProcessMovePublishToPicTaskService.java index 290af812..5f7250f7 100644 --- a/ms-biz/src/main/java/com/ms/api/task/ProcessMovePublishToPicTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/ProcessMovePublishToPicTaskService.java @@ -1,6 +1,21 @@ package com.ms.api.task; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +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.util.ObjectUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.doudian.open.api.product_addV2.ProductAddV2Request; import com.doudian.open.api.product_addV2.ProductAddV2Response; @@ -11,20 +26,50 @@ import com.doudian.open.api.product_addV2.param.RecruitInfo; import com.doudian.open.api.product_detail.ProductDetailRequest; import com.doudian.open.api.product_detail.ProductDetailResponse; import com.doudian.open.api.product_detail.param.ProductDetailParam; +import com.doudian.open.api.product_getCatePropertyV2.data.DataItem; +import com.doudian.open.api.product_getCatePropertyV2.data.ProductGetCatePropertyV2Data; import com.doudian.open.core.AccessToken; import com.ms.api.biz.MoveService; import com.ms.api.bo.MoveProductPublishToPicQueueBO; import com.ms.api.bo.MoveShopSettingBO; -import com.ms.api.common.*; -import com.ms.api.consts.*; +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.paas.RedisService; import com.ms.api.paas.StorageService; -import com.ms.api.service.*; +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.ProductToDsItemService; +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.SecurityTool; import com.ms.api.util.MoveUtil; -import com.ms.dal.entity.*; +import com.ms.dal.entity.DsRelateProductAnalysisOpOrderQueue; +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.MoveProductLog; +import com.ms.dal.entity.MoveProductPublishToPicQueue; +import com.ms.dal.entity.ProductToDsItem; +import com.ms.dal.entity.Shop; +import com.ms.dal.entity.Shop1688DsAuth; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -33,15 +78,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -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; /** * @@ -254,7 +290,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { JSONObject productDetailBase = data.getJSONObject("productDetailBase"); JSONObject sourceProductData = data.getJSONObject("sourceProductData"); JSONObject moveBaseData = data.getJSONObject("moveBaseData"); - JSONObject brandList = data.getJSONObject("brandList"); + JSONArray brandList = data.getJSONArray("brandList"); AccessToken accessToken = getShopAccessToken(shopId); // 检查详情图片数量和长度 productDetailBase.put("noteImgUrls", filterNoteImgUrls((String) productDetailBase.get("noteImgUrls"))); @@ -298,7 +334,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { return mAccessToken; } - private Ret createProduct(JSONObject productDetailBase, JSONObject sourceProductData, MoveShopSettingBO condition, MoveProductPublishToPicQueueBO queueMsg, JSONObject moveBaseData, JSONObject brandList, AccessToken accessToken) { + private Ret createProduct(JSONObject productDetailBase, JSONObject sourceProductData, MoveShopSettingBO condition, MoveProductPublishToPicQueueBO queueMsg, JSONObject moveBaseData, JSONArray brandList, AccessToken accessToken) { long shopId = queueMsg.getShopId(); Ret addRet = postDataToDdV2(productDetailBase, condition, queueMsg, moveBaseData, accessToken); // TODO 几个方法的实现 @@ -338,47 +374,80 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { } // TODO - private Ret rebuildAddRetReason(Ret addRet, JSONObject brandList, MoveShopSettingBO condition, String cid, AccessToken accessToken) { - - // if (strpos($addRet['reason'], '请重新选择品牌') !== false || strpos($addRet['reason'], '该类目下无品牌') !== false || strpos($addRet['reason'], '品牌不属于该类目') !== false) { -// if (is_numeric($condition['brandId'])) { -// $brandMap = array_column($brandList, null, 'id'); -// $brandId = $condition['brandId']; -// $brandName = $brandMap[$brandId]['brand_chinese_name'] ? $brandMap[$brandId]['brand_chinese_name'] : $brandMap[$brandId]['brand_english_name']; -// $addRet['reason'] = "当前类目无 $brandName 品牌权限,请前往店铺后台申请品牌,立即申请"; -// return $addRet; -// } else if ($condition['brandId'] == MoveConst::brandEmpty) { -// $addRet['reason'] = '当前类目品牌必填,请前往店铺后台申请品牌,立即申请
您在搬家配置设置“品牌留空”。若您已经申请品牌,请修改搬家配置,若没有申请品牌,请前往店铺后台申请品牌'; -// return $addRet; -// } else if (empty($brandList)) { -// $addRet['reason'] = '当前类目品牌必填,请前往店铺后台申请品牌,立即申请'; -// return $addRet; -// } else if (count($brandList)) { -// $brandNames = []; -// foreach ($brandList as $brand) { -// $brandNames[] = $brand['brand_chinese_name'] ? $brand['brand_chinese_name'] : $brand['brand_english_name']; -// } -// $addRet['reason'] = '当前类目无"'. implode(',', $brandNames) .'"品牌权限,请前往店铺后台申请品牌,立即申请'; -// return $addRet; -// } -// } -// -// if (strpos($addRet['reason'], '没有品牌资质,非普通店商品请使用有资质的品牌') !== false) { -// return $this->rebuildAddRetBrandQualificationReason($addRet, $brandList, $cid, $accessToken); -// } -// -// if (strpos($addRet['reason'], '颜色对应的规格值不能重复,请核对') !== false) { -// $addRet['reason'] = $addRet['reason'] . ',请检查是否包含特殊符号或违禁词(' . implode(',', MoveConst::getSpecialBanWordList()) . ')'; -// } -// -// if (preg_match('/规格值含有敏感词(?::|:)\[([^\]]+)\]/', $addRet['reason'], $matchBanWord) || preg_match('/商品规格值描述“(.*)”不符合平台要求/', $addRet['reason'], $matchBanWord)) { -// $addRet['reason'] = $addRet['reason'] . ',并且过滤后会导致sku规格值重复,请检查并手动修改'; -// } -// -// return $addRet; + private Ret rebuildAddRetReason(Ret addRet, JSONArray brandList, MoveShopSettingBO condition, String cid, AccessToken accessToken) { + + if (addRet.getReason().contains("请重新选择品牌") || addRet.getReason().contains("该类目下无品牌") || addRet.getReason().contains("品牌不属于该类目")) { + if (StringUtils.isNumeric(condition.getBrandId())) { + Map brandMap = brandList.stream().filter(x -> ((JSONObject) x).containsKey("id")).collect(Collectors.toMap(x -> ((JSONObject) x).getString("id"), x -> (JSONObject) x, (v1, v2) -> v1)); + JSONObject brand = brandMap.get(condition.getBrandId()); + String brandName = brand.getString("brand_chinese_name") != null ? brand.getString("brand_chinese_name") : brand.getString("brand_english_name"); + addRet.setReason("当前类目无 " + brandName + " 品牌权限,请前往店铺后台申请品牌,立即申请"); + return addRet; + } else if (Objects.equals(condition.getBrandId(), MoveConst.brandEmpty)) { + addRet.setReason("当前类目品牌必填,请前往店铺后台申请品牌,立即申请
您在搬家配置设置“品牌留空”。若您已经申请品牌,请修改搬家配置,若没有申请品牌,请前往店铺后台申请品牌"); + return addRet; + } else if (brandList.isEmpty()) { + addRet.setReason("当前类目品牌必填,请前往店铺后台申请品牌,立即申请"); + return addRet; + } else if (brandList.size() != 0) { + List brandNames = brandList.stream().map(x -> { + JSONObject temp = (JSONObject) x; + return temp.containsKey("brand_chinese_name") ? temp.getString("brand_chinese_name") : temp.getString("brand_english_name"); + }).collect(Collectors.toList()); + addRet.setReason("当前类目无\"" + String.join(",", brandNames) + "\"品牌权限,请前往店铺后台申请品牌,立即申请"); + return addRet; + } + } + + if (addRet.getReason().contains("没有品牌资质,非普通店商品请使用有资质的品牌")) { + return rebuildAddRetBrandQualificationReason(addRet, brandList, cid, accessToken); + } + + if (addRet.getReason().contains("颜色对应的规格值不能重复,请核对")) { + addRet.setReason(addRet.getReason() + ",请检查是否包含特殊符号或违禁词(" + String.join(",", MoveConst.getSpecialBanWordList()) + ")"); + } + + Matcher matcherBanWord = Pattern.compile("规格值含有敏感词(?::|:)\\[([^\\]]+)\\]").matcher(addRet.getReason()); + Matcher matcherBanWordDescription = Pattern.compile("商品规格值描述“(.*)”不符合平台要求").matcher(addRet.getReason()); + if (matcherBanWord.matches() || matcherBanWordDescription.matches()) { + addRet.setReason(addRet.getReason() + ",并且过滤后会导致sku规格值重复,请检查并手动修改"); + } + return addRet; } + private Ret rebuildAddRetBrandQualificationReason(Ret addRet, JSONArray brandList, String cid, AccessToken accessToken) { + Ret categoryAttrRet = moveService.getCategoryAttrV2FromDd(cid, accessToken); + if (CommonTool.isFailRet(categoryAttrRet)) { + return addRet; + } + boolean isNeedCheckShopBrand = checkIsNeedShopBrand((ProductGetCatePropertyV2Data) categoryAttrRet.getData().get("data")); + if (!isNeedCheckShopBrand) { + return addRet; + } + if (!brandList.isEmpty()) { + addRet.setReason("当前商品发布的类目未申请品牌资质,请到店铺后台申请品牌资质,前往申请"); + } + return addRet; + } + + private boolean checkIsNeedShopBrand(ProductGetCatePropertyV2Data data) { + List attrs = data.getData(); + boolean isNeed = false; + for (DataItem attr : attrs) { + if (!"品牌".equals(attr.getPropertyName())) { + continue; + } + if (ObjectUtil.isNotEmpty(attr.getRequired()) && attr.getRequired() != 0) { + break; + } + if (ObjectUtil.isEmpty(attr.getOptions())) { + isNeed = true; + } + } + return isNeed; + } + private void deleteShopCategoryBrand(long shopId, JSONObject productDetailBase, Ret addRet) { // if(CommonTool::isSuccessRet($addProductRet)) { // return ; @@ -457,7 +526,6 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { return addRet; } - private StrObjMap processAddProductError(long shopId, JSONObject productDetailBase, MoveShopSettingBO condition, MoveProductPublishToPicQueueBO queueMsg, JSONObject moveBaseData, String reason, int i, AccessToken accessToken) { boolean dataIsChange = false; // @@ -521,7 +589,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { String title = productData.getString("title"); if (!Objects.isNull(title)) { - param.setName(title.substring(0, Math.min(title.length(), 10))); + param.setName(title.substring(0, Math.min(title.length(), 10))); } String mainImgUrls = productData.getString("mainImgUrls"); @@ -590,7 +658,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { // Object productFormatNew = productData.get("productFormatNew"); // if (!Objects.isNull(productFormatNew)) { // param.setProductFormatNew(JSON.toJSONString(productFormatNew)); - param.setProductFormatNew("{\"631\":[{\"diy_type\":1,\"name\":\"嘻哈风\",\"value\":196227}],\"1467\":[{\"diy_type\":0,\"name\":\"59%-69%(含)\",\"value\":168368}],\"1551\":[{\"diy_type\":1,\"name\":\"超短裙\",\"value\":22064}],\"1687\":[{\"diy_type\":0,\"name\":\"改为具体的品牌,没有可以为空\",\"value\":0}],\"1878\":[{\"diy_type\":1,\"name\":\"高腰\",\"value\":16521}],\"2592\":[{\"diy_type\":1,\"name\":\"甜美\",\"value\":23925}],\"785\":[{\"diy_type\":0,\"name\":\"涤纶\",\"value\":25708}],\"813\":[{\"diy_type\":1,\"name\":\"X型\",\"value\":8017}],\"981\":[{\"diy_type\":1,\"name\":\"蛋糕裙\",\"value\":22253}]}"); + param.setProductFormatNew("{\"631\":[{\"diy_type\":1,\"name\":\"嘻哈风\",\"value\":196227}],\"1467\":[{\"diy_type\":0,\"name\":\"59%-69%(含)\",\"value\":168368}],\"1551\":[{\"diy_type\":1,\"name\":\"超短裙\",\"value\":22064}],\"1687\":[{\"diy_type\":0,\"name\":\"改为具体的品牌,没有可以为空\",\"value\":0}],\"1878\":[{\"diy_type\":1,\"name\":\"高腰\",\"value\":16521}],\"2592\":[{\"diy_type\":1,\"name\":\"甜美\",\"value\":23925}],\"785\":[{\"diy_type\":0,\"name\":\"涤纶\",\"value\":25708}],\"813\":[{\"diy_type\":1,\"name\":\"X型\",\"value\":8017}],\"981\":[{\"diy_type\":1,\"name\":\"蛋糕裙\",\"value\":22253}]}"); // } // Long deliveryDelayDay = productData.getLong("deliveryDelayDay"); diff --git a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java index 956ec74d..e88ca194 100644 --- a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java @@ -1327,7 +1327,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService { moveBaseData.put("brandName", brandName); // 从抖店获取的类目属性 - Ret categoryAttrRet = getCategoryAttrV2FromDd(cid, accessToken); + Ret categoryAttrRet = moveService.getCategoryAttrV2FromDd(cid, accessToken); if (CommonTool.isFailRet(categoryAttrRet)) { return categoryAttrRet; } @@ -1457,31 +1457,6 @@ public class ProcessProductPublishTaskService extends TaskBaseService { return matchAttrs; } - private Ret getCategoryAttrV2FromDd(String cid, AccessToken accessToken) { - if (StringUtils.isBlank(cid)) { - return CommonTool.failResult("参数错误"); - } - - // TODO存取添加缓存 -// $accessTokenSecret = md5($accessToken); -// if ($useCache && ($cache = $this->getCategoryAttrV2FromCache($cid, $accessTokenSecret))) { -// return CommonTool::successResult($cache); -// } - - ProductGetCatePropertyV2Request request = new ProductGetCatePropertyV2Request(); - ProductGetCatePropertyV2Param param = request.getParam(); - param.setCategoryLeafId(Long.valueOf(cid)); - ProductGetCatePropertyV2Response response = request.execute(accessToken); - Ret checkRet = CommonTool.checkDdApiRetStatus(response); - if (CommonTool.isFailRet(checkRet)) { - return checkRet; - } - -// $this->setCategoryAttrV2Cache($cid, $ret['data'], $accessTokenSecret); - - return CommonTool.successResult("data", response.getData()); - } - private List matchSourceAttr(DataItem attribute, JSONObject sourceAttrs, String title) { List matchAttr; if (attribute.getType().equals(MoveConst.attrInputTypeText)) { From 050dda6a3b17fe8e1caffa54f38383c4e29e2403 Mon Sep 17 00:00:00 2001 From: wangchaoxu Date: Wed, 13 Sep 2023 14:23:57 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=90=AC=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ms/api/biz/MoveService.java | 194 ++++++++++++++++-- .../api/spi/move/MoveAgainDetailService.java | 73 +------ .../com/ms/dal/bo/CollectTaskDetailBO.java | 30 +++ .../mapper/MoveCollectTaskDetailMapper.java | 3 + .../mapper/MoveCollectTaskDetailMapper.xml | 22 +- 5 files changed, 237 insertions(+), 85 deletions(-) create mode 100644 ms-dal/src/main/java/com/ms/dal/bo/CollectTaskDetailBO.java diff --git a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java index 2703e1ba..5b689519 100644 --- a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java +++ b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java @@ -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_getProductUpdateRule.data.FulfillmentRule; @@ -17,23 +7,52 @@ 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.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; + + /** * 根据搬家配置,修改数据 * @@ -341,4 +360,153 @@ 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; + } + } diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/MoveAgainDetailService.java b/ms-biz/src/main/java/com/ms/api/spi/move/MoveAgainDetailService.java index 1c5d7e04..b553196a 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/MoveAgainDetailService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/MoveAgainDetailService.java @@ -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 handle(BaseRequest 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; - } - - } diff --git a/ms-dal/src/main/java/com/ms/dal/bo/CollectTaskDetailBO.java b/ms-dal/src/main/java/com/ms/dal/bo/CollectTaskDetailBO.java new file mode 100644 index 00000000..ee7f2e32 --- /dev/null +++ b/ms-dal/src/main/java/com/ms/dal/bo/CollectTaskDetailBO.java @@ -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; + +} diff --git a/ms-dal/src/main/java/com/ms/dal/mapper/MoveCollectTaskDetailMapper.java b/ms-dal/src/main/java/com/ms/dal/mapper/MoveCollectTaskDetailMapper.java index f5a73d88..563e7ec9 100644 --- a/ms-dal/src/main/java/com/ms/dal/mapper/MoveCollectTaskDetailMapper.java +++ b/ms-dal/src/main/java/com/ms/dal/mapper/MoveCollectTaskDetailMapper.java @@ -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 getMoveDetailIdsByStatus(Long shopId, String status); MoveCollectTaskDetail getMoveCollectTaskDetail(Long shopId,Long moveCollectTaskDetailId); + + CollectTaskDetailBO getCollectTaskDetail(Long collectTaskDetailId); } diff --git a/ms-dal/src/main/resources/mapper/MoveCollectTaskDetailMapper.xml b/ms-dal/src/main/resources/mapper/MoveCollectTaskDetailMapper.xml index b865db39..371e0d53 100644 --- a/ms-dal/src/main/resources/mapper/MoveCollectTaskDetailMapper.xml +++ b/ms-dal/src/main/resources/mapper/MoveCollectTaskDetailMapper.xml @@ -31,6 +31,13 @@ + + + + + + + move_collect_task_detail_id,shop_id,move_collect_task_id, is_fast_mode,move_shop_config_id,source, @@ -46,12 +53,12 @@ select from move_collect_task_detail - where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} + where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} delete from move_collect_task_detail - where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} + where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} insert into move_collect_task_detail @@ -195,11 +202,11 @@ gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, - where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} + where move_collect_task_detail_id = #{moveCollectTaskDetailId,jdbcType=BIGINT} 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} + From a39a7c76c5fad64df5b97c9dc01875db2ee72bd7 Mon Sep 17 00:00:00 2001 From: daixiaogang <2510234660@qq.com> Date: Wed, 13 Sep 2023 14:28:53 +0800 Subject: [PATCH 3/4] rebuildAddRetReason --- .../java/com/ms/api/bo/MoveProductPublishQueueBO.java | 2 ++ ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java | 2 ++ .../com/ms/api/task/ProcessProductPublishTaskService.java | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ms-biz/src/main/java/com/ms/api/bo/MoveProductPublishQueueBO.java b/ms-biz/src/main/java/com/ms/api/bo/MoveProductPublishQueueBO.java index 536625da..2382eb71 100644 --- a/ms-biz/src/main/java/com/ms/api/bo/MoveProductPublishQueueBO.java +++ b/ms-biz/src/main/java/com/ms/api/bo/MoveProductPublishQueueBO.java @@ -105,4 +105,6 @@ public class MoveProductPublishQueueBO { private StrObjMap skuPresellChildSkuDetail; + private Double hasImportPrice; + } diff --git a/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java b/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java index 28f88bab..3b3abd33 100644 --- a/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java +++ b/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java @@ -172,4 +172,6 @@ public class MoveShopSettingBO { private Integer resetSkuStockNum; private Integer resetSkuZeroStockNum; private Integer quantity; + + private String skuCodeRule; } diff --git a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java index e88ca194..32efd819 100644 --- a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java @@ -1995,7 +1995,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService { price = 0; } // TODO -// skuMap = appendSkuCode(moveBaseData, queueMsg, skuMap, itemNum); + skuMap = appendSkuCode(moveBaseData, queueMsg, skuMap, itemNum); // skuList = buildSkuListAndSkuImages(mSkus.getJSONObject() ['skuMap'], mSkus['colorMap'], mSkus['sizeMap'], condition, (price > 0 ? price : queueMsg.getPrice()), queueMsg.getShopId()); // skuList = calSkuPriceByCondition($isFastMode, $skuList, $condition['price'], $moveBaseData, $cnaliDsDetailId, $hasImportPrice); // updateSkuMinPriceInfo = getUpdateSkuMinPriceInfo($condition['price'], $skuList); @@ -2009,6 +2009,12 @@ public class ProcessProductPublishTaskService extends TaskBaseService { return result; } + private JSONObject appendSkuCode(JSONObject moveBaseData, MoveProductPublishQueueBO queueMsg, JSONObject skuList, String itemNum) { + MoveShopSettingBO condition = queueMsg.getCondition(); + + return null; + } + private JSONObject resetSkuStock(MoveShopSettingBO condition, JSONObject skuMap, int isFastMode) { if (isFastMode == 0) { return skuMap; From 951d60ecd6b7e81eddfb6cac72431b7a8b5786eb Mon Sep 17 00:00:00 2001 From: daixiaogang <2510234660@qq.com> Date: Wed, 13 Sep 2023 14:39:33 +0800 Subject: [PATCH 4/4] getShopSettingSizeTemplateIdByCid --- ms-biz/src/main/java/com/ms/api/biz/MoveService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java index c6fd3eb4..bea9e884 100644 --- a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java +++ b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java @@ -326,14 +326,19 @@ public class MoveService { } if (sizeTemplateIdObj instanceof String) { long cid = moveBaseData.getLong("cid"); + long commonTemplateId = 0; // TODO 这里可能不需要 -// sizeTemplateId = $this->moveService->getShopSettingSizeTemplateIdByCid($shopId, $condition['moveShopSettingId'], $cid, $commonTemplateId); + sizeTemplateId = getShopSettingSizeTemplateIdByCid(shopId, condition.getMoveShopSettingId(), cid, commonTemplateId); } else { sizeTemplateId = (int) sizeTemplateIdObj; } return sizeTemplateId; } + private int getShopSettingSizeTemplateIdByCid(long shopId, Integer moveShopSettingId, long cid, long commonTemplateId) { + return 0; + } + public List getMovePublishAllImgs(JSONObject productDetailBase) { List imgUrls = new ArrayList<>(); imgUrls.addAll(Arrays.asList(((String) productDetailBase.getOrDefault("mainImgUrls", "")).split("\\|")));