| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- 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<ChkSafeStatList, ChkSafeStatListParam> 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<ChkSafeStatList> 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<resultList.size();i++){
- setAllCell(sheet,i,resultList.get(i));
- }
- }
- }
- /**
- * 设置 行 内容
- * @param sheet
- * @param rowNum
- * @param safeStat
- */
- private void setAllCell(Sheet sheet,int rowNum, ChkSafeStatList safeStat){
- setCellValue(sheet,7+rowNum,1,String.valueOf(safeStat.getChkGroupNum()));
- setCellValue(sheet,7+rowNum,2,String.valueOf(safeStat.getChkGroupNumUndercover()));
- setCellValue(sheet,7+rowNum,3,String.valueOf(safeStat.getChkPointNum()));
- setCellValue(sheet,7+rowNum,4,String.valueOf(safeStat.getInspGeneralChk()));
- setCellValue(sheet,7+rowNum,5,String.valueOf(safeStat.getInspGeneralRepair()));
- setCellValue(sheet,7+rowNum,6,String.valueOf(safeStat.getInspMajorChk()));
- setCellValue(sheet,7+rowNum,7,String.valueOf(safeStat.getInspMajorRepair()));
- setCellValue(sheet,7+rowNum,8,safeStat.getDangerRectFund());
- setCellValue(sheet,7+rowNum,9,String.valueOf(safeStat.getCrackDownIllegalAction()));
- setCellValue(sheet,7+rowNum,10,String.valueOf(safeStat.getRepairViolateRuleAction()));
- setCellValue(sheet,7+rowNum,11,String.valueOf(safeStat.getStopProdRect()));
- setCellValue(sheet,7+rowNum,12,String.valueOf(safeStat.getSuspendLicense()));
- setCellValue(sheet,7+rowNum,13,String.valueOf(safeStat.getShutClampDown()));
- setCellValue(sheet,7+rowNum,14,safeStat.getPenaltyFine());
- setCellValue(sheet,7+rowNum,15,String.valueOf(safeStat.getActbExpsUnit()));
- setCellValue(sheet,7+rowNum,16,String.valueOf(safeStat.getJoinPunishTrustBreakEntp()));
- }
- /**
- * 设置 单元格的值
- * @param sheet
- * @param rownum
- * @param cellnum
- * @param value
- */
- private void setCellValue(Sheet sheet, int rownum, int cellnum, String value) {
- Cell cell = sheet.getRow(rownum).getCell(cellnum);
- cell.setCellValue(value);
- }
- private void writeToResponse(HttpServletResponse response, Workbook workbook, String name) throws IOException {
- // 修改模板内容导出新模板
- response.setContentType("application/x-msdownload");
- String fileNameURL = URLEncoder.encode(name, "UTF-8");
- response.setHeader("Content-disposition", "attachment;filename=" + fileNameURL + ";filename*=utf-8''" + fileNameURL);
- OutputStream out = response.getOutputStream();
- workbook.write(out);
- out.flush();
- out.close();
- }
- /**
- * 批量上报
- * @param ids
- * @return
- */
- @Override
- public int batchReportByIds(String[] ids ){
- return this.chkSafeStatListDao.batchReportByIds(ids, new Date());
- }
- /**
- * 批量添加
- * @param chkSafeStatListList
- * @return
- */
- @Override
- public int insertBatchFile(List<ChkSafeStatList> chkSafeStatListList){
- return this.chkSafeStatListDao.insertBatchFile(chkSafeStatListList);
- }
- }
|