gongzuming
2024-08-29 cb517279ac03173f5b8d459de0a336f010aec599
积分相关
已删除1个文件
已修改9个文件
已添加3个文件
324 ■■■■ 文件已修改
src/main/java/com/mzl/flower/constant/Constants.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/point/ExchangeGoodsDTO.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/point/QueryExchangeGoodsDTO.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/point/PointGoodsRecordDTO.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/entity/point/PointGoodsRecord.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/point/PointGoodMapper.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/point/PointGoodsRecordMapper.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/BaseService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/point/PointGoodsService.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/customer/PointGoodsCustomerController.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/point/CustomerPointDetailMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/point/PointGoodMapper.xml 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/表设计-二期.xlsx 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/constant/Constants.java
@@ -493,4 +493,20 @@
            return desc;
        }
    }
    public enum POINT_GOODS_RECORD_STATUS {
        A("未使用"),
        U("已使用"),
        E("已过期");
        POINT_GOODS_RECORD_STATUS(String desc) {
            this.desc = desc;
        }
        private String desc;
        public String getDesc() {
            return desc;
        }
    }
}
src/main/java/com/mzl/flower/dto/request/point/ExchangeGoodsDTO.java
对比新文件
@@ -0,0 +1,15 @@
package com.mzl.flower.dto.request.point;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class ExchangeGoodsDTO {
    @NotNull(message = "商品id不能为空")
    private Long goodsId;
    @NotNull(message = "兑换数量不能为空")
    private Integer num;
}
src/main/java/com/mzl/flower/dto/request/point/QueryExchangeGoodsDTO.java
对比新文件
@@ -0,0 +1,14 @@
package com.mzl.flower.dto.request.point;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class QueryExchangeGoodsDTO {
    @ApiModelProperty(value = "兑换券状态(POINT_GOODS_RECORD_STATUS)")
    private String status;
    @ApiModelProperty(value = "用户ID",hidden = true)
    private String userId;
}
src/main/java/com/mzl/flower/dto/response/point/PointGoodsRecordDTO.java
对比新文件
@@ -0,0 +1,49 @@
package com.mzl.flower.dto.response.point;
import com.mzl.flower.base.AbstractTransDTO;
import com.mzl.flower.base.annotation.DictTrans;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PointGoodsRecordDTO extends AbstractTransDTO {
    @ApiModelProperty(value = "用户ID")
    private String userId;
    @ApiModelProperty(value = "商户ID")
    private Long customerId;
    @ApiModelProperty(value = "兑换码")
    private String redeemCode;
    @ApiModelProperty(value = "积分商品ID")
    private Long goodsId;
    @ApiModelProperty(value = "商品名称")
    private String name;
    @ApiModelProperty(value = "商品描述")
    private String description;
    @ApiModelProperty(value = "商品封面图")
    private String cover;
    @ApiModelProperty(value = "商品图片")
    private String pictures;
    @ApiModelProperty(value = "兑换积分数")
    private Integer point;
    @ApiModelProperty(value = "兑换数量")
    private Integer num;
    @ApiModelProperty(value = "兑换总积分")
    private Integer totalPoint;
    @ApiModelProperty(value = "兑换券状态POINT_GOODS_RECORD_STATUS")
    @DictTrans(target = "statusStr",codeType = "POINT_GOODS_RECORD_STATUS")
    private String status;
    private String statusStr;
}
src/main/java/com/mzl/flower/entity/point/PointGoodsRecord.java
@@ -15,9 +15,6 @@
    @ApiModelProperty(value = "商户ID")
    private Long customerId;
    @ApiModelProperty(value = "兑换单号")
    private String recordNo;
    @ApiModelProperty(value = "兑换码")
    private String redeemCode;
