From 70dcf4e610a0ec5fd6ca2c3daf9edf4957b30529 Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: 星期二, 25 二月 2025 16:34:46 +0800
Subject: [PATCH] 考试制证修改

---
 exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayServiceImpl.java |  199 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 187 insertions(+), 12 deletions(-)

diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayServiceImpl.java
index f090935..80b01df 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayServiceImpl.java
@@ -1,13 +1,33 @@
 package com.gkhy.exam.pay.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gkhy.exam.pay.dto.rep.NonCoalPayDetailH5RepDto;
+import com.gkhy.exam.pay.dto.rep.NonCoalPayDetailRepDto;
+import com.gkhy.exam.pay.dto.rep.NonCoalPayPageRepDto;
+import com.gkhy.exam.pay.dto.rep.NonCoalPayStudentDetailRepDto;
+import com.gkhy.exam.pay.dto.req.NonCoalPayCategoryReqDto;
+import com.gkhy.exam.pay.dto.req.NonCoalPayReqDto;
+import com.gkhy.exam.pay.dto.req.NonCoalPayTypeEditReqDto;
 import com.gkhy.exam.pay.entity.NonCoalPay;
+import com.gkhy.exam.pay.entity.NonCoalPayCategory;
+import com.gkhy.exam.pay.entity.NonCoalPayStudent;
 import com.gkhy.exam.pay.mapper.NonCoalPayMapper;
+import com.gkhy.exam.pay.mapper.NonCoalPayStudentMapper;
+import com.gkhy.exam.pay.service.NonCoalPayCategoryService;
 import com.gkhy.exam.pay.service.NonCoalPayService;
-import com.ruoyi.common.utils.DateUtils;
+import com.gkhy.exam.pay.service.NonCoalPayStudentService;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 
 
