Pārlūkot izejas kodu

feat:扣减vip次数

zhangwei 2 gadi atpakaļ
vecāks
revīzija
3519b7ce4f

+ 4 - 1
src/main/java/com/winhc/repal/repository/RepalVipMapper.java

@@ -2,12 +2,15 @@ package com.winhc.repal.repository;
 
 import com.winhc.repal.entity.RepalVip;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
 
 /**
  * @description RepalVip Mapper 接口
  * @author Generator
  * @date 2022-05-07
  */
+@Repository
 public interface RepalVipMapper extends BaseMapper<RepalVip> {
-
+    int updateSomeCount(@Param("id")Long id,@Param("code")Integer code);
 }

+ 49 - 10
src/main/java/com/winhc/repal/service/impl/RepalDynamicServiceImpl.java

@@ -4,27 +4,27 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.winhc.common.base.BeanResponse;
 import com.winhc.common.enums.CodeMsg;
 import com.winhc.common.exception.CommonException;
 import com.winhc.repal.cloud.WinCoinService;
 import com.winhc.repal.cloud.dto.WinCoinOrderFormDTO;
 import com.winhc.repal.cloud.vo.WinCoinOrderFormVO;
-import com.winhc.repal.entity.RepalBill;
-import com.winhc.repal.entity.RepalCustomer;
-import com.winhc.repal.entity.RepalDynamic;
-import com.winhc.repal.entity.RepalGroup;
+import com.winhc.repal.entity.*;
 import com.winhc.repal.enums.*;
 import com.winhc.repal.model.bo.UserContextBO;
 import com.winhc.repal.model.dto.*;
 import com.winhc.repal.model.vo.RepalLinkVO;
 import com.winhc.repal.model.vo.RepalSmsTemplateVO;
 import com.winhc.repal.repository.RepalDynamicMapper;
+import com.winhc.repal.repository.RepalVipMapper;
 import com.winhc.repal.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.winhc.repal.util.UserContextUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
@@ -57,6 +57,12 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
     @Autowired
     private RepalCustomerService repalCustomerService;
 
+    @Autowired
+    private RepalVipService repalVipService;
+
+    @Autowired
+    private RepalVipMapper repalVipMapper;
+
     @Override
     public Boolean addDynamic(DynamicContentDTO dto) {
         UserContextBO userContextBO = UserContextUtil.getUser();
@@ -97,6 +103,7 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
     }
 
     @Override
