| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package cn.com.goldenwater.dcproj.service.impl.ducha;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.dao.BisInspMtprgDao;
- import cn.com.goldenwater.dcproj.model.BisInspMtprg;
- import cn.com.goldenwater.dcproj.param.BisInspMtprgParam;
- import cn.com.goldenwater.dcproj.service.BisInspMtprgService;
- import cn.com.goldenwater.dcproj.utils.StringUtils;
- import cn.com.goldenwater.id.util.UuidUtil;
- import org.apache.poi.ss.usermodel.CellStyle;
- import org.apache.poi.ss.usermodel.Font;
- import org.apache.poi.ss.usermodel.HorizontalAlignment;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.xssf.usermodel.XSSFCell;
- import org.apache.poi.xssf.usermodel.XSSFCellStyle;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- 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.InputStream;
- import java.io.OutputStream;
- import java.net.URLEncoder;
- import java.util.Date;
- import java.util.List;
- /**
- * @author lhc
- * @date 2021-5-17
- */
- @Service
- @Transactional
- public class BisInspMtprgServiceImpl extends AbstractCrudService<BisInspMtprg, BisInspMtprgParam> implements BisInspMtprgService {
- @Value("${export.templatePath}")
- private String templatePath;
- @Autowired
- private BisInspMtprgDao bisInspMtprgDao;
- public BisInspMtprgServiceImpl(BisInspMtprgDao bisInspMtprgDao) {
- super(bisInspMtprgDao);
- this.bisInspMtprgDao = bisInspMtprgDao;
- }
- @Override
- public int insert(BisInspMtprg bisInspMtprg) {
- String uuid = UuidUtil.uuid(); // 生成uuid
- bisInspMtprg.setId(uuid);
- bisInspMtprg.setIntm(new Date());
- bisInspMtprg.setUptm(new Date());
- bisInspMtprg.setDataStat("0");
- return this.bisInspMtprgDao.insert(bisInspMtprg);
- }
- @Override
- public int update(BisInspMtprg bisInspMtprg) {
- bisInspMtprg.setUptm(new Date());
- return this.bisInspMtprgDao.update(bisInspMtprg);
- }
- @Override
- public int delete(String id) {
- return this.bisInspMtprgDao.delete(id);
- }
- @Override
- public void export(HttpServletResponse response, BisInspMtprgParam bisInspMtprgParam) {
- String path = templatePath + File.separator + "tongjiyuebao.xlsx";
- File file = new File(path);
- try {
- InputStream fs = new FileInputStream(file);
- XSSFWorkbook wb = new XSSFWorkbook(fs);
- XSSFSheet sheet = wb.getSheetAt(0);
- XSSFCell cell = sheet.getRow(0).getCell(0);
- String title = bisInspMtprgParam.getYear() + "年统计月报";
- cell.setCellValue(title);
- CellStyle cellStyle = wb.createCellStyle();
- Font font = wb.createFont();
- // font.setBoldweight((short) 600);
- font.setBold(true);
- font.setFontHeightInPoints((short) 25);// 设置字体大小
- cellStyle.setFont(font);
- cellStyle.setAlignment(HorizontalAlignment.CENTER);
- cell.setCellStyle(cellStyle);
- XSSFCellStyle cellStyleC = sheet.getRow(1).getCell(0).getCellStyle();
- List<BisInspMtprg> list = bisInspMtprgDao.findList(bisInspMtprgParam);
- if (list != null && list.size() > 0) {
- for (int i = 0; i < list.size(); i++) {
- BisInspMtprg bisInspMtprg = list.get(i);
- Row row = sheet.createRow(2 + i);
- row.createCell(0).setCellStyle(cellStyleC);
- row.getCell(0).setCellValue(isNull(bisInspMtprg.getUnitName()));
- row.createCell(1).setCellStyle(cellStyleC);
- row.getCell(1).setCellValue(isNull(bisInspMtprg.getYear()));
- row.createCell(2).setCellStyle(cellStyleC);
- row.getCell(2).setCellValue(isNull(bisInspMtprg.getMonth()));
- row.createCell(3).setCellStyle(cellStyleC);
- row.getCell(3).setCellValue(isNull(bisInspMtprg.getMatter()));
- row.createCell(4).setCellStyle(cellStyleC);
- row.getCell(4).setCellValue(isNull(bisInspMtprg.getMainWork()));
- row.createCell(5).setCellStyle(cellStyleC);
- row.getCell(5).setCellValue(isNull(bisInspMtprg.getSpcChkSize()));
- row.createCell(6).setCellStyle(cellStyleC);
- row.getCell(6).setCellValue(isNull(bisInspMtprg.getInspSize()));
- row.createCell(7).setCellStyle(cellStyleC);
- row.getCell(7).setCellValue(isNull(bisInspMtprg.getInspPersSize()));
- row.createCell(8).setCellStyle(cellStyleC);
- row.getCell(8).setCellValue(isNull(bisInspMtprg.getChkPrjSize()));
- row.createCell(9).setCellStyle(cellStyleC);
- row.getCell(9).setCellValue(isNull(bisInspMtprg.getFindPblmSize()));
- row.createCell(10).setCellStyle(cellStyleC);
- row.getCell(10).setCellValue(isNull(bisInspMtprg.getAccnUnitSize()));
- row.createCell(11).setCellStyle(cellStyleC);
- row.getCell(11).setCellValue(isNull(bisInspMtprg.getAccnPersSize()));
- row.createCell(12).setCellStyle(cellStyleC);
- row.getCell(12).setCellValue(isNull(bisInspMtprg.getPblmMendSize()));
- row.createCell(13).setCellStyle(cellStyleC);
- row.getCell(13).setCellValue(isNull(bisInspMtprg.getPubRptSize()));
- row.createCell(14).setCellStyle(cellStyleC);
- row.getCell(14).setCellValue(isNull(bisInspMtprg.getChkSysNote()));
- row.createCell(15).setCellStyle(cellStyleC);
- row.getCell(15).setCellValue(isNull(bisInspMtprg.getLeadChkSize()));
- row.createCell(16).setCellStyle(cellStyleC);
- row.getCell(16).setCellValue(isNull(bisInspMtprg.getLeadChkNote()));
- }
- }
- response.setContentType("application/x-msdownload");
- String fileNameURL = URLEncoder.encode(title, "UTF-8");
- response.setHeader("Content-disposition", "attachment;filename=" + fileNameURL + ";filename*=utf-8''" + fileNameURL);
- OutputStream out = response.getOutputStream();
- wb.write(out);
- out.flush();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public String isNull(Object v){
- if(StringUtils.isNull(v)){
- return "";
- }
- return v.toString();
- }
- }
|