package com.gkhy.exam.system.service.useSealApply.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.exam.common.api.CommonPage; import com.gkhy.exam.common.api.CommonResult; import com.gkhy.exam.common.exception.ApiException; import com.gkhy.exam.common.utils.PageUtils; import com.gkhy.exam.common.utils.SecurityUtils; import com.gkhy.exam.common.utils.StringUtils; import com.gkhy.exam.system.domain.UseSealApply; import com.gkhy.exam.system.domain.UseSealApplyFile; import com.gkhy.exam.system.domain.UseSealApplyFlow; import com.gkhy.exam.system.mapper.UseSealApplyFileMapper; import com.gkhy.exam.system.mapper.UseSealApplyFlowMapper; import com.gkhy.exam.system.mapper.UseSealApplyMapper; import com.gkhy.exam.system.service.useSealApply.UseSealApplyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.List; @Service public class UseSealApplyServiceImpl extends ServiceImpl implements UseSealApplyService { @Autowired private UseSealApplyMapper useSealApplyMapper; @Autowired private UseSealApplyFlowMapper flowMapper; @Autowired private UseSealApplyFileMapper fileMapper; @Override public CommonPage selectUseSealApplyList(UseSealApply useSealApply) { if (!SecurityUtils.adminUser()){ if (useSealApply.getCompanyId()==null){ throw new ApiException("非管理员操作,企业不可为空"); } } PageUtils.startPage(); List useSealApplies = useSealApplyMapper.selectUseApplyList(useSealApply); for (UseSealApply sealApply : useSealApplies) { List useSealApplyFlows = flowMapper.selectByUseSealId(sealApply.getId()); List useSealApplyFiles = fileMapper.selectByUseSealId(sealApply.getId()); sealApply.setFiles(useSealApplyFiles); sealApply.setFlows(useSealApplyFlows); } return CommonPage.restPage(useSealApplies); } @Override @Transactional public CommonResult insertUseSealApply(UseSealApply useSealApply) { useSealApply.setCreateBy(SecurityUtils.getUsername()); useSealApply.setCreateTime(LocalDateTime.now()); int insert = useSealApplyMapper.insert(useSealApply); if (insert>0){ List flows = useSealApply.getFlows(); for (UseSealApplyFlow flow : flows) { flow.setUseSealId(useSealApply.getId()); if (flow.getApproveUserId().equals(useSealApply.getApplyUserId()) && flow.getFlowName().equals("申请人")){ flow.setStatus(2); }else { flow.setStatus(1); } } flowMapper.insertBatchs(flows); List files = useSealApply.getFiles(); for (UseSealApplyFile file : files) { file.setUseSealId(useSealApply.getId()); } fileMapper.insertBatchs(files); } return CommonResult.success(); } @Override public CommonResult updateUseSealApply(UseSealApply useSealApply) { List useSealApplyFlows = flowMapper.selectByUseSealIdAndApplyUserId(useSealApply.getId(), useSealApply.getApplyUserId()); if (!CollectionUtils.isEmpty(useSealApplyFlows)){ return CommonResult.failed("该申请已审批,请勿修改"); } useSealApply.setUpdateBy(SecurityUtils.getUsername()); useSealApply.setUpdateTime(LocalDateTime.now()); int update = useSealApplyMapper.updateById(useSealApply); if (update>0){ fileMapper.deleteByUseSealId(useSealApply.getId()); List files = useSealApply.getFiles(); for (UseSealApplyFile file : files) { file.setUseSealId(useSealApply.getId()); } fileMapper.insertBatchs(files); } return CommonResult.success(); } @Override public CommonResult deletedUseSealApply(Integer applyId) { if (!SecurityUtils.adminUser()){ List useSealApplyFlows = flowMapper.selectByUseSealIdAndApplyUserId(applyId,null); if (!CollectionUtils.isEmpty(useSealApplyFlows)){ return CommonResult.failed("该申请已审批,请勿删除"); } } UseSealApply useSealApply = new UseSealApply(); useSealApply.setUpdateBy(SecurityUtils.getUsername()); useSealApply.setUpdateTime(LocalDateTime.now()); useSealApply.setDelFlag(2); useSealApply.setId(applyId); useSealApplyMapper.updateById(useSealApply); return CommonResult.success(); } @Override @Transactional public CommonResult approveUseSealApply(UseSealApplyFlow useSealApplyFlow) { if (useSealApplyFlow.getApproveStatus()==null){ return CommonResult.failed("审批意见不可为空"); } if (StringUtils.isEmpty(useSealApplyFlow.getApproveMess())){ return CommonResult.failed("审批意见不可为空"); } if (useSealApplyFlow.getApproveStatus()==1){ useSealApplyFlow.setApproveContent("同意"); }else { useSealApplyFlow.setApproveContent("不同意"); } useSealApplyFlow.setStatus(2); useSealApplyFlow.setApproveTime(LocalDateTime.now()); Integer i = flowMapper.updateByUseSealId(useSealApplyFlow); if (i>0){ UseSealApply useSealApply = new UseSealApply(); UseSealApplyFlow useSealApplyFlow1 = flowMapper.selectByUseId(useSealApplyFlow.getUseSealId()); if (useSealApplyFlow1!=null){ useSealApply.setNextCheck(useSealApplyFlow1.getApproveUserId()); }else { useSealApply.setStatus(2); } useSealApply.setId(useSealApplyFlow.getUseSealId()); useSealApply.setUpdateBy(SecurityUtils.getUsername()); useSealApply.setUpdateTime(LocalDateTime.now()); useSealApplyMapper.updateById(useSealApply); } return CommonResult.success(); } @Override public CommonResult applyList(Integer userId) { List useSealApplies = useSealApplyMapper.selectUseApplyByUserId(userId); for (UseSealApply sealApply : useSealApplies) { List useSealApplyFlows = flowMapper.selectByUseSealId(sealApply.getId()); sealApply.setFlows(useSealApplyFlows); } return CommonResult.success(useSealApplies); } }