From e99b35b0a72d553e30c15fadd64f517877cc1623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cxxxxxxx=E8=AF=A6?= <286460656@qq.com> Date: Fri, 15 Sep 2023 13:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8E=86=E5=8F=B2=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ms/api/biz/MoveService.java | 88 +++++++++++++++++++ .../com/ms/api/consts/ProductStatusConst.java | 15 ++++ .../move/BatchDeleteTaskDetailService.java | 38 +++++--- .../ProcessMovePublishToPicTaskService.java | 84 +----------------- 4 files changed, 130 insertions(+), 95 deletions(-) create mode 100644 ms-biz/src/main/java/com/ms/api/consts/ProductStatusConst.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 1c85842d..13a70f96 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 @@ -10,6 +10,8 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -29,6 +31,9 @@ import com.doudian.open.api.material_getFolderInfo.data.ChildFolderItem; import com.doudian.open.api.material_getFolderInfo.data.MaterialGetFolderInfoData; import com.doudian.open.api.material_getFolderInfo.param.MaterialGetFolderInfoParam; import com.doudian.open.api.product_addV2.data.ProductAddV2Data; +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.ProductGetCatePropertyV2Request; import com.doudian.open.api.product_getCatePropertyV2.ProductGetCatePropertyV2Response; import com.doudian.open.api.product_getCatePropertyV2.param.ProductGetCatePropertyV2Param; @@ -1306,4 +1311,87 @@ public class MoveService { return CommonTool.successResult("data", response.getData()); } + + private Ret getProductFromDdRequest(long productId, AccessToken accessToken) { + if (productId == 0) { + return CommonTool.failResult("请传有效的product_id或有效的out_product_id"); + } + ProductDetailRequest request = new ProductDetailRequest(); + ProductDetailParam param = request.getParam(); + param.setProductId(String.valueOf(productId)); + ProductDetailResponse response = request.execute(accessToken); + Ret checkRet = CommonTool.checkDdApiRetStatus(response); + if (CommonTool.isFailRet(checkRet)) { + return checkRet; + } + + return CommonTool.successResult("data", response.getData()); + } + + public Ret getProductFromDd(long productId, AccessToken accessToken) { + if (productId == 0) { + return CommonTool.failResult("商品id不能为空"); + } + Ret ret = null; + for (int tryTimes = 0; tryTimes < 3; tryTimes++) { + ret = getProductFromDdRequest(productId, accessToken); + //这种情况是抖店后端超时,直接重试 + Pattern pattern = Pattern.compile("系统错误读取(.*)失败", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + Matcher matcher = pattern.matcher(ret.getReason()); + if (CommonTool.isFailRet(ret) && matcher.find()) { + continue; + } + + if (CommonTool.isFailRet(ret) && (ret.getCode().equals(30001) || ret.getReason().contains("授权已被关闭"))) { + return ret; + } + break; + } + + if (CommonTool.isFailRet(ret)) { + return ret; + } + + // TODO + //dd 返回字段首字母大写,全部转成小写处理。 +// JSONObject product = (JSONObject)ret.getData().get("data"); + +// $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'])); +// } + + return CommonTool.successResult("product", ret.getData()); + } } diff --git a/ms-biz/src/main/java/com/ms/api/consts/ProductStatusConst.java b/ms-biz/src/main/java/com/ms/api/consts/ProductStatusConst.java new file mode 100644 index 00000000..700c3671 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/consts/ProductStatusConst.java @@ -0,0 +1,15 @@ +package com.ms.api.consts; + +import java.util.Arrays; +import java.util.List; + +public class ProductStatusConst { + public static final Integer onSale = 0; + public static final Integer unOnSale = 99; + public static final Integer forSale = 1; + public static final Integer recycleBin = 2; +// public static final Integer delete = -2; + public static final Integer checkSuccess = 3; + public static final Integer checkBlocked = 5; + public static final Integer checkDrafts = 1; +} diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/BatchDeleteTaskDetailService.java b/ms-biz/src/main/java/com/ms/api/spi/move/BatchDeleteTaskDetailService.java index 1cc0b5cf..9cdf1d4d 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/BatchDeleteTaskDetailService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/BatchDeleteTaskDetailService.java @@ -10,10 +10,12 @@ 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.TaskDetailService; import com.ms.api.common.R; import com.ms.api.common.Ret; import com.ms.api.common.SPIBaseService; +import com.ms.api.consts.ProductStatusConst; import com.ms.api.consts.StatusConst; import com.ms.api.dto.move.BatchDeleteTaskDetailRequestDTO; import com.ms.api.service.MoveCollectTaskDetailService; @@ -48,11 +50,14 @@ public class BatchDeleteTaskDetailService extends SPIBaseService implements Exte @Autowired private TaskDetailService taskDetailService; + @Autowired + private MoveService moveService; + @Override public BaseResponse handle(BaseRequest req) { initHandle(req); // ----参数校验---- - BatchDeleteTaskDetailRequestDTO fields = req.getData(); + BatchDeleteTaskDetailRequestDTO fields = req.getData(); int deleteProduct = fields.getDeleteProduct(); int deleteOnSaleProduct = fields.getDeleteOnSaleProduct(); // ----业务处理---- @@ -68,7 +73,7 @@ public class BatchDeleteTaskDetailService extends SPIBaseService implements Exte int delSuccessNum = 0; int delDdSuccessNum = 0; - for (int i=0; i < moveCollectTaskDetailList.size(); i++) { + for (int i = 0; i < moveCollectTaskDetailList.size(); i++) { MoveCollectTaskDetail taskDetail = moveCollectTaskDetailList.get(i); Long detailId = taskDetail.getMoveCollectTaskDetailId(); if (deleteProduct > 0 && Objects.isNull(moveProductLogMap.get(detailId))) { @@ -83,16 +88,25 @@ public class BatchDeleteTaskDetailService extends SPIBaseService implements Exte // if (CommonTool::isSuccessRet($ret) && (in_array($ret['product']['status'], [ProductStatusConst::onSale]))) { // needDeleteToDd = false; // } - ProductDetailRequest request = new ProductDetailRequest(); - ProductDetailParam param = request.getParam(); - param.setProductId(productId.toString()); - ProductDetailResponse response = request.execute(); - if (!response.getCode().equals("10000")) { - needDeleteToDd = false; - } - if (response.getCode().equals("10000") && (response.getData().getStatus() == 0)) { - needDeleteToDd = false; - } + Ret getProductDetailRet = moveService.getProductFromDd(productId, shopInfo.getShopAccessToken()); + if (CommonTool.isFailRet(getProductDetailRet)) { + needDeleteToDd = false; + } + Integer[] statusArray = {ProductStatusConst.onSale}; + if (CommonTool.isSuccessRet(getProductDetailRet) && Arrays.toString(statusArray).contains(getProductDetailRet.getData().get("product").toString())) { + needDeleteToDd = false; + } + + ProductDetailRequest request = new ProductDetailRequest(); + ProductDetailParam param = request.getParam(); + param.setProductId(productId.toString()); + ProductDetailResponse response = request.execute(); + if (!response.getCode().equals("10000")) { + needDeleteToDd = false; + } + if (response.getCode().equals("10000") && (response.getData().getStatus() == 0)) { + needDeleteToDd = false; + } } 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 7db09ea5..38475412 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 @@ -1827,7 +1827,7 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { Ret getProductDetailRet; do { tryTimes--; - getProductDetailRet = getProductFromDd(productId, accessToken); + getProductDetailRet = moveService.getProductFromDd(productId, accessToken); if (CommonTool.isFailRet(getProductDetailRet)) { if (isProductDeletedReason(getProductDetailRet.getReason())) { break; @@ -1846,88 +1846,6 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService { return reason.contains("商品不存在"); } - private Ret getProductFromDd(long productId, AccessToken accessToken) { - if (productId == 0) { - return CommonTool.failResult("商品id不能为空"); - } - Ret ret = null; - for (int tryTimes = 0; tryTimes < 3; tryTimes++) { - ret = getProductFromDdRequest(productId, accessToken); - //这种情况是抖店后端超时,直接重试 - Pattern pattern = Pattern.compile("系统错误读取(.*)失败", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); - Matcher matcher = pattern.matcher(ret.getReason()); - if (CommonTool.isFailRet(ret) && matcher.find()) { - continue; - } - - if (CommonTool.isFailRet(ret) && (ret.getCode().equals(30001) || ret.getReason().contains("授权已被关闭"))) { - return ret; - } - break; - } - - if (CommonTool.isFailRet(ret)) { - return ret; - } - - // TODO - //dd 返回字段首字母大写,全部转成小写处理。 -// JSONObject product = (JSONObject)ret.getData().get("data"); - -// $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'])); -// } - - return CommonTool.successResult("product", ret.getData()); - } - - private Ret getProductFromDdRequest(long productId, AccessToken accessToken) { - if (productId == 0) { - return CommonTool.failResult("请传有效的product_id或有效的out_product_id"); - } - ProductDetailRequest request = new ProductDetailRequest(); - ProductDetailParam param = request.getParam(); - param.setProductId(String.valueOf(productId)); - ProductDetailResponse response = request.execute(accessToken); - Ret checkRet = CommonTool.checkDdApiRetStatus(response); - if (CommonTool.isFailRet(checkRet)) { - return checkRet; - } - - return CommonTool.successResult("data", response.getData()); - } private void deleteQueueMsg(MoveProductPublishToPicQueueBO queueMsg) { moveProductPublishToPicQueueService.deleteByPrimaryKey((long) queueMsg.getMoveProductPublishToPicQueueId());