| | |
| | | import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetMngExcel; |
| | | import com.gkhy.safePlatform.targetDuty.service.TargetDivideDetailService; |
| | | import com.gkhy.safePlatform.targetDuty.service.TargetMngService; |
| | | import com.gkhy.safePlatform.targetDuty.service.baseService.TargetMngBaseService; |
| | | import com.gkhy.safePlatform.targetDuty.utils.DateUtils; |
| | | import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelLogs; |
| | | import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelUtil; |
| | |
| | | @Resource |
| | | private TargetMngService targetMngService; |
| | | @Resource |
| | | private TargetDivideDetailService targetDivideDetailService; |
| | | private TargetMngBaseService targetMngBaseService; |
| | | |
| | | @Autowired |
| | | public HttpServletRequest request; |
| | | |
| | |
| | | */ |
| | | @PostMapping(value = "/page/list") |
| | | public ResultVO selectAll(@RequestBody PageQuery<TargetMngQueryCriteria> pageQuery){ |
| | | if(pageQuery.getSearchParams().getTargetType() == null){ |
| | | return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少targetType"); |
| | | } |
| | | PageUtils.checkCheck(pageQuery); |
| | | |
| | | return this.targetMngService.queryAll(pageQuery); |
| | | } |
| | | |
| | |
| | | return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL,"缺少必填字段"); |
| | | } |
| | | if (targetMng.getId() == null) { |
| | | return new ResultVO<>(ResultCodes.OK,targetMngService.save(targetMng)); |
| | | return new ResultVO<>(ResultCodes.OK,targetMngBaseService.save(targetMng)); |
| | | } else { |
| | | targetMngService.update(targetMng,new UpdateWrapper<TargetMng>().eq("id",targetMng.getId())); |
| | | targetMngBaseService.update(targetMng,new UpdateWrapper<TargetMng>().eq("id",targetMng.getId())); |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @RequestMapping(value = "/delete",method = RequestMethod.POST) |
| | | public ResultVO delete(@RequestBody Long[] ids) { |
| | | if(ids == null){ |
| | | return new ResultVO<>(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.targetDivideDetailService.update(detail,updateWrapper); |
| | | |
| | | List<TargetMng> delList = new ArrayList<>(); |
| | | idList.forEach(f->{ |
| | | TargetMng info = new TargetMng(); |
| | | info.setDelFlag(1); |
| | | info.setId(f); |
| | | delList.add(info); |
| | | }); |
| | | this.targetMngService.updateBatchById(delList); |
| | | this.targetMngService.delete(ids); |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |
| | |
| | | */ |
| | | @GetMapping(value = "/exportTemplate") |
| | | 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(); |
| | | targetMngService.exportTemplate(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping(value = "/exportData") |
| | | 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(targetMngService.queryAll(queryCriteria), TargetMngExcel.class); |
| | | |
| | | ExcelUtil.exportExcel(map,respList , response.getOutputStream(),DateUtils.PATTERN_STANDARD); |
| | | response.getOutputStream().close(); |
| | | targetMngService.exportData(queryCriteria); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RequestMapping(value = "/importData") |
| | | public ResultVO importData(MultipartFile file) throws IOException { |
| | | String contentType = file.getContentType(); |
| | | if(!"application/vnd.ms-excel".equals(contentType) |
| | | && !"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) { |
| | | return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL, "上传的excel格式错误"); |
| | | } |
| | | |
| | | Collection<TargetMngImportExcel> importExcel = ExcelUtil.importExcel(TargetMngImportExcel.class, file.getInputStream(), "yyyy-MM-dd HH:mm:ss", new ExcelLogs() , 0); |
| | | |
| | | if (CollectionUtils.isEmpty(importExcel)) { |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |
| | | List<TargetMng> respList = BeanCopyUtils.copyBeanList((List<TargetMngImportExcel>)importExcel, TargetMng.class); |
| | | |
| | | targetMngService.saveBatch(respList); |
| | | targetMngService.importData(file); |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |