package cn.huge.module.cases.service; import cn.huge.base.common.exception.ServiceException; import cn.huge.base.common.utils.DateUtils; import cn.huge.base.common.utils.IdUtils; import cn.huge.base.common.utils.ObjectUtils; import cn.huge.module.cases.domain.dto.FileRelateDTO; import cn.huge.module.cases.domain.dto.FrontPageListDTO; import cn.huge.module.cases.domain.dto.QuiltUnitDTO; import cn.huge.module.cases.domain.po.CaseInfo; import cn.huge.module.cases.domain.po.CaseInfoUnfold; import cn.huge.module.cases.utils.TaskUsetimeUtils; import cn.huge.module.client.api.impl.CustClientImpl; import cn.huge.module.client.api.impl.SysClientImpl; import cn.huge.module.client.api.impl.UtilsClientImpl; import cn.huge.module.cases.dao.mapper.CaseSuperviseMapper; import cn.huge.module.cases.domain.po.CaseSupervise; import cn.huge.module.cust.dto.CtUserDTO; import cn.huge.module.sy.service.SyHolidayService; import cn.huge.module.sys.constant.FileOwnerTypeBaseEnum; import cn.huge.module.sys.constant.SyTimeEnum; import cn.huge.module.sys.dto.FileIdInfoBaseDTO; import cn.huge.module.sys.dto.FileIdTypeInfoBaseDTO; import cn.huge.module.sys.dto.FileInfoBaseDTO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; import java.util.*; import java.util.stream.Collectors; /** * @title: 纠纷督办信息表业务逻辑处理 * @Description 纠纷督办信息表业务逻辑处理 * @company hugeinfo * @author wangwh * @Time 2024-09-03 10:53:01 * @version 1.0.0 */ @Slf4j @Service @Transactional(rollbackFor = Exception.class) public class CaseSuperviseService extends ServiceImpl{ @Autowired private CaseSuperviseMapper mapper; @Autowired private UtilsClientImpl utilsClient; @Autowired private CustClientImpl custClient; @Autowired private SysClientImpl sysClient; @Autowired private CaseInfoService caseInfoService; @Autowired private SyHolidayService syHolidayService; /** * 条件更新对象 * @param entity 对象 * @param terms 条件 */ public void updateCaseSuperviseTerms(CaseSupervise entity, Map terms){ try{ mapper.updateCaseSuperviseTerms(entity, terms); }catch (Exception e){ log.error("[CaseSuperviseService.updateCaseSuperviseTerms]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.updateCaseSuperviseTerms", e); } } /** * 根据编号物理删除 * @param id 查询条件集合 */ public void deleteCaseSupervise(String id){ try{ mapper.deleteCaseSupervise(id); }catch (Exception e){ log.error("[CaseSuperviseService.deleteCaseSupervise]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.deleteCaseSupervise", e); } } /** * 按条件查询 * @param terms 条件 * @return List */ public List listTerms(Map terms){ return mapper.listTerms(terms); } /** * 按条件统计 * @param terms 条件 * @return long */ public long countTerms(Map terms){ return mapper.countTerms(terms); } /** * 按条件分页查询 * @param page 分页对象 * @param terms 条件 * @return Page */ public Page pageQuery(PageRequest page, Map terms){ long total = mapper.countTerms(terms); List content = mapper.pageTerms(page, terms); return new PageImpl(content, page, total); } /** * 新增或更新对象 * @param caseSupervise 实体对象 */ public void saveCaseSupervise(CaseSupervise caseSupervise){ try{ Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(caseSupervise.getId())){ caseSupervise.setId(utilsClient.getNewTimeId()); caseSupervise.setCreateTime(nowDate); } caseSupervise.setUpdateTime(nowDate); this.saveOrUpdate(caseSupervise); }catch (Exception e){ log.error("[CaseSuperviseService.saveCaseSupervise]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.saveCaseSupervise", e); } } /** * 添加督办 * @param caseSupervise 实体对象 */ public void addCaseSupervise(CaseSupervise caseSupervise, String userId){ try{ List quiltUnitDTOList = caseSupervise.getQuiltUnitDTOList(); Integer timeTerm = sysClient.getTimeLimitHour(SyTimeEnum.SY_TIME_5.getIndex()); List caseSuperviseList = new ArrayList<>(); List fileRelateDTOList = sysClient.listFileRelateByOwnerId(caseSupervise.getId()); int count = 0; List fileRelateDTOListNew = new ArrayList<>(); for(QuiltUnitDTO quiltUnitDTO: quiltUnitDTOList){ CaseSupervise caseSuperviseNew = new CaseSupervise(); BeanUtils.copyProperties(caseSupervise, caseSuperviseNew); // 获取当前登录用户 CtUserDTO loginUser = custClient.clientGetUserAll(userId); Date nowDate = DateUtils.getNowDate(); caseSuperviseNew.setSupUserId(loginUser.getId()); caseSuperviseNew.setSupUserName(loginUser.getTrueName()); caseSuperviseNew.setSupUnitId(loginUser.getUnitId()); caseSuperviseNew.setSupUnitName(loginUser.getUnitName()); caseSuperviseNew.setSupTime(nowDate); caseSuperviseNew.setQuiltUnitId(quiltUnitDTO.getQuiltUnitId()); caseSuperviseNew.setQuiltUnitName(quiltUnitDTO.getQuiltUnitName()); caseSuperviseNew.setSupStatus(0); caseSuperviseNew.setCreateTime(nowDate); caseSuperviseNew.setUpdateTime(nowDate); caseSuperviseNew.setReplyTerm(timeTerm); //给每条督办添加附件信息 if(0 != count){ String caseSupId = utilsClient.getNewTimeId(); caseSuperviseNew.setId(caseSupId); for(FileRelateDTO fileRelateDTO: fileRelateDTOList){ String fileRealateId = utilsClient.getNewTimeSysId(); FileRelateDTO fileRelateDTONew = new FileRelateDTO(); BeanUtils.copyProperties(fileRelateDTO, fileRelateDTONew); fileRelateDTONew.setOwnerId(caseSuperviseNew.getId()); fileRelateDTONew.setId(fileRealateId); fileRelateDTOListNew.add(fileRelateDTONew); } } caseSuperviseList.add(caseSuperviseNew); count++; } this.saveBatch(caseSuperviseList); if(CollectionUtils.isNotEmpty(fileRelateDTOListNew)){ sysClient.saveFileRelateList(fileRelateDTOListNew); } }catch (Exception e){ log.error("[CaseSuperviseService.saveCaseSupervise]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.saveCaseSupervise", e); } } /** * 批量添加督办 * @param caseSuperviseList */ public void addBatchCaseSupervise(List caseSuperviseList, String userId){ try{ List caseSuperviseListNew = new ArrayList<>(); List fileRelateDTOListNew = new ArrayList<>(); //查询附件 List fileRelateDTOList = sysClient.listFileRelateByOwnerId(caseSuperviseList.get(0).getId()); // 获取当前登录用户 CtUserDTO loginUser = custClient.clientGetUserAll(userId); //查询任务时限 Integer timeTerm = sysClient.getTimeLimitHour(SyTimeEnum.SY_TIME_5.getIndex()); for(CaseSupervise caseSupervise: caseSuperviseList){ List quiltUnitDTOList = caseSupervise.getQuiltUnitDTOList(); int count = 0; for(QuiltUnitDTO quiltUnitDTO: quiltUnitDTOList){ CaseSupervise caseSuperviseNew = new CaseSupervise(); BeanUtils.copyProperties(caseSupervise, caseSuperviseNew); Date nowDate = DateUtils.getNowDate(); caseSuperviseNew.setSupUserId(loginUser.getId()); caseSuperviseNew.setSupUserName(loginUser.getTrueName()); caseSuperviseNew.setSupUnitId(loginUser.getUnitId()); caseSuperviseNew.setSupUnitName(loginUser.getUnitName()); caseSuperviseNew.setSupTime(nowDate); caseSuperviseNew.setQuiltUnitId(quiltUnitDTO.getQuiltUnitId()); caseSuperviseNew.setQuiltUnitName(quiltUnitDTO.getQuiltUnitName()); caseSuperviseNew.setSupStatus(0); caseSuperviseNew.setCreateTime(nowDate); caseSuperviseNew.setUpdateTime(nowDate); caseSuperviseNew.setReplyTerm(timeTerm); //给每条督办添加附件信息 if(0 != count){ String caseSupId = utilsClient.getNewTimeId(); caseSuperviseNew.setId(caseSupId); for(FileRelateDTO fileRelateDTO: fileRelateDTOList){ String fileRealateId = utilsClient.getNewTimeSysId(); FileRelateDTO fileRelateDTONew = new FileRelateDTO(); BeanUtils.copyProperties(fileRelateDTO, fileRelateDTONew); fileRelateDTONew.setOwnerId(caseSuperviseNew.getId()); fileRelateDTONew.setId(fileRealateId); fileRelateDTOListNew.add(fileRelateDTONew); } } caseSuperviseListNew.add(caseSuperviseNew); count++; } } this.saveBatch(caseSuperviseListNew); if(CollectionUtils.isNotEmpty(fileRelateDTOListNew)){ sysClient.saveFileRelateList(fileRelateDTOListNew); } }catch (Exception e){ log.error("[CaseSuperviseService.saveCaseSupervise]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.saveCaseSupervise", e); } } /** * 回复督办 * @param caseSupervise 对象 */ public void replyCaseSupervise(CaseSupervise caseSupervise, String userId){ try{ CaseSupervise caseSupervisePO = mapper.selectById(caseSupervise.getId()); // 获取当前登录用户 CtUserDTO loginUser = custClient.clientGetUserAll(userId); Date now = DateUtils.getNowDate(); caseSupervise.setSupStatus(1); caseSupervise.setReplyUserId(loginUser.getId()); caseSupervise.setReplyUserName(loginUser.getTrueName()); caseSupervise.setReplyTime(now); caseSupervise.setUpdateTime(now); caseSupervise.setUsetimeHour(TaskUsetimeUtils.getUsetimeHour(caseSupervise.getReplyTime(), caseSupervisePO.getSupTime())); caseSupervise.setOvertimeStatus(TaskUsetimeUtils.getOvertimeStatus(caseSupervise.getReplyTime(), syHolidayService.getExpiryHour(caseSupervisePO.getSupTime(), caseSupervisePO.getReplyTerm()))); caseSupervise.setOvertimeHour(TaskUsetimeUtils.getOvertimeHour(caseSupervise.getReplyTime(), syHolidayService.getExpiryHour(caseSupervisePO.getSupTime(), caseSupervisePO.getReplyTerm()))); mapper.updateCaseSupervise(caseSupervise); }catch (Exception e){ log.error("[CaseSuperviseService.replyCaseSupervise]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.replyCaseSupervise", e); } } /** * 流转办理-督办列表 * @param caseId 事项Id */ public Page pageCaseSupervise(String caseId, PageRequest page, int supStatus, String userId, int type){ try{ CtUserDTO loginUser = custClient.clientGetUserAll(userId); String quiltUnitId = loginUser.getUnitId(); Map terms = new HashMap<>(); terms.put("caseId", caseId); terms.put("type", type); if(1 == type){ terms.put("supStatus", supStatus); terms.put("quiltUnitId", quiltUnitId); }else if(2 == type){ terms.put("supStatus", supStatus); } long countSuperviseList = mapper.countCaseSupervise(terms); List caseSuperviseList = mapper.pageCaseSupervise(terms, page); CaseInfo caseInfo = new CaseInfo(); if(CollectionUtils.isNotEmpty(caseSuperviseList)){ if(1 != type){ QueryWrappercaseInfoQueryWrapper = new QueryWrapper<>(); caseInfoQueryWrapper.eq("id", caseId); caseInfo = caseInfoService.getOne(caseInfoQueryWrapper); for(CaseSupervise caseSupervise: caseSuperviseList){ if(ObjectUtils.isNotEmpty(caseSupervise.getSupTime()) && ObjectUtils.isNotEmpty(caseSupervise.getReplyTerm())){ caseSupervise.setTimeLimit(syHolidayService.getExpiryHour(caseSupervise.getSupTime(), caseSupervise.getReplyTerm())); } if(ObjectUtils.isNotEmpty(caseInfo)){ caseSupervise.setCaseGrade(caseInfo.getCaseLevel()); } } }else{ Mapmap = new HashMap<>(); map.put("mainId", caseId); map.put("ownerIds", "'" + caseSuperviseList.stream().map(CaseSupervise::getId).collect(Collectors.joining("','"))+ "'"); map.put("types", "'"+ FileOwnerTypeBaseEnum.OWNER_TYPE_506.getIndex()+ "','" +FileOwnerTypeBaseEnum.OWNER_TYPE_507.getIndex()+"'"); List fileIdTypeInfoBaseDTOList = sysClient.listIdTypeInfoByOwnerIdList(map); for(CaseSupervise caseSupervise: caseSuperviseList){ for(FileIdTypeInfoBaseDTO fileIdTypeInfoBaseDTO: fileIdTypeInfoBaseDTOList){ if(caseSupervise.getId().equals(fileIdTypeInfoBaseDTO.getOwnerId())){ caseSupervise.setFileInfoList(fileIdTypeInfoBaseDTO.getFileList()); } } } } } return new PageImpl(caseSuperviseList, page, countSuperviseList); }catch (Exception e){ log.error("[CaseSuperviseService.pageReplied]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.pageReplied", e); } } /** * 首页-督办 * @param page * @param terms */ public Page pageMyTaskDb(PageRequest page, Map terms){ try{ long countSuperviseList = mapper.countMyTaskDb(terms); List caseSuperviseList = mapper.pageMyTaskDb(page, terms); return new PageImpl(caseSuperviseList, page, countSuperviseList); }catch (Exception e){ log.error("[CaseSuperviseService.pageReplied]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.pageReplied", e); } } /** * 查询督办数量 * @param supStatus 回复状态 * @param quiltUnitId 被督办组织编号 * @return long */ public long countCaseSuperviseList(Integer supStatus, String quiltUnitId){ return mapper.countCaseSuperviseList(supStatus, quiltUnitId); } /** * 根据督办编号查询督办信息 * @param id 督办编号 * @return List */ public CaseSupervise getById(String id){ try { CaseSupervise caseSupervise = mapper.selectById(id); Map terms = new HashMap<>(); terms.put("mainId", caseSupervise.getCaseId()); terms.put("ownerIds", "'" + id + "'"); List fileIdTypeInfoBaseDTOList = sysClient.listIdTypeInfoByOwnerIdList(terms); if(CollectionUtils.isNotEmpty(fileIdTypeInfoBaseDTOList)){ caseSupervise.setFileInfoList(fileIdTypeInfoBaseDTOList.get(0).getFileList()); } return caseSupervise; }catch (Exception e){ log.error("[CaseSuperviseService.getById]调用失败,异常信息:"+e, e); throw new ServiceException("CaseSuperviseService.getById", e); } } }