@@ -37,14 +34,17 @@
    private String pictures;
    @ApiModelProperty(value = "兑换积分数")
    private String point;
    private Integer point;
    @ApiModelProperty(value = "兑换数量")
    private String num;
    private Integer num;
    @ApiModelProperty(value = "兑换总积分")
    private String totalPoint;
    private Integer totalPoint;
    @ApiModelProperty(value = "兑换状态")
    @ApiModelProperty(value = "兑换券状态POINT_GOODS_RECORD_STATUS")
    private String status;
    @ApiModelProperty(value = "绑定订单ID")
    private String orderId;
}
src/main/java/com/mzl/flower/mapper/point/PointGoodMapper.java
文件已删除
src/main/java/com/mzl/flower/mapper/point/PointGoodsRecordMapper.java
@@ -1,9 +1,16 @@
package com.mzl.flower.mapper.point;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mzl.flower.entity.point.CustomerPointDetail;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.point.QueryExchangeGoodsDTO;
import com.mzl.flower.dto.response.point.PointGoodsRecordDTO;
import com.mzl.flower.entity.point.PointGoodsRecord;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PointGoodsRecordMapper extends BaseMapper<CustomerPointDetail> {
public interface PointGoodsRecordMapper extends BaseMapper<PointGoodsRecord> {
    List<PointGoodsRecordDTO> selectMyExchangeGoods(@Param("dto") QueryExchangeGoodsDTO dto, Page page);
}
src/main/java/com/mzl/flower/service/BaseService.java
@@ -459,6 +459,16 @@
        return p;
    }
    protected Customer getCustomerByUserId(String userId){
        Customer p = customerMapper.selectOne(new QueryWrapper<Customer>()
                .eq("user_id", userId));
        if(p == null){
            throw new ValidationException("客户不存在");
        }
        return p;
    }
    protected Customer getCustomer(Long id){
        Customer p = customerMapper.selectById(id);
src/main/java/com/mzl/flower/service/point/PointGoodsService.java
@@ -1,17 +1,24 @@
package com.mzl.flower.service.point;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.point.PointGoodsCreateDTO;
import com.mzl.flower.dto.request.point.PointGoodsQueryDTO;
import com.mzl.flower.dto.request.point.PointGoodsUpdateDTO;
import com.mzl.flower.dto.request.point.*;
import com.mzl.flower.dto.response.point.PointGoodsDTO;
import com.mzl.flower.dto.response.point.PointGoodsListDTO;
import com.mzl.flower.dto.response.point.PointGoodsRecordDTO;
import com.mzl.flower.entity.point.CustomerPoint;
import com.mzl.flower.entity.point.CustomerPointDetail;
import com.mzl.flower.entity.point.PointGoods;
import com.mzl.flower.entity.point.PointGoodsRecord;
import com.mzl.flower.mapper.point.CustomerPointDetailMapper;
import com.mzl.flower.mapper.point.CustomerPointMapper;
import com.mzl.flower.mapper.point.PointGoodsMapper;
import com.mzl.flower.mapper.point.PointGoodsRecordMapper;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.utils.UUIDGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -25,6 +32,16 @@
    @Autowired
    private PointGoodsMapper pointGoodsMapper;
    @Autowired
    private PointGoodsRecordMapper pointGoodsRecordMapper;
    @Autowired
    private CustomerPointMapper customerPointMapper;
    @Autowired
    private CustomerPointDetailMapper customerPointDetailMapper;
    public Long addPointGoods(PointGoodsCreateDTO dto){
        PointGoods p = new PointGoods();
@@ -86,4 +103,75 @@
        p.update(SecurityUtils.getUserId());
        pointGoodsMapper.updateById(p);
    }
    public synchronized void exchangeGoods(ExchangeGoodsDTO dto) {
        PointGoods p = pointGoodsMapper.selectById(dto.getGoodsId());
        if(p == null){
            throw new ValidationException("商品未找到");
        }
        if(!Constants.POINT_GOODS_STATUS.A.name().equals(p.getStatus())){
            throw new ValidationException("商品未上架");
        }
        if(p.getStock()< dto.getNum()){
            throw new ValidationException("商品库存不足");
        }
        CustomerPoint cp = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>()
                .eq(CustomerPoint::getUserId, SecurityUtils.getUserId()));
        if(cp == null || (cp.getTotalPoint()-cp.getUsedPoint()-cp.getExpiredPoint()) < p.getPoint() * dto.getNum()){
            throw new ValidationException("积分不足");
        }
        //记录兑换记录
        PointGoodsRecord record = new PointGoodsRecord();
        record.setUserId(SecurityUtils.getUserId());
        record.setCustomerId(getCustomerByUserId(SecurityUtils.getUserId()).getId());
        record.setGoodsId(dto.getGoodsId());
        record.setNum(dto.getNum());
        record.setPoint(p.getPoint());
        record.setName(p.getName());
        record.setPictures(p.getPictures());
        record.setDescription(p.getDescription());
        record.setTotalPoint(p.getPoint() * dto.getNum());
        record.setCover(p.getCover());
        record.setRedeemCode(UUIDGenerator.getUUID());
        record.setStatus(Constants.POINT_GOODS_RECORD_STATUS.A.name());//未使用
        pointGoodsRecordMapper.insert(record);
        //更新积分汇总
        cp.setUsedPoint(cp.getUsedPoint()+record.getTotalPoint());
        customerPointMapper.updateById(cp);
        //记录积分明细
        CustomerPointDetail detail = new CustomerPointDetail();
        detail.setUserId(SecurityUtils.getUserId());
        detail.setCustomerId(record.getCustomerId());
        detail.setPoint(record.getTotalPoint());
        detail.setChangeType(Constants.POINT_CHANGE_TYPE.reduce.name());
        detail.setType(Constants.POINT_TYPE.exchange.name());
        detail.create(SecurityUtils.getUserId());
        customerPointDetailMapper.insert(detail);
        //更新库存
        p.setStock(p.getStock()- dto.getNum());
        pointGoodsMapper.updateById(p);
    }
    public Page<PointGoodsRecordDTO> myExchangeGoods(QueryExchangeGoodsDTO dto, Page page) {
        dto.setUserId(SecurityUtils.getUserId());
        List<PointGoodsRecordDTO> list = pointGoodsRecordMapper.selectMyExchangeGoods(dto,page);
        page.setRecords(list);
        return page;
    }
    public void useExchangeGoods(Long recordId,String orderId) {
        PointGoodsRecord record = pointGoodsRecordMapper.selectById(recordId);
        if(record == null){
            throw new ValidationException("兑换券不存在");
        }
        if(!Constants.POINT_GOODS_RECORD_STATUS.A.name().equals(record.getStatus())){
            throw new ValidationException("兑换券已使用或过期");
        }
        record.setStatus(Constants.POINT_GOODS_RECORD_STATUS.U.name());
        record.setOrderId(orderId);
        pointGoodsRecordMapper.updateById(record);
    }
}
src/main/java/com/mzl/flower/web/customer/PointGoodsCustomerController.java
@@ -4,12 +4,14 @@
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.point.PointGoodsCreateDTO;
import com.mzl.flower.dto.request.point.PointGoodsQueryDTO;
import com.mzl.flower.dto.request.point.PointGoodsUpdateDTO;
import com.mzl.flower.dto.request.point.*;
import com.mzl.flower.dto.response.point.CustomerPointDetailDTO;
import com.mzl.flower.dto.response.point.PointGoodsDTO;
import com.mzl.flower.dto.response.point.PointGoodsListDTO;
import com.mzl.flower.dto.response.point.PointGoodsRecordDTO;
import com.mzl.flower.entity.point.PointGoodsRecord;
import com.mzl.flower.service.point.PointGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -47,4 +49,22 @@
        return returnData(R.SUCCESS.getCode(), pointGoodsService.getGoodsInfo(id));
    }
    @PostMapping("/exchange")
    @ApiOperation(value = "积分商品兑换", notes = "积分商品兑换")
    public ResponseEntity<ReturnDataDTO> exchangeGoods(@Validated @RequestBody ExchangeGoodsDTO dto) {
        pointGoodsService.exchangeGoods(dto);
        return returnData(R.SUCCESS.getCode(),null);
    }
    @GetMapping("/exchange/list")
    @ApiOperation(value = "积分商品兑换券列表", notes = "积分商品兑换券列表")
    public ResponseEntity<ReturnDataDTO<Page<PointGoodsRecordDTO>>> myExchangeGoods(QueryExchangeGoodsDTO dto, Page page) {
        return returnData(R.SUCCESS.getCode(), pointGoodsService.myExchangeGoods(dto,page));
    }
}
src/main/resources/mapper/point/CustomerPointDetailMapper.xml
@@ -15,6 +15,6 @@
        <if test="dto.type != null and dto.type != ''">
            and t.type = #{dto.type}
        </if>
        order by t.update_time desc
        order by t.c desc
    </select>
