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.module.cases.domain.dto.QuiltUnitDTO; 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.sys.constant.FileOwnerTypeBaseEnum; import cn.huge.module.sys.constant.SyTimeEnum; 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.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; /** * 条件更新对象 * @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.getTimeLimit("dyh_case_supervise", SyTimeEnum.SY_TIME_5.getIndex()); List caseSuperviseList = 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.setSupTime(nowDate); caseSuperviseNew.setQuiltUnitId(quiltUnitDTO.getQuiltUnitId()); caseSuperviseNew.setQuiltUnitName(quiltUnitDTO.getQuiltUnitName()); caseSuperviseNew.setSupStatus(0); caseSuperviseNew.setCreateTime(nowDate); caseSuperviseNew.setUpdateTime(nowDate); caseSuperviseNew.setReplyTerm(timeTerm); caseSuperviseList.add(caseSuperviseNew); } this.saveBatch(caseSuperviseList); }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{ // 获取当前登录用户 CtUserDTO loginUser = custClient.clientGetUserAll(userId); Date now = DateUtils.getNowDate(); caseSupervise.setSupStatus(1); caseSupervise.setReplyUserId(loginUser.getId()); caseSupervise.setReplyUserName(loginUser.getTrueName()); caseSupervise.setReplyTime(String.valueOf(now)); caseSupervise.setUpdateTime(now); 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){ try{ CtUserDTO loginUser = custClient.clientGetUserAll(userId); String quiltUnitId = loginUser.getUnitId(); long countSuperviseList = mapper.countCaseSupervise(caseId, supStatus, quiltUnitId); List caseSuperviseList = mapper.pageCaseSupervise(caseId, page, supStatus, quiltUnitId); 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()); 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 supStatus 回复状态 * @param quiltUnitId 被督办组织编号 * @return long */ public long countCaseSuperviseList(Integer supStatus, String quiltUnitId){ return mapper.countCaseSuperviseList(supStatus, quiltUnitId); } }