diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/dao/CouponStoreDao.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/dao/CouponStoreDao.java new file mode 100644 index 00000000..3456510e --- /dev/null +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/dao/CouponStoreDao.java @@ -0,0 +1,7 @@ +package com.skyeye.coupon.dao; + +import com.skyeye.coupon.entity.CouponStore; +import com.skyeye.eve.dao.SkyeyeBaseMapper; + +public interface CouponStoreDao extends SkyeyeBaseMapper { +} diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/Coupon.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/Coupon.java index ec183e24..cf603ae3 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/Coupon.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/Coupon.java @@ -35,9 +35,9 @@ import java.util.List; @ApiModel(value = "优惠券/模版信息管理实体类") public class Coupon extends BaseGeneralInfo { - @TableField(value = "store_id") - @ApiModelProperty(value = "发布门店id") - private String storeId; + @TableField(value = "store_id_list") + @ApiModelProperty(value = "发布门店id列表", required = "json") + private List storeIdList; @TableField(value = "template_id") @ApiModelProperty(value = "模板id") diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/CouponStore.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/CouponStore.java new file mode 100644 index 00000000..b1f6c1e6 --- /dev/null +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/entity/CouponStore.java @@ -0,0 +1,28 @@ +package com.skyeye.coupon.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.skyeye.annotation.api.ApiModel; +import com.skyeye.annotation.api.ApiModelProperty; +import com.skyeye.common.entity.CommonInfo; +import com.skyeye.common.entity.features.BaseGeneralInfo; +import lombok.Data; + +@Data +@TableName(value = "shop_coupon_store") +@ApiModel(value = "门店与优惠券关联表实体类") +public class CouponStore extends CommonInfo { + + @TableId("id") + @ApiModelProperty("主键id。为空时新增,不为空时编辑") + private String id; + + @TableField(value = "store_id") + @ApiModelProperty(value = "门店id") + private String storeId; + + @TableField(value = "coupon_id") + @ApiModelProperty(value = "优惠券id") + private String couponId; +} diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponStoreService.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponStoreService.java new file mode 100644 index 00000000..b9db4195 --- /dev/null +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponStoreService.java @@ -0,0 +1,14 @@ +package com.skyeye.coupon.service; + +import com.skyeye.base.business.service.SkyeyeBusinessService; +import com.skyeye.coupon.entity.CouponStore; + +import java.util.List; + +public interface CouponStoreService extends SkyeyeBusinessService { + void createEntity(String couponId, List storeIdList); + + List queryListByStoreId(String storeId); + + void deleteByCouponIds(List ids); +} diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponUseService.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponUseService.java index 84d0bf40..48536c86 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponUseService.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/CouponUseService.java @@ -29,4 +29,6 @@ public interface CouponUseService extends SkyeyeBusinessService { void updateState(String couponUseId); void UpdateUsedCount(String couponUseId); + + void deleteByCouponIds(List ids); } diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponServiceImpl.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponServiceImpl.java index c6ac8445..d3d08bb3 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponServiceImpl.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponServiceImpl.java @@ -23,16 +23,21 @@ import com.skyeye.common.util.mybatisplus.MybatisPlusUtil; import com.skyeye.coupon.dao.CouponDao; import com.skyeye.coupon.entity.Coupon; import com.skyeye.coupon.entity.CouponMaterial; +import com.skyeye.coupon.entity.CouponStore; import com.skyeye.coupon.enums.CouponValidityType; import com.skyeye.coupon.enums.PromotionDiscountType; import com.skyeye.coupon.enums.PromotionMaterialScope; import com.skyeye.coupon.service.CouponMaterialService; import com.skyeye.coupon.service.CouponService; +import com.skyeye.coupon.service.CouponStoreService; import com.skyeye.coupon.service.CouponUseService; import com.skyeye.eve.rest.quartz.SysQuartzMation; import com.skyeye.eve.service.IQuartzService; import com.skyeye.exception.CustomException; import com.skyeye.rest.shopmaterialnorms.sevice.IShopMaterialNormsService; +import com.skyeye.xxljob.ShopXxlJob; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -65,6 +70,11 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl Integer.parseInt(coupon.getDiscountLimitPrice())) { + throw new CustomException("价格折扣类型优惠券,折扣金额不能大于等于优惠上限金额"); + } + if (Integer.parseInt(coupon.getDiscountPrice()) > Integer.parseInt(coupon.getUsePrice())) { + throw new CustomException("价格折扣类型优惠券,折扣金额不能大于等于使用金额"); + } } else { if (coupon.getDiscountPercent() == null) { throw new CustomException("折扣率类型优惠券,折扣率不能为空"); @@ -109,7 +125,7 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl queryWrapper = new QueryWrapper<>(); String storeId = params.get("storeId").toString(); String type = params.get("type").toString(); - if (StrUtil.isNotEmpty(storeId)) { - queryWrapper.eq(MybatisPlusUtil.toColumns(Coupon::getStoreId), storeId); + List couponStoreList = couponStoreService.queryListByStoreId(storeId); + List couponIdList = couponStoreList.stream().map(CouponStore::getCouponId).distinct().collect(Collectors.toList()); + if(CollectionUtil.isEmpty(couponIdList)){ + return; } + queryWrapper.in(CommonConstants.ID, couponIdList); String typeKey = MybatisPlusUtil.toColumns(Coupon::getTemplateId); if (StrUtil.equals(type, CommonNumConstants.NUM_ZERO.toString())) { queryWrapper.and(wrapper -> { @@ -224,7 +248,9 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl ids) { - couponMaterialService.deleteByCouponId(ids); + couponMaterialService.deleteByCouponId(ids);// 删除优惠券的适用对象 + couponStoreService.deleteByCouponIds(ids);// 删除优惠券与门店关联的信息 + couponUseService.deleteByCouponIds(ids); // 删除已领取的但是未使用的优惠券 } @Override diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponStoreServiceImpl.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponStoreServiceImpl.java new file mode 100644 index 00000000..d08f64c3 --- /dev/null +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponStoreServiceImpl.java @@ -0,0 +1,46 @@ +package com.skyeye.coupon.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.skyeye.annotation.service.SkyeyeService; +import com.skyeye.base.business.service.impl.SkyeyeBusinessServiceImpl; +import com.skyeye.common.util.mybatisplus.MybatisPlusUtil; +import com.skyeye.coupon.dao.CouponStoreDao; +import com.skyeye.coupon.entity.CouponStore; +import com.skyeye.coupon.service.CouponStoreService; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +@SkyeyeService(name = "门店与优惠券关联表信息管理", groupName = "门店与优惠券关联表信息管理") +public class CouponStoreServiceImpl extends SkyeyeBusinessServiceImpl implements CouponStoreService { + + @Override + public void createEntity(String couponId, List storeIdList) { + List list = super.queryAllData(); + for (String s : storeIdList) { + CouponStore couponStore = new CouponStore(); + couponStore.setStoreId(s); + couponStore.setCouponId(couponId); + list.add(couponStore); + } + super.createEntity(list, StrUtil.EMPTY); + } + + @Override + public List queryListByStoreId(String storeId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq(MybatisPlusUtil.toColumns(CouponStore::getStoreId), storeId); + return CollectionUtil.isEmpty(list(queryWrapper)) ? new ArrayList<>() : list(queryWrapper); + } + + @Override + public void deleteByCouponIds(List ids) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in(MybatisPlusUtil.toColumns(CouponStore::getCouponId), ids); + remove(queryWrapper); + } +} \ No newline at end of file diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponUseServiceImpl.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponUseServiceImpl.java index 8d716dce..d18afc4e 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponUseServiceImpl.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/coupon/service/impl/CouponUseServiceImpl.java @@ -14,6 +14,7 @@ import com.skyeye.annotation.service.SkyeyeService; import com.skyeye.base.business.service.impl.SkyeyeBusinessServiceImpl; import com.skyeye.common.constans.CommonConstants; import com.skyeye.common.constans.QuartzConstants; +import com.skyeye.common.constans.SysUserAuthConstants; import com.skyeye.common.enumeration.WhetherEnum; import com.skyeye.common.object.GetUserToken; import com.skyeye.common.object.InputObject; @@ -33,7 +34,9 @@ import com.skyeye.coupon.service.CouponUseService; import com.skyeye.eve.rest.quartz.SysQuartzMation; import com.skyeye.eve.service.IQuartzService; import com.skyeye.exception.CustomException; -import org.joda.time.LocalDate; +import com.skyeye.xxljob.ShopXxlJob; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -66,6 +69,8 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl list = list(queryWrapper); couponService.setDataMation(list, CouponUse::getCouponId); - return JSONUtil.toList(JSONUtil.toJsonStr(list), null); + List collect = list.stream().map(item -> { + item.setUsageCount(item.getCouponMation().getUseCount()); + return item; + }).collect(Collectors.toList()); + return JSONUtil.toList(JSONUtil.toJsonStr(collect), null); } @Override @@ -211,6 +222,11 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl(); } + String userTokenUserId = GetUserToken.getUserTokenUserId(InputObject.getRequest()); + Boolean aBoolean = SysUserAuthConstants.exitUserLoginRedisCache(userTokenUserId); + if (!aBoolean) { + return new HashMap<>(); + } String userId = InputObject.getLogParamsStatic().get("id").toString(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.select(MybatisPlusUtil.toColumns(CouponUse::getCouponId), "count(id) as total"); @@ -265,4 +281,12 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl ids) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in(MybatisPlusUtil.toColumns(CouponUse::getCouponId), ids); + queryWrapper.eq(MybatisPlusUtil.toColumns(CouponUse::getState), CouponUseState.UNUSED.getKey()); + remove(queryWrapper); + } } \ No newline at end of file diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderItemServiceImpl.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderItemServiceImpl.java index cb2be349..ecd6eed7 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderItemServiceImpl.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderItemServiceImpl.java @@ -156,7 +156,7 @@ public class OrderItemServiceImpl extends SkyeyeBusinessServiceImpl updateWrapper = new UpdateWrapper<>(); diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderServiceImpl.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderServiceImpl.java index 92e043d0..a7dc6ff8 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderServiceImpl.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/order/service/impl/OrderServiceImpl.java @@ -53,7 +53,10 @@ import com.skyeye.rest.shopmaterialnorms.sevice.IShopMaterialNormsService; import com.skyeye.store.entity.ShopAddress; import com.skyeye.store.service.ShopAddressService; import com.skyeye.store.service.ShopTradeCartService; +import com.skyeye.xxljob.ShopXxlJob; import com.xxl.job.core.util.IpUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -105,6 +108,8 @@ public class OrderServiceImpl extends SkyeyeBusinessServiceImpl @Autowired private ShopTradeCartService shopTradeCartService; + private static Logger log = LoggerFactory.getLogger(ShopXxlJob.class); + @Override public void createPrepose(Order order) { if (order == null&& ObjUtil.isEmpty(order)) { @@ -269,7 +274,9 @@ public class OrderServiceImpl extends SkyeyeBusinessServiceImpl public void createPostpose(Order order, String userId) { orderItemService.setValueAndCreateEntity(order, userId); couponUseService.updateState(order.getCouponUseId());// 更新用户领取的优惠券状态 + log.info("订单id:"+order.getId()+"创建定时任务-- 开始"); startUpTaskQuartz(order.getId(), order.getOddNumber(), DateUtil.getTimeAndToString()); + log.info("订单id:"+order.getId()+"创建定时任务-- 结束"); shopTradeCartService.deleteMySelect(userId); } @@ -486,6 +493,9 @@ public class OrderServiceImpl extends SkyeyeBusinessServiceImpl updateWrapper.set(MybatisPlusUtil.toColumns(Order::getCancelType), params.get("cancelType")); updateWrapper.set(MybatisPlusUtil.toColumns(Order::getCancelTime), DateUtil.getTimeAndToString()); update(updateWrapper); + log.info("订单id" + one.getId() + "取消订单--取消定时任务-- 开始"); + iQuartzService.stopAndDeleteTaskQuartz(one.getId());// 删除任务 + log.info("订单id" + one.getId() + "取消订单--取消定时任务-- 结束"); refreshCache(params.get("id").toString()); } else { throw new CustomException("订单不可取消"); @@ -543,7 +553,9 @@ public class OrderServiceImpl extends SkyeyeBusinessServiceImpl updateWrapper.set(MybatisPlusUtil.toColumns(Order::getExtensionNo), payOrderRespDTO.get("no").toString()); update(updateWrapper); refreshCache(id); + log.info("订单id" + one.getId() + "支付成功--删除定时任务-- 开始"); iQuartzService.stopAndDeleteTaskQuartz(id);// 删除定时任务 + log.info("订单id" + one.getId() + "支付成功--删除定时任务-- 结束"); } @Override @@ -611,7 +623,7 @@ public class OrderServiceImpl extends SkyeyeBusinessServiceImpl boolean allTwo = orderItemList.stream().map(OrderItem::getOrderItemState) .allMatch(orderItemState -> orderItemState == ShopOrderItemState.FINISHED.getKey()); if (allTwo) { - updateOrderState(orderId, ShopOrderState.COMPLETED.getKey()); + updateOrderState(orderId, ShopOrderState.SIGN.getKey()); } else { updateOrderState(orderId, ShopOrderState.PARTIALLYDONE.getKey()); } diff --git a/skyeye-shop/shop-store/src/main/java/com/skyeye/xxljob/ShopXxlJob.java b/skyeye-shop/shop-store/src/main/java/com/skyeye/xxljob/ShopXxlJob.java index 44448b04..39aac077 100644 --- a/skyeye-shop/shop-store/src/main/java/com/skyeye/xxljob/ShopXxlJob.java +++ b/skyeye-shop/shop-store/src/main/java/com/skyeye/xxljob/ShopXxlJob.java @@ -11,6 +11,8 @@ import com.skyeye.eve.service.IQuartzService; import com.skyeye.order.service.OrderService; import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.handler.annotation.XxlJob; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -39,16 +41,24 @@ public class ShopXxlJob { @Autowired private IQuartzService iQuartzService; + private static Logger log = LoggerFactory.getLogger(ShopXxlJob.class); + @XxlJob("setShopCouponStateService") public void setShopCouponStateService() { String param = XxlJobHelper.getJobParam(); Map paramMap = JSONUtil.toBean(param, null); String couponId = paramMap.get("objectId");// 优惠券id try { + log.info("优惠券id(couponId)" + couponId + "---修改优惠券的状态---开始"); couponService.setStateByCoupon(couponId);// 修改优惠券的状态 + log.info("优惠券id(couponId)" + couponId + "---修改优惠券的状态---结束"); + log.info("优惠券id(couponId)" + couponId + "---修改领取的优惠券的状态---开始"); couponUseService.setCouponUseStateByDate(couponId);// 修改领取的优惠券的状态 + log.info("优惠券id(couponId)" + couponId + "---修改领取的优惠券的状态---结束"); } finally { + log.info("优惠券id(couponId)" + couponId + "---删除任务---开始"); iQuartzService.stopAndDeleteTaskQuartz(couponId);// 删除任务 + log.info("优惠券id(couponId)" + couponId + "---删除任务---结束"); } } @@ -59,9 +69,13 @@ public class ShopXxlJob { String userId = paramMap.get("userId"); String couponUseId = paramMap.get("objectId");// 领取的优惠券id try { + log.info("领取优惠券的id(couponUseId)" + couponUseId + "---修改领取的优惠券的状态---开始"); couponUseService.setCouponUseStateByTerm(userId, couponUseId);// 修改领取的优惠券的状态} + log.info("领取优惠券的id(couponUseId)" + couponUseId + "---修改领取的优惠券的状态---结束"); } finally { + log.info("领取优惠券的id(couponUseId)" + couponUseId + "---删除任务---开始"); iQuartzService.stopAndDeleteTaskQuartz(couponUseId);// 删除任务 + log.info("领取优惠券的id(couponUseId)" + couponUseId + "---删除任务---结束"); } } @@ -71,9 +85,13 @@ public class ShopXxlJob { Map paramMap = JSONUtil.toBean(param, null); String orderId = paramMap.get("objectId");// 订单的主键id try { + log.info("订单的主键id(orderId)" + orderId + "---修改订单的状态为取消---开始"); orderService.setOrderCancle(orderId);// 修改订单的状态为取消 + log.info("订单的主键id(orderId)" + orderId + "---修改订单的状态为取消---结束"); } finally { + log.info("订单的主键id(orderId)" + orderId + "---删除任务---开始"); iQuartzService.stopAndDeleteTaskQuartz(orderId);// 删除任务 + log.info("订单的主键id(orderId)" + orderId + "---删除任务---结束"); } } }