| | |
| | | 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.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 org.springframework.data.jpa.domain.Specification; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Base64Utils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | import javax.persistence.criteria.CriteriaQuery; |
| | | import javax.persistence.criteria.Predicate; |
| | | import javax.persistence.criteria.Root; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.text.NumberFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | |
| | | } |
| | | |
| | | @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(); |
| | | } |
| | | } |
| | | } |
| | | return StatusEnum.SUCCESS.getCode(); |
| | | // // 保存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 |