@@ -21,6 +41,12 @@
 public class NonCoalPayServiceImpl extends ServiceImpl<NonCoalPayMapper, NonCoalPay> implements NonCoalPayService {
     @Resource
     private NonCoalPayMapper nonCoalPayMapper;
+    @Resource
+    private NonCoalPayCategoryService nonCoalPayCategoryService;
+    @Resource
+    private NonCoalPayStudentService nonCoalPayStudentService;
+    @Resource
+    private NonCoalPayStudentMapper nonCoalPayStudentMapper;
 
     /**
      * 查询【请填写功能名称】
@@ -29,9 +55,15 @@
      * @return 【请填写功能名称】
      */
     @Override
-    public NonCoalPay selectNonCoalPayById(Long id) {
-        return nonCoalPayMapper.selectNonCoalPayById(id);
+    public NonCoalPayDetailRepDto selectNonCoalPayById(Long id) {
+        return nonCoalPayMapper.getNonCoalPayById(id);
     }
+
+    @Override
+    public List<NonCoalPayDetailH5RepDto> selectNonCoalPayByStu(String phone, String idCard) {
+        return nonCoalPayMapper.selectNonCoalPayByParam(phone, idCard);
+    }
+
 
     /**
      * 查询【请填写功能名称】列表
@@ -40,8 +72,48 @@
      * @return 【请填写功能名称】
      */
     @Override
-    public List<NonCoalPay> selectNonCoalPayList(NonCoalPay nonCoalPay) {
-        return nonCoalPayMapper.selectNonCoalPayList(nonCoalPay);
+    public List<NonCoalPayPageRepDto> selectNonCoalPayList(NonCoalPay nonCoalPay) {
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
+            if (!Constants.DIS_XINJIANG_CODE.equals(SecurityUtils.getDeptDistrictCode())) {
+                nonCoalPay.setDistrictCode(SecurityUtils.getDeptDistrictCode());
+            }
+        }
+        return nonCoalPayMapper.getNonCoalPayList(nonCoalPay);
+    }
+
+    @Override
+    public NonCoalPayStudentDetailRepDto getNonCoalPayStudentByPayId(Long id) {
+        NonCoalPayDetailRepDto nonCoalPayById = nonCoalPayMapper.getNonCoalPayById(id);
+        NonCoalPayStudentDetailRepDto data = new NonCoalPayStudentDetailRepDto();
+        if (nonCoalPayById != null) {
+            BeanUtils.copyProperties(nonCoalPayById, data);
+            NonCoalPayStudent student = new NonCoalPayStudent();
+            student.setNonCoalPayId(nonCoalPayById.getId());
+            List<NonCoalPayStudent> nonCoalPayStudents = nonCoalPayStudentService.selectNonCoalPayStudentList(student);
+            data.setNonCoalPayStudentList(nonCoalPayStudents);
+            if (nonCoalPayStudents != null && !nonCoalPayStudents.isEmpty()) {
+                int payCount = (int) nonCoalPayStudents.stream()
+                        .filter(stu -> stu.getPayStatus() == 1)
+                        .count();
+                int size = nonCoalPayStudents.size();
+                data.setPayCount(payCount);
+                data.setUnPayCount(size - payCount);
+                data.setTotalCount(size);
+                data.setPayCountFee(new BigDecimal(payCount).multiply(data.getAmount()));
+                data.setUnPayCountFee(new BigDecimal(size - payCount).multiply(data.getAmount()));
+                data.setTotalCountFee(new BigDecimal(size).multiply(data.getAmount()));
+            } else {
+                data.setPayCount(0);
+                data.setUnPayCount(0);
+                data.setTotalCount(0);
+                data.setPayCountFee(new BigDecimal(0));
+                data.setUnPayCountFee(new BigDecimal(0));
+                data.setTotalCountFee(new BigDecimal(0));
+            }
+
+            return data;
+        }
+        return null;
     }
 
     /**
@@ -51,9 +123,57 @@
      * @return 结果
      */
     @Override
-    public int insertNonCoalPay(NonCoalPay nonCoalPay) {
-        nonCoalPay.setCreateTime(DateUtils.getNowDate());
-        return nonCoalPayMapper.insertNonCoalPay(nonCoalPay);
+    @Transactional
+    public int insertNonCoalPay(NonCoalPayReqDto nonCoalPay) {
+        if (!nonCoalPay.getDistrictCode().startsWith(Constants.DIS_XINJIANG_CODE)) {
+            throw new RuntimeException("地州信息错误");
+        }
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
+            if (Constants.DIS_XINJIANG_CODE.equals(nonCoalPay.getDistrictCode())) {
+                throw new RuntimeException("仅可选择下级地州");
+            }
+
+        }
+        checkData(nonCoalPay);
+        NonCoalPay nonCoalPay1 = new NonCoalPay();
+        BeanUtils.copyProperties(nonCoalPay, nonCoalPay1);
+        nonCoalPay1.setCreateBy(SecurityUtils.getUsername());
+
+        int i = nonCoalPayMapper.insertNonCoalPay(nonCoalPay1);
+        if (i > 0) {
+            saveNonCoalPayCategory(nonCoalPay.getNonCoalPayCategoryList(), nonCoalPay1.getId());
+        }
+        return i;
+    }
+
+    private void saveNonCoalPayCategory(List<NonCoalPayCategoryReqDto> nonCoalPayCategoryList, Long id) {
+        List<NonCoalPayCategory> nonCoalPayCategories = new ArrayList<>();
+        for (NonCoalPayCategoryReqDto nonCoalPayCategory : nonCoalPayCategoryList) {
+            NonCoalPayCategory nonCoalPayCategory1 = new NonCoalPayCategory();
+            BeanUtils.copyProperties(nonCoalPayCategory, nonCoalPayCategory1);
+            nonCoalPayCategory1.setNonCoalPayId(id);
+            nonCoalPayCategory1.setCreateBy(SecurityUtils.getUsername());
+            nonCoalPayCategories.add(nonCoalPayCategory1);
+        }
+        boolean b = nonCoalPayCategoryService.saveBatchData(nonCoalPayCategories);
+        if (!b) {
+            throw new ServiceException("保存失败");
+        }
+    }
+
+
+    private void checkData(NonCoalPayReqDto nonCoalPay) {
+        LambdaQueryWrapper<NonCoalPay> lambdaQueryWrapper = Wrappers.<NonCoalPay>lambdaQuery()
+                .eq(NonCoalPay::getDistrictCode, nonCoalPay.getDistrictCode())
+                .eq(NonCoalPay::getBatchName, nonCoalPay.getBatchName())
+                .eq(NonCoalPay::getDelFlag, 0);
+        if (nonCoalPay.getId() != null) {
+            lambdaQueryWrapper.ne(NonCoalPay::getId, nonCoalPay.getId());
+        }
+        Long l = baseMapper.selectCount(lambdaQueryWrapper);
+        if (l > 0) {
+            throw new ServiceException("该批次已存在");
+        }
     }
 
     /**
@@ -63,9 +183,54 @@
      * @return 结果
      */
     @Override
-    public int updateNonCoalPay(NonCoalPay nonCoalPay) {
-        nonCoalPay.setUpdateTime(DateUtils.getNowDate());
-        return nonCoalPayMapper.updateNonCoalPay(nonCoalPay);
+    @Transactional
+    public int updateNonCoalPay(NonCoalPayReqDto nonCoalPay) {
+
+        checkData(nonCoalPay);
+        checkHavePay(nonCoalPay.getId());
+        NonCoalPay nonCoalPay1 = new NonCoalPay();
+        BeanUtils.copyProperties(nonCoalPay, nonCoalPay1);
+        nonCoalPay1.setDistrictCode(null);
+        nonCoalPay1.setUpdateBy(SecurityUtils.getUsername());
+        int i = nonCoalPayMapper.updateNonCoalPay(nonCoalPay1);
+        if (i > 0) {
+            int i1 = nonCoalPayCategoryService.deleteNonCoalPayCategoryByPayId(nonCoalPay.getId());
+            if (i1 < 1) {
+                throw new ServiceException("更新失败");
+            }
+            saveNonCoalPayCategory(nonCoalPay.getNonCoalPayCategoryList(), nonCoalPay1.getId());
+        }
+        return i;
+    }
+
+    @Override
+    public int updateNonCoalPayType(NonCoalPayTypeEditReqDto nonCoalPay) {
+        NonCoalPay nonCoalPay1 = new NonCoalPay();
+        BeanUtils.copyProperties(nonCoalPay, nonCoalPay1);
+        nonCoalPay1.setUpdateBy(SecurityUtils.getUsername());
+        return nonCoalPayMapper.updateNonCoalPay(nonCoalPay1);
+    }
+
+    @Override
+    @Transactional
+    public int updateNonCoalPayTypeStatus(int payPersonType, Long id) {
+        NonCoalPay byId = nonCoalPayMapper.selectNonCoalPayById(id);
+        if (byId == null) {
+            throw new ServiceException("该数据不存在");
+        }
+        if (byId.getPayPersonType() == 2) {
+            throw new ServiceException("已是团体缴费不可变更缴费方式!");
+        }
+        NonCoalPay nonCoalPay1 = new NonCoalPay();
+        nonCoalPay1.setPayPersonType(payPersonType);
+        nonCoalPay1.setId(id);
+        nonCoalPay1.setUpdateBy(SecurityUtils.getUsername());
+        int i = nonCoalPayMapper.updateNonCoalPay(nonCoalPay1);
+        if (payPersonType == 2) {
+            //更新未缴费的为团体
+            nonCoalPayStudentMapper.updateNonCoalPayStudentType(id, SecurityUtils.getUsername());
+        }
+        return i;
     }
 
     /**
@@ -87,6 +252,16 @@
      */
     @Override
     public int deleteNonCoalPayById(Long id) {
-        return nonCoalPayMapper.deleteNonCoalPayById(id);
+        NonCoalPay nonCoalPay = nonCoalPayMapper.selectNonCoalPayById(id);
+        if (nonCoalPay == null) {
+            throw new ServiceException("该数据不存在");
+        }
+        //验证是否有学员已缴费
+        checkHavePay(id);
+        return nonCoalPayMapper.deleteNonCoalPayById(id, SecurityUtils.getUsername());
+    }
+
+    private void checkHavePay(Long id) {
+        nonCoalPayStudentService.checkHavePayData(id);
     }
 }
\ No newline at end of file

--
Gitblit v1.9.2