diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/entity/ActivePriceRecord.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/entity/ActivePriceRecord.java new file mode 100644 index 000000000..9a892e95c --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/entity/ActivePriceRecord.java @@ -0,0 +1,58 @@ +package com.fuint.business.marketingActivity.activePrice.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 分时优惠、显示特价活动用户参与记录表 + * @author : vinjor-m + * @date : 2024-9-21 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@TableName("active_price_record") +public class ActivePriceRecord extends Model { + /** 主键id */ + @TableId(type = IdType.AUTO) + private Integer id ; + /** 活动id */ + private Integer actId ; + /** 活动规则id */ + private Integer ruleId ; + /** 所属店铺id */ + private Integer storeId ; + /** 用户id */ + private Integer userId ; + /** 订单id(主订单表) */ + private Integer orderId ; + /** 活动名称,冗余字段 */ + private String actName ; + /** 活动规则名称,冗余字段 */ + private String ruleName ; + /** 活动类型(1分时优惠|2限时特价) */ + private String actType ; + /** 优惠金额(元) */ + private Double disAmount ; + /** 创建人 */ + private String createBy ; + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + private Date createTime ; + /** 更新人 */ + private String updateBy ; + /** 更新时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8") + private Date updateTime ; + + public static final String ACT_TYPE_1 = "1"; + public static final String ACT_TYPE_2 = "2"; + public static final String ACT_TYPE_1_TEXT = "分时优惠"; + public static final String ACT_TYPE_2_TEXT = "限时特价"; +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRecordMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRecordMapper.java new file mode 100644 index 000000000..98e6e70b9 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRecordMapper.java @@ -0,0 +1,23 @@ +package com.fuint.business.marketingActivity.activePrice.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePrice; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord; +import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceReqVO; +import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRespVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 分时优惠、显示特价活动用户参与记录表数据库访问层 + * + * @author : vinjor-m + * @date : 2024-9-21 + */ +@Mapper +public interface ActivePriceRecordMapper extends BaseMapper { + + +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRuleMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRuleMapper.java index dac937e17..6cd91bf5d 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRuleMapper.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActivePriceRuleMapper.java @@ -9,6 +9,9 @@ import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.Date; +import java.util.List; + /** * 价格营销活动规则;(active_price_rule)表数据库访问层 * @author : pqz @@ -35,4 +38,14 @@ public interface ActivePriceRuleMapper extends BaseMapper { * @return com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO **/ ActivePriceRuleRespVO getRuleById(@Param("id") int id); + + /** + * 查店铺生效中的活动规则 + * @author vinjor-M + * @date 14:11 2024/9/21 + * @param storeId 店铺Id + * @param nowDate 结算时间 + * @return java.util.List + **/ + List selectActiveByStoreId(@Param("storeId")Integer storeId,@Param("nowDate") String nowDate); } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActiveSubPriceMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActiveSubPriceMapper.java index 6adc467cf..49ca571f0 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActiveSubPriceMapper.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/ActiveSubPriceMapper.java @@ -3,7 +3,13 @@ package com.fuint.business.marketingActivity.activePrice.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil; import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPrice; +import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO; +import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; /** * 立减营销活动规则 @@ -12,5 +18,13 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface ActiveSubPriceMapper extends BaseMapper { - + /** + * 查店铺生效中的活动规则 + * @author vinjor-M + * @date 14:11 2024/9/21 + * @param storeId 店铺Id + * @param nowDate 结算时间 + * @return java.util.List + **/ + List selectActiveByStoreId(@Param("storeId")Integer storeId, @Param("nowDate") String nowDate); } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRecordMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRecordMapper.xml new file mode 100644 index 000000000..bd1e13fd2 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRecordMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRuleMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRuleMapper.xml index 88145e329..d0b6a6c5b 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRuleMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActivePriceRuleMapper.xml @@ -12,7 +12,13 @@ - + + + + + + + \ No newline at end of file diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActiveSubPriceMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActiveSubPriceMapper.xml index 7c2309389..6fb22aa54 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActiveSubPriceMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/mapper/xml/ActiveSubPriceMapper.xml @@ -1,5 +1,36 @@ - + + + + + + + \ No newline at end of file diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRecordService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRecordService.java new file mode 100644 index 000000000..77eb177ec --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRecordService.java @@ -0,0 +1,28 @@ +package com.fuint.business.marketingActivity.activePrice.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord; + +import java.util.List; + +/** + * 分时优惠、显示特价活动用户参与记录表服务接口 + * + * @author : vinjor-m + * @date : 2024-9-21 + */ +public interface ActivePriceRecordService extends IService { + + /** + * 根据用户Id和活动ids查询所有参与的记录 + * @author vinjor-M + * @date 13:55 2024/9/21 + * @param userId 用户Id + * @param ruleIdList 活动规则ids + * @param actIdList 活动ids + * @param actTypeList 活动类型 + * @return java.util.List + **/ + List selectListByUserIdAndActIds(Integer userId,List ruleIdList,List actIdList,List actTypeList); +} + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRuleService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRuleService.java index a32009631..dd8c08c97 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRuleService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActivePriceRuleService.java @@ -8,6 +8,9 @@ import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule; import com.fuint.business.marketingActivity.activePrice.vo.*; import com.fuint.framework.exception.BusinessCheckException; +import java.util.Date; +import java.util.List; + /** * 价格营销活动规则;(active_price_rule)表服务接口 * @@ -55,5 +58,15 @@ public interface ActivePriceRuleService extends IService { **/ void removeByActId(Integer actId); + /** + * 查店铺生效中的活动规则 + * @author vinjor-M + * @date 10:55 2024/9/21 + * @param storeId 店铺id + * @param nowDate 当前时间 + * @return java.util.List + **/ + List selectAllAct(Integer storeId, Date nowDate); + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActiveSubPriceService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActiveSubPriceService.java index 092e31b94..2c01c019a 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActiveSubPriceService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/ActiveSubPriceService.java @@ -6,6 +6,9 @@ import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO; import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceSaveVO; import com.fuint.framework.exception.BusinessCheckException; +import java.util.Date; +import java.util.List; + /** * 立减营销; * @@ -46,5 +49,15 @@ public interface ActiveSubPriceService extends IService { */ int deleteActiveSubPriceById(Integer id); + /** + * 查某店铺某时间节点可用的立减营销活动 + * @author vinjor-M + * @date 18:13 2024/9/21 + * @param storeId 店铺Id + * @param nowDate 结算时间 + * @return java.util.List + **/ + List selectAllAct(Integer storeId, Date nowDate); + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRecordServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRecordServiceImpl.java new file mode 100644 index 000000000..f5d58d89e --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRecordServiceImpl.java @@ -0,0 +1,47 @@ +package com.fuint.business.marketingActivity.activePrice.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord; +import com.fuint.business.marketingActivity.activePrice.mapper.ActivePriceRecordMapper; +import com.fuint.business.marketingActivity.activePrice.service.ActivePriceRecordService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 分时优惠、显示特价活动用户参与记录表服务接口 + * + * @author : vinjor-m + * @date : 2024-9-2 + */ +@Service("ActivePriceRecordService") +public class ActivePriceRecordServiceImpl extends ServiceImpl implements ActivePriceRecordService { + + /** + * 根据用户Id和活动ids查询所有参与的记录 + * + * @param userId 用户Id + * @param ruleIdList 活动规则ids + * @param actIdList 活动ids + * @param actTypeList 活动类型 + * @return java.util.List + * @author vinjor-M + * @date 13:55 2024/9/21 + **/ + @Override + public List selectListByUserIdAndActIds(Integer userId, List ruleIdList, List actIdList, List actTypeList) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper() + .eq(ActivePriceRecord::getUserId, userId); + if (null != ruleIdList && !ruleIdList.isEmpty()) { + lambdaQueryWrapper.in(ActivePriceRecord::getRuleId, ruleIdList); + } + if (null != actIdList && !actIdList.isEmpty()) { + lambdaQueryWrapper.in(ActivePriceRecord::getActId, actIdList); + } + if (null != actTypeList && !actTypeList.isEmpty()) { + lambdaQueryWrapper.in(ActivePriceRecord::getActType, actTypeList); + } + return this.list(lambdaQueryWrapper); + } +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRuleServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRuleServiceImpl.java index 8d1a3afdb..a642b08e6 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRuleServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActivePriceRuleServiceImpl.java @@ -1,5 +1,6 @@ package com.fuint.business.marketingActivity.activePrice.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -220,4 +221,18 @@ public class ActivePriceRuleServiceImpl extends ServiceImpl + * @author vinjor-M + * @date 10:55 2024/9/21 + **/ + @Override + public List selectAllAct(Integer storeId, Date nowDate) { + return activePriceRuleMapper.selectActiveByStoreId(storeId,DateUtil.formatDate(nowDate)); + } + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActiveSubPriceServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActiveSubPriceServiceImpl.java index 3a3ba71d4..defb59102 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActiveSubPriceServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/service/impl/ActiveSubPriceServiceImpl.java @@ -1,5 +1,6 @@ package com.fuint.business.marketingActivity.activePrice.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -40,6 +41,8 @@ public class ActiveSubPriceServiceImpl extends ServiceImpl + * @author vinjor-M + * @date 18:13 2024/9/21 + **/ + @Override + public List selectAllAct(Integer storeId, Date nowDate) { + return activeSubPriceMapper.selectActiveByStoreId(storeId, DateUtil.formatDate(nowDate)); + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/vo/ActivePriceRuleRespVO.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/vo/ActivePriceRuleRespVO.java index 6238544a8..575951b89 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/vo/ActivePriceRuleRespVO.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activePrice/vo/ActivePriceRuleRespVO.java @@ -1,5 +1,6 @@ package com.fuint.business.marketingActivity.activePrice.vo; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil; import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule; import com.fuint.business.userManager.entity.UserLabel; import com.fuint.repository.model.MtUserGrade; @@ -33,10 +34,23 @@ public class ActivePriceRuleRespVO extends ActivePriceRule { /**标签集合*/ private List labelIdList; - /** 活动名称 分时优惠 类型 */ + /** 价格营销活动类型(1-分时优惠|2-限时特价) */ private String activeType ; /** * 创建人 */ private String createName; + + /** + * 活动优惠类型(1-固定价格|2-折扣|3-减价) + **/ + private String activeCategory; + /** + * 折扣/减价金额(两个字段合用一个) + **/ + private Double activeDisValue; + /** + * 活动适用的油号 + **/ + private List oilList; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/UserDiscountMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/UserDiscountMapper.java index 0758ac4ed..c935463c8 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/UserDiscountMapper.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/UserDiscountMapper.java @@ -3,10 +3,23 @@ package com.fuint.business.userGroup.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO; import com.fuint.business.userGroup.entity.UserDiscount; import com.fuint.business.userGroup.vo.UserDiscountVo; import org.apache.ibatis.annotations.Param; +import java.util.List; + public interface UserDiscountMapper extends BaseMapper { IPage queryPage(Page page, @Param("entity") UserDiscountVo userDiscountVo); + + /** + * 查店铺生效中的活动规则 + * @author vinjor-M + * @date 14:11 2024/9/21 + * @param storeId 店铺Id + * @param nowDate 结算时间 + * @return java.util.List + **/ + List selectActiveByStoreId(@Param("storeId")Integer storeId, @Param("nowDate") String nowDate); } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/xml/UserDiscountMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/xml/UserDiscountMapper.xml index 798eb34ed..d19bbe548 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/xml/UserDiscountMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/mapper/xml/UserDiscountMapper.xml @@ -25,5 +25,17 @@ ORDER BY create_time DESC + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/UserDiscountService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/UserDiscountService.java index 17921bd22..d80963c3e 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/UserDiscountService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/UserDiscountService.java @@ -2,9 +2,13 @@ package com.fuint.business.userGroup.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO; import com.fuint.business.userGroup.entity.UserDiscount; import com.fuint.business.userGroup.vo.UserDiscountVo; +import java.util.Date; +import java.util.List; + /** * 会员折扣表(UserDiscount)表服务接口 * @@ -52,4 +56,13 @@ public interface UserDiscountService { */ int deleteById(Integer id); + /** + * 查某店铺某时间节点可用的会员折扣营销活动 + * @author vinjor-M + * @date 18:13 2024/9/22 + * @param storeId 店铺Id + * @param nowDate 结算时间 + **/ + List selectAllAct(Integer storeId, Date nowDate); + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/impl/UserDiscountServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/impl/UserDiscountServiceImpl.java index 8c0e1a7aa..6522de047 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/impl/UserDiscountServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userGroup/service/impl/UserDiscountServiceImpl.java @@ -1,5 +1,6 @@ package com.fuint.business.userGroup.service.impl; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -9,10 +10,17 @@ import com.fuint.business.userGroup.service.UserDiscountService; import com.fuint.business.userGroup.vo.UserDiscountVo; import com.fuint.common.dto.AccountInfo; import com.fuint.common.util.TokenUtil; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; +import java.util.List; + @Service public class UserDiscountServiceImpl extends ServiceImpl implements UserDiscountService { + @Autowired + private UserDiscountMapper userDiscountMapper; + @Override public IPage queryPage(Page page, UserDiscountVo userDiscountVo) { AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); @@ -42,4 +50,17 @@ public class UserDiscountServiceImpl extends ServiceImpl selectAllAct(Integer storeId, Date nowDate) { + return userDiscountMapper.selectActiveByStoreId(storeId, DateUtil.formatDate(nowDate)); + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/UserBalanceService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/UserBalanceService.java index cb0129049..8ddb52da9 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/UserBalanceService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/userManager/service/UserBalanceService.java @@ -58,6 +58,14 @@ public interface UserBalanceService extends IService { * @return */ public UserBalance selectUserBalance(int userId, int chainStoreId); + /** + * 根据店铺Id和会员Id查询正在使用的会员卡信息 + * @author vinjor-M + * @date 10:07 2024/9/21 + * @param userId 用户Id + * @param storeId 店铺Id + * @return com.fuint.business.userManager.entity.UserBalance + **/ public UserBalance selectUserBalanceByStorId(int userId, int storeId); /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/controller/PayCenterController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/controller/PayCenterController.java index 070905d8a..52ef88374 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/controller/PayCenterController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/controller/PayCenterController.java @@ -4,8 +4,10 @@ import com.fuint.common.dto.AccountInfo; import com.fuint.common.util.TokenUtil; import com.fuint.framework.web.BaseController; import com.fuint.framework.web.ResponseObject; +import com.fuint.pay.service.PayCenterService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @@ -20,7 +22,8 @@ import java.util.Map; @RequestMapping("/pay/paycenter") public class PayCenterController extends BaseController { private Logger logger = LoggerFactory.getLogger(PayCenterController.class); - + @Autowired + private PayCenterService payCenterService; /** * 收银台获取可用优惠券和可以参加的优惠活动 * @author vinjor-M @@ -32,21 +35,7 @@ public class PayCenterController extends BaseController { @GetMapping("/getActivityAndCoupon") public ResponseObject getActivityAndCoupon(Map map,HttpServletRequest request) throws Exception { logger.info("收银台获取可用优惠券和可以参加的优惠活动参数:{}", map); - AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); - //会员的用户id - String userId = map.get("userId"); - //油号 - String oil = map.get("oil"); - //加油金额(不含商品金额) - String oilAmount = map.get("oilAmount"); - //订单总额(含商品金额) - String orderAmount = map.get("orderAmount"); - //油升数 - String oilLiter = map.get("oilLiter"); - //当前店铺id - Integer storeId = nowAccountInfo.getStoreId(); - - return getSuccessResult("查询成功",); + return getSuccessResult("查询成功",payCenterService.getActivityAndCoupon(map)); } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java index f28f8a107..66e129796 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java @@ -1,16 +1,54 @@ package com.fuint.pay.service.impl; +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule; +import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPrice; +import com.fuint.business.marketingActivity.activePrice.service.ActivePriceRecordService; +import com.fuint.business.marketingActivity.activePrice.service.ActivePriceRuleService; +import com.fuint.business.marketingActivity.activePrice.service.ActivePriceService; +import com.fuint.business.marketingActivity.activePrice.service.ActiveSubPriceService; +import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO; +import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO; +import com.fuint.business.userGroup.entity.UserDiscount; +import com.fuint.business.userGroup.service.UserDiscountService; +import com.fuint.business.userManager.entity.UserBalance; +import com.fuint.business.userManager.service.UserBalanceService; +import com.fuint.common.dto.AccountInfo; +import com.fuint.common.util.StringUtils; +import com.fuint.common.util.TokenUtil; import com.fuint.module.AlipayApi.service.impl.AlipayServiceImpl1; import com.fuint.pay.service.PayCenterService; +import com.fuint.pay.util.CheckUtil; +import com.fuint.pay.vo.ActivityVO; +import com.fuint.pay.vo.CouponVO; +import com.google.common.collect.ImmutableList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; @Service public class PayCenterServiceImpl implements PayCenterService { private static final Logger logger = LoggerFactory.getLogger(PayCenterServiceImpl.class); + @Autowired + private CheckUtil checkUtil; + @Autowired + private UserBalanceService userBalanceService; + @Autowired + private ActivePriceRuleService activePriceRuleService; + @Autowired + private ActivePriceRecordService activePriceRecordService; + @Autowired + private ActiveSubPriceService activeSubPriceService; + @Autowired + private UserDiscountService userDiscountService; /** * 收银台获取可用优惠券和可以参加的优惠活动 * @@ -21,6 +59,224 @@ public class PayCenterServiceImpl implements PayCenterService { **/ @Override public Object getActivityAndCoupon(Map map) { - return null; + JSONObject rtnObj = new JSONObject(); + //可参加的营销活动 + List activityVOList = new ArrayList<>(); + //可用的优惠券 + List couponVOList = new ArrayList<>(); + /*1.先把所有用到的值取出来 */ + //当前时间,从点击结算的这一刻算 + Date nowDate = new Date(); + //当前店铺id + AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); + Integer storeId = nowAccountInfo.getStoreId(); + int userId = Integer.parseInt(map.get("userId")); + //查会员等级 + UserBalance userBalance = userBalanceService.selectUserBalanceByStorId(userId,storeId); + if(null==userBalance){ + //非会员,不能参加任何活动 + rtnObj.put("activity",activityVOList); + rtnObj.put("coupon",couponVOList); + return rtnObj; + } + //会员等级 + int gradeId = userBalance.getGradeId(); + //会员标签,会有多个,一个集和 + List labelIdList = new ArrayList<>(); + if(StringUtils.isNotEmpty(userBalance.getUserLabelId())){ + List labelIdStrList = Arrays.asList(userBalance.getUserLabelId().split(StrUtil.COMMA)); + labelIdStrList.forEach(str->labelIdList.add(Integer.parseInt(str))); + } + //油号id + Integer oilId = Integer.valueOf(map.get("oilId")); + //油单价 + Double oilPrice = Double.valueOf(map.get("oilPrice")); + //加油金额(不含商品金额) + Double oilAmount = Double.valueOf(map.get("oilAmount")); + //订单总额(含商品金额) + Double orderAmount = Double.valueOf(map.get("orderAmount")); + //油升数 + Double oilLiter = Double.valueOf(map.get("oilLiter")); + /*2.查询所有可参加的营销活动 */ + List actList = new ArrayList<>(); + //2.1 查可参加的分时优惠和限时特价 + actList.addAll(this.getFenshiAndTejiaAct(nowDate,userId,gradeId,storeId,labelIdList,oilAmount,oilLiter,oilId,oilPrice)); + //2.2 查可参加的立减营销 + actList.addAll(this.getLijianAct(nowDate,userId,gradeId,storeId,labelIdList,oilAmount,oilLiter,oilId)); + //2.3 查可参加的折扣营销(会员折扣) + actList.addAll(this.getZhekouAct(nowDate,gradeId,storeId,oilAmount)); + /*3.查询所有可用的优惠券 TODO 需要等待优惠券表修改完以后再处理 */ + List couponList = new ArrayList<>(); + rtnObj.put("activity",actList); + rtnObj.put("coupon",couponList); + return rtnObj; + } + + /** + * 获取当前会员可以参加的分时优惠和限时特价活动 + * @author vinjor-M + * @date 10:15 2024/9/21 + * @param nowDate 结算那一刻的时间 + * @param userId 用户Id + * @param gradeId 会员等级 + * @param storeId 店铺id + * @param labelIdList 会员标签id集和 + * @param oilAmount 当前加油金额 + * @param oilLiter 当前加油升数 + * @param oilId 当前加油选择的油号id + * @param oilPrice 油单价 + * @return java.util.List + **/ + private List getFenshiAndTejiaAct(Date nowDate,Integer userId,Integer gradeId,Integer storeId, + List labelIdList,Double oilAmount,Double oilLiter, + Integer oilId,Double oilPrice){ + /*1.先查满足条件的所有生效中的活动规则*/ + List activePriceRuleList = activePriceRuleService.selectAllAct(storeId, nowDate); + /*2.进行初步过滤,这里只过滤活动硬性的限制*/ + List filteredList = activePriceRuleList.stream() + //适用当前会员等级的 + .filter(rule->rule.getLevelId().equals(gradeId.toString())) + //适用当前会员标签的 + .filter(rule->checkUtil.checkLabelId(rule.getBabelIds(),labelIdList)) + //适用当前加油金额或加油升数的 + .filter(rule -> checkUtil.checkConsume(rule,oilAmount,oilLiter)) + //适用当前时间段的 + .filter(rule -> checkUtil.checkTime(rule.getTimeSlots(),rule.getDayStartTime(),rule.getDayEndTime(),nowDate)) + //适用当前油号的 + .filter(rule-> checkUtil.checkOil(rule.getOilList(),oilId)).collect(Collectors.toList()); + if(filteredList.isEmpty()){ + return new ArrayList<>(); + } + /*3.再次过滤,这里过滤掉用户已经超出参加次数限制的*/ + //符合条件的活动规则,查询当前会员已经参与的记录,此处查分时特价和限时特价的 + List actTypeList = Arrays.asList("1,2".split(StrUtil.COMMA)); + List recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId, + filteredList.stream().map(ActivePriceRuleRespVO::getId).collect(Collectors.toList()),null,actTypeList); + filteredList = filteredList.stream() + //过滤掉超过每日参加次数限制的 + .filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList, "day")) + //过滤掉超过累计参加次数限制的 + .filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList()); + /*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/ + List rtnList = new ArrayList<>(); + if(!filteredList.isEmpty()){ + for(ActivePriceRuleRespVO rule:filteredList){ + ActivityVO activityVO = new ActivityVO(); + activityVO.setActId(rule.getActiveId()); + activityVO.setRuleId(rule.getId()); + activityVO.setType(rule.getActiveType()); + activityVO.setActName(rule.getActiveTitle()); + activityVO.setRuleName(rule.getRuleName()); + activityVO.setPayTypes(rule.getPaymentType()); + activityVO.setDisAmount(checkUtil.computeDisAmount(rule,oilId,oilPrice,oilAmount,oilLiter)); + } + } + return rtnList; + } + + /** + * 获取当前会员可以参加的立减营销活动 + * @author vinjor-M + * @date 17:28 2024/9/21 + * @param nowDate 结算那一刻的时间 + * @param userId 用户Id + * @param gradeId 会员等级 + * @param storeId 店铺id + * @param labelIdList 会员标签id集和 + * @param oilAmount 当前加油金额 + * @param oilLiter 当前加油升数 + * @param oilId 当前加油选择的油号id + * @return java.util.List + **/ + private List getLijianAct(Date nowDate,Integer userId,Integer gradeId,Integer storeId, + List labelIdList,Double oilAmount,Double oilLiter, + Integer oilId){ + /*1.先查满足条件的所有生效中的活动规则*/ + List activeSubPriceList = activeSubPriceService.selectAllAct(storeId,nowDate); + /*2.进行初步过滤,这里只过滤活动硬性的限制*/ + List filteredList = activeSubPriceList.stream() + //适用当前会员等级的 + .filter(rule->Arrays.asList(rule.getLevelId().split(StrUtil.COMMA)).contains(gradeId.toString())) + //适用当前会员标签的 + .filter(rule->checkUtil.checkLabelId(rule.getBabelIds(),labelIdList)) + //适用当前时间段的 + .filter(rule -> checkUtil.checkTime(rule.getTimeSlots(),checkUtil.getTimeFromDate(rule.getTimeApplyStart()),checkUtil.getTimeFromDate(rule.getTimeApplyEnd()),nowDate)) + //适用当前油号的 + .filter(rule-> checkUtil.checkOilLijian(rule.getApplyOilType(),rule.getApplyOil(),oilId)).collect(Collectors.toList()); + /*3.再次过滤,这里过滤掉用户已经超出参加次数限制的*/ + //符合条件的活动规则,查询当前会员已经参与的记录,此处查立减营销的参与记录 + List actTypeList = Arrays.asList("3".split(StrUtil.COMMA)); + List recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId, + null,filteredList.stream().map(ActiveSubPriceRespVO::getId).collect(Collectors.toList()),actTypeList); + filteredList = filteredList.stream() + //过滤掉超过每日参加次数限制的 + .filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList,"day")) + //过滤掉超过每月参加次数限制的 + .filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getMonthLimitNum(),nowDate,recordAllList,"month")) + //过滤掉超过累计参加次数限制的 + .filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList()); + /*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/ + List rtnList = new ArrayList<>(); + if(!filteredList.isEmpty()){ + for(ActiveSubPriceRespVO rule:filteredList){ + ActivityVO activityVO = new ActivityVO(); + activityVO.setActId(rule.getId()); + activityVO.setType("3"); + activityVO.setActName(rule.getActiveName()); + activityVO.setPayTypes(rule.getPaymentType()); + activityVO.setDisAmount(checkUtil.computeDisAmountLijian(rule,oilAmount,oilLiter)); + } + } + return rtnList; + } + + /** + * 获取当前会员可以参加的折扣营销活动 + * @author vinjor-M + * @date 11:46 2024/9/22 + * @param nowDate 结算那一刻的时间 + * @param gradeId 会员等级 + * @param storeId 店铺id + * @param oilAmount 当前加油金额 + * @return java.util.List + **/ + private List getZhekouAct(Date nowDate,Integer gradeId,Integer storeId,Double oilAmount){ + /*1.先查满足条件的所有生效中的活动规则*/ + List userDiscountList = userDiscountService.selectAllAct(storeId,nowDate); + /*2.进行初步过滤,这里只过滤活动硬性的限制*/ + List filteredList = userDiscountList.stream() + //适用当前会员等级的 + .filter(rule->rule.getGradeId().equals(gradeId)) + //节假日要求是否满足 + .filter(rule->checkUtil.checkTimeJiejiari(rule.getHolidayIsUse(),nowDate)) + //适用当前时间段的 + .filter(rule -> checkUtil.checkTime(rule.getSuitDate(),checkUtil.getTimeFromDate(rule.getSuitTimeSlotFront()),checkUtil.getTimeFromDate(rule.getSuitDateAfter()),nowDate)) + //是否满足最低消费金额 + .filter(rule-> rule.getConsumeAmount() <=oilAmount).collect(Collectors.toList()); + /*3.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/ + List rtnList = new ArrayList<>(); + if(!filteredList.isEmpty()){ + UserDiscount discount; + if(filteredList.size()==1){ + discount = filteredList.get(0); + }else{ + //取折扣最大的,也就是折扣数值最小的,正序排列,取第一个 + discount = filteredList.stream().sorted(Comparator.comparingDouble(UserDiscount::getDiscount)).collect(Collectors.toList()).get(0); + } + ActivityVO activityVO = new ActivityVO(); + activityVO.setActId(discount.getId()); + activityVO.setType("4"); + activityVO.setActName("折扣营销"); + activityVO.setPayTypes(discount.getUsePaymentWay()); + //计算优惠金额 + double disAmount = 0.0; + if(null!=discount.getDiscount()){ + Double newOilAmount = oilAmount*discount.getDiscount(); + disAmount = oilAmount-newOilAmount; + } + activityVO.setDisAmount(disAmount); + rtnList.add(activityVO); + } + return rtnList; } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java new file mode 100644 index 000000000..c7072238b --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java @@ -0,0 +1,518 @@ +package com.fuint.pay.util; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil; +import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord; +import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule; +import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO; +import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO; +import com.fuint.business.userGroup.entity.UserDiscount; +import com.fuint.common.util.StringUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.time.LocalDate; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 收银台判断使用的util + * @author vinjor-M + * @date 11:25 2024/9/21 +**/ +@Component +@Slf4j +public class CheckUtil { + /** + * 判断某活动设置的可用会员标签,当前会员标签是否可用 + * @author vinjor-M + * @date 11:12 2024/9/21 + * @param labelIds 活动适用的会员标签Ids + * @param labelIdList 当前会员的标签集和 + * @return java.lang.Boolean + **/ + public Boolean checkLabelId(String labelIds, List labelIdList){ + if(StringUtils.isEmpty(labelIds)){ + //活动没有会员标签显示,可用 + return true; + }else if(labelIdList.isEmpty()){ + //活动设置的会员标签,但是当前用户没有会员标签,不可用 + return false; + }else{ + //活动设置了会员标签,当前用户也有会员标签,判断是否有重叠的标签 + List actLabelIdStrList = Arrays.asList(labelIds.split(StrUtil.COMMA)); + List actLabelIdList = actLabelIdStrList.stream().map(Integer::parseInt).collect(Collectors.toList()); + //比较两个list是否有重叠,如果有,则可用 + return actLabelIdList.stream().anyMatch(labelIdList::contains); + } + } + + /** + * 判断当前加油金额或加油升数是否符合某活动的消费条件限制 + * @author vinjor-M + * @date 11:31 2024/9/21 + * @param rule 活动规则 + * @param oilAmount 当前加油金额 + * @param oilLiter 当前加油升数 + * @return java.lang.Boolean + **/ + public Boolean checkConsume(ActivePriceRuleRespVO rule, Double oilAmount, Double oilLiter){ + if("0".equals(rule.getConsumeType())){ + //活动规则设置的消费规则是根据实收金额判断 + return isBetween(oilAmount,rule.getMoneyMin(),rule.getMoneyMax()); + }else if("1".equals(rule.getConsumeType())){ + //活动规则设置的消费规则是根据加油升数判断 + return isBetween(oilLiter,rule.getLiterMin(),rule.getLiterMax()); + }else { + //超出预设值返回,默认不满足 + return false; + } + } + + /** + * 判断结算时间是否符合活动设置的适用时间 + * @author vinjor-M + * @date 11:41 2024/9/21 + * @param timeSlots 适用时间 + * @param startTime 某天适用的开始时间 + * @param endTime 某天适用的结束时间 + * @param nowDate 结算时间 + * @return java.lang.Boolean + **/ + public Boolean checkTime(String timeSlots,String startTime,String endTime, Date nowDate){ + String timeSlotsStr = timeSlots; + if(timeSlots.contains("周")){ + //周几汉字转数字 + timeSlotsStr = changeWeekNumber(timeSlots); + } + List timeSlotStrList = Arrays.asList(timeSlotsStr.split(StrUtil.COMMA)); + //转换为int类型 + List timeSlotList = timeSlotStrList.stream().map(Integer::parseInt).collect(Collectors.toList()); + if(timeSlotStrList.isEmpty() && (StringUtils.isNotEmpty(startTime) || StringUtils.isNotEmpty(endTime))){ + //没有设置时间段,但是生效时间又设置了,代表每天的某个时间范围 + return checkDayTime(nowDate,startTime,endTime); + }else{ + //设置了时间段,需要判断时间段是否符合 + if(timeSlots.contains("周")){ + //活动设置的适用时间类型是每周 + //结算时间是周几,特殊情况(0是周日,需要转换为7 方便判断) + int nowWeek = DateUtil.dayOfWeek(nowDate)-1; + if(0==nowWeek){ + nowWeek =7; + } + if(timeSlotList.contains(nowWeek)){ + //周几是符合的,进而判断时间是否符合 + return checkDayTime(nowDate,startTime,endTime); + }else{ + return false; + } + }else{ + //活动设置的适用时间类型是每月 + //结算时间是每月几号 + int nowDay = DateUtil.dayOfMonth(nowDate); + if(timeSlotList.contains(nowDay)){ + //每月几号是符合的,进而判断时间是否符合 + return checkDayTime(nowDate,startTime,endTime); + }else{ + return false; + } + } + } + } + + /** + * 判断结算时间是否符合活动设置的【不适用时间】!!!!注意,判断是否处在不适用的时间范围内 + * @author vinjor-M + * @date 11:41 2024/9/21 + * @param timeSlots 适用时间 + * @param startTime 某天适用的开始时间 + * @param endTime 某天适用的结束时间 + * @param nowDate 结算时间 + * @return java.lang.Boolean + **/ + public Boolean checkTimeReverse(String timeSlots,String startTime,String endTime, Date nowDate){ + String timeSlotsStr = timeSlots; + if(timeSlots.contains("周")){ + //周几汉字转数字 + timeSlotsStr = changeWeekNumber(timeSlots); + } + List timeSlotStrList = Arrays.asList(timeSlotsStr.split(StrUtil.COMMA)); + //转换为int类型 + List timeSlotList = timeSlotStrList.stream().map(Integer::parseInt).collect(Collectors.toList()); + if(timeSlotStrList.isEmpty() && (StringUtils.isNotEmpty(startTime) || StringUtils.isNotEmpty(endTime))){ + //没有设置时间段,但是生效时间又设置了,代表每天的某个时间范围 + return checkDayTimeReverse(nowDate,startTime,endTime); + }else{ + //设置了时间段,需要判断时间段是否符合 + if(timeSlots.contains("周")){ + //活动设置的适用时间类型是每周 + //结算时间是周几,特殊情况(0是周日,需要转换为7 方便判断) + int nowWeek = DateUtil.dayOfWeek(nowDate)-1; + if(0==nowWeek){ + nowWeek =7; + } + if(timeSlotList.contains(nowWeek)){ + //周几是符合的,返回不可用 + return false; + }else{ + //周几是不符合的,进而判断时间是否符合 + return checkDayTimeReverse(nowDate,startTime,endTime); + } + }else{ + //活动设置的适用时间类型是每月 + //结算时间是每月几号 + int nowDay = DateUtil.dayOfMonth(nowDate); + if(timeSlotList.contains(nowDay)){ + //每月几号是符合的,返回不可用 + return false; + }else{ + //每月几号是不符合的,进而判断时间是否符合 + return checkDayTimeReverse(nowDate,startTime,endTime); + } + } + } + } + + /** + * 判断结算时间是否符合活动设置的适用时间 + * @author vinjor-M + * @date 12:08 2024/9/22 + * @param holidayIsUse 节假日是否可用 + * @param nowDate 结算日期 + * @return boolean + **/ + public boolean checkTimeJiejiari(String holidayIsUse,Date nowDate){ + if("1".equals(holidayIsUse)){ + //节假日不可用,需要判断当前日期是否为节假日 TODO + return true; + }else{ + //节假日可用,直接反回可用 + return true; + } + } + + /** + * 判断当前加油的油号是否符合活动规则预设的油号----限时特价和分时优惠使用 + * @author vinjor-M + * @date 14:42 2024/9/21 + * @param oilList 活动适用的油号集和 + * @param oilId 当前加油选择的油号id + * @return java.lang.Boolean + **/ + public Boolean checkOil(List oilList, Integer oilId){ + List oilIdList = oilList.stream().map(ActivePriceOil::getOilId).collect(Collectors.toList()); + return oilIdList.contains(oilId); + } + + /** + * 判断当前加油的油号是否符合活动规则预设的油号----立减营销使用 + * @author vinjor-M + * @date 14:42 2024/9/21 + * @param applyOilType 适用油品油号类型:0不限;1自定义 + * @param applyOil 适用油品油号 + * @param oilId 当前加油选择的油号id + * @return java.lang.Boolean + **/ + public Boolean checkOilLijian(String applyOilType,String applyOil, Integer oilId){ + if("0".equals(applyOilType)){ + return true; + }else{ + if(StringUtils.isNotEmpty(applyOil)){ + List oilIdList = Arrays.asList(applyOil.split(StrUtil.COMMA)); + return oilIdList.contains(oilId.toString()); + }else{ + //没有配置可用油号,不满足 + return false; + } + } + } + + + /** + * 判断当前加油的油号是否符合活动规则预设的油号 + * @author vinjor-M + * @date 14:51 2024/9/21 + * @param ruleId 活动规则Id或活动Id + * @param maxNum 最大次数限制 + * @param nowDate 结算日期 + * @param recordAllList 所有参加记录 + * @param filterType 过滤类型 day 天 | month 月 | null 累计 + * @return java.lang.Boolean + **/ + public Boolean checkUseNum(Integer ruleId,Integer maxNum,Date nowDate,List recordAllList,String filterType){ + if(0==maxNum){ + //最大次数限制为0,代表不限制 + return true; + } + int nowNum = 0; + if(!recordAllList.isEmpty()){ + //有参与记录 + if(null!=nowDate){ + //有时间限制 + if("day".equals(filterType)){ + //过滤出当天的 + LocalDate dateToFilter = LocalDate.of(DateUtil.year(nowDate), DateUtil.month(nowDate)+1, DateUtil.dayOfMonth(nowDate)); + nowNum = (int) recordAllList.stream().filter(item->item.getCreateTime().equals(dateToFilter)) + .filter(item->item.getRuleId().equals(ruleId)).count(); + }else if("month".equals(filterType)){ + //过滤出当月的 + int thisYear = DateUtil.year(nowDate); + int thisMonth = DateUtil.month(nowDate); + nowNum = (int) recordAllList.stream() + .filter(item->DateUtil.year(item.getCreateTime())==thisYear) + .filter(item->DateUtil.month(item.getCreateTime())==thisMonth) + .filter(item->item.getRuleId().equals(ruleId)).count(); + } + }else{ + //没时间限制,查累计的 + nowNum = (int) recordAllList.stream().filter(item->item.getRuleId().equals(ruleId)).count(); + } + } + return maxNum>nowNum; + } + + /** + * 根据活动优惠规则,计算优惠金额,,四舍五入保留2位小数--分时优惠和限时特价使用 + * @author vinjor-M + * @date 16:35 2024/9/21 + * @param rule 活动规则 + * @param oilId 当前油号id + * @param oilPrice 当前油单价 + * @param oilAmount 加油总价 + * @param oilLiter 加油升数 + * @return java.lang.Double + **/ + public Double computeDisAmount(ActivePriceRuleRespVO rule,Integer oilId,Double oilPrice,Double oilAmount,Double oilLiter){ + //默认优惠后总价等于原来的总价 + Double newOilAmount = oilAmount; + //优惠金额 + Double disAmount = 0.0; + DecimalFormat df = new DecimalFormat("#.00"); + try { + if("1".equals(rule.getActiveCategory())){ + //固定价格,取本活动设置的当前油号的活动价格 + Double newOilPrice = rule.getOilList().stream().filter(oil->oil.getOilId().equals(oilId)).collect(Collectors.toList()).get(0).getPrice(); + if(null!=newOilPrice && newOilPricerule.getActiveDisValue()){ + //减价必须有值且小于单价 + Double newOilPrice = oilPrice-rule.getActiveDisValue(); + newOilAmount = newOilPrice*oilLiter; + } + }else{ + //超出预设值范围,不打折 + } + //计算优惠金额 + disAmount = newOilAmount-oilAmount; + if(disAmount>rule.getDisMax()){ + //超出最大优惠金额 + disAmount = rule.getDisMax(); + } + }catch (Exception e){ + log.error("分时优惠和限时特价优惠金额计算失败:"+e.getMessage(),e); + } + return Double.valueOf(df.format(disAmount)); + } + + /** + * 根据活动优惠规则,计算优惠金额,,四舍五入保留2位小数--立减营销专用 + * @author vinjor-M + * @date 16:35 2024/9/21 + * @param act 活动 + * @param oilAmount 加油总价 + * @param oilLiter 加油升数 + * @return java.lang.Double + **/ + public Double computeDisAmountLijian(ActiveSubPriceRespVO act, Double oilAmount, Double oilLiter){ + //默认优惠后总价等于原来的总价 + Double newOilAmount = oilAmount; + //优惠金额 + Double disAmount = 0.0; + DecimalFormat df = new DecimalFormat("#.00"); + try { + //本订单满足的优惠规则 + ActiveSubPriceRule rule = null; + if ("0".equals(act.getActiveManner())) { + //活动优惠方式,按订单金额优惠 + rule = getRuleLijian(act.getRuleList(), oilAmount, null); + } else if ("1".equals(act.getActiveManner())) { + //活动优惠方式,按加油升数优惠 + rule = getRuleLijian(act.getRuleList(), null, oilLiter); + } else { + //超出预设值范围,不优惠 + } + if (null != rule) { + //匹配到优惠规则,计算优惠金额 + if ("0".equals(act.getOfferType())) { + //立减优惠 + if ("0".equals(act.getActiveType())) { + //固定满减 + disAmount = rule.getSub().doubleValue(); + } else if ("1".equals(act.getActiveType())) { + //随机满减 + Random random = new Random(); + disAmount = Math.round((random.nextDouble() * (rule.getRandomAfter().doubleValue() - rule.getRandomFront().doubleValue()) + rule.getRandomFront().doubleValue()) * 100.0) / 100.0; + } else if ("2".equals(act.getActiveType())) { + //每满,这里需要判断下是按油升数还是按订单金额 + Double thisValue = "0".equals(act.getActiveManner()) ? oilAmount : oilLiter; + //计算能除尽多少次,就减多少次 + int thisInt = (int) (thisValue / rule.getFull().doubleValue()); + //计算优惠金额 + disAmount = thisInt * rule.getSub().doubleValue(); + if (disAmount > rule.getMaxPreferential().doubleValue()) { + //超出最大优惠金额 + disAmount = rule.getMaxPreferential().doubleValue(); + } + } + } else if ("1".equals(act.getOfferType())) { + //折扣优惠 + newOilAmount = oilAmount * rule.getEnjoyDiscount().doubleValue(); + //计算优惠金额 + disAmount = oilAmount - newOilAmount; + if (disAmount > rule.getMaxPreferential().doubleValue()) { + //超出最大优惠金额 + disAmount = rule.getMaxPreferential().doubleValue(); + } + } + } + }catch (Exception e){ + log.error("立减营销优惠金额计算失败:"+e.getMessage(),e); + } + return Double.valueOf(df.format(disAmount)); + } + + /** + * 从一个日期里面获取时间,00:00格式 + * @author vinjor-M + * @date 19:12 2024/9/21 + * @param date 日期 + * @return java.lang.String + **/ + public String getTimeFromDate(Date date){ + String rtn = ""; + if(null!=date){ + rtn = DateUtil.formatTime(date).substring(0,5); + } + return rtn; + } + + /** + * 获取最符合条件的优惠规则--立减营销 + * @author vinjor-M + * @date 10:41 2024/9/22 + * @param ruleList 所有规则 + * @param oilAmount 加油金额 + * @param oilLiter 加油升数 + * @return com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule + **/ + private static ActiveSubPriceRule getRuleLijian(List ruleList,Double oilAmount,Double oilLiter){ + ActiveSubPriceRule thisRule = new ActiveSubPriceRule(); + if(null!=oilAmount){ + //按加油金额 + ruleList = ruleList.stream() + .filter(rule-> checkNumber(BigDecimal.valueOf(oilAmount),rule.getFull())).collect(Collectors.toList()); + }else{ + //按加油升数 + ruleList = ruleList.stream() + .filter(rule-> checkNumber(BigDecimal.valueOf(oilLiter),rule.getFull())).collect(Collectors.toList()); + } + if(!ruleList.isEmpty()){ + //取出最大限度符合条件的一个,也就是按full字段倒叙排列取第一个 + thisRule = ruleList.stream().sorted(Comparator.comparing(ActiveSubPriceRule::getFull).reversed()).collect(Collectors.toList()).get(0); + } + return thisRule; + } + + /** + * 比较一个数是否大于或等于另一个数 + * @author vinjor-M + * @date 10:46 2024/9/22 + * @param thisNumber 要比较的数 + * @param toNumber 另一个数 + * @return boolean + **/ + private static boolean checkNumber(BigDecimal thisNumber,BigDecimal toNumber){ + int comparisonResult =thisNumber.compareTo(toNumber); + return comparisonResult>=0; + } + + /** + * 判断结算时间是否在活动设置的时间范围内 + * @author vinjor-M + * @date 12:18 2024/9/21 + * @param nowDate 结算时间 + * @param dayStartTime 活动设置的开始时间(时分秒) + * @param dayEndTime 活动设置的结束时间(时分秒) + * @return boolean + **/ + private static boolean checkDayTime(Date nowDate,String dayStartTime,String dayEndTime){ + String dayStr = DateUtil.date(nowDate).toString(); + //时间范围区间 + Date startTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayStartTime)?(dayStartTime+":00"):"00:00:00")); + Date endTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayEndTime)?(dayEndTime+":59"):"23:59:59")); + return DateUtil.isIn(nowDate,startTime,endTime); + } + /** + * 判断结算时间是否在活动设置的 【不适用时间】!!!!注意,判断是否处在不适用的时间范围内 + * @author vinjor-M + * @date 12:18 2024/9/21 + * @param nowDate 结算时间 + * @param dayStartTime 活动设置的不适用开始时间(时分秒) + * @param dayEndTime 活动设置的不适用结束时间(时分秒) + * @return boolean + **/ + private static boolean checkDayTimeReverse(Date nowDate,String dayStartTime,String dayEndTime){ + String dayStr = DateUtil.date(nowDate).toString(); + //时间范围区间 + Date startTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayStartTime)?(dayStartTime+":00"):"00:00:00")); + Date endTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayEndTime)?(dayEndTime+":59"):"23:59:59")); + return !DateUtil.isIn(nowDate,startTime,endTime); + } + + + /** + * 判断某值是否处于一个区间值范围,等于也算 + * @author vinjor-M + * @date 11:36 2024/9/21 + * @param value 要判断的值 + * @param min 区间下限 + * @param max 区间上限 + * @return boolean + **/ + private static boolean isBetween(double value, double min, double max) { + return value > min && value < max; + } + + /** + * 周几汉字转换成数字,1至7 + * @author vinjor-M + * @date 17:22 2024/9/21 + * @param timesStr 周几 + * @return java.lang.String + **/ + private static String changeWeekNumber(String timesStr){ + timesStr = timesStr.replace("周一","1"); + timesStr = timesStr.replace("周二","2"); + timesStr = timesStr.replace("周三","3"); + timesStr = timesStr.replace("周四","4"); + timesStr = timesStr.replace("周五","5"); + timesStr = timesStr.replace("周六","6"); + timesStr = timesStr.replace("周日","7"); + return timesStr; + } +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/vo/ActivityVO.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/vo/ActivityVO.java index 9e133a242..9b75ea4a3 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/vo/ActivityVO.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/vo/ActivityVO.java @@ -12,7 +12,17 @@ import java.io.Serializable; @Data public class ActivityVO implements Serializable { /** 活动id */ - private Integer id; - /** 活动类别 */ + private Integer actId; + /** 活动规则id */ + private Integer ruleId; + /** 活动类别(1-分时优惠|2-限时特价|3-立减营销|4-折扣营销) */ private String type; + /** 活动名称 */ + private String actName; + /** 活动规则名称 */ + private String ruleName; + /** 可使用支付方式 直接存的汉字-数据字典 */ + private String payTypes; + /** 优惠金额 */ + private Double disAmount; } diff --git a/产品文档/油站数据库设计.xls b/产品文档/油站数据库设计.xls index 80257d23f..cecfab2eb 100644 Binary files a/产品文档/油站数据库设计.xls and b/产品文档/油站数据库设计.xls differ