58d63d914ff70b394cae3a46e311262cca16ffbc.svn-base 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package cn.com.goldenwater.dcproj.service.impl;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.ChkSafeStatListDao;
  4. import cn.com.goldenwater.dcproj.model.ChkSafeStatList;
  5. import cn.com.goldenwater.dcproj.param.ChkSafeStatListParam;
  6. import cn.com.goldenwater.dcproj.service.ChkSafeStatListService;
  7. import cn.com.goldenwater.id.util.UuidUtil;
  8. import org.apache.poi.ss.usermodel.Cell;
  9. import org.apache.poi.ss.usermodel.Sheet;
  10. import org.apache.poi.ss.usermodel.Workbook;
  11. import org.apache.poi.ss.usermodel.WorkbookFactory;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.FileNotFoundException;
  22. import java.io.IOException;
  23. import java.io.OutputStream;
  24. import java.net.URLEncoder;
  25. import java.text.SimpleDateFormat;
  26. import java.time.LocalDate;
  27. import java.util.Date;
  28. import java.util.List;
  29. /**
  30. * 成都市水务行业安全大检查情况统计Service业务层处理
  31. *
  32. * @author ruoyi
  33. * @date 2023-02-22
  34. */
  35. @Service
  36. @Transactional
  37. public class ChkSafeStatListServiceImpl extends AbstractCrudService<ChkSafeStatList, ChkSafeStatListParam> implements ChkSafeStatListService
  38. {
  39. private Logger logger = LoggerFactory.getLogger(getClass());
  40. @Autowired
  41. private ChkSafeStatListDao chkSafeStatListDao;
  42. @Value("${export.templatePath}")
  43. private String templatePath;
  44. /**
  45. * 导出模板
  46. * 水务行业安全大检查情况表
  47. */
  48. private String templateName = "chkSafeStatListExport.xls";
  49. public ChkSafeStatListServiceImpl(ChkSafeStatListDao chkSafeStatListDao) {
  50. super(chkSafeStatListDao);
  51. this.chkSafeStatListDao = chkSafeStatListDao;
  52. }
  53. /**
  54. * 增加成都市水务行业安全大检查情况统计
  55. *
  56. * @return 成都市水务行业安全大检查情况统计
  57. */
  58. @Override
  59. public int insert(ChkSafeStatList chkSafeStatList) {
  60. logger.debug("ChkSafeStatList 新增");
  61. String uuid = UuidUtil.uuid(); // 生成uuid
  62. chkSafeStatList.setId(uuid);
  63. chkSafeStatList.setIntm(new Date());
  64. chkSafeStatList.setUptm(chkSafeStatList.getIntm());
  65. chkSafeStatList.setDataStat("0");
  66. //填报状态 1新增 2上报
  67. chkSafeStatList.setFillRepoStat("1");
  68. chkSafeStatList.setChkSubmitDttm(chkSafeStatList.getIntm());
  69. return this.chkSafeStatListDao.insert(chkSafeStatList);
  70. }
  71. /**
  72. * 更新 成都市水务行业安全大检查情况统计
  73. * 主键更新
  74. * @param chkSafeStatList 成都市水务行业安全大检查情况统计
  75. * @return 成都市水务行业安全大检查情况统计
  76. */
  77. @Override
  78. public int update(ChkSafeStatList chkSafeStatList) {
  79. logger.debug("ChkSafeStatList 更新");
  80. chkSafeStatList.setUptm(new Date());
  81. return this.chkSafeStatListDao.update(chkSafeStatList);
  82. }
  83. /**
  84. * 主键删除 成都市水务行业安全大检查情况统计
  85. *
  86. * @param id 成都市水务行业安全大检查情况统计主键
  87. * @return 成都市水务行业安全大检查情况统计
  88. */
  89. @Override
  90. public int delete(String id) {
  91. logger.debug("ChkSafeStatList 删除");
  92. return this.chkSafeStatListDao.delete(id);
  93. }
  94. /**
  95. * 导出 成都市水务行业安全大检查情况统计
  96. *
  97. * @param chkSafeStatListParam 筛选查询参数
  98. * @param response
  99. */
  100. @Override
  101. public void export(ChkSafeStatListParam chkSafeStatListParam, HttpServletResponse response) {
  102. logger.debug("ChkSafeStatList 导出");
  103. // 读取导出模板
  104. String fileName = templatePath + File.separator + templateName ;
  105. File file = new File(fileName);
  106. if(file.exists()){
  107. // 模板存在
  108. try {
  109. FileInputStream inputStream = new FileInputStream(file);
  110. Workbook workbook = WorkbookFactory.create(inputStream);
  111. exportFile(workbook, chkSafeStatListParam);
  112. writeToResponse(response, workbook, "成都市水务行业安全大检查情况统计表.xls");
  113. } catch (FileNotFoundException e) {
  114. e.printStackTrace();
  115. } catch (IOException e) {
  116. e.printStackTrace();
  117. }
  118. }else {
  119. logger.error("导出模板不存在");
  120. }
  121. }
  122. /**
  123. * 把数据写入excel
  124. * @param xssfWorkbook
  125. * @param chkSafeStatListParam
  126. */
  127. private void exportFile(Workbook xssfWorkbook,ChkSafeStatListParam chkSafeStatListParam){
  128. // 先查询统计数据
  129. List<ChkSafeStatList> resultList = this.chkSafeStatListDao.countTotalByIndustry(chkSafeStatListParam);
  130. // 日期标题
  131. String titleDate = String.format("至%d月%d日(累计)",LocalDate.now().getMonthValue(),LocalDate.now().getDayOfMonth());
  132. if(null != chkSafeStatListParam.getChkSubmitDttm()){
  133. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月d日");
  134. titleDate = sdf.format(chkSafeStatListParam.getChkSubmitDttm());
  135. }
  136. Sheet sheet = xssfWorkbook.getSheetAt(0);
  137. // 设置 标题
  138. setCellValue(sheet,2,4,titleDate);
  139. // 设置 表格数据
  140. if(null != resultList && resultList.size()>0){
  141. // 填报单位
  142. if(!"2".equals(chkSafeStatListParam.getFillRepoStat())){
  143. String chkSubmitDept = resultList.get(0).getChkSubmitDept();
  144. setCellValue(sheet,2,2,chkSubmitDept);
  145. }
  146. // 把查询结果 写入到模板中
  147. for (int i=0;i<resultList.size();i++){
  148. setAllCell(sheet,i,resultList.get(i));
  149. }
  150. }
  151. }
  152. /**
  153. * 设置 行 内容
  154. * @param sheet
  155. * @param rowNum
  156. * @param safeStat
  157. */
  158. private void setAllCell(Sheet sheet,int rowNum, ChkSafeStatList safeStat){
  159. setCellValue(sheet,7+rowNum,1,String.valueOf(safeStat.getChkGroupNum()));
  160. setCellValue(sheet,7+rowNum,2,String.valueOf(safeStat.getChkGroupNumUndercover()));
  161. setCellValue(sheet,7+rowNum,3,String.valueOf(safeStat.getChkPointNum()));
  162. setCellValue(sheet,7+rowNum,4,String.valueOf(safeStat.getInspGeneralChk()));
  163. setCellValue(sheet,7+rowNum,5,String.valueOf(safeStat.getInspGeneralRepair()));
  164. setCellValue(sheet,7+rowNum,6,String.valueOf(safeStat.getInspMajorChk()));
  165. setCellValue(sheet,7+rowNum,7,String.valueOf(safeStat.getInspMajorRepair()));
  166. setCellValue(sheet,7+rowNum,8,safeStat.getDangerRectFund());
  167. setCellValue(sheet,7+rowNum,9,String.valueOf(safeStat.getCrackDownIllegalAction()));
  168. setCellValue(sheet,7+rowNum,10,String.valueOf(safeStat.getRepairViolateRuleAction()));
  169. setCellValue(sheet,7+rowNum,11,String.valueOf(safeStat.getStopProdRect()));
  170. setCellValue(sheet,7+rowNum,12,String.valueOf(safeStat.getSuspendLicense()));
  171. setCellValue(sheet,7+rowNum,13,String.valueOf(safeStat.getShutClampDown()));
  172. setCellValue(sheet,7+rowNum,14,safeStat.getPenaltyFine());
  173. setCellValue(sheet,7+rowNum,15,String.valueOf(safeStat.getActbExpsUnit()));
  174. setCellValue(sheet,7+rowNum,16,String.valueOf(safeStat.getJoinPunishTrustBreakEntp()));
  175. }
  176. /**
  177. * 设置 单元格的值
  178. * @param sheet
  179. * @param rownum
  180. * @param cellnum
  181. * @param value
  182. */
  183. private void setCellValue(Sheet sheet, int rownum, int cellnum, String value) {
  184. Cell cell = sheet.getRow(rownum).getCell(cellnum);
  185. cell.setCellValue(value);
  186. }
  187. private void writeToResponse(HttpServletResponse response, Workbook workbook, String name) throws IOException {
  188. // 修改模板内容导出新模板
  189. response.setContentType("application/x-msdownload");
  190. String fileNameURL = URLEncoder.encode(name, "UTF-8");
  191. response.setHeader("Content-disposition", "attachment;filename=" + fileNameURL + ";filename*=utf-8''" + fileNameURL);
  192. OutputStream out = response.getOutputStream();
  193. workbook.write(out);
  194. out.flush();
  195. out.close();
  196. }
  197. /**
  198. * 批量上报
  199. * @param ids
  200. * @return
  201. */
  202. @Override
  203. public int batchReportByIds(String[] ids ){
  204. return this.chkSafeStatListDao.batchReportByIds(ids, new Date());
  205. }
  206. /**
  207. * 批量添加
  208. * @param chkSafeStatListList
  209. * @return
  210. */
  211. @Override
  212. public int insertBatchFile(List<ChkSafeStatList> chkSafeStatListList){
  213. return this.chkSafeStatListDao.insertBatchFile(chkSafeStatListList);
  214. }
  215. }