|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package com.hfkj.jd.Impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hfkj.common.utils.RedisUtil; |
|
|
|
|
import com.hfkj.common.utils.ResponseMsgUtil; |
|
|
|
|
import com.hfkj.entity.*; |
|
|
|
@ -9,6 +10,11 @@ import com.hfkj.service.BsMerService; |
|
|
|
|
import com.hfkj.service.BsProductConfigService; |
|
|
|
|
import com.hfkj.service.goods.*; |
|
|
|
|
import com.hfkj.sysenum.order.OrderChildProductTypeEnum; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryDeliveryInfo.DeliveryInfoQueryOpenResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryDeliveryInfo.LogisticInfoOrderOpenResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryDeliveryInfo.TrackInfoOrderOpenResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryOrderDetail.QueryOrderOpenResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryOrderDetail.StateOrderOpenResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSellPrice.GetSellPriceGoodsResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSellPrice.OpenRpcResult; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuDetailInfo.GetSkuPoolInfoGoodsResp; |
|
|
|
@ -16,10 +22,15 @@ import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImag |
|
|
|
|
import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.SkuImageItemGoodsResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopsp.SkuPoolGoodsProvider.response.getSkuPoolInfo.GetSkuPoolInfoItemGoodsResp; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopsp.SkuPoolGoodsProvider.response.querySkuByPage.OpenPagingResult; |
|
|
|
|
import com.jd.open.api.sdk.domain.vopxx.MsgRecordProvider.response.queryTransByVopNormal.VopBizTransMessage; |
|
|
|
|
import com.jd.open.api.sdk.response.vopdd.VopOrderQueryDeliveryInfoResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopdd.VopOrderQueryOrderDetailResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopsh.VopAfsCreateAfsApplyResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuDetailInfoResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuImageListResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuPoolInfoResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuStateListResponse; |
|
|
|
|
import com.jd.open.api.sdk.response.vopxx.VopMessageQueryTransByVopNormalResponse; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
@ -27,9 +38,7 @@ import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue; |
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import java.util.concurrent.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,7 +66,22 @@ public class JdServiceImpl implements JdService { |
|
|
|
|
@Resource |
|
|
|
|
private GoodsSpecsService goodsSpecsService; |
|
|
|
|
|
|
|
|
|
private List<Long> skuList = new ArrayList<>(); |
|
|
|
|
@Resource |
|
|
|
|
private BsOrderGoodsService bsOrderGoodsService; |
|
|
|
|
|
|
|
|
|
private final List<Long> skuListIds = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int cpuCoreCnt = Runtime.getRuntime().availableProcessors(); //获取服务器CPU核心数
|
|
|
|
|
static int corePoolSize = cpuCoreCnt; // 核心线程数
|
|
|
|
|
static int maximumPoolSize = cpuCoreCnt; // 最大线程数
|
|
|
|
|
static int keepAliveTime = 30; // 非核心线程的空闲存活时长(分钟)
|
|
|
|
|
static int queueCapacity = 9999; // 队列最大长度
|
|
|
|
|
public static BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(queueCapacity); |
|
|
|
|
static ThreadPoolExecutor threadPool; |
|
|
|
|
static { |
|
|
|
|
threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MINUTES, queue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getToken() throws Exception { |
|
|
|
@ -66,252 +90,309 @@ public class JdServiceImpl implements JdService { |
|
|
|
|
if (token == null) { |
|
|
|
|
// 请求回调 会在回调存入参数
|
|
|
|
|
JdPostService.getAccessToken(); |
|
|
|
|
getToken(); |
|
|
|
|
// getToken();
|
|
|
|
|
} |
|
|
|
|
return token.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void getGoodsJd() throws Exception { |
|
|
|
|
String token = getToken(); |
|
|
|
|
// 获取京东商品池
|
|
|
|
|
VopGoodsGetSkuPoolInfoResponse sku = JdPostService.getSkuPoolInfo(token); |
|
|
|
|
// 获取sku列表
|
|
|
|
|
List<GetSkuPoolInfoItemGoodsResp> skuList = sku.getOpenRpcResult().getResult().getSkuPoolList(); |
|
|
|
|
// List<Long> skuIdList;
|
|
|
|
|
// for (GetSkuPoolInfoItemGoodsResp skuPoolInfoItemGoodsResp : skuList) {
|
|
|
|
|
// skuIdList = getSkuList(token , skuPoolInfoItemGoodsResp.getBizPoolId() , 0L);
|
|
|
|
|
// }
|
|
|
|
|
// BsMer bsMer = bsMerService.getDetail("166241009282");
|
|
|
|
|
|
|
|
|
|
// 初始化商品信息
|
|
|
|
|
GoodsMsg goodsMsg; |
|
|
|
|
// 初始化商品规格
|
|
|
|
|
GoodsSpecs goodsSpecs; |
|
|
|
|
/** |
|
|
|
|
* 处理数据 |
|
|
|
|
* @param handleList |
|
|
|
|
*/ |
|
|
|
|
public void task(List<Long> handleList , String token , BsProductConfig productConfig , BsMer bsMer) { |
|
|
|
|
//处理数据
|
|
|
|
|
handleList.forEach(item->{ |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Long aLong : handleList) { |
|
|
|
|
|
|
|
|
|
// 根据skuId 查询商品详情
|
|
|
|
|
VopGoodsGetSkuDetailInfoResponse skuDetail = JdPostService.getSkuDetailInfo(token, aLong); |
|
|
|
|
GetSkuPoolInfoGoodsResp detail = skuDetail.getOpenRpcResult().getResult(); |
|
|
|
|
if (detail != null) { |
|
|
|
|
// 根据skuId 查询商品售价
|
|
|
|
|
OpenRpcResult priceResponse = JdPostService.getSellPrice(token, String.valueOf(aLong)).getOpenRpcResult(); |
|
|
|
|
if (priceResponse.getSuccess()) { |
|
|
|
|
GetSellPriceGoodsResp price = priceResponse.getResult().get(0); |
|
|
|
|
// 根据skuId 查询商品图片
|
|
|
|
|
|
|
|
|
|
com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.OpenRpcResult imageListResponse = JdPostService.getSkuImageList(token, String.valueOf(aLong)).getOpenRpcResult(); |
|
|
|
|
if (imageListResponse.getSuccess()) { |
|
|
|
|
GetSkuImageGoodsResp img = imageListResponse.getResult().get(0); |
|
|
|
|
// 查询分类
|
|
|
|
|
String[] categoryS = detail.getCategory().split(";"); |
|
|
|
|
|
|
|
|
|
// 查询一级分类
|
|
|
|
|
String category1 = JdPostService.getCategoryInfoList(token, categoryS[0]).getOpenRpcResult().getResult().get(0).getCategoryName(); |
|
|
|
|
// 查询二级分类
|
|
|
|
|
String category2 = JdPostService.getCategoryInfoList(token, categoryS[1]).getOpenRpcResult().getResult().get(0).getCategoryName(); |
|
|
|
|
|
|
|
|
|
GoodsType goodsType1 = goodsTypeService.queryDetail(category1); |
|
|
|
|
GoodsType goodsType2 = goodsTypeService.queryDetail(category2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果goodsType1为null,则创建一个新的GoodsType对象
|
|
|
|
|
if (goodsType1 == null) { |
|
|
|
|
goodsType1 = new GoodsType(); |
|
|
|
|
// 设置title为category1
|
|
|
|
|
goodsType1.setTitle(category1); |
|
|
|
|
// 设置status为1
|
|
|
|
|
goodsType1.setStatus(1); |
|
|
|
|
goodsType1.setBusinessType(1); |
|
|
|
|
// 设置sort为8
|
|
|
|
|
goodsType1.setSort(8); |
|
|
|
|
// 设置createTime为当前时间
|
|
|
|
|
goodsType1.setCreateTime(new Date()); |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsType1.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsTypeService的create方法,将goodsType1对象保存到数据库中
|
|
|
|
|
goodsTypeService.create(goodsType1); |
|
|
|
|
} else { |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsType1.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsTypeService的update方法,将goodsType1对象更新到数据库中
|
|
|
|
|
goodsTypeService.update(goodsType1); |
|
|
|
|
} |
|
|
|
|
if (goodsType2 == null) { |
|
|
|
|
goodsType2 = new GoodsType(); |
|
|
|
|
// 设置title为category2
|
|
|
|
|
goodsType2.setTitle(category2); |
|
|
|
|
goodsType2.setParentId(goodsType1.getId()); |
|
|
|
|
// 设置status为1
|
|
|
|
|
goodsType2.setStatus(1); |
|
|
|
|
// 设置businessType为1
|
|
|
|
|
goodsType2.setBusinessType(1); |
|
|
|
|
// 设置sort为8
|
|
|
|
|
goodsType2.setSort(1); |
|
|
|
|
// 设置createTime为当前时间
|
|
|
|
|
goodsType2.setCreateTime(new Date()); |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsType2.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsTypeService的create方法,将goodsType2对象保存到数据库中
|
|
|
|
|
goodsTypeService.create(goodsType2); |
|
|
|
|
} else { |
|
|
|
|
goodsType2.setParentId(goodsType1.getId()); |
|
|
|
|
goodsType2.setUpdateTime(new Date()); |
|
|
|
|
goodsTypeService.update(goodsType2); |
|
|
|
|
} |
|
|
|
|
// 从brands中筛选出title等于detail.getBrandName()的元素,并返回第一个元素,如果没有找到则返回null
|
|
|
|
|
GoodsBrand goodsBrand = goodsBrandService.queryDetail(detail.getBrandName()); |
|
|
|
|
// 如果goodsBrand为null,则创建一个新的GoodsBrand对象
|
|
|
|
|
if (goodsBrand == null) { |
|
|
|
|
goodsBrand = new GoodsBrand(); |
|
|
|
|
// 设置title为detail.getBrandName()
|
|
|
|
|
goodsBrand.setTitle(detail.getBrandName()); |
|
|
|
|
// 设置status为1
|
|
|
|
|
goodsBrand.setStatus(1); |
|
|
|
|
// 设置createTime为当前时间
|
|
|
|
|
goodsBrand.setCreateTime(new Date()); |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsBrand.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsBrandService的create方法,将goodsBrand对象保存到数据库中
|
|
|
|
|
goodsBrandService.create(goodsBrand); |
|
|
|
|
} else { |
|
|
|
|
goodsBrand.setUpdateTime(new Date()); |
|
|
|
|
goodsBrandService.update(goodsBrand); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BsMer bsMer = bsMerService.getDetail("166241009282"); |
|
|
|
|
// 查询分类
|
|
|
|
|
List<GoodsType> goodsType = goodsTypeService.getList(new HashMap<>()); |
|
|
|
|
List<GoodsBrand> brands = goodsBrandService.getList(new HashMap<>()); |
|
|
|
|
Map<String, Object> goodsMap = new HashMap<>(); |
|
|
|
|
goodsMap.put("type", 1); |
|
|
|
|
goodsMap.put("childType", 1); |
|
|
|
|
List<GoodsMsg> goodsMsgs = goodsMsgService.getList(goodsMap); |
|
|
|
|
List<GoodsSpecs> goodsSpecsList = goodsSpecsService.getList(new HashMap<>()); |
|
|
|
|
BsProductConfig productConfig = productConfigService.queryDetail(OrderChildProductTypeEnum.type6.getCode()); |
|
|
|
|
List<Long> skuIdList; |
|
|
|
|
for (GetSkuPoolInfoItemGoodsResp skuPoolInfoItemGoodsResp : skuList) { |
|
|
|
|
|
|
|
|
|
skuIdList = getSkuList(token , skuPoolInfoItemGoodsResp.getBizPoolId() , 0L); |
|
|
|
|
|
|
|
|
|
for (Long aLong : skuIdList) { |
|
|
|
|
|
|
|
|
|
// 根据skuId 查询商品详情
|
|
|
|
|
VopGoodsGetSkuDetailInfoResponse skuDetail = JdPostService.getSkuDetailInfo(token, aLong); |
|
|
|
|
GetSkuPoolInfoGoodsResp detail = skuDetail.getOpenRpcResult().getResult(); |
|
|
|
|
if (detail != null) { |
|
|
|
|
// 根据skuId 查询商品售价
|
|
|
|
|
OpenRpcResult priceResponse = JdPostService.getSellPrice(token, String.valueOf(aLong)).getOpenRpcResult(); |
|
|
|
|
if (priceResponse.getSuccess()) { |
|
|
|
|
GetSellPriceGoodsResp price = priceResponse.getResult().get(0); |
|
|
|
|
// 根据skuId 查询商品图片
|
|
|
|
|
|
|
|
|
|
com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.OpenRpcResult imageListResponse = JdPostService.getSkuImageList(token, String.valueOf(aLong)).getOpenRpcResult(); |
|
|
|
|
if (imageListResponse.getSuccess()) { |
|
|
|
|
GetSkuImageGoodsResp img = imageListResponse.getResult().get(0); |
|
|
|
|
// 查询分类
|
|
|
|
|
String[] categoryS = detail.getCategory().split(";"); |
|
|
|
|
|
|
|
|
|
// 查询一级分类
|
|
|
|
|
String category1 = JdPostService.getCategoryInfoList(token, categoryS[0]).getOpenRpcResult().getResult().get(0).getCategoryName(); |
|
|
|
|
// 查询二级分类
|
|
|
|
|
String category2 = JdPostService.getCategoryInfoList(token, categoryS[1]).getOpenRpcResult().getResult().get(0).getCategoryName(); |
|
|
|
|
|
|
|
|
|
GoodsType goodsType1 = goodsType.stream().filter(s -> s.getTitle().equals(category1)).findFirst().orElse(null); |
|
|
|
|
GoodsType goodsType2 = goodsType.stream().filter(s -> s.getTitle().equals(category2)).findFirst().orElse(null); |
|
|
|
|
|
|
|
|
|
// 如果goodsType1为null,则创建一个新的GoodsType对象
|
|
|
|
|
if (goodsType1 == null) { |
|
|
|
|
goodsType1 = new GoodsType(); |
|
|
|
|
// 设置title为category1
|
|
|
|
|
goodsType1.setTitle(category1); |
|
|
|
|
// 设置status为1
|
|
|
|
|
goodsType1.setStatus(1); |
|
|
|
|
goodsType1.setBusinessType(1); |
|
|
|
|
// 设置sort为8
|
|
|
|
|
goodsType1.setSort(8); |
|
|
|
|
// 设置createTime为当前时间
|
|
|
|
|
goodsType1.setCreateTime(new Date()); |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsType1.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsTypeService的create方法,将goodsType1对象保存到数据库中
|
|
|
|
|
goodsTypeService.create(goodsType1); |
|
|
|
|
goodsType.add(goodsType1); |
|
|
|
|
} |
|
|
|
|
if (goodsType2 == null) { |
|
|
|
|
goodsType2 = new GoodsType(); |
|
|
|
|
// 设置title为category2
|
|
|
|
|
goodsType2.setTitle(category2); |
|
|
|
|
goodsType2.setParentId(goodsType1.getId()); |
|
|
|
|
// 设置status为1
|
|
|
|
|
goodsType2.setStatus(1); |
|
|
|
|
// 设置businessType为1
|
|
|
|
|
goodsType2.setBusinessType(1); |
|
|
|
|
// 设置sort为8
|
|
|
|
|
goodsType2.setSort(1); |
|
|
|
|
// 设置createTime为当前时间
|
|
|
|
|
goodsType2.setCreateTime(new Date()); |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsType2.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsTypeService的create方法,将goodsType2对象保存到数据库中
|
|
|
|
|
goodsTypeService.create(goodsType2); |
|
|
|
|
goodsType.add(goodsType2); |
|
|
|
|
} else { |
|
|
|
|
goodsType2.setParentId(goodsType1.getId()); |
|
|
|
|
goodsType2.setUpdateTime(new Date()); |
|
|
|
|
goodsTypeService.update(goodsType2); |
|
|
|
|
} |
|
|
|
|
// 从brands中筛选出title等于detail.getBrandName()的元素,并返回第一个元素,如果没有找到则返回null
|
|
|
|
|
GoodsBrand goodsBrand = brands.stream().filter(s -> s.getTitle().equals(detail.getBrandName())).findFirst().orElse(null); |
|
|
|
|
// 如果goodsBrand为null,则创建一个新的GoodsBrand对象
|
|
|
|
|
if (goodsBrand == null) { |
|
|
|
|
goodsBrand = new GoodsBrand(); |
|
|
|
|
// 设置title为detail.getBrandName()
|
|
|
|
|
goodsBrand.setTitle(detail.getBrandName()); |
|
|
|
|
// 设置status为1
|
|
|
|
|
goodsBrand.setStatus(1); |
|
|
|
|
// 设置createTime为当前时间
|
|
|
|
|
goodsBrand.setCreateTime(new Date()); |
|
|
|
|
// 设置updateTime为当前时间
|
|
|
|
|
goodsBrand.setUpdateTime(new Date()); |
|
|
|
|
// 调用goodsBrandService的create方法,将goodsBrand对象保存到数据库中
|
|
|
|
|
goodsBrandService.create(goodsBrand); |
|
|
|
|
brands.add(goodsBrand); |
|
|
|
|
} |
|
|
|
|
// 创建一个GoodsMsg对象
|
|
|
|
|
GoodsMsg goodsMsg = goodsMsgService.queryDetail(aLong.toString()); |
|
|
|
|
|
|
|
|
|
// 创建一个GoodsMsg对象
|
|
|
|
|
goodsMsg = new GoodsMsg(); |
|
|
|
|
// 设置更新时间为当前时间
|
|
|
|
|
goodsMsg.setUpdateTime(new Date()); |
|
|
|
|
// 设置商家ID为bsMer的ID
|
|
|
|
|
goodsMsg.setMerId(bsMer.getId()); |
|
|
|
|
// 设置商家名称为bsMer的名称
|
|
|
|
|
goodsMsg.setMerName(bsMer.getMerName()); |
|
|
|
|
// 设置商品名称为detail.getGoodsName()
|
|
|
|
|
goodsMsg.setTitle(detail.getSkuName()); |
|
|
|
|
// 设置商品类型为3
|
|
|
|
|
goodsMsg.setType(1); |
|
|
|
|
// 设置商品状态为1
|
|
|
|
|
goodsMsg.setStatus(1); |
|
|
|
|
// 设置商品子类型为1
|
|
|
|
|
goodsMsg.setChildType(1); |
|
|
|
|
// 设置商品品牌ID
|
|
|
|
|
goodsMsg.setGoodsBrand(goodsBrand.getId()); |
|
|
|
|
// 设置商品品牌名称
|
|
|
|
|
goodsMsg.setGoodsBrandName(goodsBrand.getTitle()); |
|
|
|
|
// 设置商品类型ID
|
|
|
|
|
goodsMsg.setGoodsType(goodsType2.getId()); |
|
|
|
|
// 设置商品类型名称
|
|
|
|
|
goodsMsg.setGoodsTypeName(goodsType2.getTitle()); |
|
|
|
|
// 设置商品类型父级ID
|
|
|
|
|
goodsMsg.setGoodsTypeParent(goodsType1.getId()); |
|
|
|
|
// 设置商品类型父级名称
|
|
|
|
|
goodsMsg.setGoodsTypeParentName(goodsType1.getTitle()); |
|
|
|
|
goodsMsg.setThirdId(aLong.toString()); |
|
|
|
|
StringBuilder imgS = new StringBuilder(); |
|
|
|
|
// 遍历商品图片列表
|
|
|
|
|
for (SkuImageItemGoodsResp skuImage : img.getSkuImageList()) { |
|
|
|
|
// 如果图片是主图
|
|
|
|
|
if (skuImage.getIsPrimary() == 1) { |
|
|
|
|
// 设置主图
|
|
|
|
|
goodsMsg.setListImg("https://img13.360buyimg.com/n1/" + skuImage.getShortPath()); |
|
|
|
|
if (goodsMsg == null) { |
|
|
|
|
goodsMsg = new GoodsMsg(); |
|
|
|
|
} |
|
|
|
|
// 如果图片不是主图
|
|
|
|
|
if (skuImage.getIsPrimary() == 0) { |
|
|
|
|
|
|
|
|
|
imgS.append("https://img13.360buyimg.com/n1/").append(skuImage.getShortPath()).append(","); |
|
|
|
|
|
|
|
|
|
// 设置商家ID为bsMer的ID
|
|
|
|
|
goodsMsg.setMerId(bsMer.getId()); |
|
|
|
|
// 设置商家名称为bsMer的名称
|
|
|
|
|
goodsMsg.setMerName(bsMer.getMerName()); |
|
|
|
|
// 设置商品名称为detail.getGoodsName()
|
|
|
|
|
goodsMsg.setTitle(detail.getSkuName()); |
|
|
|
|
// 设置商品类型为1
|
|
|
|
|
goodsMsg.setType(1); |
|
|
|
|
// 设置商品状态为1
|
|
|
|
|
goodsMsg.setStatus(1); |
|
|
|
|
// 设置商品子类型为1
|
|
|
|
|
goodsMsg.setChildType(1); |
|
|
|
|
// 设置商品品牌ID
|
|
|
|
|
goodsMsg.setGoodsBrand(goodsBrand.getId()); |
|
|
|
|
// 设置商品品牌名称
|
|
|
|
|
goodsMsg.setGoodsBrandName(goodsBrand.getTitle()); |
|
|
|
|
// 设置商品类型ID
|
|
|
|
|
goodsMsg.setGoodsType(goodsType2.getId()); |
|
|
|
|
// 设置商品类型名称
|
|
|
|
|
goodsMsg.setGoodsTypeName(goodsType2.getTitle()); |
|
|
|
|
// 设置商品类型父级ID
|
|
|
|
|
goodsMsg.setGoodsTypeParent(goodsType1.getId()); |
|
|
|
|
// 设置商品类型父级名称
|
|
|
|
|
goodsMsg.setGoodsTypeParentName(goodsType1.getTitle()); |
|
|
|
|
goodsMsg.setThirdId(aLong.toString()); |
|
|
|
|
StringBuilder imgS = new StringBuilder(); |
|
|
|
|
// 遍历商品图片列表
|
|
|
|
|
for (SkuImageItemGoodsResp skuImage : img.getSkuImageList()) { |
|
|
|
|
// 如果图片是主图
|
|
|
|
|
if (skuImage.getIsPrimary() == 1) { |
|
|
|
|
// 设置主图
|
|
|
|
|
goodsMsg.setListImg("https://img13.360buyimg.com/n1/" + skuImage.getShortPath()); |
|
|
|
|
} |
|
|
|
|
// 如果图片不是主图
|
|
|
|
|
if (skuImage.getIsPrimary() == 0) { |
|
|
|
|
|
|
|
|
|
imgS.append("https://img13.360buyimg.com/n1/").append(skuImage.getShortPath()).append(","); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (imgS.length() > 0) { |
|
|
|
|
imgS.deleteCharAt(imgS.length() - 1); |
|
|
|
|
} |
|
|
|
|
if (imgS.length() > 0) { |
|
|
|
|
imgS.deleteCharAt(imgS.length() - 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 设置轮播图
|
|
|
|
|
goodsMsg.setBannerImg(String.valueOf(imgS)); |
|
|
|
|
// 设置详情图
|
|
|
|
|
goodsMsg.setDetailImg(String.valueOf(imgS)); |
|
|
|
|
GoodsMsg msg = goodsMsgs.stream().filter(s -> s.getThirdId().equals(aLong.toString())).findFirst().orElse(null); |
|
|
|
|
|
|
|
|
|
if (msg != null) { |
|
|
|
|
goodsMsg.setId(msg.getId()); |
|
|
|
|
// 更新商品信息
|
|
|
|
|
goodsMsgService.update(goodsMsg); |
|
|
|
|
} else { |
|
|
|
|
// 设置销售数量为0
|
|
|
|
|
goodsMsg.setSaleNum(0); |
|
|
|
|
goodsMsg.setCreateTime(new Date()); |
|
|
|
|
// 创建商品信息
|
|
|
|
|
goodsMsgService.create(goodsMsg); |
|
|
|
|
// 设置轮播图
|
|
|
|
|
goodsMsg.setBannerImg(String.valueOf(imgS)); |
|
|
|
|
// 设置详情图
|
|
|
|
|
goodsMsg.setDetailImg(String.valueOf(imgS)); |
|
|
|
|
|
|
|
|
|
if (goodsMsg.getId() != null) { |
|
|
|
|
// 设置更新时间为当前时间
|
|
|
|
|
goodsMsg.setUpdateTime(new Date()); |
|
|
|
|
// 更新商品信息
|
|
|
|
|
goodsMsgService.update(goodsMsg); |
|
|
|
|
} else { |
|
|
|
|
// 设置销售数量为0
|
|
|
|
|
goodsMsg.setSaleNum(0); |
|
|
|
|
goodsMsg.setCreateTime(new Date()); |
|
|
|
|
// 创建商品信息
|
|
|
|
|
goodsMsgService.create(goodsMsg); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 创建商品规格
|
|
|
|
|
goodsSpecs = new GoodsSpecs(); |
|
|
|
|
// 设置商品ID
|
|
|
|
|
goodsSpecs.setGoodsId(goodsMsg.getId()); |
|
|
|
|
// 设置商品名称
|
|
|
|
|
goodsSpecs.setName(detail.getSpuName()); |
|
|
|
|
// 设置更新时间
|
|
|
|
|
goodsSpecs.setUpdateTime(new Date()); |
|
|
|
|
// 设置采购限制
|
|
|
|
|
goodsSpecs.setPurLimit(99999); |
|
|
|
|
// 设置状态
|
|
|
|
|
goodsSpecs.setStatus(1); |
|
|
|
|
goodsSpecs.setThirdId(aLong.toString()); |
|
|
|
|
// 设置库存
|
|
|
|
|
goodsSpecs.setStock(10000); |
|
|
|
|
BigDecimal profitPrice = price.getSalePrice().multiply(productConfig.getDiscount().divide(new BigDecimal(100) , 2, RoundingMode.HALF_UP)); |
|
|
|
|
// 设置销售价格
|
|
|
|
|
goodsSpecs.setSalePrice(profitPrice.add(price.getSalePrice())); |
|
|
|
|
// 设置原价
|
|
|
|
|
goodsSpecs.setOriginalPrice(price.getMarketPrice()); |
|
|
|
|
goodsSpecs.setThirdPrice(price.getJdPrice()); |
|
|
|
|
// 设置展示图片
|
|
|
|
|
goodsSpecs.setShowImg(goodsMsg.getListImg()); |
|
|
|
|
|
|
|
|
|
goodsSpecsList = goodsSpecsList.stream().filter(s-> s.getThirdId() != null).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
GoodsSpecs specs = goodsSpecsList.stream().filter(s -> s.getThirdId().equals(aLong.toString())).findFirst().orElse(null); |
|
|
|
|
|
|
|
|
|
if (specs != null) { |
|
|
|
|
goodsSpecs.setId(specs.getId()); |
|
|
|
|
// 更新商品规格
|
|
|
|
|
goodsSpecsService.update(goodsSpecs); |
|
|
|
|
} else { |
|
|
|
|
// 设置创建时间
|
|
|
|
|
goodsSpecs.setCreateTime(new Date()); |
|
|
|
|
// 创建商品规格
|
|
|
|
|
goodsSpecsService.create(goodsSpecs); |
|
|
|
|
GoodsSpecs goodsSpecs = goodsSpecsService.queryDetailByThirdId(aLong.toString()); |
|
|
|
|
if (goodsSpecs == null) { |
|
|
|
|
goodsSpecs = new GoodsSpecs(); |
|
|
|
|
} |
|
|
|
|
goodsSpecs.setGoodsId(goodsMsg.getId()); |
|
|
|
|
// 设置商品ID
|
|
|
|
|
goodsSpecs.setGoodsId(goodsMsg.getId()); |
|
|
|
|
// 设置商品名称
|
|
|
|
|
goodsSpecs.setName(detail.getSpuName()); |
|
|
|
|
// 设置更新时间
|
|
|
|
|
goodsSpecs.setUpdateTime(new Date()); |
|
|
|
|
// 设置采购限制
|
|
|
|
|
goodsSpecs.setPurLimit(99999); |
|
|
|
|
// 设置状态
|
|
|
|
|
goodsSpecs.setStatus(1); |
|
|
|
|
goodsSpecs.setThirdId(aLong.toString()); |
|
|
|
|
// 设置库存
|
|
|
|
|
goodsSpecs.setStock(10000); |
|
|
|
|
BigDecimal profitPrice = price.getSalePrice().multiply(productConfig.getDiscount().divide(new BigDecimal(100) , 2, RoundingMode.HALF_UP)); |
|
|
|
|
// 设置销售价格
|
|
|
|
|
goodsSpecs.setSalePrice(profitPrice.add(price.getSalePrice())); |
|
|
|
|
// 设置原价
|
|
|
|
|
goodsSpecs.setOriginalPrice(price.getMarketPrice()); |
|
|
|
|
goodsSpecs.setThirdPrice(price.getJdPrice()); |
|
|
|
|
// 设置展示图片
|
|
|
|
|
goodsSpecs.setShowImg(goodsMsg.getListImg()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (goodsSpecs.getId() != null) { |
|
|
|
|
// 更新商品规格
|
|
|
|
|
goodsSpecsService.update(goodsSpecs); |
|
|
|
|
} else { |
|
|
|
|
// 设置创建时间
|
|
|
|
|
goodsSpecs.setCreateTime(new Date()); |
|
|
|
|
// 创建商品规格
|
|
|
|
|
goodsSpecsService.create(goodsSpecs); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void getGoodsJd() throws Exception { |
|
|
|
|
String token = getToken(); |
|
|
|
|
// 获取京东商品池
|
|
|
|
|
VopGoodsGetSkuPoolInfoResponse sku = JdPostService.getSkuPoolInfo(token); |
|
|
|
|
// 获取京东商品池编码
|
|
|
|
|
List<GetSkuPoolInfoItemGoodsResp> skuPoolList = sku.getOpenRpcResult().getResult().getSkuPoolList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
skuListIds.clear(); |
|
|
|
|
|
|
|
|
|
BsProductConfig productConfig = productConfigService.queryDetail(OrderChildProductTypeEnum.type6.getCode()); |
|
|
|
|
BsMer bsMer = bsMerService.getDetail("166241009282"); |
|
|
|
|
|
|
|
|
|
// 循环商品池变化获取sku
|
|
|
|
|
for (GetSkuPoolInfoItemGoodsResp skuPoolInfoItemGoodsResp : skuPoolList) { |
|
|
|
|
getSkuList(token , skuPoolInfoItemGoodsResp.getBizPoolId() , 0L); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
System.out.println("=========================当前cpu核数:{}" + cpuCoreCnt); |
|
|
|
|
//通过对核心数取余来计算每个线程需要处理的数据量大小
|
|
|
|
|
int size = skuListIds.size() % cpuCoreCnt > 0 ? skuListIds.size() / cpuCoreCnt +1 : skuListIds.size() / cpuCoreCnt; |
|
|
|
|
// 用于存储所有任务的Future
|
|
|
|
|
List<Future> futureList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
// 记录开始时间
|
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < cpuCoreCnt; i++) { |
|
|
|
|
//获取每个线程要处理的数据集
|
|
|
|
|
List<Long> handleList = skuListIds.subList(i * size, Math.min(skuListIds.size(), i * size + size)); |
|
|
|
|
//创建异步任务添加到线程池,这里使用jdk8的CompletableFuture
|
|
|
|
|
CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> { |
|
|
|
|
//数据集处理任务
|
|
|
|
|
task(handleList , token , productConfig , bsMer); |
|
|
|
|
}, threadPool); |
|
|
|
|
//将CompletableFuture添加到futureList用于计算耗时
|
|
|
|
|
futureList.add(completableFuture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 非阻塞等待所有任务完成
|
|
|
|
|
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).thenRunAsync(() -> { |
|
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
|
long totalTime = endTime - startTime; |
|
|
|
|
System.out.println("处理完成,耗时: " + totalTime + "毫秒"); |
|
|
|
|
//关闭线程池
|
|
|
|
|
threadPool.shutdown(); |
|
|
|
|
}, threadPool); |
|
|
|
|
System.out.println(skuListIds.size()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @MethodName getSkuList |
|
|
|
|
* @Description: 获取全量商品池 |
|
|
|
|
* @param token |
|
|
|
|
* @param bizPoolId |
|
|
|
|
* @param offset |
|
|
|
|
* @return: java.util.List<java.lang.Long> |
|
|
|
|
* @Author: Sum1Dream |
|
|
|
|
* @Date: 2024/11/27 上午10:41 |
|
|
|
|
*/ |
|
|
|
|
private List<Long> getSkuList(String token , String bizPoolId , Long offset) throws Exception { |
|
|
|
|
OpenPagingResult result = JdPostService.querySkuByPage(token, bizPoolId, offset).getOpenRpcResult().getResult(); |
|
|
|
|
skuList.addAll(result.getSkus()); |
|
|
|
|
if (result.getRemainPage() > 0) { |
|
|
|
|
getSkuList(token, bizPoolId, result.getOffset()); |
|
|
|
|
if (result != null) { |
|
|
|
|
skuListIds.addAll(result.getSkus()); |
|
|
|
|
if (result.getRemainPage() > 0) { |
|
|
|
|
getSkuList(token, bizPoolId, result.getOffset()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return skuList; |
|
|
|
|
return skuListIds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -321,37 +402,125 @@ public class JdServiceImpl implements JdService { |
|
|
|
|
VopGoodsGetSkuStateListResponse skuStateListResponse = JdPostService.getSkuState(getToken(), goodsMsg.getThirdId()); |
|
|
|
|
|
|
|
|
|
if (skuStateListResponse.getOpenRpcResult().getResult().get(0).getSkuState() == 0) { |
|
|
|
|
// 创建线程
|
|
|
|
|
ThreadPoolExecutor executor = new ThreadPoolExecutor( |
|
|
|
|
2, // 核心线程数
|
|
|
|
|
5, // 最大线程数
|
|
|
|
|
1, // 线程空闲时间
|
|
|
|
|
TimeUnit.MINUTES, // 时间单位
|
|
|
|
|
new ArrayBlockingQueue<>(5), // 任务队列
|
|
|
|
|
new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
|
|
|
|
|
); |
|
|
|
|
// 提交任务给线程池
|
|
|
|
|
executor.execute(() -> { |
|
|
|
|
goodsMsg.setStatus(0); |
|
|
|
|
goodsMsgService.update(goodsMsg); |
|
|
|
|
}); |
|
|
|
|
// 关闭线程池
|
|
|
|
|
executor.shutdown(); |
|
|
|
|
deleteMsg(goodsMsg.getThirdId()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
BsProductConfig productConfig = productConfigService.queryDetail(OrderChildProductTypeEnum.type6.getCode()); |
|
|
|
|
|
|
|
|
|
updatePrice(goodsMsg); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean checkGoods(BsOrder bsOrder) throws Exception { |
|
|
|
|
|
|
|
|
|
BsOrderGoods orderGoods = bsOrderGoodsService.findGoodsOrder(bsOrder.getOrderNo()); |
|
|
|
|
if (orderGoods != null) { |
|
|
|
|
GoodsMsg goodsMsg = goodsMsgService.queryDetail(orderGoods.getGoodsId()); |
|
|
|
|
|
|
|
|
|
if (orderGoods.getThirdOrderNo() == null) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
// 查询上游订单
|
|
|
|
|
VopOrderQueryOrderDetailResponse orderDetailResponse = JdPostService.queryOrderDetail(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo()); |
|
|
|
|
|
|
|
|
|
QueryOrderOpenResp resp = orderDetailResponse.getOpenRpcResult().getResult().get(0); |
|
|
|
|
|
|
|
|
|
if (resp.getSkuInfoList().get(0).getSkuId() != Long.parseLong(goodsMsg.getThirdId())) { |
|
|
|
|
JdPostService.cancelOrder(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo() , "skuId编码错误"); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
if (!goodsMsg.getTitle().equals(resp.getSkuInfoList().get(0).getSkuName())) { |
|
|
|
|
JdPostService.cancelOrder(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo() , "商品错误!"); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (resp.getOrderPrice().getOrderTotalPrice().compareTo(bsOrder.getTotalPrice()) > 0) { |
|
|
|
|
JdPostService.cancelOrder(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo() , "商品价格错误"); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void cancelOrder(String childNo){ |
|
|
|
|
try { |
|
|
|
|
BsOrderGoods orderGoods = bsOrderGoodsService.findGoodsOrderByChild(childNo); |
|
|
|
|
if (orderGoods.getThirdOrderNo() != null) { |
|
|
|
|
JdPostService.cancelOrder(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo() , "取消订单!"); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void deleteMsg() throws Exception { |
|
|
|
|
|
|
|
|
|
String token = getToken(); |
|
|
|
|
|
|
|
|
|
VopMessageQueryTransByVopNormalResponse msgList = JdPostService.queryTransByVopNormal(token); |
|
|
|
|
|
|
|
|
|
List<VopBizTransMessage> messages = msgList.getOpenRpcResult().getResult(); |
|
|
|
|
|
|
|
|
|
StringBuilder stringBuffer = new StringBuilder(); |
|
|
|
|
if (messages != null) { |
|
|
|
|
for (VopBizTransMessage message : messages) { |
|
|
|
|
|
|
|
|
|
JSONObject jsonObj = JSONObject.parseObject(message.getContent()); |
|
|
|
|
|
|
|
|
|
//商品上下架变更消息
|
|
|
|
|
if (message.getType() == 4) { |
|
|
|
|
// state:1代表在主站(jd.com)上架; state:0代表下架
|
|
|
|
|
if (jsonObj.getInteger("state") == 0) { |
|
|
|
|
deleteMsg(jsonObj.getString("skuId")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 商品池内商品添加、删除消息
|
|
|
|
|
if (message.getType() == 6) { |
|
|
|
|
if (jsonObj.getInteger("state") == 2) { |
|
|
|
|
deleteMsg(jsonObj.getString("skuId")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//商品信息变更消息
|
|
|
|
|
if (message.getType() == 16) { |
|
|
|
|
updateGoodsMsg(token , jsonObj.getLong("skuId")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stringBuffer.length() == 0) { |
|
|
|
|
stringBuffer.append(message.getId()); |
|
|
|
|
} else { |
|
|
|
|
stringBuffer.append(",").append(message.getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
JdPostService.deleteClientMsgByIdList(token , stringBuffer.toString()); |
|
|
|
|
if (!messages.isEmpty()){ |
|
|
|
|
deleteMsg(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void confirmOrder(BsOrderGoods orderGoods) throws Exception { |
|
|
|
|
JdPostService.confirmOrder(getToken() , Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo() , "确认订单"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新商品价格
|
|
|
|
|
private void updatePrice(GoodsMsg goodsMsg) throws Exception { |
|
|
|
|
BsProductConfig productConfig = productConfigService.queryDetail(OrderChildProductTypeEnum.type6.getCode()); |
|
|
|
|
// 查询规格
|
|
|
|
|
GoodsSpecs specs = goodsSpecsService.queryDetailByThirdId(goodsMsg.getThirdId()); |
|
|
|
|
|
|
|
|
|
// 根据skuId 查询商品详情
|
|
|
|
|
VopGoodsGetSkuDetailInfoResponse skuDetail = JdPostService.getSkuDetailInfo(getToken(), Long.valueOf(goodsMsg.getThirdId())); |
|
|
|
|
GetSkuPoolInfoGoodsResp detail = skuDetail.getOpenRpcResult().getResult(); |
|
|
|
|
// 根据skuId 查询商品售价
|
|
|
|
|
OpenRpcResult priceResponse = JdPostService.getSellPrice(getToken(), String.valueOf(goodsMsg.getThirdId())).getOpenRpcResult(); |
|
|
|
|
GetSellPriceGoodsResp price = priceResponse.getResult().get(0); |
|
|
|
|
// 设置商品名称
|
|
|
|
|
specs.setName(detail.getSpuName()); |
|
|
|
|
// 设置涨价
|
|
|
|
|
BigDecimal profitPrice = price.getSalePrice().multiply(productConfig.getDiscount().divide(new BigDecimal(100) , 2, RoundingMode.HALF_UP)); |
|
|
|
|
// 设置销售价格
|
|
|
|
|
specs.setSalePrice(profitPrice.add(price.getSalePrice())); |
|
|
|
@ -359,8 +528,193 @@ public class JdServiceImpl implements JdService { |
|
|
|
|
specs.setOriginalPrice(price.getMarketPrice()); |
|
|
|
|
specs.setThirdPrice(price.getJdPrice()); |
|
|
|
|
// 设置展示图片
|
|
|
|
|
specs.setShowImg(goodsMsg.getListImg()); |
|
|
|
|
goodsSpecsService.update(specs); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public VopOrderQueryDeliveryInfoResponse queryDeliveryInfo(BsOrderGoods orderGoods) throws Exception{ |
|
|
|
|
return JdPostService.queryDeliveryInfo(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新商品信息
|
|
|
|
|
private void updateGoodsMsg(String token , Long aLong) throws Exception { |
|
|
|
|
// 根据skuId 查询商品详情
|
|
|
|
|
VopGoodsGetSkuDetailInfoResponse skuDetail = JdPostService.getSkuDetailInfo(token, aLong); |
|
|
|
|
GetSkuPoolInfoGoodsResp detail = skuDetail.getOpenRpcResult().getResult(); |
|
|
|
|
// 根据skuId 查询商品图片
|
|
|
|
|
com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.OpenRpcResult imageListResponse = JdPostService.getSkuImageList(token, String.valueOf(aLong)).getOpenRpcResult(); |
|
|
|
|
|
|
|
|
|
// 创建一个GoodsMsg对象
|
|
|
|
|
GoodsMsg goodsMsg = goodsMsgService.queryDetail(aLong.toString()); |
|
|
|
|
GetSkuImageGoodsResp img = imageListResponse.getResult().get(0); |
|
|
|
|
StringBuilder imgS = new StringBuilder(); |
|
|
|
|
// 遍历商品图片列表
|
|
|
|
|
for (SkuImageItemGoodsResp skuImage : img.getSkuImageList()) { |
|
|
|
|
// 如果图片是主图
|
|
|
|
|
if (skuImage.getIsPrimary() == 1) { |
|
|
|
|
// 设置主图
|
|
|
|
|
goodsMsg.setListImg("https://img13.360buyimg.com/n1/" + skuImage.getShortPath()); |
|
|
|
|
} |
|
|
|
|
// 如果图片不是主图
|
|
|
|
|
if (skuImage.getIsPrimary() == 0) { |
|
|
|
|
imgS.append("https://img13.360buyimg.com/n1/").append(skuImage.getShortPath()).append(","); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (imgS.length() > 0) { |
|
|
|
|
imgS.deleteCharAt(imgS.length() - 1); |
|
|
|
|
} |
|
|
|
|
goodsMsg.setTitle(detail.getSkuName()); |
|
|
|
|
// 设置轮播图
|
|
|
|
|
goodsMsg.setBannerImg(String.valueOf(imgS)); |
|
|
|
|
// 设置详情图
|
|
|
|
|
goodsMsg.setDetailImg(String.valueOf(imgS)); |
|
|
|
|
|
|
|
|
|
// 更新商品信息
|
|
|
|
|
goodsMsgService.update(goodsMsg); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 下架商品
|
|
|
|
|
private void deleteMsg(String aLong) { |
|
|
|
|
GoodsMsg goodsMsg = goodsMsgService.queryDetail(aLong); |
|
|
|
|
|
|
|
|
|
if (goodsMsg != null) { |
|
|
|
|
goodsMsg.setStatus(0); |
|
|
|
|
goodsMsg.setUpdateTime(new Date()); |
|
|
|
|
goodsMsgService.update(goodsMsg); |
|
|
|
|
|
|
|
|
|
GoodsSpecs specs = goodsSpecsService.queryDetailByThirdId(goodsMsg.getThirdId()); |
|
|
|
|
|
|
|
|
|
if (specs != null) { |
|
|
|
|
specs.setStatus(0); |
|
|
|
|
specs.setUpdateTime(new Date()); |
|
|
|
|
goodsSpecsService.update(specs); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public GoodsLogistics updateDeliveryInfo(BsOrderGoods orderGoods) throws Exception { |
|
|
|
|
// 查询京东物流
|
|
|
|
|
VopOrderQueryDeliveryInfoResponse deliveryInfoResponse = queryDeliveryInfo(orderGoods); |
|
|
|
|
com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryDeliveryInfo.OpenRpcResult result = deliveryInfoResponse.getOpenRpcResult(); |
|
|
|
|
|
|
|
|
|
if (result.getSuccess()) { |
|
|
|
|
DeliveryInfoQueryOpenResp deliveryInfo = result.getResult(); |
|
|
|
|
|
|
|
|
|
// 判断物流信息是否与订单相同
|
|
|
|
|
if (Objects.equals(deliveryInfo.getThirdOrderId(), orderGoods.getChildOrderNo())) { |
|
|
|
|
// 查询物流信息是否存在
|
|
|
|
|
if (!deliveryInfo.getTrackInfoList().isEmpty()) { |
|
|
|
|
LogisticInfoOrderOpenResp logisticInfo = deliveryInfo.getLogisticInfoList().get(0); |
|
|
|
|
// 查询物流信息
|
|
|
|
|
GoodsLogistics logistics = bsOrderGoodsService.findGoodsLogisticsByNum(logisticInfo.getDeliveryOrderId()); |
|
|
|
|
// 获取物流信息列表
|
|
|
|
|
List<TrackInfoOrderOpenResp> trackInfoList = deliveryInfo.getTrackInfoList(); |
|
|
|
|
// 创建一个JSON对象列表
|
|
|
|
|
List<JSONObject> objects = new ArrayList<>(); |
|
|
|
|
// 遍历物流信息列表
|
|
|
|
|
for (TrackInfoOrderOpenResp trackInfo : trackInfoList) { |
|
|
|
|
// 创建一个JSON对象
|
|
|
|
|
JSONObject object = new JSONObject(); |
|
|
|
|
// 将物流信息时间放入JSON对象
|
|
|
|
|
object.put("time", trackInfo.getTrackMsgTime()); |
|
|
|
|
// 将物流信息内容放入JSON对象
|
|
|
|
|
object.put("desc", trackInfo.getTrackContent()); |
|
|
|
|
// 将JSON对象添加到列表中
|
|
|
|
|
objects.add(object); |
|
|
|
|
} |
|
|
|
|
// 获取京东物流状态
|
|
|
|
|
JSONObject jsonObject = jdLogisticsStatus(orderGoods); |
|
|
|
|
// 如果物流信息为空
|
|
|
|
|
if (logistics == null) { |
|
|
|
|
// 创建一个新的物流信息对象
|
|
|
|
|
logistics = new GoodsLogistics(); |
|
|
|
|
// 设置物流信息订单号
|
|
|
|
|
logistics.setNumber(logisticInfo.getDeliveryOrderId()); |
|
|
|
|
// 设置物流信息任务号
|
|
|
|
|
logistics.setTaskNo(logisticInfo.getJdOrderId().toString()); |
|
|
|
|
// 设置物流状态
|
|
|
|
|
logistics.setLogisticsStatus(jsonObject.getString("logisticsStatus")); |
|
|
|
|
// 设置物流状态描述
|
|
|
|
|
logistics.setLogisticsStatusDesc(jsonObject.getString("logisticsStatusDesc")); |
|
|
|
|
// 设置物流跟踪详情
|
|
|
|
|
logistics.setLogisticsTraceDetails(objects.toString()); |
|
|
|
|
// 设置物流公司名称
|
|
|
|
|
logistics.setExpressCompanyName(logisticInfo.getDeliveryCarrier()); |
|
|
|
|
// 设置创建时间
|
|
|
|
|
logistics.setCreateTime(new Date()); |
|
|
|
|
// 创建物流信息
|
|
|
|
|
bsOrderGoodsService.create(logistics); |
|
|
|
|
} else { |
|
|
|
|
// 设置物流状态
|
|
|
|
|
logistics.setLogisticsStatus(jsonObject.getString("logisticsStatus")); |
|
|
|
|
// 设置物流状态描述
|
|
|
|
|
logistics.setLogisticsStatusDesc(jsonObject.getString("logisticsStatusDesc")); |
|
|
|
|
// 设置物流跟踪详情
|
|
|
|
|
logistics.setLogisticsTraceDetails(objects.toString()); |
|
|
|
|
// 更新物流信息
|
|
|
|
|
bsOrderGoodsService.update(logistics); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orderGoods.setLogisticsStatus(jsonObject.getString("logisticsStatus")); |
|
|
|
|
orderGoods.setLogisticsStatusDesc(jsonObject.getString("logisticsStatusDesc")); |
|
|
|
|
orderGoods.setLogisticsNo(logisticInfo.getDeliveryOrderId()); |
|
|
|
|
bsOrderGoodsService.update(orderGoods); |
|
|
|
|
return logistics; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public VopOrderQueryOrderDetailResponse queryOrderDetail(BsOrderGoods orderGoods) throws Exception { |
|
|
|
|
return JdPostService.queryOrderDetail(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public VopAfsCreateAfsApplyResponse createAfsApply(String thirdApplyId, Integer customerExpect, Long wareId, String wareName, Integer wareNum, Long jdOrderId, String customerName, Integer pickWareProvince, Integer pickWareCounty, Integer pickWareCity, String pickWareAddress, Integer returnWareProvince, Integer returnWareCounty, Integer returnWareCity, String returnWareAddress) throws Exception { |
|
|
|
|
return JdPostService.createAfsApply(getToken(), thirdApplyId, customerExpect, wareId, wareName, wareNum, jdOrderId, customerName, pickWareProvince, pickWareCounty, pickWareCity, pickWareAddress, returnWareProvince, returnWareCounty, returnWareCity, returnWareAddress); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private JSONObject jdLogisticsStatus(BsOrderGoods orderGoods) throws Exception { |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
// 查询上游订单
|
|
|
|
|
VopOrderQueryOrderDetailResponse orderDetailResponse = JdPostService.queryOrderDetail(getToken(), Long.valueOf(orderGoods.getThirdOrderNo()), orderGoods.getChildOrderNo()); |
|
|
|
|
com.jd.open.api.sdk.domain.vopdd.QueryOrderOpenProvider.response.queryOrderDetail.OpenRpcResult result = orderDetailResponse.getOpenRpcResult(); |
|
|
|
|
if (result.getSuccess()) { |
|
|
|
|
QueryOrderOpenResp queryOrderOpenResp = result.getResult().get(0); |
|
|
|
|
StateOrderOpenResp stateOrderOpenResp = queryOrderOpenResp.getOrderState(); |
|
|
|
|
// 查看订单是否已确认
|
|
|
|
|
if (stateOrderOpenResp.getConfirmState() == 1) { |
|
|
|
|
jsonObject.put("logisticsStatus", "SIGN"); |
|
|
|
|
jsonObject.put("logisticsStatusDesc", "已签收"); |
|
|
|
|
} |
|
|
|
|
// 订单状态为567为待揽收
|
|
|
|
|
if (stateOrderOpenResp.getConfirmState() == 5 || stateOrderOpenResp.getConfirmState() == 6 || stateOrderOpenResp.getConfirmState() == 7) { |
|
|
|
|
jsonObject.put("logisticsStatus", "WAIT_ACCEPT"); |
|
|
|
|
jsonObject.put("logisticsStatusDesc", "待揽收"); |
|
|
|
|
} |
|
|
|
|
// 订单状态为8,9,10为待发货
|
|
|
|
|
if (stateOrderOpenResp.getConfirmState() == 8 || stateOrderOpenResp.getConfirmState() == 9 || stateOrderOpenResp.getConfirmState() == 10) { |
|
|
|
|
jsonObject.put("logisticsStatus", "ACCEPT"); |
|
|
|
|
jsonObject.put("logisticsStatusDesc", "已揽件"); |
|
|
|
|
} |
|
|
|
|
// 订单状态为11,12,13,14为运输中
|
|
|
|
|
if (stateOrderOpenResp.getConfirmState() == 11 || stateOrderOpenResp.getConfirmState() == 12 || stateOrderOpenResp.getConfirmState() == 13 || stateOrderOpenResp.getConfirmState() == 14) { |
|
|
|
|
jsonObject.put("logisticsStatus", "TRANSPORT"); |
|
|
|
|
jsonObject.put("logisticsStatusDesc", "运输中"); |
|
|
|
|
} |
|
|
|
|
// 订单状态为16为派件中
|
|
|
|
|
if (stateOrderOpenResp.getConfirmState() == 16) { |
|
|
|
|
jsonObject.put("logisticsStatus", "DELIVERING"); |
|
|
|
|
jsonObject.put("logisticsStatusDesc", "派件中"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return jsonObject; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|