| | |
| | | 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.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | private NonCoalPayMapper nonCoalPayMapper; |
| | | @Resource |
| | | private NonCoalPayCategoryService nonCoalPayCategoryService; |
| | | @Resource |
| | | private NonCoalPayStudentService nonCoalPayStudentService; |
| | | @Resource |
| | | private NonCoalPayStudentMapper nonCoalPayStudentMapper; |
| | | |
| | | /** |
| | | * 查询【请填写功能名称】 |
| | |
| | | * @return 【请填写功能名称】 |
| | | */ |
| | | @Override |
| | | public NonCoalPay selectNonCoalPayById(Long id) { |
| | | return nonCoalPayMapper.selectNonCoalPayById(id); |
| | | public NonCoalPayDetailRepDto selectNonCoalPayById(Long id) { |
| | | return nonCoalPayMapper.getNonCoalPayById(id); |
| | | } |
| | | |
| | | @Override |
| | | public NonCoalPayDetailH5RepDto selectNonCoalPayByStu(String phone, String idCard) { |
| | | return nonCoalPayMapper.selectNonCoalPayByParam(phone, idCard); |
| | | } |
| | | |
| | | |
| | |
| | | * @return 【请填写功能名称】 |
| | | */ |
| | | @Override |
| | | public List<NonCoalPay> selectNonCoalPayList(NonCoalPay nonCoalPay) { |
| | | return nonCoalPayMapper.selectNonCoalPayList(nonCoalPay); |
| | | public List<NonCoalPayPageRepDto> selectNonCoalPayList(NonCoalPay nonCoalPay) { |
| | | if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) { |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional |
| | | public int insertNonCoalPay(NonCoalPayReqDto nonCoalPay) { |
| | | //todo 校验 |
| | | 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()); |
| | | saveNonCoalPayCategory(nonCoalPay.getNonCoalPayCategoryList(), nonCoalPay1.getId()); |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | private void saveNonCoalPayCategory(List<NonCoalPayCategoryReqDto> nonCoalPayCategoryList) { |
| | | 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); |
| | | } |
| | | nonCoalPayCategoryService.saveBacth(nonCoalPayCategories); |
| | | 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("该批次已存在"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional |
| | | public int updateNonCoalPay(NonCoalPayReqDto nonCoalPay) { |
| | | //todo 校验 |
| | | checkData(nonCoalPay); |
| | | checkHavePay(nonCoalPay.getId()); |
| | | NonCoalPay nonCoalPay1 = new NonCoalPay(); |
| | | BeanUtils.copyProperties(nonCoalPay, nonCoalPay1); |
| | | nonCoalPay1.setUpdateBy(SecurityUtils.getUsername()); |
| | |
| | | if (i1 < 1) { |
| | | throw new ServiceException("更新失败"); |
| | | } |
| | | saveNonCoalPayCategory(nonCoalPay.getNonCoalPayCategoryList()); |
| | | 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 = getById(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; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public int deleteNonCoalPayById(Long id) { |
| | | return nonCoalPayMapper.deleteNonCoalPayById(id); |
| | | NonCoalPay byId = getById(id); |
| | | if (byId == null) { |
| | | throw new ServiceException("该数据不存在"); |
| | | } |
| | | //验证是否有学员已缴费 |
| | | checkHavePay(id); |
| | | return nonCoalPayMapper.deleteNonCoalPayById(id, SecurityUtils.getUsername()); |
| | | } |
| | | |
| | | private void checkHavePay(Long id) { |
| | | nonCoalPayStudentService.checkHavePayData(id); |
| | | } |
| | | } |