| | |
| | | package com.gkhy.labRiskManage.domain.basic.service.impl; |
| | | |
| | | import com.gkhy.labRiskManage.api.controller.basic.dto.repDto.OldRiskAssessQueryReqBO; |
| | | import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessExportRespDTO; |
| | | import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessQueryRespDTO; |
| | | import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessResDTO; |
| | | import com.gkhy.labRiskManage.commons.domain.Result; |
| | | import com.gkhy.labRiskManage.commons.domain.SearchResult; |
| | | import com.gkhy.labRiskManage.commons.enums.ResultCode; |
| | | import com.gkhy.labRiskManage.commons.enums.StatusEnum; |
| | |
| | | import com.gkhy.labRiskManage.domain.basic.repository.jpa.OldRiskAssessRepository; |
| | | import com.gkhy.labRiskManage.domain.basic.service.OldRiskAssessService; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.PageRequest; |
| | |
| | | import javax.persistence.criteria.CriteriaQuery; |
| | | import javax.persistence.criteria.Predicate; |
| | | import javax.persistence.criteria.Root; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.text.NumberFormat; |
| | | import java.time.LocalDateTime; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int exportOldRiskAssess(Long currentUserId, OldRiskAssessQueryReqBO queryReqDO) { |
| | | public Result<OldRiskAssessExportRespDTO> exportOldRiskAssess(Long currentUserId, OldRiskAssessQueryReqBO queryReqDO , HttpServletResponse response, HttpServletRequest request) { |
| | | |
| | | //组装查询条件 |
| | | Specification<OldRiskAssess> specification = new Specification<OldRiskAssess>() { |
| | |
| | | } |
| | | }; |
| | | List<OldRiskAssess> list = repository.findAll(specification); |
| | | Result result = new Result<>(); |
| | | |
| | | //创建工作薄 |
| | | HSSFWorkbook workbook = new HSSFWorkbook(); |
| | |
| | | cell.setCellValue(oldRiskAssess.getControlLevel()); |
| | | } |
| | | |
| | | // 保存Excel文件 |
| | | try{ |
| | | // 获取桌面路径 |
| | | String desktopPath = System.getProperty("user.home") + "/Desktop/"; |
| | | // 导出文件名 |
| | | String fileName = desktopPath + "评分标准.xlsx"; |
| | | FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName)); |
| | | // 将工作簿写入文件 |
| | | workbook.write(fileOutputStream); |
| | | workbook.close(); |
| | | fileOutputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally{ |
| | | if (workbook != null){ |
| | | try { |
| | | workbook.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // // 保存Excel文件 |
| | | // try{ |
| | | // ServletOutputStream out = null; |
| | | // response.setContentType("application/json"); |
| | | // response.setCharacterEncoding("utf-8"); |
| | | // response.setContentType("application/octet-stream;charset=UTF-8"); |
| | | // String fileName = "测试测试.xls"; |
| | | // |
| | | // String agent = request.getHeader("USER-AGENT").toLowerCase(); |
| | | // String uncodeFileNameString = ""; |
| | | // if(agent.contains("firefox")){ |
| | | // // 火狐 |
| | | // uncodeFileNameString = "=?UTF-8?B?" + (new String(Base64Utils.encodeToString(fileName.getBytes("UTF-8")))) + "?="; |
| | | // }else{ |
| | | // // 其他 |
| | | // uncodeFileNameString = URLEncoder.encode(fileName, "UTF-8"); |
| | | // uncodeFileNameString = uncodeFileNameString.replace("+", "%20"); // 空格被转为了 "+" ,要转成utf-8的空格符号 "%20" |
| | | // } |
| | | // response.setContentType("application/octet-stream;charset=UTF-8"); |
| | | // response.setHeader("Content-disposition", "attachment; filename=" + uncodeFileNameString); |
| | | // out = response.getOutputStream(); |
| | | // |
| | | // |
| | | //// // 获取桌面路径 |
| | | //// String desktopPath = System.getProperty("user.home") + "/Desktop/"; |
| | | //// // 导出文件名 |
| | | //// String fileName = desktopPath + "评分标准.xlsx"; |
| | | //// FileOutputStream fileOutputStream = new FileOutputStream(new File(fileName)); |
| | | // // 将工作簿写入文件 |
| | | // workbook.write(out); |
| | | // workbook.close(); |
| | | // out.close(); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | result.setData(list); |
| | | result.setCount(list.size()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<OldRiskAssessResDTO> getOldRiskAssessListByRegion(List<String> region) { |
| | | |
| | | Specification<OldRiskAssess> specification = new Specification<OldRiskAssess>() { |
| | | @Override |
| | | public Predicate toPredicate(Root<OldRiskAssess> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) { |
| | | query.orderBy(criteriaBuilder.asc(root.get("region"))); |
| | | List<Predicate> predicateList = new ArrayList<>(); |
| | | predicateList.add(criteriaBuilder.in(root.get("region")).value(region)); |
| | | |
| | | predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode())); |
| | | //返回组装的条件 |
| | | return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0]))); |
| | | } |
| | | }; |
| | | |
| | | List<OldRiskAssess> all = repository.findAll(specification); |
| | | if (ObjectUtils.isEmpty(all)){ |
| | | return null; |
| | | } |
| | | return StatusEnum.SUCCESS.getCode(); |
| | | List<OldRiskAssessResDTO> oldRiskAssessResDTOS = BeanCopyUtils.copyBeanList(all, OldRiskAssessResDTO.class); |
| | | oldRiskAssessResDTOS.forEach(oldRiskAssessResDTO -> { |
| | | oldRiskAssessResDTO.setSort(oldRiskAssessResDTOS.indexOf(oldRiskAssessResDTO) + 1); |
| | | }); |
| | | return oldRiskAssessResDTOS; |
| | | } |
| | | |
| | | @Override |