package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.ChkSafeStatListDao; import cn.com.goldenwater.dcproj.model.ChkSafeStatList; import cn.com.goldenwater.dcproj.param.ChkSafeStatListParam; import cn.com.goldenwater.dcproj.service.ChkSafeStatListService; import cn.com.goldenwater.id.util.UuidUtil; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.Date; import java.util.List; /** * 成都市水务行业安全大检查情况统计Service业务层处理 * * @author ruoyi * @date 2023-02-22 */ @Service @Transactional public class ChkSafeStatListServiceImpl extends AbstractCrudService implements ChkSafeStatListService { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private ChkSafeStatListDao chkSafeStatListDao; @Value("${export.templatePath}") private String templatePath; /** * 导出模板 * 水务行业安全大检查情况表 */ private String templateName = "chkSafeStatListExport.xls"; public ChkSafeStatListServiceImpl(ChkSafeStatListDao chkSafeStatListDao) { super(chkSafeStatListDao); this.chkSafeStatListDao = chkSafeStatListDao; } /** * 增加成都市水务行业安全大检查情况统计 * * @return 成都市水务行业安全大检查情况统计 */ @Override public int insert(ChkSafeStatList chkSafeStatList) { logger.debug("ChkSafeStatList 新增"); String uuid = UuidUtil.uuid(); // 生成uuid chkSafeStatList.setId(uuid); chkSafeStatList.setIntm(new Date()); chkSafeStatList.setUptm(chkSafeStatList.getIntm()); chkSafeStatList.setDataStat("0"); //填报状态 1新增 2上报 chkSafeStatList.setFillRepoStat("1"); chkSafeStatList.setChkSubmitDttm(chkSafeStatList.getIntm()); return this.chkSafeStatListDao.insert(chkSafeStatList); } /** * 更新 成都市水务行业安全大检查情况统计 * 主键更新 * @param chkSafeStatList 成都市水务行业安全大检查情况统计 * @return 成都市水务行业安全大检查情况统计 */ @Override public int update(ChkSafeStatList chkSafeStatList) { logger.debug("ChkSafeStatList 更新"); chkSafeStatList.setUptm(new Date()); return this.chkSafeStatListDao.update(chkSafeStatList); } /** * 主键删除 成都市水务行业安全大检查情况统计 * * @param id 成都市水务行业安全大检查情况统计主键 * @return 成都市水务行业安全大检查情况统计 */ @Override public int delete(String id) { logger.debug("ChkSafeStatList 删除"); return this.chkSafeStatListDao.delete(id); } /** * 导出 成都市水务行业安全大检查情况统计 * * @param chkSafeStatListParam 筛选查询参数 * @param response */ @Override public void export(ChkSafeStatListParam chkSafeStatListParam, HttpServletResponse response) { logger.debug("ChkSafeStatList 导出"); // 读取导出模板 String fileName = templatePath + File.separator + templateName ; File file = new File(fileName); if(file.exists()){ // 模板存在 try { FileInputStream inputStream = new FileInputStream(file); Workbook workbook = WorkbookFactory.create(inputStream); exportFile(workbook, chkSafeStatListParam); writeToResponse(response, workbook, "成都市水务行业安全大检查情况统计表.xls"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }else { logger.error("导出模板不存在"); } } /** * 把数据写入excel * @param xssfWorkbook * @param chkSafeStatListParam */ private void exportFile(Workbook xssfWorkbook,ChkSafeStatListParam chkSafeStatListParam){ // 先查询统计数据 List resultList = this.chkSafeStatListDao.countTotalByIndustry(chkSafeStatListParam); // 日期标题 String titleDate = String.format("至%d月%d日(累计)",LocalDate.now().getMonthValue(),LocalDate.now().getDayOfMonth()); if(null != chkSafeStatListParam.getChkSubmitDttm()){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月d日"); titleDate = sdf.format(chkSafeStatListParam.getChkSubmitDttm()); } Sheet sheet = xssfWorkbook.getSheetAt(0); // 设置 标题 setCellValue(sheet,2,4,titleDate); // 设置 表格数据 if(null != resultList && resultList.size()>0){ // 填报单位 if(!"2".equals(chkSafeStatListParam.getFillRepoStat())){ String chkSubmitDept = resultList.get(0).getChkSubmitDept(); setCellValue(sheet,2,2,chkSubmitDept); } // 把查询结果 写入到模板中 for (int i=0;i chkSafeStatListList){ return this.chkSafeStatListDao.insertBatchFile(chkSafeStatListList); } }