+    @Transactional
     public Boolean urgeBySms(RepalSmsDTO dto) {
         //校验权限
         UserContextBO userContextBO = UserContextUtil.getUser();
@@ -104,7 +111,6 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
         if(!allFlag){
             throw new CommonException(CodeMsg.FORBIDDEN,"暂无此权限,可联系超级管理员在我的-成员管理页面开通");
         }
-        //todo 扣减vip次数
         if(CollUtil.isEmpty(dto.getLinks())){
             throw new CommonException(CodeMsg.FAILED,"请至少选择一个联系人");
         }
@@ -116,7 +122,15 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
         if(ObjectUtil.isNull(repalBill) || CollUtil.isEmpty(templates)){
             throw new CommonException(CodeMsg.FAILED,"发送失败");
         }
-
+        //扣减vip次数
+        RepalVip repalVip = repalVipService.getOne(Wrappers.lambdaQuery(RepalVip.class).eq(RepalVip::getRepalGroupId,repalBill.getRepalGroupId()),false);
+        if(ObjectUtil.isNull(repalVip) || RepalVipSignEnum.无特权.getCode().equals(repalVip.getRepalVipSign())){
+            throw new CommonException(CodeMsg.FAILED,"请先开通特权");
+        }
+        int count = repalVipMapper.updateSomeCount(repalVip.getId(),RepalDynamicTypeEnum.短信.getCode());
+        if(count < 1){
+            throw new CommonException(CodeMsg.FAILED,"可用短信次数不足");
+        }
         for(RepalSmsTemplateVO template:templates){
             if(template.getSmsCode().equals(dto.getSmsCode())){
                 Map<String,Object> paraMap = new HashMap<>();
@@ -157,6 +171,7 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
     }
 
     @Override
+    @Transactional
     public Boolean urgeByLawyerLetter(RepalLetterDTO dto) {
         //校验权限
         UserContextBO userContextBO = UserContextUtil.getUser();
@@ -164,11 +179,19 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
         if(!allFlag){
             throw new CommonException(CodeMsg.FORBIDDEN,"暂无此权限,可联系超级管理员在我的-成员管理页面开通");
         }
-        //todo 扣减vip次数
         RepalBill repalBill = repalBillService.getById(dto.getRepalBillId());
         if(ObjectUtil.isNull(repalBill)){
             throw new CommonException(CodeMsg.FAILED,"发送失败,账款不存在");
         }
+        //扣减vip次数
+        RepalVip repalVip = repalVipService.getOne(Wrappers.lambdaQuery(RepalVip.class).eq(RepalVip::getRepalGroupId,repalBill.getRepalGroupId()),false);
+        if(ObjectUtil.isNull(repalVip) || RepalVipSignEnum.无特权.getCode().equals(repalVip.getRepalVipSign())){
+            throw new CommonException(CodeMsg.FAILED,"请先开通特权");
+        }
+        int count = repalVipMapper.updateSomeCount(repalVip.getId(),RepalDynamicTypeEnum.律师函.getCode());
+        if(count < 1){
+            throw new CommonException(CodeMsg.FAILED,"可用催款函次数不足");
+        }
         Map<String,Object> paraMap = new HashMap<>();
         paraMap.put("company",repalBill.getCustomerName());
         paraMap.put("links",dto.getLinks());
@@ -196,6 +219,7 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
     }
 
     @Override
+    @Transactional
     public Boolean urgeByConsult(RepalConsultDTO dto) {
         //校验权限
         UserContextBO userContextBO = UserContextUtil.getUser();
@@ -203,12 +227,19 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
         if(!allFlag){
             throw new CommonException(CodeMsg.FORBIDDEN,"暂无此权限,可联系超级管理员在我的-成员管理页面开通");
         }
-        //todo 扣减vip次数
         RepalBill repalBill = repalBillService.getById(dto.getRepalBillId());
         if(ObjectUtil.isNull(repalBill)){
             throw new CommonException(CodeMsg.FAILED,"参数有误");
         }
-
+        //扣减vip次数
+        RepalVip repalVip = repalVipService.getOne(Wrappers.lambdaQuery(RepalVip.class).eq(RepalVip::getRepalGroupId,repalBill.getRepalGroupId()),false);
+        if(ObjectUtil.isNull(repalVip) || RepalVipSignEnum.无特权.getCode().equals(repalVip.getRepalVipSign())){
+            throw new CommonException(CodeMsg.FAILED,"请先开通特权");
+        }
+        int count = repalVipMapper.updateSomeCount(repalVip.getId(),RepalDynamicTypeEnum.咨询.getCode());
+        if(count < 1){
+            throw new CommonException(CodeMsg.FAILED,"咨询律师次数不足");
+        }
         Map<String,Object> paraMap = new HashMap<>();
         paraMap.put("province",dto.getProvince());
         paraMap.put("city",dto.getCity());
@@ -239,6 +270,7 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
     }
 
     @Override
+    @Transactional
     public Boolean urgeByLawsuit(RepalLawDTO dto) {
         //校验权限
         UserContextBO userContextBO = UserContextUtil.getUser();
@@ -246,12 +278,19 @@ public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, Rep
         if(!allFlag){
             throw new CommonException(CodeMsg.FORBIDDEN,"暂无此权限,可联系超级管理员在我的-成员管理页面开通");
         }
-        //todo 扣减vip次数
         RepalBill repalBill = repalBillService.getById(dto.getRepalBillId());
         RepalCustomer repalCustomer = repalCustomerService.getById(repalBill.getCustomerId());
         if(ObjectUtil.isNull(repalBill) || ObjectUtil.isNull(repalCustomer)){
             throw new CommonException(CodeMsg.FAILED,"参数有误");
         }
+        RepalVip repalVip = repalVipService.getOne(Wrappers.lambdaQuery(RepalVip.class).eq(RepalVip::getRepalGroupId,repalBill.getRepalGroupId()),false);
+        if(ObjectUtil.isNull(repalVip) || RepalVipSignEnum.无特权.getCode().equals(repalVip.getRepalVipSign())){
+            throw new CommonException(CodeMsg.FAILED,"请先开通特权");
+        }
+        int count = repalVipMapper.updateSomeCount(repalVip.getId(),RepalDynamicTypeEnum.诉讼.getCode());
+        if(count < 1){
+            throw new CommonException(CodeMsg.FAILED,"诉讼追款次数不足");
+        }
         String productCode = "205";
         if(RepalBillStageEnum.NON_PROSECUTE.getCode().equals(dto.getCaseStage())){
             productCode = "203";

+ 16 - 0
src/main/resources/mapper/RepalVipMapper.xml

@@ -2,4 +2,20 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.winhc.repal.repository.RepalVipMapper">
 
+    <update id="updateSomeCount">
+        update REPAL_VIP SET
+        <if test="code == 1">
+            SMS_REMAIN_COUNT = SMS_REMAIN_COUNT-1 WHERE SMS_REMAIN_COUNT> 0
+        </if>
+        <if test="code == 2">
+            LETTER_REMAIN_COUNT = LETTER_REMAIN_COUNT-1 WHERE LETTER_REMAIN_COUNT> 0
+        </if>
+        <if test="code == 3">
+            CONSULT_REMAIN_COUNT = CONSULT_REMAIN_COUNT-1 WHERE CONSULT_REMAIN_COUNT> 0
+        </if>
+        <if test="code == 4">
+            LAWSUIT_REMAIN_COUNT = LAWSUIT_REMAIN_COUNT-1 WHERE LAWSUIT_REMAIN_COUNT> 0
+        </if>
+        AND ID = #{id}
+    </update>
 </mapper>