ddf5f052379967252a9117f7d065ef00114540de.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package cn.com.goldenwater.dcproj.service.impl.ducha;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.BisInspMtprgDao;
  4. import cn.com.goldenwater.dcproj.model.BisInspMtprg;
  5. import cn.com.goldenwater.dcproj.param.BisInspMtprgParam;
  6. import cn.com.goldenwater.dcproj.service.BisInspMtprgService;
  7. import cn.com.goldenwater.dcproj.utils.StringUtils;
  8. import cn.com.goldenwater.id.util.UuidUtil;
  9. import org.apache.poi.ss.usermodel.CellStyle;
  10. import org.apache.poi.ss.usermodel.Font;
  11. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  12. import org.apache.poi.ss.usermodel.Row;
  13. import org.apache.poi.xssf.usermodel.XSSFCell;
  14. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  15. import org.apache.poi.xssf.usermodel.XSSFSheet;
  16. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.io.File;
  23. import java.io.FileInputStream;
  24. import java.io.InputStream;
  25. import java.io.OutputStream;
  26. import java.net.URLEncoder;
  27. import java.util.Date;
  28. import java.util.List;
  29. /**
  30. * @author lhc
  31. * @date 2021-5-17
  32. */
  33. @Service
  34. @Transactional
  35. public class BisInspMtprgServiceImpl extends AbstractCrudService<BisInspMtprg, BisInspMtprgParam> implements BisInspMtprgService {
  36. @Value("${export.templatePath}")
  37. private String templatePath;
  38. @Autowired
  39. private BisInspMtprgDao bisInspMtprgDao;
  40. public BisInspMtprgServiceImpl(BisInspMtprgDao bisInspMtprgDao) {
  41. super(bisInspMtprgDao);
  42. this.bisInspMtprgDao = bisInspMtprgDao;
  43. }
  44. @Override
  45. public int insert(BisInspMtprg bisInspMtprg) {
  46. String uuid = UuidUtil.uuid(); // 生成uuid
  47. bisInspMtprg.setId(uuid);
  48. bisInspMtprg.setIntm(new Date());
  49. bisInspMtprg.setUptm(new Date());
  50. bisInspMtprg.setDataStat("0");
  51. return this.bisInspMtprgDao.insert(bisInspMtprg);
  52. }
  53. @Override
  54. public int update(BisInspMtprg bisInspMtprg) {
  55. bisInspMtprg.setUptm(new Date());
  56. return this.bisInspMtprgDao.update(bisInspMtprg);
  57. }
  58. @Override
  59. public int delete(String id) {
  60. return this.bisInspMtprgDao.delete(id);
  61. }
  62. @Override
  63. public void export(HttpServletResponse response, BisInspMtprgParam bisInspMtprgParam) {
  64. String path = templatePath + File.separator + "tongjiyuebao.xlsx";
  65. File file = new File(path);
  66. try {
  67. InputStream fs = new FileInputStream(file);
  68. XSSFWorkbook wb = new XSSFWorkbook(fs);
  69. XSSFSheet sheet = wb.getSheetAt(0);
  70. XSSFCell cell = sheet.getRow(0).getCell(0);
  71. String title = bisInspMtprgParam.getYear() + "年统计月报";
  72. cell.setCellValue(title);
  73. CellStyle cellStyle = wb.createCellStyle();
  74. Font font = wb.createFont();
  75. // font.setBoldweight((short) 600);
  76. font.setBold(true);
  77. font.setFontHeightInPoints((short) 25);// 设置字体大小
  78. cellStyle.setFont(font);
  79. cellStyle.setAlignment(HorizontalAlignment.CENTER);
  80. cell.setCellStyle(cellStyle);
  81. XSSFCellStyle cellStyleC = sheet.getRow(1).getCell(0).getCellStyle();
  82. List<BisInspMtprg> list = bisInspMtprgDao.findList(bisInspMtprgParam);
  83. if (list != null && list.size() > 0) {
  84. for (int i = 0; i < list.size(); i++) {
  85. BisInspMtprg bisInspMtprg = list.get(i);
  86. Row row = sheet.createRow(2 + i);
  87. row.createCell(0).setCellStyle(cellStyleC);
  88. row.getCell(0).setCellValue(isNull(bisInspMtprg.getUnitName()));
  89. row.createCell(1).setCellStyle(cellStyleC);
  90. row.getCell(1).setCellValue(isNull(bisInspMtprg.getYear()));
  91. row.createCell(2).setCellStyle(cellStyleC);
  92. row.getCell(2).setCellValue(isNull(bisInspMtprg.getMonth()));
  93. row.createCell(3).setCellStyle(cellStyleC);
  94. row.getCell(3).setCellValue(isNull(bisInspMtprg.getMatter()));
  95. row.createCell(4).setCellStyle(cellStyleC);
  96. row.getCell(4).setCellValue(isNull(bisInspMtprg.getMainWork()));
  97. row.createCell(5).setCellStyle(cellStyleC);
  98. row.getCell(5).setCellValue(isNull(bisInspMtprg.getSpcChkSize()));
  99. row.createCell(6).setCellStyle(cellStyleC);
  100. row.getCell(6).setCellValue(isNull(bisInspMtprg.getInspSize()));
  101. row.createCell(7).setCellStyle(cellStyleC);
  102. row.getCell(7).setCellValue(isNull(bisInspMtprg.getInspPersSize()));
  103. row.createCell(8).setCellStyle(cellStyleC);
  104. row.getCell(8).setCellValue(isNull(bisInspMtprg.getChkPrjSize()));
  105. row.createCell(9).setCellStyle(cellStyleC);
  106. row.getCell(9).setCellValue(isNull(bisInspMtprg.getFindPblmSize()));
  107. row.createCell(10).setCellStyle(cellStyleC);
  108. row.getCell(10).setCellValue(isNull(bisInspMtprg.getAccnUnitSize()));
  109. row.createCell(11).setCellStyle(cellStyleC);
  110. row.getCell(11).setCellValue(isNull(bisInspMtprg.getAccnPersSize()));
  111. row.createCell(12).setCellStyle(cellStyleC);
  112. row.getCell(12).setCellValue(isNull(bisInspMtprg.getPblmMendSize()));
  113. row.createCell(13).setCellStyle(cellStyleC);
  114. row.getCell(13).setCellValue(isNull(bisInspMtprg.getPubRptSize()));
  115. row.createCell(14).setCellStyle(cellStyleC);
  116. row.getCell(14).setCellValue(isNull(bisInspMtprg.getChkSysNote()));
  117. row.createCell(15).setCellStyle(cellStyleC);
  118. row.getCell(15).setCellValue(isNull(bisInspMtprg.getLeadChkSize()));
  119. row.createCell(16).setCellStyle(cellStyleC);
  120. row.getCell(16).setCellValue(isNull(bisInspMtprg.getLeadChkNote()));
  121. }
  122. }
  123. response.setContentType("application/x-msdownload");
  124. String fileNameURL = URLEncoder.encode(title, "UTF-8");
  125. response.setHeader("Content-disposition", "attachment;filename=" + fileNameURL + ";filename*=utf-8''" + fileNameURL);
  126. OutputStream out = response.getOutputStream();
  127. wb.write(out);
  128. out.flush();
  129. out.close();
  130. } catch (Exception e) {
  131. e.printStackTrace();
  132. }
  133. }
  134. public String isNull(Object v){
  135. if(StringUtils.isNull(v)){
  136. return "";
  137. }
  138. return v.toString();
  139. }
  140. }