|
|
|
@ -270,6 +270,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
MoveProductPublishQueueBO queueMsg = (MoveProductPublishQueueBO) getTaskRet.getQueueMsg();
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
long shopId = queueMsg.getShopId();
|
|
|
|
|
AuthThreadLocalUtil.set(String.valueOf(shopId));
|
|
|
|
|
MoveShopSettingBO condition = queueMsg.getCondition();
|
|
|
|
|
|
|
|
|
|
// 获取源产品数据
|
|
|
|
@ -292,9 +293,8 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
|
|
|
|
|
// 修改为抖店要求的参数
|
|
|
|
|
JSONObject moveBaseData = (JSONObject) processRet.getData().get("moveBaseData");
|
|
|
|
|
AccessToken accessToken = getShopAccessToken(shopId);
|
|
|
|
|
AuthThreadLocalUtil.set(String.valueOf(shopId));
|
|
|
|
|
Ret ret = buildCreateProductV2Data(moveBaseData, queueMsg, accessToken, condition);
|
|
|
|
|
|
|
|
|
|
Ret ret = buildCreateProductV2Data(moveBaseData, queueMsg, condition);
|
|
|
|
|
if (CommonTool.isFailRet(ret)) {
|
|
|
|
|
ret.setQueueMsg(queueMsg);
|
|
|
|
|
return ret;
|
|
|
|
@ -304,7 +304,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
StrObjMap brandList = (StrObjMap) ret.getData().get("'brandList'");
|
|
|
|
|
|
|
|
|
|
// 图片处理 这边会加入到素材的buffer
|
|
|
|
|
Ret processImgsRet = processAndUploadMoveProductImgs(shopId, queueMsg, productDetailBase, moveBaseData, condition, accessToken);
|
|
|
|
|
Ret processImgsRet = processAndUploadMoveProductImgs(shopId, queueMsg, productDetailBase, moveBaseData, condition);
|
|
|
|
|
if (CommonTool.isFailRet(processImgsRet)) {
|
|
|
|
|
processImgsRet.setQueueMsg(queueMsg);
|
|
|
|
|
return processImgsRet;
|
|
|
|
@ -334,16 +334,16 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return processTaskRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret processAndUploadMoveProductImgs(long shopId, MoveProductPublishQueueBO queueMsg, JSONObject productDetailBase, JSONObject moveBaseData, MoveShopSettingBO condition, AccessToken accessToken) {
|
|
|
|
|
String folderId = moveService.getUploadImgFolderId(shopId, accessToken, false);
|
|
|
|
|
Ret getProductDetailBaseRet = uploadMoveProductImg(shopId, productDetailBase, folderId, accessToken);
|
|
|
|
|
private Ret processAndUploadMoveProductImgs(long shopId, MoveProductPublishQueueBO queueMsg, JSONObject productDetailBase, JSONObject moveBaseData, MoveShopSettingBO condition) {
|
|
|
|
|
String folderId = moveService.getUploadImgFolderId(shopId, false);
|
|
|
|
|
Ret getProductDetailBaseRet = uploadMoveProductImg(shopId, productDetailBase, folderId);
|
|
|
|
|
if (CommonTool.isFailRet(getProductDetailBaseRet)) {
|
|
|
|
|
return getProductDetailBaseRet;
|
|
|
|
|
}
|
|
|
|
|
return CommonTool.successResult("productDetailBase", productDetailBase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret uploadMoveProductImg(long shopId, JSONObject productDetailBase, String folderId, AccessToken accessToken) {
|
|
|
|
|
private Ret uploadMoveProductImg(long shopId, JSONObject productDetailBase, String folderId) {
|
|
|
|
|
List<String> imgUrls = moveService.getMovePublishAllImgs(productDetailBase);
|
|
|
|
|
log.info("getMovePublishAllImgs : " + imgUrls);
|
|
|
|
|
imgUrls = uploadImgsFilterExist(shopId, imgUrls);
|
|
|
|
@ -355,19 +355,19 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
List<List<String>> imgChunks = CommonTool.chunkList(imgUrls, 50);
|
|
|
|
|
for (List<String> imgChunk : imgChunks) {
|
|
|
|
|
log.info("start uploadMoveProductImgToDd");
|
|
|
|
|
Ret uploadRet = moveService.uploadMoveProductImgToDd(shopId, imgChunk, folderId, "false", accessToken);
|
|
|
|
|
Ret uploadRet = moveService.uploadMoveProductImgToDd(shopId, imgChunk, folderId, "false");
|
|
|
|
|
log.info("end uploadMoveProductImgToDd");
|
|
|
|
|
if (CommonTool.isFailRet(uploadRet)) {
|
|
|
|
|
if (uploadRet.getReason().contains(MaterialConst.imgSpaceFull) || uploadRet.getReason().contains(MaterialConst.imgSpaceFull1) || uploadRet.getReason().contains("授权已被关闭")) {
|
|
|
|
|
return uploadRet;
|
|
|
|
|
}
|
|
|
|
|
log.info("uploadMoveProductImgToDd ret" + uploadRet + " folderId is :" + folderId);
|
|
|
|
|
Map<String, Object> sourceImgUrlToOssImgUrlMap = retryUploadMoveProductImg(shopId, imgChunk, folderId, accessToken);
|
|
|
|
|
Map<String, Object> sourceImgUrlToOssImgUrlMap = retryUploadMoveProductImg(shopId, imgChunk, folderId);
|
|
|
|
|
productDetailBase = MoveUtil.replaceMoveProductImg(productDetailBase, sourceImgUrlToOssImgUrlMap, false);
|
|
|
|
|
} else {
|
|
|
|
|
List<String> failUrls = getUploadImgSuccessMapAndFailUrls(uploadRet.getData(), imgChunk);
|
|
|
|
|
if (!failUrls.isEmpty()) {
|
|
|
|
|
Map<String, Object> sourceImgUrlToOssImgUrlMap = retryUploadMoveProductImg(shopId, failUrls, folderId, accessToken);
|
|
|
|
|
Map<String, Object> sourceImgUrlToOssImgUrlMap = retryUploadMoveProductImg(shopId, failUrls, folderId);
|
|
|
|
|
productDetailBase = MoveUtil.replaceMoveProductImg(productDetailBase, sourceImgUrlToOssImgUrlMap, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -395,7 +395,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return failUrls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> retryUploadMoveProductImg(long shopId, List<String> imgUrls, String folderId, AccessToken accessToken) {
|
|
|
|
|
private Map<String, Object> retryUploadMoveProductImg(long shopId, List<String> imgUrls, String folderId) {
|
|
|
|
|
String key = "retryUploadMoveProductImg" + LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
|
|
|
|
redisTemplate.opsForValue().increment(key, imgUrls.size());
|
|
|
|
|
redisTemplate.expire(key, 3600 * 24 * 3, TimeUnit.SECONDS);
|
|
|
|
@ -418,7 +418,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
sourceImgUrlToOssImgUrlMap.put(imgUrl, currOssImgUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ret ret = uploadMaterialImageSyncToDd(shopId, filter, accessToken);
|
|
|
|
|
Ret ret = uploadMaterialImageSyncToDd(shopId, filter);
|
|
|
|
|
if (CommonTool.isSuccessRet(ret)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -439,7 +439,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
}
|
|
|
|
|
String ossUrl = gifCheckRet.getData().get("ossUrl").toString();
|
|
|
|
|
sourceImgUrlToOssImgUrlMap.put(imgUrl, filter.put("url", ossUrl));
|
|
|
|
|
ret = uploadMaterialImageSyncToDd(shopId, filter, accessToken);
|
|
|
|
|
ret = uploadMaterialImageSyncToDd(shopId, filter);
|
|
|
|
|
if (CommonTool.isSuccessRet(ret)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -447,7 +447,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
Map<String, String> ossImgUrlMap = MoveUtil.transferMoveSourceImgToOss(shopId, Collections.singletonList(imgUrl), null);
|
|
|
|
|
String currOssImgUrl = ossImgUrlMap.get(imgUrl);
|
|
|
|
|
sourceImgUrlToOssImgUrlMap.put(imgUrl, filter.put("url", currOssImgUrl));
|
|
|
|
|
ret = uploadMaterialImageSyncToDd(shopId, filter, accessToken);
|
|
|
|
|
ret = uploadMaterialImageSyncToDd(shopId, filter);
|
|
|
|
|
|
|
|
|
|
moveService.delOssMainImgUrls(new String[]{currOssImgUrl});
|
|
|
|
|
if (CommonTool.isSuccessRet(ret)) {
|
|
|
|
@ -497,11 +497,11 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return byteArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Ret uploadMaterialImageSyncToDd(long shopId, Map<String, String> filter, AccessToken accessToken) {
|
|
|
|
|
public Ret uploadMaterialImageSyncToDd(long shopId, Map<String, String> filter) {
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
Ret retryRet = realUploadMaterialImageSyncToDd(shopId, filter, accessToken);
|
|
|
|
|
Ret retryRet = realUploadMaterialImageSyncToDd(shopId, filter);
|
|
|
|
|
if (CommonTool.isFailRet(retryRet) && (retryRet.getCode().equals(String.valueOf(MaterialConst.folderIdUnExist)) || retryRet.getReason().contains("该文件夹已经被删除"))) {
|
|
|
|
|
String folderId = moveService.getUploadImgFolderId(shopId, accessToken, true);
|
|
|
|
|
String folderId = moveService.getUploadImgFolderId(shopId, true);
|
|
|
|
|
if (folderId != null) {
|
|
|
|
|
filter.put("folderId", folderId);
|
|
|
|
|
continue;
|
|
|
|
@ -512,7 +512,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret realUploadMaterialImageSyncToDd(Long shopId, Map<String, String> filter, AccessToken accessToken) {
|
|
|
|
|
private Ret realUploadMaterialImageSyncToDd(Long shopId, Map<String, String> filter) {
|
|
|
|
|
MaterialUploadImageSyncRequest request = new MaterialUploadImageSyncRequest();
|
|
|
|
|
MaterialUploadImageSyncParam param = request.getParam();
|
|
|
|
|
if (filter.containsKey("url")) {
|
|
|
|
@ -544,8 +544,8 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return imgUrls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret buildCreateProductV2Data(JSONObject mMoveBaseData, MoveProductPublishQueueBO queueMsg, AccessToken accessToken, MoveShopSettingBO condition) {
|
|
|
|
|
Ret getPostDataRet = getCompletePostData(mMoveBaseData, queueMsg, accessToken);
|
|
|
|
|
private Ret buildCreateProductV2Data(JSONObject mMoveBaseData, MoveProductPublishQueueBO queueMsg, MoveShopSettingBO condition) {
|
|
|
|
|
Ret getPostDataRet = getCompletePostData(mMoveBaseData, queueMsg);
|
|
|
|
|
if (CommonTool.isFailRet(getPostDataRet)) {
|
|
|
|
|
return getPostDataRet;
|
|
|
|
|
}
|
|
|
|
@ -651,7 +651,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return key.replace("type_", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret getCompletePostData(JSONObject moveBaseData, MoveProductPublishQueueBO queueMsg, AccessToken accessToken) {
|
|
|
|
|
private Ret getCompletePostData(JSONObject moveBaseData, MoveProductPublishQueueBO queueMsg) {
|
|
|
|
|
String cid = queueMsg.getCid();
|
|
|
|
|
MoveShopSettingBO condition = queueMsg.getCondition();
|
|
|
|
|
long shopId = queueMsg.getShopId();
|
|
|
|
@ -660,7 +660,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
// $itemNum = $this->moveUtil->buildItemNum($moveBaseData, $condition, $isFastMode, $queueMsg);
|
|
|
|
|
// $moveBaseData['itemNum'] = $itemNum;
|
|
|
|
|
|
|
|
|
|
Ret buildProductDetailBaseRet = moveService.buildProductDetailBase(moveBaseData, queueMsg, accessToken);
|
|
|
|
|
Ret buildProductDetailBaseRet = moveService.buildProductDetailBase(moveBaseData, queueMsg);
|
|
|
|
|
if (CommonTool.isFailRet(buildProductDetailBaseRet)) {
|
|
|
|
|
return buildProductDetailBaseRet;
|
|
|
|
|
}
|
|
|
|
@ -694,7 +694,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
Ret matchBrandRet = null;
|
|
|
|
|
brandName = getSourceAttrBrandName(moveBaseData.getJSONObject("sourceAttrs"));
|
|
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
|
|
|
matchBrandRet = searchBrandIdByBrandNameFromDd(cid, brandName, accessToken, true);
|
|
|
|
|
matchBrandRet = searchBrandIdByBrandNameFromDd(cid, brandName, true);
|
|
|
|
|
if (CommonTool.isSuccessRet(matchBrandRet) || !CommonTool.checkIsFrequencyLimitReason(matchBrandRet.getReason())) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -2046,7 +2046,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService {
|
|
|
|
|
return saleProp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Ret searchBrandIdByBrandNameFromDd(String cid, String brandName, AccessToken accessToken, boolean isReturnNoBrand) {
|
|
|
|
|
private Ret searchBrandIdByBrandNameFromDd(String cid, String brandName, boolean isReturnNoBrand) {
|
|
|
|
|
// 此处算兼容api的bug,品牌名"gefeila/歌菲拉"拿去接口查不到,但是gefeila 或者 /歌菲拉 或者 歌菲拉 都查的到
|
|
|
|
|
String queryName = brandName;
|
|
|
|
|
if (brandName.contains("/")) {
|
|
|
|
|