胡锐 6 months ago
commit 5375bc301d
  1. 71
      cweb/src/main/java/com/cweb/controller/discount/DiscountController.java
  2. 7
      order/src/main/java/com/order/controller/business/BsOrderGoodsController.java
  3. 1
      service/src/main/java/com/hfkj/model/order/OrderChildModel.java
  4. 7
      service/src/main/java/com/hfkj/model/order/OrderModel.java
  5. 1
      service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java
  6. 14
      service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountServiceImpl.java
  7. 19
      service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java
  8. 11
      service/src/main/java/com/hfkj/service/goods/impl/BsOrderGoodsServiceImpl.java
  9. 14
      service/src/main/java/com/hfkj/service/order/OrderCreateService.java
  10. 21
      service/src/main/java/com/hfkj/service/order/impl/BsOrderChildServiceImpl.java
  11. 18
      service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.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;
@ -34,6 +31,10 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value="/discount")
@ -47,6 +48,8 @@ public class DiscountController {
@Resource
private CouponDiscountUserRelService discountUserRelService;
@Resource
private CouponDiscountService couponDiscountService;
@RequestMapping(value = "/getListUserDiscount", method = RequestMethod.GET)
@ResponseBody
@ -70,6 +73,66 @@ 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<String, Object> map = new HashMap<>();
map.put("userId", userSession.getUser().getId());
map.put("status", 1);
List<CouponDiscountUserRel> list = discountUserRelService.getList(map);
List<CouponDiscountUserRel> listDiscount = list.stream().filter(distinctByKey(CouponDiscountUserRel::getDiscountId)).collect(Collectors.toList());
List<CouponDiscountUserRel> listFind = new ArrayList<>();
listDiscount.forEach(d -> {
Map<String, Object> mapSpecs = new HashMap<>();
mapSpecs.put("discountId", d.getDiscountId());
// 查询规格可用优惠券
List<CouponDiscountGoodsRel> couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs);
List<Long> specsIdList = new ArrayList<>();
couponDiscountGoodsRel.forEach(dg -> {
specsIdList.add(dg.getSpecsId());
});
String specsIdsStr = StringUtils.join(specsIdList, ",");
if (specsIdsStr.contains(specsIds)) {
listFind.add(d);
}
});
List<CouponDiscountUserRel> filteredList = list.stream()
.filter(obj -> listFind.stream()
.map(CouponDiscountUserRel::getDiscountId)
.collect(Collectors.toList())
.contains(obj.getDiscountId()))
.collect(Collectors.toList());
return ResponseMsgUtil.success(filteredList);
} catch (Exception e) {
log.error("GoodsDetailController --> getListUser() error!", e);
return ResponseMsgUtil.exception(e);
}
}
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
}

@ -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("更新成功!");

@ -1,6 +1,7 @@
package com.hfkj.model.order;
import com.hfkj.entity.BsOrderChild;
import com.hfkj.entity.BsOrderGoods;
import lombok.Data;
/**

@ -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;
/**
* 子订单列表
*/

@ -40,4 +40,5 @@ public interface CouponDiscountUserRelService {
* @return
*/
CouponDiscountUserRel getRel(Long id);
CouponDiscountUserRel getRel(Map<String , Object> map);
}

@ -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<Long> list = new ArrayList<>();
for (String specsId : specsIds) {
list.add(Long.valueOf(specsId));
}
criteria.andSpecsIdIn(list);
}
return couponDiscountGoodsRelMapper.selectByExample(example);
}

@ -52,5 +52,24 @@ public class CouponDiscountUserRelServiceImpl implements CouponDiscountUserRelSe
return couponDiscountUserRelMapper.selectByPrimaryKey(id);
}
@Override
public CouponDiscountUserRel getRel(Map<String, Object> 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;
}
}

@ -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;

@ -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<String, Object>) orderChild.getBusiness());
}
jsonObject.put("address", address);
// 创建实物订单
BsOrderGoods orderGoods = new BsOrderGoods();
@ -206,10 +214,16 @@ public class OrderCreateService {
bsOrderGoodsService.create(orderGoods);
jsonObject.put("orderGoodsId", orderGoods.getId());
if (object.getLong("shopCartId") != null) {
shoppingCartService.delete(object.getLong("shopCartId"));
}
orderChild.setBusiness(jsonObject);
return orderChild;
}

@ -70,19 +70,28 @@ public class BsOrderChildServiceImpl implements BsOrderChildService {
List<BsOrderChild> list = orderChildMapper.selectByExample(example);
List<OrderChildModel> 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<String, Object>) 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<String, Object>) 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);

@ -7,7 +7,6 @@ import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.RandomUtils;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.BsOrderMapper;
import com.hfkj.dao.CouponDiscountGoodsRelMapper;
import com.hfkj.entity.*;
import com.hfkj.model.order.OrderChildModel;
import com.hfkj.model.order.OrderModel;
@ -33,7 +32,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.DateUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
@ -127,11 +125,16 @@ public class BsOrderServiceImpl implements BsOrderService {
// 提交订单前实物商品处理
if (child.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) {
child = orderCreateService.goods(order, child);
// todo 1.0阶段暂时需要返回收货地址使用
order.setBusiness(child.getBusiness());
} else if (child.getProductType().equals(OrderChildProductTypeEnum.type2.getCode())) {
// 提交订单虚拟商品处理
child = orderCreateService.product(order, child);
}
// 提交订单前产品处理
if (child.getProductType().equals(OrderChildProductTypeEnum.type2.getCode())) {
child = orderCreateService.product(order, child);
}
child.setProductTotalPrice(child.getProductPrice().multiply(new BigDecimal(child.getProductCount().toString())));
child.setStatus(OrderChildStatusEnum.status1.getCode());
@ -445,6 +448,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;

Loading…
Cancel
Save