src/main/java/com/mzl/flower/constant/Constants.java
@@ -483,7 +483,8 @@ activity("活动获取"), giveaway("积分赠送"), deduction("积分扣减"), exchange("积分兑换"); exchange("积分兑换"), expired("积分过期"); POINT_TYPE(String desc) { this.desc = desc; src/main/java/com/mzl/flower/dto/response/point/ExpiredPointDTO.java
对比新文件 @@ -0,0 +1,16 @@ package com.mzl.flower.dto.response.point; import lombok.Data; @Data public class ExpiredPointDTO { private String userId; private Long customerId; private Integer addPoint; private Integer reducePoint; } src/main/java/com/mzl/flower/entity/point/CustomerPointDetail.java
@@ -37,14 +37,8 @@ @ApiModelProperty("积分类型:增加(消费获取、活动获取、积分赠送),减少(积分扣减、积分兑换)") private String type; @ApiModelProperty("积分(积分=使用积分+过期积分)") @ApiModelProperty("积分变更数量") private Integer point; @ApiModelProperty("使用积分") private Integer usePoint; @ApiModelProperty("过期积分") private Integer expiredPoint; @ApiModelProperty("备注(可记录积分的来源或去向,如订单号、兑换内容、活动名称等)") private String remarks; src/main/java/com/mzl/flower/mapper/partner/PartnerMapper.java
@@ -19,5 +19,5 @@ PartnerDTO getCurrentPartner(@Param("userId")String userId); Partner getByIdOrUserId(@Param("partnerUserId") String partnerUserId); List<Partner> getByIdOrUserId(@Param("partnerUserId") String partnerUserId); } src/main/java/com/mzl/flower/mapper/point/CustomerPointDetailMapper.java
@@ -3,28 +3,21 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.dto.request.point.CustomerPointDetailQueryDTO; import com.mzl.flower.dto.request.point.PointGoodQueryDTO; import com.mzl.flower.dto.response.point.CustomerPointDetailVO; import com.mzl.flower.dto.response.point.PointGoodVO; import com.mzl.flower.dto.response.point.ExpiredPointDTO; import com.mzl.flower.entity.point.CustomerPointDetail; import com.mzl.flower.entity.point.PointGood; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.time.LocalDate; import java.util.List; /** * @author fanghaowei * @version version2.0 * @className CustomerPointDetailMapper * @date 2024/8/29 * @description CustomerPointDetailMapper */ @SuppressWarnings("ALL") @Repository public interface CustomerPointDetailMapper extends BaseMapper<CustomerPointDetail> { List<CustomerPointDetailVO> queryPage(@Param("dto") CustomerPointDetailQueryDTO dto, Page page); List<ExpiredPointDTO> tongjiExpiredPoint(LocalDate lastYear); } src/main/java/com/mzl/flower/schedule/PointScheduleService.java
对比新文件 @@ -0,0 +1,90 @@ package com.mzl.flower.schedule; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.response.point.ExpiredPointDTO; import com.mzl.flower.entity.flower.FlowerCategory; import com.mzl.flower.entity.partner.Partner; import com.mzl.flower.entity.point.CustomerPoint; import com.mzl.flower.entity.point.CustomerPointDetail; import com.mzl.flower.mapper.point.CustomerPointDetailMapper; import com.mzl.flower.mapper.point.CustomerPointMapper; import com.mzl.flower.utils.DateUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateFormatUtils; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.List; @Component @Slf4j public class PointScheduleService { private final CustomerPointMapper customerPointMapper; private final CustomerPointDetailMapper customerPointDetailMapper; public PointScheduleService(CustomerPointMapper customerPointMapper, CustomerPointDetailMapper customerPointDetailMapper) { this.customerPointMapper = customerPointMapper; this.customerPointDetailMapper = customerPointDetailMapper; } /** * 定时计算用户过期积分 */ @Scheduled(cron = "0 0 2 * * ?") public void calculatingExpiredPoint() { log.info("过期积分计算开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); LocalDate now = LocalDate.now().minusDays(1);//前一天 LocalDate lastYear = now.minus(1, ChronoUnit.YEARS); // 日期减去一年 List<ExpiredPointDTO> pointDTOS = customerPointDetailMapper.tongjiExpiredPoint(lastYear); if(pointDTOS != null && pointDTOS.size() > 0){ for (ExpiredPointDTO pointDTO : pointDTOS) { if(pointDTO.getAddPoint().intValue()> pointDTO.getReducePoint().intValue()){ //积分增加大于减少 Integer expiredPoint = pointDTO.getAddPoint().intValue() - pointDTO.getReducePoint().intValue(); CustomerPointDetail customerPointDetail = new CustomerPointDetail(); customerPointDetail.setUserId(pointDTO.getUserId()); customerPointDetail.setCustomerId(pointDTO.getCustomerId()); customerPointDetail.setChangeType(Constants.POINT_CHANGE_TYPE.reduce.name()); customerPointDetail.setType(Constants.POINT_TYPE.expired.name()); customerPointDetail.setPoint(expiredPoint); customerPointDetail.setRecordDate(now); customerPointDetail.create("sys"); customerPointDetail.setRemarks(DateUtils.toString(lastYear,"yyyy-MM-dd")+"过期积分结算"); customerPointDetailMapper.insert(customerPointDetail); //更新用户积分记录 CustomerPoint customerPoint = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>() .eq(CustomerPoint::getCustomerId, pointDTO.getCustomerId()) .eq(CustomerPoint::getUserId, pointDTO.getUserId())); if(customerPoint == null ){ customerPoint = new CustomerPoint(); customerPoint.setCustomerId(pointDTO.getCustomerId()); customerPoint.setUserId(pointDTO.getUserId()); customerPoint.setTotalPoint(0); customerPoint.setUsedPoint(0); customerPoint.setExpiredPoint(0); customerPoint.create("sys"); customerPointMapper.insert(customerPoint); }else { customerPoint.setExpiredPoint(expiredPoint); customerPointMapper.updateById(customerPoint); } } } } log.info("过期积分计算结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); } } src/main/java/com/mzl/flower/service/customer/CustomerService.java
@@ -16,6 +16,7 @@ import com.mzl.flower.entity.partner.Partner; import com.mzl.flower.mapper.customer.CustomerMapper; import com.mzl.flower.mapper.partner.PartnerMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -25,6 +26,7 @@ @Service @Transactional @Slf4j public class CustomerService { @@ -169,10 +171,14 @@ } // Partner partner = partnerMapper.selectOne(new QueryWrapper<Partner>() // .eq("user_id", dto.getPartnerUserId())); Partner partner = partnerMapper.getByIdOrUserId(dto.getPartnerUserId()); //适配id和userId if (partner == null) { List<Partner> partners = partnerMapper.getByIdOrUserId(dto.getPartnerUserId()); //适配id和userId if(partners== null || partners.size() == 0){ throw new ValidationException("合伙人不存在"); } if(partners.size() > 1){ log.error("合伙人信息重复,userId:{}", dto.getPartnerUserId()); } Partner partner = partners.get(0); if (!"P".equals(partner.getStatus())) { throw new ValidationException("合伙人信息未审核通过,请联系客服人员"); } @@ -182,7 +188,14 @@ public String getPartnerName(String partnerUserId) { if (StringUtils.isNotBlank(partnerUserId)) { Partner partner = partnerMapper.getByIdOrUserId(partnerUserId); List<Partner> partners = partnerMapper.getByIdOrUserId(partnerUserId); //适配id和userId if(partners== null || partners.size() == 0){ throw new ValidationException("合伙人不存在"); } if(partners.size() > 1){ log.error("合伙人信息重复,userId:{}", partnerUserId); } Partner partner = partners.get(0); if (partner == null) { throw new ValidationException("合伙人不存在"); } src/main/java/com/mzl/flower/service/point/CustomerPointService.java
@@ -84,16 +84,15 @@ if(POINT_CHANGE_TYPE.add.name().equals(detail.getChangeType())){ point.setTotalPoint(point.getTotalPoint() + detail.getPoint()); point.setUsedPoint(point.getUsedPoint() + detail.getUsePoint()); point.setExpiredPoint(point.getExpiredPoint() + detail.getExpiredPoint()); }else if(POINT_CHANGE_TYPE.reduce.name().equals(detail.getChangeType())){ // if(point.getTotalPoint()!= null && point.getTotalPoint()!=0 && point.getTotalPoint()>= detail.getPoint()){ // point.setTotalPoint(point.getTotalPoint() - detail.getPoint()); // }else{ // //积分不足,直接清0 // point.setTotalPoint(0); // } point.setTotalPoint(point.getTotalPoint() - detail.getPoint()); if(point.getTotalPoint()!= null && point.getTotalPoint()!=0 && point.getTotalPoint()>= detail.getPoint()){ point.setTotalPoint(point.getTotalPoint() - detail.getPoint()); }else{ //积分不足,直接清0 point.setTotalPoint(0); detail.setPoint(point.getTotalPoint()); detail.setRemarks(detail.getRemarks()+",积分不足,扣除剩余积分"+point.getTotalPoint()); } } if(isAdd){ customerPointMapper.insert(point); @@ -114,10 +113,10 @@ detail.setChangeType(POINT_CHANGE_TYPE.reduce.name()); detail.setType(POINT_TYPE.deduction.name()); detail.create(SecurityUtils.getUserId()); customerPointDetailMapper.insert(detail); //更新汇总表 updateCustomerPoint(detail); customerPointDetailMapper.insert(detail); } public void consumptionPoint(BigDecimal orderAmount, String orderNo,String userId) { src/main/java/com/mzl/flower/utils/DateUtils.java
@@ -2,6 +2,7 @@ import org.apache.poi.util.LocaleUtil; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Calendar; @@ -40,6 +41,19 @@ } /** * 将LocalDateTime对象转换为字符串 * @return */ public static String toString(LocalDate date,String format) { // 定义日期时间格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); String str = date.format(formatter); return str; } public static Date getJavaDate(double date) { return getJavaDate(date, false, (TimeZone)null, false); } src/main/resources/mapper/point/CustomerPointDetailMapper.xml
@@ -17,4 +17,24 @@ </if> order by t.c desc </select> <select id="tongjiExpiredPoint" resultType="com.mzl.flower.dto.response.point.ExpiredPointDTO" parameterType="java.time.LocalDate"> SELECT p.user_id, p.customer_id, SUM(CASE WHEN p.change_type = 'add' THEN point ELSE 0 END) AS addPoint, SUM(CASE WHEN p.change_type = 'reduce' THEN point ELSE 0 END) AS reducePoint FROM t_customer_point_detail p WHERE p.deleted= 0 <if test="lastYear!=null "> <![CDATA[ p.record_date <= #{lastYear} ]]> </if> GROUP BY p.user_id, p.customer_id </select> </mapper> src/main/表设计-二期.xlsxBinary files differ