</mapper>
src/main/resources/mapper/point/PointGoodMapper.xml
@@ -1,26 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mzl.flower.mapper.point.PointGoodMapper">
    <select id="queryPage" resultType="com.mzl.flower.dto.response.point.PointGoodVO">
        select * from t_point_goods t where t.deleted= 0
        <if test="dto.name != null and dto.name != ''">
            and t.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.status != null and dto.status != ''">
            and t.status = #{dto.status}
        </if>
        order by t.update_time desc
    </select>
    <select id="queryList" resultType="com.mzl.flower.dto.response.point.PointGoodVO"
            parameterType="com.mzl.flower.dto.request.point.PointGoodQueryDTO">
        select * from t_point_goods t where t.deleted= 0
        <if test="dto.name != null and dto.name != ''">
            and t.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.status != null and dto.status != ''">
            and t.status = #{dto.status}
        </if>
<mapper namespace="com.mzl.flower.mapper.point.PointGoodsRecordMapper">
        order by t.update_time desc
    <select id="selectMyExchangeGoods" resultType="com.mzl.flower.dto.response.point.PointGoodsRecordDTO">
        SELECT
            *
        FROM
            t_point_goods_record p
        WHERE
            p.deleted = 0
          <if test="dto.userId != null and dto.userId != ''">
              AND p.user_id = #{dto.userId}
          </if>
          <if test="dto.status != null and dto.status != ''">
              AND p.`status` = #{dto.status}
          </if>
        ORDER BY
            p.create_time DESC
    </select>
</mapper>
src/main/表设计-二期.xlsx
Binary files differ