Merge remote-tracking branch 'origin/company_server' into company_server

This commit is contained in:
luluyuyu 2024-12-14 20:41:21 +08:00
commit 22c017f0f4
11 changed files with 190 additions and 13 deletions

View file

@ -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<CouponStore> {
}

View file

@ -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<String> storeIdList;
@TableField(value = "template_id")
@ApiModelProperty(value = "模板id")

View file

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

View file

@ -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<CouponStore> {
void createEntity(String couponId, List<String> storeIdList);
List<CouponStore> queryListByStoreId(String storeId);
void deleteByCouponIds(List<String> ids);
}

View file

@ -29,4 +29,6 @@ public interface CouponUseService extends SkyeyeBusinessService<CouponUse> {
void updateState(String couponUseId);
void UpdateUsedCount(String couponUseId);
void deleteByCouponIds(List<String> ids);
}

View file

@ -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<CouponDao, Coup
@Autowired
private IQuartzService iQuartzService;
@Autowired
private CouponStoreService couponStoreService;
private static Logger log = LoggerFactory.getLogger(ShopXxlJob.class);
@Override
public void validatorEntity(Coupon coupon) {
// 模板新增
@ -101,6 +111,12 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
if (coupon.getDiscountPrice() == null) {
throw new CustomException("价格折扣类型优惠券,折扣金额不能为空");
}
if (Integer.parseInt(coupon.getDiscountPrice()) > 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<CouponDao, Coup
if (coupon.getTotalCount() <= CommonNumConstants.NUM_ZERO && coupon.getTotalCount() != -1) {
throw new CustomException("优惠券总量不能为空");
}
if (coupon.getUseCount()<=0){
if (coupon.getUseCount() <= CommonNumConstants.NUM_ZERO) {
throw new CustomException("优惠券总使用次数不能为零");
}
}
@ -121,9 +137,14 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
@Override
public void createPostpose(Coupon entity, String userId) {
if (CollectionUtil.isNotEmpty(entity.getStoreIdList())) {// 优惠券关联门店
couponStoreService.createEntity(entity.getId(),entity.getStoreIdList());
}
if (StrUtil.isNotEmpty(entity.getTemplateId())) {// 优惠券
if (Objects.equals(entity.getValidityType(), CouponValidityType.DATE.getKey())) {
log.info("优惠券id" + entity.getId() + "创建定时任务-- 开始");
startUpTaskQuartz(entity.getId(), entity.getName(), entity.getValidEndTime());
log.info("优惠券id" + entity.getId() + "创建定时任务-- 结束");
}
}
}
@ -192,9 +213,12 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
QueryWrapper<Coupon> 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<CouponStore> couponStoreList = couponStoreService.queryListByStoreId(storeId);
List<String> 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<CouponDao, Coup
@Override
public void deletePostpose(List<String> ids) {
couponMaterialService.deleteByCouponId(ids);
couponMaterialService.deleteByCouponId(ids);// 删除优惠券的适用对象
couponStoreService.deleteByCouponIds(ids);// 删除优惠券与门店关联的信息
couponUseService.deleteByCouponIds(ids); // 删除已领取的但是未使用的优惠券
}
@Override

View file

@ -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<CouponStoreDao, CouponStore> implements CouponStoreService {
@Override
public void createEntity(String couponId, List<String> storeIdList) {
List<CouponStore> 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<CouponStore> queryListByStoreId(String storeId) {
QueryWrapper<CouponStore> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(MybatisPlusUtil.toColumns(CouponStore::getStoreId), storeId);
return CollectionUtil.isEmpty(list(queryWrapper)) ? new ArrayList<>() : list(queryWrapper);
}
@Override
public void deleteByCouponIds(List<String> ids) {
QueryWrapper<CouponStore> queryWrapper = new QueryWrapper<>();
queryWrapper.in(MybatisPlusUtil.toColumns(CouponStore::getCouponId), ids);
remove(queryWrapper);
}
}

View file

@ -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<CouponUseDao
@Autowired
private IQuartzService iQuartzService;
private static Logger log = LoggerFactory.getLogger(ShopXxlJob.class);
private void check(Coupon coupon) {
if (ObjectUtil.isEmpty(coupon)) {
throw new CustomException("优惠券不存在");
@ -116,8 +121,8 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl<CouponUseDao
couponUse.setValidEndTime(coupon.getValidEndTime());
} else {
DateFormat df = new SimpleDateFormat(DateUtil.YYYY_MM_DD_HH_MM_SS);
couponUse.setValidStartTime(df.format(DateUtil.getAfDate(LocalDate.now().toDate(), coupon.getFixedStartTime(), "d")));
couponUse.setValidEndTime(df.format(DateUtil.getAfDate(LocalDate.now().toDate(), coupon.getFixedEndTime(), "d")));
couponUse.setValidStartTime(df.format(DateUtil.getAfDate(DateUtil.getPointTime(DateUtil.getTimeAndToString(), DateUtil.YYYY_MM_DD_HH_MM_SS), coupon.getFixedStartTime(), "d")));
couponUse.setValidEndTime(df.format(DateUtil.getAfDate(DateUtil.getPointTime(DateUtil.getTimeAndToString(), DateUtil.YYYY_MM_DD_HH_MM_SS), coupon.getFixedEndTime(), "d")));
}
// 领取非固定类型优惠券时借助couponMation成员变量存储优惠券信息便于后置执行新增定时任务
couponUse.setCouponMation(coupon);
@ -144,7 +149,9 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl<CouponUseDao
// 定时任务
Coupon couponMation = couponUse.getCouponMation();
if (Objects.equals(couponMation.getValidityType(), CouponValidityType.TERM.getKey())) {
log.info("领取优惠券的id(couponUseId)" + couponUse.getId() + "创建定时任务--开始");
startUpTaskQuartz(couponUse.getId(), couponMation.getName(), couponUse.getValidEndTime());
log.info("领取优惠券的id(couponUseId)" + couponUse.getId() + "创建定时任务--结束");
}
}
@ -202,7 +209,11 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl<CouponUseDao
// 查询时获取数据
List<CouponUse> list = list(queryWrapper);
couponService.setDataMation(list, CouponUse::getCouponId);
return JSONUtil.toList(JSONUtil.toJsonStr(list), null);
List<CouponUse> 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<CouponUseDao
if (StrUtil.isEmpty(userToken)) {
return new HashMap<>();
}
String userTokenUserId = GetUserToken.getUserTokenUserId(InputObject.getRequest());
Boolean aBoolean = SysUserAuthConstants.exitUserLoginRedisCache(userTokenUserId);
if (!aBoolean) {
return new HashMap<>();
}
String userId = InputObject.getLogParamsStatic().get("id").toString();
QueryWrapper<CouponUse> queryWrapper = new QueryWrapper<>();
queryWrapper.select(MybatisPlusUtil.toColumns(CouponUse::getCouponId), "count(id) as total");
@ -265,4 +281,12 @@ public class CouponUseServiceImpl extends SkyeyeBusinessServiceImpl<CouponUseDao
throw new CustomException("优惠券使用次数已达到上限");
}
}
@Override
public void deleteByCouponIds(List<String> ids) {
QueryWrapper<CouponUse> queryWrapper = new QueryWrapper<>();
queryWrapper.in(MybatisPlusUtil.toColumns(CouponUse::getCouponId), ids);
queryWrapper.eq(MybatisPlusUtil.toColumns(CouponUse::getState), CouponUseState.UNUSED.getKey());
remove(queryWrapper);
}
}

View file

@ -156,7 +156,7 @@ public class OrderItemServiceImpl extends SkyeyeBusinessServiceImpl<OrderItemDao
@Override
public void UpdateOrderItemState(String orderItemId) {
OrderItem orderItem = selectById(orderItemId);
if (orderItem.getOrderItemState().equals(CommonNumConstants.NUM_TWO)) {
if (orderItem.getOrderItemState()==CommonNumConstants.NUM_TWO) {
throw new CustomException("该订单已收货");
}
UpdateWrapper<OrderItem> updateWrapper = new UpdateWrapper<>();

View file

@ -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<OrderDao, Order>
@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<OrderDao, Order>
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<OrderDao, Order>
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<OrderDao, Order>
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<OrderDao, Order>
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());
}

View file

@ -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<String, String> 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<String, String> 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 + "---删除任务---结束");
}
}
}