diff --git a/src/main/java/cn/van/business/model/jd/OrderRow.java b/src/main/java/cn/van/business/model/jd/OrderRow.java index cb672b8..5a94119 100644 --- a/src/main/java/cn/van/business/model/jd/OrderRow.java +++ b/src/main/java/cn/van/business/model/jd/OrderRow.java @@ -164,10 +164,8 @@ public class OrderRow { @Column(name = "rid") private Long rid; - //@OneToOne(cascade = CascadeType.ALL) - //@JoinColumn(name = "goods_info_id", referencedColumnName = "id") - //private GoodsInfoVO goodsInfo; - + @Column(name = "goods_info_id") + private Long goodsInfoId; @Column(name = "express_status") private Integer expressStatus; @@ -548,13 +546,13 @@ public class OrderRow { this.rid = rid; } - //public GoodsInfoVO getGoodsInfo() { - // return goodsInfo; - //} - // - //public void setGoodsInfo(GoodsInfoVO goodsInfo) { - // this.goodsInfo = goodsInfo; - //} + public Long getGoodsInfoId() { + return goodsInfoId; + } + + public void setGoodsInfoId(Long goodsInfoId) { + this.goodsInfoId = goodsInfoId; + } public Integer getExpressStatus() { return expressStatus; diff --git a/src/main/java/cn/van/business/repository/GoodsInfoRepository.java b/src/main/java/cn/van/business/repository/GoodsInfoRepository.java new file mode 100644 index 0000000..d73b63c --- /dev/null +++ b/src/main/java/cn/van/business/repository/GoodsInfoRepository.java @@ -0,0 +1,13 @@ +package cn.van.business.repository; + +import cn.van.business.model.jd.GoodsInfoVO; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface GoodsInfoRepository extends JpaRepository { + + Optional findFirstByImageUrlAndShopName(String imageUrl, String shopName); +} diff --git a/src/main/java/cn/van/business/util/JDScheduleJob.java b/src/main/java/cn/van/business/util/JDScheduleJob.java index bf8dc7a..451dc27 100644 --- a/src/main/java/cn/van/business/util/JDScheduleJob.java +++ b/src/main/java/cn/van/business/util/JDScheduleJob.java @@ -2,11 +2,14 @@ package cn.van.business.util; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; +import cn.van.business.model.jd.GoodsInfoVO; import cn.van.business.model.jd.OrderRow; import cn.van.business.model.pl.Comment; import cn.van.business.model.wx.SuperAdmin; import cn.van.business.repository.CommentRepository; +import cn.van.business.repository.GoodsInfoRepository; import cn.van.business.repository.OrderRowRepository; +import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.GoodsInfo; import cn.van.business.util.jdReq.*; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; @@ -59,6 +62,7 @@ public class JDScheduleJob { private static final String JD_REFRESH_TAG = "jd:refresh:tag:"; private final StringRedisTemplate redisTemplate; private final OrderRowRepository orderRowRepository; + private final GoodsInfoRepository goodsInfoRepository; private final OrderUtil orderUtil; private final JDUtil jdUtil; private final CommentRepository commentRepository; @@ -81,9 +85,10 @@ public class JDScheduleJob { // 构造函数中注入StringRedisTemplate @Autowired - public JDScheduleJob(WXUtil wxUtil, StringRedisTemplate redisTemplate, OrderRowRepository orderRowRepository, OrderUtil orderUtil, JDUtil jdUtil, CommentRepository commentRepository) { + public JDScheduleJob(WXUtil wxUtil, StringRedisTemplate redisTemplate, OrderRowRepository orderRowRepository, GoodsInfoRepository goodsInfoRepository, OrderUtil orderUtil, JDUtil jdUtil, CommentRepository commentRepository) { this.redisTemplate = redisTemplate; this.orderRowRepository = orderRowRepository; + this.goodsInfoRepository = goodsInfoRepository; this.orderUtil = orderUtil; this.jdUtil = jdUtil; this.commentRepository = commentRepository; @@ -123,14 +128,10 @@ public class JDScheduleJob { orderRow.setPayMonth(orderRowResp.getPayMonth()); orderRow.setSiteId(orderRowResp.getSiteId()); orderRow.setParentId(orderRowResp.getParentId()); - //GoodsInfo goodsInfo = orderRowResp.getGoodsInfo(); - //GoodsInfoVO goodsInfoVO = new GoodsInfoVO(); - //goodsInfoVO.setShopId(String.valueOf(goodsInfo.getShopId())); - //goodsInfoVO.setShopName(goodsInfo.getShopName()); - //goodsInfoVO.setOwner(goodsInfo.getOwner()); - //goodsInfoVO.setProductId(String.valueOf(goodsInfo.getProductId())); - //goodsInfoVO.setImageUrl(goodsInfo.getImageUrl()); - //orderRow.setGoodsInfo(goodsInfoVO); + GoodsInfoVO goodsInfoVO = resolveGoodsInfo(orderRowResp.getGoodsInfo(), orderRowResp.getSkuId()); + if (goodsInfoVO != null) { + orderRow.setGoodsInfoId(goodsInfoVO.getId()); + } orderRow.setCallerItemId(orderRowResp.getCallerItemId()); orderRow.setPid(orderRowResp.getPid()); orderRow.setCid1(orderRowResp.getCid1()); @@ -165,6 +166,39 @@ public class JDScheduleJob { return orderRow; } + private GoodsInfoVO resolveGoodsInfo(GoodsInfo goodsInfo, Long skuId) { + if (goodsInfo == null) { + return null; + } + String imageUrl = goodsInfo.getImageUrl(); + String shopName = goodsInfo.getShopName(); + if ((imageUrl == null || imageUrl.isBlank()) && (shopName == null || shopName.isBlank())) { + return null; + } + if (imageUrl != null && shopName != null) { + Optional existing = goodsInfoRepository.findFirstByImageUrlAndShopName(imageUrl, shopName); + if (existing.isPresent()) { + return existing.get(); + } + } + GoodsInfoVO vo = new GoodsInfoVO(); + vo.setImageUrl(imageUrl); + vo.setShopName(shopName); + vo.setOwner(goodsInfo.getOwner()); + if (goodsInfo.getShopId() != null) { + vo.setShopId(String.valueOf(goodsInfo.getShopId())); + } + if (goodsInfo.getMainSkuId() != null) { + vo.setMainSkuId(String.valueOf(goodsInfo.getMainSkuId())); + } else if (skuId != null) { + vo.setMainSkuId(String.valueOf(skuId)); + } + if (goodsInfo.getProductId() != null) { + vo.setProductId(String.valueOf(goodsInfo.getProductId())); + } + return goodsInfoRepository.save(vo); + } + /** * 根据指定的日期时间拉取订单 * @@ -453,7 +487,7 @@ public class JDScheduleJob { orderReq.setStartTime(startTime); orderReq.setEndTime(endTime); orderReq.setType(1); - + orderReq.setFields("goodsInfo"); request.setOrderReq(orderReq); request.setVersion("1.0");