| | |
| | | package com.gkhy.safePlatform.targetDuty.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.safePlatform.commons.enums.ResultCodes; |
| | | import com.gkhy.safePlatform.commons.query.PageQuery; |
| | | import com.gkhy.safePlatform.commons.utils.BeanCopyUtils; |
| | | import com.gkhy.safePlatform.commons.utils.PageUtils; |
| | | import com.gkhy.safePlatform.commons.vo.ResultVO; |
| | | import com.gkhy.safePlatform.commons.vo.SearchResultVO; |
| | | import com.gkhy.safePlatform.targetDuty.entity.*; |
| | | import com.gkhy.safePlatform.targetDuty.excepiton.TargetDutyException; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetCheckAndSubmitQueryCriteria; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetDivideDetailQueryCriteria; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetMngImportExcel; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetMngQueryCriteria; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetCheckAndSubmitDto; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetDivideDetailDto; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetMngDto; |
| | | import com.gkhy.safePlatform.targetDuty.repository.*; |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetMngExcel; |
| | | import com.gkhy.safePlatform.targetDuty.service.CommonService; |
| | | import com.gkhy.safePlatform.targetDuty.service.TargetDivideDetailService; |
| | | import com.gkhy.safePlatform.targetDuty.service.TargetMngService; |
| | | import com.gkhy.safePlatform.targetDuty.service.baseService.*; |
| | | import com.gkhy.safePlatform.targetDuty.utils.DateUtils; |
| | | import com.gkhy.safePlatform.targetDuty.utils.QueryHelpPlus; |
| | | import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelLogs; |
| | | import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.Serializable; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | |
| | | * @since 2022-07-20 11:49:22 |
| | | */ |
| | | @Service("targetMngService") |
| | | public class TargetMngServiceImpl extends ServiceImpl<TargetMngRepository, TargetMng> implements TargetMngService { |
| | | public class TargetMngServiceImpl implements TargetMngService { |
| | | |
| | | @Autowired |
| | | private TargetMngRepository targetMngRepository; |
| | | private TargetMngBaseService targetMngBaseService; |
| | | |
| | | @Resource |
| | | private TargetDivideDetailService targetDivideDetailService; |
| | | |
| | | @Autowired |
| | | private TargetDivideDetailRepository targetDivideDetailRepository; |
| | | private TargetDivideDetailBaseService targetDivideDetailBaseService; |
| | | |
| | | @Resource |
| | | private TargetDutyWorkApproveRepository targetDutyWorkApproveRepository; |
| | | private TargetDutyWorkApproveBaseService targetDutyWorkApproveBaseService; |
| | | |
| | | @Resource |
| | | private CommonService commonService; |
| | | |
| | | @Autowired |
| | | private TargetTypeRepository targetTypeRepository; |
| | | private TargetTypeBaseService targetTypeBaseService; |
| | | |
| | | @Autowired |
| | | private TargetExamineRepository targetExamineRepository; |
| | | private TargetExamineBaseService targetExamineBaseService; |
| | | |
| | | @Autowired |
| | | public HttpServletResponse response; |
| | | |
| | | |
| | | @Override |
| | | public ResultVO queryAll(PageQuery<TargetMngQueryCriteria> pageQuery) { |
| | | if(pageQuery.getSearchParams().getTargetType() == null){ |
| | | return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少targetType"); |
| | | } |
| | | PageUtils.checkCheck(pageQuery); |
| | | Long pageIndex = pageQuery.getPageIndex(); |
| | | Long pageSize = pageQuery.getPageSize(); |
| | | IPage<TargetMng> page = new Page<>(pageIndex, pageSize); |
| | | |
| | | page = baseMapper.selectPage(page, |
| | | page = targetMngBaseService.selectPage(page, |
| | | QueryHelpPlus.getPredicate(TargetMng.class, pageQuery.getSearchParams())); |
| | | List<TargetMngDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), TargetMngDto.class); |
| | | respList.forEach(dto -> { |
| | | respList.forEach(dto->{ |
| | | // --------------------------- 获取部门信息----------------------- |
| | | dto.setMakerDepartmentName(commonService.getDepName(dto.getMakerDepartmentId())); |
| | | |
| | | //查询关联分解信息 |
| | | TargetDivideDetailQueryCriteria criteria = new TargetDivideDetailQueryCriteria(); |
| | | criteria.setTargetId(dto.getId()); |
| | | List<TargetDivideDetailDto> respList1 = BeanCopyUtils.copyBeanList(targetDivideDetailService.queryAll(criteria), TargetDivideDetailDto.class); |
| | | List<TargetDivideDetailDto> respList1 = BeanCopyUtils.copyBeanList(targetDivideDetailBaseService.queryAll(criteria), TargetDivideDetailDto.class); |
| | | |
| | | // --------------------------- 获取部门信息----------------------- |
| | | //收集所用到的部门ID |
| | | Set<Long> collectDepIdSet = new HashSet(); |
| | | respList1.forEach(f -> { |
| | | respList1.forEach(f->{ |
| | | collectDepIdSet.add(f.getDutyDepartmentId()); |
| | | collectDepIdSet.add(f.getMakerDepartmentId()); |
| | | }); |
| | | //获取部门名集合 |
| | | Map<Long, String> depNameMap = commonService.getDepName(collectDepIdSet); |
| | | |
| | | respList1.forEach(f -> { |
| | | respList1.forEach(f->{ |
| | | f.setDutyDepartmentName(depNameMap.get(f.getDutyDepartmentId())); |
| | | f.setMakerDepartmentName(depNameMap.get(f.getMakerDepartmentId())); |
| | | }); |
| | |
| | | // --------------------------- 获取目标分类名称----------------------- |
| | | //收集所用到的目标分类ID |
| | | Set<Long> collectTypeSet = new HashSet(); |
| | | respList1.forEach(f -> { |
| | | respList1.forEach(f->{ |
| | | collectTypeSet.add(f.getTargetTypeId()); |
| | | }); |
| | | //获取目标分类名集合 |
| | | if (!collectTypeSet.isEmpty()) { |
| | | List<TargetType> typeList = targetTypeRepository.selectBatchIds(collectTypeSet); // TODO |
| | | if(!collectTypeSet.isEmpty()){ |
| | | List<TargetType> typeList = targetTypeBaseService.selectBatchIds(collectTypeSet); |
| | | Map<Long, String> typeNameMap = typeList.stream() |
| | | .collect(Collectors.toMap(TargetType::getId, TargetType::getTypeName, (k1, k2) -> k1)); |
| | | .collect(Collectors.toMap(TargetType::getId, TargetType::getTypeName,(k1, k2)->k1)); |
| | | |
| | | respList1.forEach(f -> { |
| | | respList1.forEach(f->{ |
| | | f.setTargetTypeName(typeNameMap.get(f.getDutyDepartmentId())); |
| | | }); |
| | | } |
| | |
| | | return new SearchResultVO<>( |
| | | true, |
| | | pageIndex, |
| | | pageSize, page.getPages(), |
| | | pageSize,page.getPages(), |
| | | page.getTotal(), |
| | | respList, |
| | | ResultCodes.OK |
| | |
| | | |
| | | @Override |
| | | public List<TargetMng> queryAll(TargetMngQueryCriteria criteria) { |
| | | return baseMapper.selectList(QueryHelpPlus.getPredicate(TargetMng.class, criteria)); |
| | | return targetMngBaseService.queryAll( criteria); |
| | | } |
| | | |
| | | @Override |
| | | public Object selectOne(Serializable id) { |
| | | TargetMng targetMng = baseMapper.selectById(id); |
| | | if (targetMng == null) { |
| | | TargetMng targetMng = targetMngBaseService.getById(id); |
| | | if(targetMng == null){ |
| | | return null; |
| | | } |
| | | TargetMngDto targetMngDto = BeanCopyUtils.copyBean(targetMng, TargetMngDto.class); |
| | |
| | | //查询关联分解信息 |
| | | TargetDivideDetailQueryCriteria criteria = new TargetDivideDetailQueryCriteria(); |
| | | criteria.setTargetId(targetMng.getId()); |
| | | List<TargetDivideDetailDto> respList = BeanCopyUtils.copyBeanList(targetDivideDetailService.queryAll(criteria), TargetDivideDetailDto.class); |
| | | List<TargetDivideDetailDto> respList = BeanCopyUtils.copyBeanList(targetDivideDetailBaseService.queryAll(criteria), TargetDivideDetailDto.class); |
| | | |
| | | // --------------------------- 获取部门信息----------------------- |
| | | //收集所用到的部门ID |
| | | Set<Long> collectDepIdSet = new HashSet(); |
| | | respList.forEach(f -> { |
| | | respList.forEach(f->{ |
| | | collectDepIdSet.add(f.getDutyDepartmentId()); |
| | | collectDepIdSet.add(f.getMakerDepartmentId()); |
| | | }); |
| | | //获取部门名集合 |
| | | Map<Long, String> depNameMap = commonService.getDepName(collectDepIdSet); |
| | | |
| | | respList.forEach(f -> { |
| | | respList.forEach(f->{ |
| | | f.setDutyDepartmentName(depNameMap.get(f.getDutyDepartmentId())); |
| | | f.setMakerDepartmentName(depNameMap.get(f.getMakerDepartmentId())); |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | // --------------------------- 获取考核结果----------------------- |
| | | //收集所用到的分解详情ID |
| | | Set<Long> collectExamResultSet = new HashSet(); |
| | | respList.forEach(f -> { |
| | | respList.forEach(f->{ |
| | | collectExamResultSet.add(f.getId()); |
| | | }); |
| | | //获取核结果集合 |
| | | if (!collectExamResultSet.isEmpty()) { |
| | | List<TargetExamine> typeList = targetExamineRepository.selectList(new QueryWrapper<TargetExamine>().in("target_divide_detail_id", collectExamResultSet)); |
| | | if(!collectExamResultSet.isEmpty()){ |
| | | List<TargetExamine> typeList = targetExamineBaseService.selectList(new QueryWrapper<TargetExamine>().in("target_divide_detail_id",collectExamResultSet)); |
| | | Map<Long, TargetExamine> examResultMap = typeList.stream() |
| | | .collect(Collectors.toMap(TargetExamine::getTargetDivideDetailId, Function.identity(), (k1, k2) -> k1)); |
| | | .collect(Collectors.toMap(TargetExamine::getTargetDivideDetailId, Function.identity(),(k1, k2)->k1)); |
| | | |
| | | respList.forEach(f -> { |
| | | respList.forEach(f->{ |
| | | TargetExamine targetExamine = examResultMap.get(f.getId()); |
| | | if (targetExamine != null) { |
| | | if(targetExamine != null){ |
| | | f.setExamineResult(targetExamine.getExamineResult()); |
| | | f.setExamineDate(targetExamine.getExamineDate()); |
| | | f.setExaminePersonId(targetExamine.getExaminePersonId()); |
| | |
| | | public ResultVO queryAll(Long uid, PageQuery<TargetCheckAndSubmitQueryCriteria> pageQuery) { |
| | | Long pageIndex = pageQuery.getPageIndex(); |
| | | Long pageSize = pageQuery.getPageSize(); |
| | | Page<TargetMng> page = new Page<>(pageIndex, pageSize); |
| | | IPage<TargetMng> page = new Page<>(pageIndex, pageSize); |
| | | |
| | | page = baseMapper.selectPage(page, |
| | | page = targetMngBaseService.selectPage(page, |
| | | QueryHelpPlus.getPredicate(TargetMng.class, pageQuery.getSearchParams())); |
| | | List<TargetCheckAndSubmitDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), TargetCheckAndSubmitDto.class); |
| | | |
| | | // 判断审批人 |
| | | respList.forEach(dto -> { |
| | | List<TargetDutyWorkApprove> list = targetDutyWorkApproveRepository.selectList( |
| | | new QueryWrapper<TargetDutyWorkApprove>().eq("del_flag", 0) |
| | | .eq("relate_type", pageQuery.getSearchParams().getRelateType()) |
| | | .eq("relate_id", dto.getId()) |
| | | respList.forEach(dto->{ |
| | | List<TargetDutyWorkApprove> list = targetDutyWorkApproveBaseService.selectList( |
| | | new QueryWrapper<TargetDutyWorkApprove>().eq("del_flag",0) |
| | | .eq("relate_type",pageQuery.getSearchParams().getRelateType()) |
| | | .eq("relate_id",dto.getId()) |
| | | .orderByDesc("sort")); |
| | | |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | |
| | | dto.setApproveStatus(list.get(0).getApproveStatus()); |
| | | dto.setApprovePersonId(list.get(0).getApprovePersonId()); |
| | | // 审批中 判断审批人是否人与当前登录人 |
| | | if (dto.getApproveStatus() != null && dto.getApproveStatus() == 2) { |
| | | if (dto.getApproveStatus()!=null && dto.getApproveStatus()==2){ |
| | | dto.setCheckApprove(dto.getApprovePersonId().equals(uid)); |
| | | } |
| | | } |
| | |
| | | return new SearchResultVO<>( |
| | | true, |
| | | pageIndex, |
| | | pageSize, page.getPages(), |
| | | pageSize,page.getPages(), |
| | | page.getTotal(), |
| | | respList, |
| | | ResultCodes.OK |
| | |
| | | // 查询总数 |
| | | Integer total = 0; |
| | | // 完成数量 |
| | | Integer complete = 0; |
| | | Integer complete=0; |
| | | |
| | | // 查询目标已分解且事件类型对一个的目标 |
| | | List<TargetMng> targetMngList = targetMngRepository.selectList( |
| | | List<TargetMng> targetMngList = targetMngBaseService.selectList( |
| | | new QueryWrapper<TargetMng>() |
| | | .eq("del_flag", 0) |
| | | .eq("target_type", criteria.getTargetType()) |
| | | .eq("divide_status", 1) |
| | | .eq("target_type",criteria.getTargetType()) |
| | | .eq("divide_status",1) |
| | | ); |
| | | if (!targetMngList.isEmpty()) { |
| | | if (!targetMngList.isEmpty()){ |
| | | total = targetMngList.size(); |
| | | // 查询目标下的所有分解项 |
| | | for (TargetMng targetMng : targetMngList) { |
| | | for (TargetMng targetMng : targetMngList){ |
| | | Boolean completeFlag = true; |
| | | List<TargetDivideDetail> targetDivideDetailList = targetDivideDetailRepository.selectList( |
| | | List<TargetDivideDetail> targetDivideDetailList = targetDivideDetailBaseService.selectList( |
| | | new QueryWrapper<TargetDivideDetail>() |
| | | .eq("del_flag", 0) |
| | | .eq("target_id", targetMng.getId()) |
| | | .eq("target_id",targetMng.getId()) |
| | | ); |
| | | if (!targetDivideDetailList.isEmpty()) { |
| | | if (!targetDivideDetailList.isEmpty()){ |
| | | // 查询分解项 是否已经审核通过 |
| | | for (TargetDivideDetail targetDivideDetail : targetDivideDetailList) { |
| | | List<TargetExamine> targetExamineList = targetExamineRepository.selectList( |
| | | for (TargetDivideDetail targetDivideDetail :targetDivideDetailList){ |
| | | List<TargetExamine> targetExamineList = targetExamineBaseService.selectList( |
| | | new QueryWrapper<TargetExamine>() |
| | | .eq("del_flag", 0) |
| | | .eq("target_divide_detail_id", targetDivideDetail.getId()) |
| | | .eq("examine_result", 1) |
| | | .eq("target_divide_detail_id",targetDivideDetail.getId()) |
| | | .eq("examine_result",1) |
| | | ); |
| | | if (targetExamineList.isEmpty()) { |
| | | completeFlag = false; |
| | | if (targetExamineList.isEmpty()){ |
| | | completeFlag=false; |
| | | } |
| | | } |
| | | } |
| | | // 该目标中有未评价的或者不合格的 |
| | | if (completeFlag) { |
| | | if (completeFlag){ |
| | | complete++; |
| | | } |
| | | } |
| | | } |
| | | //未完成数 |
| | | int noComplete = total - complete; |
| | | map.put("total", total + ""); |
| | | map.put("noComplete", noComplete + ""); |
| | | map.put("complete", complete + ""); |
| | | int noComplete = total-complete; |
| | | map.put("total",total+""); |
| | | map.put("noComplete",noComplete+""); |
| | | map.put("complete",complete+""); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public void delete(Long[] ids) { |
| | | if(ids == null){ |
| | | throw new TargetDutyException(ResultCodes.CLIENT_PARAM_ILLEGAL); |
| | | } |
| | | List<Long> idList = Arrays.asList(ids); |
| | | |
| | | //删除关联表数据 |
| | | UpdateWrapper<TargetDivideDetail> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("target_id",idList); |
| | | TargetDivideDetail detail = new TargetDivideDetail(); |
| | | detail.setDelFlag(1); |
| | | this.targetDivideDetailBaseService.update(detail,updateWrapper); |
| | | |
| | | List<TargetMng> delList = new ArrayList<>(); |
| | | idList.forEach(f->{ |
| | | TargetMng info = new TargetMng(); |
| | | info.setDelFlag(1); |
| | | info.setId(f); |
| | | delList.add(info); |
| | | }); |
| | | targetMngBaseService.updateBatchById(delList); |
| | | } |
| | | |
| | | @Override |
| | | public void importData(MultipartFile file) throws IOException { |
| | | String contentType = file.getContentType(); |
| | | if(!"application/vnd.ms-excel".equals(contentType) |
| | | && !"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) { |
| | | throw new TargetDutyException("上传的excel格式错误"); |
| | | } |
| | | |
| | | Collection<TargetMngImportExcel> importExcel = ExcelUtil.importExcel(TargetMngImportExcel.class, file.getInputStream(), "yyyy-MM-dd HH:mm:ss", new ExcelLogs() , 0); |
| | | |
| | | if (CollectionUtils.isEmpty(importExcel)) { |
| | | return; |
| | | } |
| | | |
| | | List<TargetMng> respList = BeanCopyUtils.copyBeanList((List<TargetMngImportExcel>)importExcel, TargetMng.class); |
| | | |
| | | targetMngBaseService.saveBatch(respList); |
| | | } |
| | | |
| | | @Override |
| | | public void exportTemplate() throws IOException { |
| | | Map<String,String> map = new LinkedHashMap<>(); |
| | | map.put("1","安全目标指标"); |
| | | map.put("2","目标指标编号"); |
| | | map.put("3","指标类型 1:年指标 2:月指标 3:半年 4:季度"); |
| | | map.put("4","年度"); |
| | | map.put("5","指标值"); |
| | | map.put("6","指标级别 1:公司级 2:部门分厂级 3:工段班组级"); |
| | | map.put("7","完成期限(yyyy-MM-dd HH:mm:ss)"); |
| | | map.put("8","备注信息"); |
| | | |
| | | String fileName = URLEncoder.encode("目标设置数据导入模板.xls", "UTF-8"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | |
| | | ExcelUtil.exportExcel(map,new ArrayList<>() , response.getOutputStream()); |
| | | response.getOutputStream().close(); |
| | | } |
| | | |
| | | @Override |
| | | public void exportData(TargetMngQueryCriteria queryCriteria) throws IOException { |
| | | Map<String,String> map = new LinkedHashMap<>(); |
| | | map.put("1","安全目标指标"); |
| | | map.put("2","目标指标编号"); |
| | | map.put("3","年度"); |
| | | map.put("4","指标值"); |
| | | map.put("5","指标级别"); |
| | | map.put("6","指标类型"); |
| | | map.put("7","完成期限"); |
| | | map.put("8","状态"); |
| | | map.put("9","备注信息"); |
| | | |
| | | String key = DateUtils.date2String(new Date(), DateUtils.PATTERN_ALLTIME_NOSIGN) ; |
| | | String fileName = URLEncoder.encode("目标设置"+key+".xls", "UTF-8"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | |
| | | |
| | | List<TargetMngExcel> respList = BeanCopyUtils.copyBeanList(this.queryAll(queryCriteria), TargetMngExcel.class); |
| | | |
| | | ExcelUtil.exportExcel(map,respList , response.getOutputStream(),DateUtils.PATTERN_STANDARD); |
| | | response.getOutputStream().close(); |
| | | } |
| | | |
| | | |
| | | } |