|
@@ -1,18 +1,33 @@
|
|
package com.xynet.marketing.service.factory.promotion.impl.base;
|
|
package com.xynet.marketing.service.factory.promotion.impl.base;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.xynet.marketing.entity.Promotion;
|
|
import com.xynet.marketing.entity.Promotion;
|
|
|
|
+import com.xynet.marketing.enums.PromotionStatusEnum;
|
|
|
|
+import com.xynet.marketing.enums.PromotionTypeEnum;
|
|
import com.xynet.marketing.mapper.PromotionMapper;
|
|
import com.xynet.marketing.mapper.PromotionMapper;
|
|
import com.xynet.marketing.service.MercProjectDeviceService;
|
|
import com.xynet.marketing.service.MercProjectDeviceService;
|
|
import com.xynet.marketing.service.MercProjectGoodsService;
|
|
import com.xynet.marketing.service.MercProjectGoodsService;
|
|
import com.xynet.marketing.service.factory.promotion.PromotionFactory;
|
|
import com.xynet.marketing.service.factory.promotion.PromotionFactory;
|
|
import com.xynet.marketing.utils.Emptys;
|
|
import com.xynet.marketing.utils.Emptys;
|
|
|
|
+import com.xynet.marketing.utils.collections.map.JHashMap;
|
|
import com.xynet.marketing.utils.collections.map.JMap;
|
|
import com.xynet.marketing.utils.collections.map.JMap;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 促销活动工厂-基类
|
|
* 促销活动工厂-基类
|
|
*
|
|
*
|
|
@@ -58,4 +73,142 @@ public class PromotionFactoryBase extends ServiceImpl<PromotionMapper, Promotion
|
|
|
|
|
|
return save.getId();
|
|
return save.getId();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<JMap<String, Object>> goodsListPrice(JMap<String, Object> param) {
|
|
|
|
+ List<JMap<String, Object>> goodsList = param.getListMap("goodsList");
|
|
|
|
+ String deviceId = param.getString("deviceId");
|
|
|
|
+ Integer mercId = param.getInt("mercId");
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ LocalDateTime orderCreateTime = LocalDateTime.parse(param.getString("orderCreateTime"), formatter);
|
|
|
|
+ //设置是否有促销活动默认值为false
|
|
|
|
+ for (int g = 0; g < goodsList.size(); g++) {
|
|
|
|
+ JMap<String, Object> goods = goodsList.get(g);
|
|
|
|
+ goods.set("promotionType1", false);
|
|
|
|
+ goods.set("promotionType2", false);
|
|
|
|
+ goods.set("promotionType3", false);
|
|
|
|
+ goods.set("havePromotion", false);
|
|
|
|
+ goods.set("promotionList", new ArrayList<Promotion>());
|
|
|
|
+ goods.set("priceOnsale", goods.get("price"));
|
|
|
|
+ }
|
|
|
|
+ //查询可使用方案列表
|
|
|
|
+ LambdaQueryWrapper<Promotion> lqw = new LambdaQueryWrapper<Promotion>()
|
|
|
|
+ .eq(Promotion::getMercId, mercId)
|
|
|
|
+ .eq(Promotion::getStatus, PromotionStatusEnum.UNDERWAY.getCode())
|
|
|
|
+ .eq(Promotion::getEnableStatus, true)
|
|
|
|
+ .le(Promotion::getStartTime, orderCreateTime)
|
|
|
|
+ .ge(Promotion::getEndTime, orderCreateTime)
|
|
|
|
+ .orderByDesc(Promotion::getWeight);
|
|
|
|
+ List<Promotion> promotionList = list(lqw);
|
|
|
|
+ if (!Emptys.check(promotionList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ //判断设备是否符合
|
|
|
|
+ for (int i = 0; i < promotionList.size(); i++) {
|
|
|
|
+ Promotion promotion = promotionList.get(i);
|
|
|
|
+ Boolean deviceCondition = promotion.getIsAllDevice();
|
|
|
|
+ //活动非所有设备适用,判断设备是否符合
|
|
|
|
+ if (!deviceCondition) {
|
|
|
|
+ //非全部设备,查看活动设备表中是否存在
|
|
|
|
+ deviceCondition = deviceService.checkDeviceId(promotion.getId(), deviceId, "promotion");
|
|
|
|
+ if (!deviceCondition) {
|
|
|
|
+ //设备不符合,直接从LIST删除
|
|
|
|
+ promotionList.remove(i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //重新判断活动是否为空
|
|
|
|
+ if (!Emptys.check(promotionList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ //查询活动商品表
|
|
|
|
+ List<Integer> promotionIdList = promotionList.stream().map(Promotion::getId).collect(Collectors.toList());
|
|
|
|
+ List<Map<String, Object>> actGoodsList = goodsService.list(new JHashMap<String, Object>()
|
|
|
|
+ .set("actIdList", promotionIdList)
|
|
|
|
+ .set("type", "promotion")
|
|
|
|
+ );
|
|
|
|
+ Map<Integer, List<Map<String, Object>>> actGoodsMap =
|
|
|
|
+ actGoodsList.stream().collect(
|
|
|
|
+ Collectors.groupingBy(i -> Integer.valueOf(i.get("actId").toString()))
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ //封装商品所属活动
|
|
|
|
+ /*
|
|
|
|
+ * 1.查询商品是否有特价活动
|
|
|
|
+ * 2.查询商品是否有折扣活动
|
|
|
|
+ * 3.查询满减活动
|
|
|
|
+ */
|
|
|
|
+ //查询特价活动
|
|
|
|
+ for (int p = 0; p < promotionList.size(); p++) {
|
|
|
|
+ Promotion promotion = promotionList.get(p);
|
|
|
|
+ if (Objects.equals(promotion.getType(), PromotionTypeEnum.T_3.getCode())) {
|
|
|
|
+ List<Map<String, Object>> promotionGoodsList = actGoodsMap.get(promotion.getId());
|
|
|
|
+ Map<String, Map<String, Object>> promotionGoodsMap = promotionGoodsList.stream().collect(Collectors.toMap(i -> i.get("goodsId").toString(), i -> i));
|
|
|
|
+ //循环商品,判断商品是否有特价
|
|
|
|
+ for (int g = 0; g < goodsList.size(); g++) {
|
|
|
|
+ JMap<String, Object> goods = goodsList.get(g);
|
|
|
|
+ Map<String, Object> promotionGoods = promotionGoodsMap.get(goods.getString("goodsId"));
|
|
|
|
+ if (Emptys.check(promotionGoods)) {
|
|
|
|
+ //设置优惠信息
|
|
|
|
+ goods.set("havePromotion", true);
|
|
|
|
+ goods.set("promotionType3", true);
|
|
|
|
+ //优惠价格
|
|
|
|
+ goods.set("priceOnsale", promotionGoods.get("priceOnsale"));
|
|
|
|
+ //优惠活动
|
|
|
|
+ List<Object> promotionList1 = goods.getList("promotionList");
|
|
|
|
+ promotionList1.add(promotion);
|
|
|
|
+ goods.set("promotionList", promotionList1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //查询商品是否有折扣、满减活动
|
|
|
|
+ for (int p = 0; p < promotionList.size(); p++) {
|
|
|
|
+ Promotion promotion = promotionList.get(p);
|
|
|
|
+ if (Objects.equals(promotion.getType(), PromotionTypeEnum.T_2.getCode())
|
|
|
|
+ || Objects.equals(promotion.getType(), PromotionTypeEnum.T_1.getCode())
|
|
|
|
+ ) {
|
|
|
|
+ for (int g = 0; g < goodsList.size(); g++) {
|
|
|
|
+ JMap<String, Object> goods = goodsList.get(g);
|
|
|
|
+ Boolean isPromotion = false;
|
|
|
|
+ //没有特价活动的
|
|
|
|
+ if (!goods.getBoolean("promotionType3")) {
|
|
|
|
+ if (promotion.getIsAllGoods()) {
|
|
|
|
+ isPromotion = true;
|
|
|
|
+ } else {
|
|
|
|
+ List<Map<String, Object>> promotionGoodsList = actGoodsMap.get(promotion.getId());
|
|
|
|
+ Map<String, Map<String, Object>> promotionGoodsMap = promotionGoodsList.stream().collect(
|
|
|
|
+ Collectors.toMap(i -> i.get("goodsId").toString(), i -> i));
|
|
|
|
+ Map<String, Object> promotionGoods = promotionGoodsMap.get(goods.getString("goodsId"));
|
|
|
|
+ if (Emptys.check(promotionGoods)) {
|
|
|
|
+ isPromotion = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (isPromotion) {
|
|
|
|
+ goods.set("havePromotion", true);
|
|
|
|
+ //折扣活动
|
|
|
|
+ if (Objects.equals(promotion.getType(), PromotionTypeEnum.T_2.getCode())) {
|
|
|
|
+ JSONObject priceJson = JSONUtil.parseObj(promotion.getPrice());
|
|
|
|
+ //设置优惠信息
|
|
|
|
+ BigDecimal scalar = new BigDecimal(priceJson.getStr("scalar"));
|
|
|
|
+ //优惠价格
|
|
|
|
+ //TODO 处理计算精度问题
|
|
|
|
+ goods.set("priceOnsale", goods.getInt("price") * scalar.doubleValue());
|
|
|
|
+ goods.set("promotionType2", true);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.equals(promotion.getType(), PromotionTypeEnum.T_1.getCode())) {
|
|
|
|
+ goods.set("promotionType3", true);
|
|
|
|
+ }
|
|
|
|
+ //优惠活动
|
|
|
|
+ goods.set("havePromotion", true);
|
|
|
|
+ List<Object> promotionList1 = goods.getList("promotionList");
|
|
|
|
+ promotionList1.add(promotion);
|
|
|
|
+ goods.set("promotionList", promotionList1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return goodsList;
|
|
|
|
+ }
|
|
}
|
|
}
|