doum
昨天 c25fecae568a074e338bce625a92960aca859fb8
server/dmmall_service/src/main/java/com/doumee/service/business/impl/CouponServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
@@ -30,6 +31,7 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * 优惠券信息表Service实现
@@ -55,24 +57,21 @@
    @Override
    public Integer create(Coupon coupon) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        coupon.setType(Constants.ONE);
        coupon.setGetMethod(Constants.ZERO);
        isCreateParamValid(coupon);
        /**平台优惠券是兑换优惠券,商家优惠券是领取优惠券*/
        if(Constants.equalsInteger(coupon.getType(),Constants.ZERO)){
            coupon.setGetMethod(Constants.ZERO);
        }else if(Constants.equalsInteger(coupon.getType(),Constants.ONE)){
          coupon.setGetMethod(Constants.ONE);
        }
        coupon.setIsdeleted(Constants.ZERO);
        coupon.setCreator(user.getId());
        coupon.setCreateDate(new Date());
        coupon.setStatus(Constants.ONE);
        coupon.setEditor(user.getId());
        coupon.setEditDate(new Date());
        coupon.setStatus(Constants.ONE);//默认禁用
        couponMapper.insert(coupon);
        return coupon.getId();
    }
    public void isCreateParamValid(Coupon coupon){
        if(StringUtils.isBlank(coupon.getName())
                || coupon.getType()==null
                ||coupon.getLimitPrice()==null
@@ -81,7 +80,7 @@
              /*  ||coupon.getIntegral()==null*/
                ||coupon.getStartDate()==null
                ||coupon.getEndDate()==null
                ||coupon.getValidDays()==null
//                ||coupon.getValidDays()==null
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), ResponseStatus.BAD_REQUEST.getMessage());
@@ -98,11 +97,17 @@
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "关联的店铺不存在!");
            }
        }
        coupon.setApplyIds("");
        if(Constants.equalsInteger(coupon.getApplyType(),Constants.TWO) && coupon.getApplyIdList()!=null){
            coupon.setApplyIds(coupon.getApplyIdList().stream().map(String::valueOf).collect(Collectors.joining(",")));//使用对象编码集合
        }
        if(Constants.equalsInteger(coupon.getApplyType(),Constants.ONE) && coupon.getApplyCateIdList()!=null){
            coupon.setApplyIds(coupon.getApplyCateIdList().stream().map(String::valueOf).collect(Collectors.joining(",")));//使用对象编码集合
        }
    }
    @Override
    public void deleteById(Integer id) {
        Coupon query= couponMapper.selectById(id);
        initCouponStatus(query);
        if(!Constants.equalsInteger(query.getCouponStatus(),Constants.ZERO)){
@@ -134,9 +139,9 @@
        isCreateParamValid(coupon);
        Coupon query= couponMapper.selectById(coupon.getId());
        initCouponStatus(query);
        if(!Constants.equalsInteger(query.getCouponStatus(),Constants.ZERO)){
     /*   if(!Constants.equalsInteger(query.getCouponStatus(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "活动已开始/已结束状态,不支持编辑操作");
        }
        }*/
        coupon.setEditor(user.getId());
        coupon.setEditDate(new Date());
        couponMapper.updateById(coupon);
@@ -187,8 +192,9 @@
        Utils.MP.blankToNull(pageWrap );
        queryWrapper.selectAll(Coupon.class);
        queryWrapper.like(StringUtils.isNotBlank(pageWrap. getName()),Coupon::getName,pageWrap.getName());
        queryWrapper.eq(pageWrap.getStatus()!=null,Coupon::getStatus,pageWrap.getStatus());
        queryWrapper.eq(Coupon::getIsdeleted,Constants.ZERO);
        queryWrapper.orderByDesc(Coupon::getCreateDate);
        queryWrapper.orderByDesc(Coupon::getId);
        List<Coupon> result =  couponJoinMapper.selectList( queryWrapper);
        for(Coupon model:result){
            initCouponStatus(model);
@@ -202,11 +208,13 @@
        MPJLambdaWrapper<Coupon> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.selectAll(Coupon.class);
        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and COUPON_ID=t.id) as received");
        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and COUPON_ID=t.id and STATUS=0) as unused");
        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and COUPON_ID=t.id and STATUS=1) as used");
        //已发放数量(不包含定向发放)
        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and COUPON_ID=t.id and GET_METHOD !=2) as received");
//        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and COUPON_ID=t.id and STATUS=0) as unused");
//        queryWrapper.select("(select count(id) from member_coupon where ISDELETED=0 and COUPON_ID=t.id and STATUS=1) as used");
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Coupon::getName,pageWrap.getModel().getName());
        queryWrapper.eq(pageWrap.getModel().getCouponType()!=null,Coupon::getCouponType,pageWrap.getModel().getCouponType());
        queryWrapper.eq(Coupon::getIsdeleted,Constants.ZERO);
        queryWrapper.orderByDesc(Coupon::getCreateDate);
        IPage<Coupon> result =  couponJoinMapper.selectJoinPage(page,Coupon.class, queryWrapper);