From cd824e15be7c0c8aad3515e4a61bf10717099cb6 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Thu, 23 May 2024 09:23:07 +0800 Subject: [PATCH] Changes --- .../discount/DiscountController.java | 49 +++++++++++++++++-- .../business/BsOrderGoodsController.java | 7 ++- .../java/com/hfkj/model/order/OrderModel.java | 7 +++ .../discount/CouponDiscountService.java | 2 +- .../CouponDiscountUserRelService.java | 1 + .../impl/CouponDiscountServiceImpl.java | 14 ++++-- .../CouponDiscountUserRelServiceImpl.java | 19 +++++++ .../goods/impl/BsOrderGoodsServiceImpl.java | 11 +++-- .../service/order/OrderCreateService.java | 10 ++++ .../order/impl/BsOrderChildServiceImpl.java | 24 ++++++--- .../order/impl/BsOrderServiceImpl.java | 10 ++++ 11 files changed, 135 insertions(+), 19 deletions(-) diff --git a/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java b/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java index 50ced44..50ea6f0 100644 --- a/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java +++ b/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java @@ -9,10 +9,7 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.SessionObject; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; -import com.hfkj.entity.CouponDiscount; -import com.hfkj.entity.CouponDiscountGoodsRel; -import com.hfkj.entity.GoodsMsg; -import com.hfkj.entity.GoodsSpecs; +import com.hfkj.entity.*; import com.hfkj.model.ResponseData; import com.hfkj.model.SecUserSessionObject; import com.hfkj.model.UserSessionObject; @@ -47,6 +44,8 @@ public class DiscountController { @Resource private CouponDiscountUserRelService discountUserRelService; + @Resource + private CouponDiscountService couponDiscountService; @RequestMapping(value = "/getListUserDiscount", method = RequestMethod.GET) @ResponseBody @@ -70,6 +69,48 @@ public class DiscountController { } } + @RequestMapping(value = "/getGoodsDiscount", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取商品可用优惠券") + public ResponseData getGoodsDiscount(@RequestParam(value = "specsIds", required = true) String specsIds) { + try { + + // 用户session + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + + Map mapSpecs = new HashMap<>(); + + mapSpecs.put("specsIds", specsIds); + + // 查询规格可用优惠券 + List couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs); + + if (couponDiscountGoodsRel == null) { + return ResponseMsgUtil.success(null); + } + + + List list = new ArrayList<>(); + + for(CouponDiscountGoodsRel rel : couponDiscountGoodsRel) { + Map map = new HashMap<>(); + + map.put("userId", userSession.getUser().getId()); + map.put("status", 1); + map.put("discountId", rel.getDiscountId()); + CouponDiscountUserRel couponDiscountUserRel = discountUserRelService.getRel(map); + list.add(couponDiscountUserRel); + } + + + return ResponseMsgUtil.success(list); + + } catch (Exception e) { + log.error("GoodsDetailController --> getListUser() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java b/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java index 585ac05..a2649b7 100644 --- a/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java +++ b/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java @@ -15,6 +15,7 @@ import com.hfkj.entity.GoodsLogistics; import com.hfkj.model.ResponseData; import com.hfkj.model.SecUserSessionObject; import com.hfkj.service.goods.BsOrderGoodsService; +import com.hfkj.service.order.BsOrderService; import com.hfkj.sysenum.SecUserObjectTypeEnum; import com.hfkj.sysenum.order.OrderGoodsStatusEnum; import io.swagger.annotations.Api; @@ -45,6 +46,9 @@ public class BsOrderGoodsController { @Resource private UserCenter userCenter; + @Resource + private BsOrderService orderService; + @RequestMapping(value="/getListGoods",method = RequestMethod.GET) @ResponseBody @@ -122,7 +126,8 @@ public class BsOrderGoodsController { if (goodsOrder.getStatus() == OrderGoodsStatusEnum.status1.getCode()) { goodsOrder.setStatus(OrderGoodsStatusEnum.status2.getCode()); } - + // 删除缓存 + orderService.cacheDelete(goodsOrder.getOrderNo()); bsOrderGoodsService.update(goodsOrder); return ResponseMsgUtil.success("更新成功!"); diff --git a/service/src/main/java/com/hfkj/model/order/OrderModel.java b/service/src/main/java/com/hfkj/model/order/OrderModel.java index 0352b1d..7a94d4b 100644 --- a/service/src/main/java/com/hfkj/model/order/OrderModel.java +++ b/service/src/main/java/com/hfkj/model/order/OrderModel.java @@ -3,6 +3,7 @@ package com.hfkj.model.order; import com.hfkj.entity.BsOrder; import com.hfkj.entity.BsOrderChild; import com.hfkj.entity.BsOrderDeduction; +import com.hfkj.entity.GoodsUserAddress; import lombok.Data; import java.util.List; @@ -21,6 +22,12 @@ public class OrderModel extends BsOrder { */ private BsOrderDeduction deduction; + /** + * 业务信息 + * todo 1.0阶段暂用后续会删除 + */ + private Object business; + /** * 子订单列表 */ diff --git a/service/src/main/java/com/hfkj/service/discount/CouponDiscountService.java b/service/src/main/java/com/hfkj/service/discount/CouponDiscountService.java index 751c052..afe5ca5 100644 --- a/service/src/main/java/com/hfkj/service/discount/CouponDiscountService.java +++ b/service/src/main/java/com/hfkj/service/discount/CouponDiscountService.java @@ -116,5 +116,5 @@ public interface CouponDiscountService { * @return void */ void deleteDiscountGoodsRelDiscountId(Long discountId); - + } diff --git a/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java b/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java index 97e5390..4fe7ba4 100644 --- a/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java +++ b/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java @@ -40,4 +40,5 @@ public interface CouponDiscountUserRelService { * @return */ CouponDiscountUserRel getRel(Long id); + CouponDiscountUserRel getRel(Map map); } diff --git a/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountServiceImpl.java index 4561bc2..9a62ba6 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountServiceImpl.java @@ -9,10 +9,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; @Service("couponDiscountService") public class CouponDiscountServiceImpl implements CouponDiscountService { @@ -85,6 +82,15 @@ public class CouponDiscountServiceImpl implements CouponDiscountService { criteria.andDiscountIdEqualTo(MapUtils.getLong(map, "discountId")); } + if (StringUtils.isNotBlank(MapUtils.getString(map, "specsIds"))) { + String[] specsIds = MapUtils.getString(map, "specsIds").split(","); + List list = new ArrayList<>(); + for (String specsId : specsIds) { + list.add(Long.valueOf(specsId)); + } + criteria.andSpecsIdIn(list); + } + return couponDiscountGoodsRelMapper.selectByExample(example); } diff --git a/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java index c7decfa..861c90c 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java @@ -52,5 +52,24 @@ public class CouponDiscountUserRelServiceImpl implements CouponDiscountUserRelSe return couponDiscountUserRelMapper.selectByPrimaryKey(id); } + @Override + public CouponDiscountUserRel getRel(Map map) { + CouponDiscountUserRelExample example = new CouponDiscountUserRelExample(); + CouponDiscountUserRelExample.Criteria criteria = example.createCriteria(); + + + if (MapUtils.getInteger(map, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); + } + if (MapUtils.getInteger(map, "discountId") != null) { + criteria.andDiscountIdEqualTo(MapUtils.getLong(map, "discountId")); + } + + if (MapUtils.getInteger(map, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); + } + return null; + } + } diff --git a/service/src/main/java/com/hfkj/service/goods/impl/BsOrderGoodsServiceImpl.java b/service/src/main/java/com/hfkj/service/goods/impl/BsOrderGoodsServiceImpl.java index 86a9c61..236728c 100644 --- a/service/src/main/java/com/hfkj/service/goods/impl/BsOrderGoodsServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/goods/impl/BsOrderGoodsServiceImpl.java @@ -26,6 +26,11 @@ import java.util.Objects; @Service("bsOrderGoodsService") public class BsOrderGoodsServiceImpl implements BsOrderGoodsService { + // 缓存前缀KEY + public final static String CACHE_KEY = "LOGISTICS:"; + // 订单缓存时间 7天 + public final static Integer CACHE_TIME = 60*60*6; + @Resource private BsOrderGoodsMapper bsOrderGoodsMapper; @Resource @@ -203,7 +208,7 @@ public class BsOrderGoodsServiceImpl implements BsOrderGoodsService { @Override public Object getLogisticsMsg(Long orderGoodsId) { - Object data = redisUtil.get("logisticsMsg" + orderGoodsId); + Object data = redisUtil.get(CACHE_KEY + orderGoodsId); if (data == null) { BsOrderGoods orderGoods = queryDetail(orderGoodsId); if (orderGoods == null || orderGoods.getLogisticsNo() == null) { @@ -216,11 +221,11 @@ public class BsOrderGoodsServiceImpl implements BsOrderGoodsService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂未发货!"); } - redisUtil.set("logisticsMsgOl" + orderGoodsId , jsonObjects ,21600); + redisUtil.set(CACHE_KEY + orderGoods.getLogisticsNo(), jsonObjects, CACHE_TIME); if (jsonObjects.getInteger("code") == 200 && jsonObjects.getBoolean("success")) { jsonObjects.getJSONObject("data").put("orderId" , orderGoodsId); GoodsLogistics logistics = editLogistics((JSONObject) jsonObjects.get("data")); - redisUtil.set("logisticsMsg" + orderGoodsId , logistics ,21600); + redisUtil.set(CACHE_KEY + orderGoodsId, logistics, CACHE_TIME); return logistics; } return jsonObjects; diff --git a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java index eae3357..551dcfd 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java @@ -179,6 +179,14 @@ public class OrderCreateService { if (address == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的收货地址"); } + JSONObject jsonObject; + if (orderChild.getBusiness() == null) { + jsonObject = new JSONObject(); + } else { + jsonObject = new JSONObject((Map) orderChild.getBusiness()); + } + + jsonObject.put("address", address); // 创建实物订单 BsOrderGoods orderGoods = new BsOrderGoods(); @@ -210,6 +218,8 @@ public class OrderCreateService { shoppingCartService.delete(object.getLong("shopCartId")); } + orderChild.setBusiness(jsonObject); + return orderChild; } diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java index 4be4581..126dc2d 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java @@ -70,21 +70,33 @@ public class BsOrderChildServiceImpl implements BsOrderChildService { List list = orderChildMapper.selectByExample(example); List orderChildModelList = new ArrayList<>(); + for (BsOrderChild orderChild : list) { OrderChildModel childModel = new OrderChildModel(); BeanUtils.copyProperties(orderChild, childModel); BsOrderGoods orderGoods = orderGoodsService.findGoodsOrder(orderNo); - GoodsUserAddress address = goodsUserAddressService.queryDetail(orderGoods.getId()); - - JSONObject object = new JSONObject((Map) childModel.getBusiness()); + if (orderGoods != null) { + GoodsUserAddress address = goodsUserAddressService.queryDetail(orderGoods.getDeliveryAddressId()); + JSONObject object; + if (childModel.getBusiness() == null) { + object = new JSONObject(); + } else { + object = new JSONObject((Map) childModel.getBusiness()); + } + + object.put("address", address); + if (orderGoods.getLogisticsNo() != null) { + object.put("logisticsNo", orderGoods.getLogisticsNo()); + } + childModel.setBusiness(object); - object.put("address", address); - if (orderGoods.getLogisticsNo() != null) { - object.put("logisticsNo", orderGoods.getLogisticsNo()); } + + + orderChildModelList.add(childModel); } return orderChildModelList; diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index e319291..c3c616b 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -1,5 +1,6 @@ package com.hfkj.service.order.impl; +import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; @@ -445,6 +446,15 @@ public class BsOrderServiceImpl implements BsOrderService { // 子订单 orderModel.setOrderChildList(orderChildService.getOrderChildListByOrderNo(orderNo)); + // todo 1.0阶段暂时需要返回收货地址使用 + for (OrderChildModel orderChild : orderModel.getOrderChildList()) { + + if (orderChild.getProductType() == 1) { + orderModel.setBusiness(orderChild.getBusiness()); + } + + } + // 更新缓存 cache(orderModel); return orderModel;