package com.gkhy.exam.pay.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.exam.pay.dto.rep.CoalPayRepDto; import com.gkhy.exam.pay.dto.rep.CoalPayStudentRep; import com.gkhy.exam.pay.dto.req.CoalPayDto; import com.gkhy.exam.pay.dto.req.CoalPayReq; import com.gkhy.exam.pay.dto.req.CoalPayStudentReq; import com.gkhy.exam.pay.dto.req.CoalPayTypeReq; import com.gkhy.exam.pay.entity.CoalCategory; import com.gkhy.exam.pay.entity.CoalPay; import com.gkhy.exam.pay.entity.CoalPayCategory; import com.gkhy.exam.pay.entity.CoalPayStudent; import com.gkhy.exam.pay.mapper.CoalCategoryMapper; import com.gkhy.exam.pay.mapper.CoalPayCategoryMapper; import com.gkhy.exam.pay.mapper.CoalPayMapper; import com.gkhy.exam.pay.service.CoalPayService; import com.gkhy.exam.pay.service.CoalPayStudentService; import com.ruoyi.common.constant.ResultConstants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.system.mapper.SysDeptMapper; import javafx.print.Collation; import org.aspectj.weaver.loadtime.Aj; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @Service public class CoalPayServiceImpl extends ServiceImpl implements CoalPayService { @Resource private CoalPayMapper coalPayMapper; @Resource private CoalPayCategoryMapper coalPayCategoryMapper; @Resource private SysDeptMapper sysDeptMapper; @Resource private CoalCategoryMapper coalCategoryMapper; @Autowired private CoalPayStudentService coalPayStudentService; /** * 缴费管理列表 * @param coalPay * @return */ @Override public List selectCoalPayList(CoalPayReq coalPay) { List coalPayRepDtos = new ArrayList<>(); List coalPays = coalPayMapper.selectCoalPayList(coalPay); for (CoalPay pay : coalPays) { CoalPayRepDto coalPayRepDto = new CoalPayRepDto(); BeanUtils.copyProperties(pay,coalPayRepDto); //部门数据 SysDept sysDept = sysDeptMapper.selectDeptById(pay.getDeptId()); coalPayRepDto.setDeptName(sysDept.getDeptName()); //工种数据 List coalCategories = coalCategoryMapper.selectByCoalPayId(pay.getId()); coalPayRepDto.setCoalCategoryList(coalCategories); //学员数据 List coalPayStudents = coalPayStudentService.selectByCoalPayId(pay.getId()); List havePay = coalPayStudents.stream() .filter(stu -> stu.getPayStatus() != null && stu.getPayStatus().equals(1)) .collect(Collectors.toList()); coalPayRepDto.setTotalNum(coalPayStudents.size()); coalPayRepDto.setHavePayNum(havePay.size()); coalPayRepDtos.add(coalPayRepDto); } return coalPayRepDtos; } @Override public CoalPayRepDto selectCoalPayById(Long id) { CoalPayRepDto coalPayRepDto = new CoalPayRepDto(); //基本数据 CoalPay coalPay = coalPayMapper.selectById(id); BeanUtils.copyProperties(coalPay,coalPayRepDto); //考点名称 SysDept sysDept = sysDeptMapper.selectDeptById(coalPay.getDeptId()); coalPayRepDto.setDeptName(sysDept.getDeptName()); //工种类别 List coalCategories = coalCategoryMapper.selectByCoalPayId(coalPay.getId()); coalPayRepDto.setCoalCategoryList(coalCategories); //学员数据 List coalPayStudents = coalPayStudentService.selectByCoalPayId(id); List havePay = coalPayStudents.stream() .filter(stu -> stu.getPayStatus() != null && stu.getPayStatus().equals(0)) .collect(Collectors.toList()); coalPayRepDto.setTotalNum(coalPayStudents.size()); coalPayRepDto.setHavePayNum(havePay.size()); return coalPayRepDto; } @Override public int insertCoalPay(CoalPayDto coalPayDto) { CoalPay coalPay = new CoalPay(); BeanUtils.copyProperties(coalPayDto,coalPay); coalPay.setCreateBy(SecurityUtils.getUsername()); coalPay.setCreateTime(new Date()); int insert = coalPayMapper.insertBath(coalPay); if (CollectionUtils.isEmpty(coalPayDto.getCoalPayCategoryies())){ throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"工种类别不能为空"); } List coalPayCategories = coalPayDto.getCoalPayCategoryies(); for (CoalPayCategory coalPayCategory : coalPayCategories) { coalPayCategory.setCoalPayId(coalPay.getId()); coalPayCategoryMapper.insert(coalPayCategory); } return insert; } /** * 修改缴费信息 * @param coalPayDto * @return */ @Override public int updateCoalPay(CoalPayDto coalPayDto) { CoalPay coalPay = new CoalPay(); BeanUtils.copyProperties(coalPayDto,coalPay); coalPay.setUpdateBy(SecurityUtils.getUsername()); coalPay.setUpdateTime(new Date()); int i = coalPayMapper.updateCoalPayById(coalPay); int update = coalPayCategoryMapper.deleteByCoalPayId(coalPayDto.getId()); if (update>0){ List coalPayCategories = coalPayDto.getCoalPayCategoryies(); for (CoalPayCategory coalPayCategory : coalPayCategories) { coalPayCategory.setCoalPayId(coalPay.getId()); coalPayCategoryMapper.insert(coalPayCategory); } } return i; } @Override public AjaxResult deleteCoalPayByIds(Long[] ids) { for (Long id : ids) { List coalPayStudents = coalPayStudentService.selectByCoalPayIdAndPayStatus(id,1); if (!CollectionUtils.isEmpty(coalPayStudents)){ throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR,"已有学员完成缴费,请勿删除"); } } int i = coalPayMapper.updateByIds(ids); if (i>0){ return AjaxResult.success(); } return AjaxResult.error(); } //个人查询缴费 @Override public List selectCoalPay(CoalPayStudentReq coalPayStudent) { //查询个人需要缴费 List coalPayStudents = coalPayStudentService.selectbyIdcard(coalPayStudent); List coalPayStudentReps = new ArrayList<>(); for (CoalPayStudent payStudent : coalPayStudents) { //封装学生基础信息 CoalPayStudentRep coalPayStudentRep = new CoalPayStudentRep(); coalPayStudentRep.setName(payStudent.getName()); coalPayStudentRep.setIdCard(payStudent.getIdCard()); coalPayStudentRep.setPhone(payStudent.getPhone()); coalPayStudentRep.setSex(payStudent.getSex()); coalPayStudentRep.setPayStatus(payStudent.getPayStatus()); //查询对应批次以及批次包含工种类别 CoalPay coalPay = coalPayMapper.selectById(payStudent.getCoalPayId()); CoalPayRepDto coalPayRepDto = new CoalPayRepDto(); BeanUtils.copyProperties(coalPay,coalPayRepDto); //考点名称 SysDept sysDept = sysDeptMapper.selectDeptById(coalPay.getDeptId()); coalPayRepDto.setDeptName(sysDept.getDeptName()); //查询批次对应工种类别 List coalCategories = coalCategoryMapper.selectByCoalPayId(payStudent.getCoalPayId()); coalPayRepDto.setCoalCategoryList(coalCategories); coalPayStudentRep.setCoalPays(coalPayRepDto); coalPayStudentReps.add(coalPayStudentRep); } return coalPayStudentReps; } @Override public int updateCoalPayType(CoalPayTypeReq coalPayTypeReq) { CoalPay byId = coalPayMapper.selectById(coalPayTypeReq.getCoalPayId()); if (coalPayTypeReq.getPayPersonType() != null && byId.getPayPersonType() == 2){ throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"已为团体缴费,不可更改"); } return coalPayMapper.updateByPayId(coalPayTypeReq); } }