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.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; /** * 【请填写功能名称】Service业务层处理 * * @author hh * @date 2025-01-16 */ @Service public class NonCoalPayServiceImpl extends ServiceImpl implements NonCoalPayService { @Resource private NonCoalPayMapper nonCoalPayMapper; @Resource private NonCoalPayCategoryService nonCoalPayCategoryService; @Resource private NonCoalPayStudentService nonCoalPayStudentService; @Resource private NonCoalPayStudentMapper nonCoalPayStudentMapper; /** * 查询【请填写功能名称】 * * @param id 【请填写功能名称】主键 * @return 【请填写功能名称】 */ @Override public NonCoalPayDetailRepDto selectNonCoalPayById(Long id) { return nonCoalPayMapper.getNonCoalPayById(id); } @Override public List selectNonCoalPayByStu(String phone, String idCard) { return nonCoalPayMapper.selectNonCoalPayByParam(phone, idCard); } /** * 查询【请填写功能名称】列表 * * @param nonCoalPay 【请填写功能名称】 * @return 【请填写功能名称】 */ @Override public List 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 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; } /** * 新增【请填写功能名称】 * * @param nonCoalPay 【请填写功能名称】 * @return 结果 */ @Override @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 nonCoalPayCategoryList, Long id) { List 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 lambdaQueryWrapper = Wrappers.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("该批次已存在"); } } /** * 修改【请填写功能名称】 * * @param nonCoalPay 【请填写功能名称】 * @return 结果 */ @Override @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; } /** * 批量删除【请填写功能名称】 * * @param ids 需要删除的【请填写功能名称】主键 * @return 结果 */ @Override public int deleteNonCoalPayByIds(Long[] ids) { return nonCoalPayMapper.deleteNonCoalPayByIds(ids); } /** * 删除【请填写功能名称】信息 * * @param id 【请填写功能名称】主键 * @return 结果 */ @Override public int deleteNonCoalPayById(Long 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); } }