去除各种accesstoken

20230922-ljl-fixBug
wangchaoxu 1 year ago
parent 2cc24944d1
commit 26ffefb70c

@ -132,10 +132,9 @@ public class MoveService {
*
* @param moveBaseData
* @param queueMsg
* @param accessToken
* @return
*/
public Ret buildProductDetailBase(JSONObject moveBaseData, MoveProductPublishQueueBO queueMsg, AccessToken accessToken) {
public Ret buildProductDetailBase(JSONObject moveBaseData, MoveProductPublishQueueBO queueMsg) {
MoveShopSettingBO condition = queueMsg.getCondition();
long shopId = queueMsg.getShopId();
@ -204,7 +203,7 @@ public class MoveService {
}
ProductGetProductUpdateRuleParam param = new ProductGetProductUpdateRuleParam();
param.setCategoryId(Long.valueOf(queueMsg.getCid()));
ApiResult<ProductGetProductUpdateRuleData> productUpdateRuleRet = DdRequestUtil.getBrandListV2FromDdNotEx(param, accessToken);
ApiResult<ProductGetProductUpdateRuleData> productUpdateRuleRet = DdRequestUtil.getBrandListV2FromDdNotEx(param);
if (productUpdateRuleRet.isSuccess()) {
FulfillmentRule fulfillmentRule = productUpdateRuleRet.getData().getFulfillmentRule();
if (ObjectUtil.isNotNull(fulfillmentRule)) {
@ -229,7 +228,7 @@ public class MoveService {
long freightTemplateId = condition.getFreightTemplateId() > 0 ? condition.getFreightTemplateId() : MoveConst.DEFAULT_FREIGHT_TEMPLATE_ID;
productDetailBase.put("freightTemplateId", freightTemplateId);
productDetailBase.put("supply7dayReturn", buildSupply7dayReturn(queueMsg, condition, accessToken));
productDetailBase.put("supply7dayReturn", buildSupply7dayReturn(queueMsg, condition));
boolean commit = condition.getMoveOnsaleType() != MoveConst.MOVE_ON_SALE_TYPE_DRAFT;
productDetailBase.put("commit", commit);
if (condition.getMoveOnsaleType() == MoveConst.MOVE_ON_SALE_TYPE_ON_SALE || condition.getMoveOnsaleType() == MoveConst.MOVE_ON_SALE_TYPE_FOR_SALE) {
@ -239,7 +238,7 @@ public class MoveService {
productDetailBase.put("status", MoveConst.MOVE_ON_SALE_TYPE_FOR_SALE);
}
Object[] supply7dayReturn = buildSupply7dayReturn(queueMsg, condition, accessToken);
Object[] supply7dayReturn = buildSupply7dayReturn(queueMsg, condition);
productDetailBase.put("supply7dayReturn", supply7dayReturn[0]);
productDetailBase.put("afterSaleService", supply7dayReturn[1]);
return CommonTool.successResult("productDetailBase", productDetailBase);
@ -312,7 +311,7 @@ public class MoveService {
return price;
}
public Object[] buildSupply7dayReturn(MoveProductPublishQueueBO queueMsg, MoveShopSettingBO condition, AccessToken accessToken) {
public Object[] buildSupply7dayReturn(MoveProductPublishQueueBO queueMsg, MoveShopSettingBO condition) {
Integer supply7dayReturn = null;
if (ObjectUtil.isNotNull(queueMsg.getSupply7dayReturn())) {
supply7dayReturn = queueMsg.getSupply7dayReturn();
@ -320,7 +319,7 @@ public class MoveService {
supply7dayReturn = condition.getSupply7dayReturn();
}
Map<String, String> supply7dayReturnOptions = getSupply7dayReturnOptions(queueMsg.getCid(), accessToken);
Map<String, String> supply7dayReturnOptions = getSupply7dayReturnOptions(queueMsg.getCid());
if (ObjectUtil.isNull(supply7dayReturn) || !supply7dayReturnOptions.containsKey(supply7dayReturn.toString())) {
List<String> defaultValues = Arrays.asList("2", "5", "4", "3", "6", "8", "0", "1");
for (String defaultValue : defaultValues) {
@ -337,11 +336,11 @@ public class MoveService {
return new Object[]{supply7dayReturn, afterSaleService};
}
public Map<String, String> getSupply7dayReturnOptions(String cid, AccessToken accessToken) {
public Map<String, String> getSupply7dayReturnOptions(String cid) {
Map<String, String> allOptions = MoveConst.getSupply7dayReturnOption();
ProductGetProductUpdateRuleParam param = new ProductGetProductUpdateRuleParam();
param.setCategoryId(Long.valueOf(cid));
ApiResult<ProductGetProductUpdateRuleData> productUpdateRuleRet = DdRequestUtil.getBrandListV2FromDdNotEx(param, accessToken);
ApiResult<ProductGetProductUpdateRuleData> productUpdateRuleRet = DdRequestUtil.getBrandListV2FromDdNotEx(param);
if (!productUpdateRuleRet.isSuccess()) {
return new HashMap<>();
}
@ -1077,16 +1076,16 @@ public class MoveService {
return str.trim();
}
public Ret uploadMoveProductImgToDd(long shopId, List<String> imgUrls, String folderId, String distinct, AccessToken accessToken) {
Ret ret = realUploadMoveProductImgToDd(shopId, imgUrls, folderId, distinct, accessToken);
public Ret uploadMoveProductImgToDd(long shopId, List<String> imgUrls, String folderId, String distinct) {
Ret ret = realUploadMoveProductImgToDd(shopId, imgUrls, folderId, distinct);
if (CommonTool.isFailRet(ret) && ret.getReason().contains("该文件夹已经被删除")) {
String mFolderId = getUploadImgFolderId(shopId, accessToken, true);
return realUploadMoveProductImgToDd(shopId, imgUrls, mFolderId, distinct, accessToken);
String mFolderId = getUploadImgFolderId(shopId, true);
return realUploadMoveProductImgToDd(shopId, imgUrls, mFolderId, distinct);
}
return ret;
}
private Ret realUploadMoveProductImgToDd(Long shopId, List<String> imgUrls, String folderId, String distinct, AccessToken accessToken) {
private Ret realUploadMoveProductImgToDd(Long shopId, List<String> imgUrls, String folderId, String distinct) {
List<MaterialsItem> materials = new ArrayList<>();
for (String imgUrl : imgUrls) {
String uniqid = SecurityTool.MD5(UUID.randomUUID().toString());
@ -1191,10 +1190,10 @@ public class MoveService {
}
}
public String getUploadImgFolderId(long shopId, AccessToken accessToken, boolean forceApi) {
public String getUploadImgFolderId(long shopId, boolean forceApi) {
int retry = 0;
while (true) {
String folderId = realGetUploadImgFolderId(shopId, accessToken, forceApi);
String folderId = realGetUploadImgFolderId(shopId, forceApi);
if (StringUtils.isNotBlank(folderId)) {
return folderId;
}
@ -1212,7 +1211,7 @@ public class MoveService {
}
}
private String realGetUploadImgFolderId(long shopId, AccessToken accessToken, boolean forceApi) {
private String realGetUploadImgFolderId(long shopId, boolean forceApi) {
String folderId = "";
JSONObject filter = new JSONObject();
filter.put("folderId", "0");

@ -29,7 +29,7 @@ public interface CategoryService {
boolean deleteShopCategoryQueue(Integer shopId);
List<DataItem> getAllShopCategorysFromDd(Long cid, AccessToken accessToken);
List<DataItem> getAllShopCategorysFromDd(Long cid);
List<Long> recordShopCategorys(Integer shopId, List<DataItem> shopAllCategoryList);

@ -116,16 +116,16 @@ public class CategoryServiceImpl implements CategoryService{
}
@Override
public List<DataItem> getAllShopCategorysFromDd(Long cid, AccessToken accessToken) {
public List<DataItem> getAllShopCategorysFromDd(Long cid) {
List<DataItem> dataAll = new ArrayList<>();
List<DataItem> dataGet = DdRequestUtil.getShopCategory(cid, accessToken);
List<DataItem> dataGet = DdRequestUtil.getShopCategory(cid);
if (dataGet.isEmpty()) {
return dataGet;
}
dataAll.addAll(dataGet);
for (DataItem datum : dataGet) {
if (datum.getEnable() && !datum.getIsLeaf()) {
List<DataItem> data1 = DdRequestUtil.getShopCategory(datum.getId(), accessToken);
List<DataItem> data1 = DdRequestUtil.getShopCategory(datum.getId());
dataAll.addAll(data1);
}
}

@ -601,11 +601,11 @@ public class ProcessMovePublishToPicTaskService extends TaskBaseService {
dataIsChange = true;
Long shopId = queueMsg.getShopId();
String folderId = moveService.getUploadImgFolderId(shopId, accessToken, false);
String folderId = moveService.getUploadImgFolderId(shopId, false);
List<String> batchUploadPics = Arrays.stream(mainImgUrls).filter(pic -> !pic.contains(CommonConst.ddImgUrlNeedle)).collect(Collectors.toList());
if (!batchUploadPics.isEmpty()) {
moveService.uploadMoveProductImgToDd(shopId, batchUploadPics, folderId, "false", accessToken);
moveService.uploadMoveProductImgToDd(shopId, batchUploadPics, folderId, "false");
}
E.throwMSException(String.join("|", mainImgUrls));
}

@ -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("/")) {

@ -80,10 +80,12 @@ public class SyncShopCategoryQueueTaskService extends TaskBaseService {
Integer shopId = queue.getShopId();
AuthThreadLocalUtil.set(shopId.toString());
log.info("getAllShopCategorysFromDd");
AccessToken accessToken = getShopAccessToken(shopId);
AuthThreadLocalUtil.set(shopId.toString());
List<DataItem> shopAllCategoryList = categoryService.getAllShopCategorysFromDd(0L, accessToken);
List<DataItem> shopAllCategoryList = categoryService.getAllShopCategorysFromDd(0L);
log.info("recordShopCategorys");
List<Long> recordCategoryIds = categoryService.recordShopCategorys(shopId, shopAllCategoryList);
log.info("end recordShopCategorys");

@ -203,7 +203,7 @@ public class DdRequestUtil {
}
///shop/getShopCategory
public static List<com.doudian.open.api.shop_getShopCategory.data.DataItem> getShopCategory(Long cid, AccessToken accessToken) {
public static List<com.doudian.open.api.shop_getShopCategory.data.DataItem> getShopCategory(Long cid) {
ShopGetShopCategoryRequest request = new ShopGetShopCategoryRequest();
ShopGetShopCategoryParam param = request.getParam();
param.setCid(cid);
@ -245,16 +245,12 @@ public class DdRequestUtil {
}
}
public static ProductGetProductUpdateRuleData getProductUpdateRuleFromDd(ProductGetProductUpdateRuleParam param, AccessToken accessToken) {
String activeProfile = System.getenv("sys-deploy-env");
if (!"Prod".equals(activeProfile)) {
AuthThreadLocalUtil.set(AppConst.TEST_SHOP_ID);
}
public static ProductGetProductUpdateRuleData getProductUpdateRuleFromDd(ProductGetProductUpdateRuleParam param) {
ProductGetProductUpdateRuleRequest request = new ProductGetProductUpdateRuleRequest();
request.setParam(param);
log.info("=============Dd请求餐素:{}===================", JSONObject.toJSONString(param));
ProductGetProductUpdateRuleResponse response = ObjectUtil.isNull(accessToken) ? request.execute() : request.execute(accessToken);
ProductGetProductUpdateRuleResponse response = request.execute();
log.info("=============Dd请求返回:{}===================", JSONObject.toJSONString(response));
boolean success = CommonTool.checkDdApiRequestIsSuccess(response);
if (success && ObjectUtil.isNotEmpty(response.getData())) {
@ -263,9 +259,9 @@ public class DdRequestUtil {
throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg()));
}
public static ApiResult<ProductGetProductUpdateRuleData> getBrandListV2FromDdNotEx(ProductGetProductUpdateRuleParam param, AccessToken accessToken) {
public static ApiResult<ProductGetProductUpdateRuleData> getBrandListV2FromDdNotEx(ProductGetProductUpdateRuleParam param) {
try {
ProductGetProductUpdateRuleData data = getProductUpdateRuleFromDd(param, accessToken);
ProductGetProductUpdateRuleData data = getProductUpdateRuleFromDd(param);
return ApiResult.ok(data);
} catch (RuntimeException e) {
return ApiResult.fail(e.getMessage());

Loading…
Cancel
Save