|
@@ -3,40 +3,42 @@ package com.steerinfo.ems.emssafeinfo.controller;
|
|
|
import com.steerinfo.auth.utils.JwtUtil;
|
|
|
import com.steerinfo.ems.Utils.DateUtils;
|
|
|
import com.steerinfo.ems.emssafeinfo.mapper.EmsSafeinfoMapper;
|
|
|
-import com.steerinfo.ems.emssafeinfo.model.EmsSafeinfo;
|
|
|
-import com.steerinfo.ems.emssafeinfo.service.IEmsSafeinfoService;
|
|
|
import com.steerinfo.framework.controller.BaseRESTfulController;
|
|
|
import com.steerinfo.framework.controller.RESTfulResult;
|
|
|
import com.steerinfo.framework.service.pagehelper.PageList;
|
|
|
import com.steerinfo.framework.utils.collection.ListUtils;
|
|
|
-import com.steerinfo.framework.utils.text.Charsets;
|
|
|
+import com.steerinfo.ems.emssafeinfo.model.EmsSafeinfo;
|
|
|
+import com.steerinfo.ems.emssafeinfo.service.IEmsSafeinfoService;
|
|
|
import com.steerinfo.ftp.uploadfile.utils.IDutils;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.commons.io.Charsets;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.*;
|
|
|
-import java.net.URLEncoder;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
|
/**
|
|
|
* EmsSafeinfo RESTful接口:
|
|
|
* @author generator
|
|
|
- * @version 1.0-SNAPSHORT 2023-04-24 10:51
|
|
|
+ * @version 1.0-SNAPSHORT 2023-05-15 10:07
|
|
|
* 类描述
|
|
|
* 修订历史:
|
|
|
- * 日期:2023-04-24
|
|
|
+ * 日期:2023-05-15
|
|
|
* 作者:generator
|
|
|
* 参考:
|
|
|
* 描述:EmsSafeinfo RESTful接口
|
|
@@ -52,7 +54,6 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
|
|
|
@Autowired
|
|
|
EmsSafeinfoMapper emsSafeinfoMapper;
|
|
|
-
|
|
|
@ApiOperation(value="获取列表", notes="分页查询")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
|
|
@@ -61,7 +62,7 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
//@RequiresPermissions("emssafeinfo:view")
|
|
|
@GetMapping(value = "/")
|
|
|
public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
|
|
|
- HashMap<String,Object> hashMap = new HashMap<>();
|
|
|
+// HashMap<String,Object> hashMap = new HashMap<>();
|
|
|
String[] arr= null;
|
|
|
String[] arr2= null;
|
|
|
String dates=null;
|
|
@@ -70,13 +71,12 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
arr =parmas.get("process").toString().split(",");
|
|
|
}
|
|
|
|
|
|
- if (parmas.get("type")!=null){
|
|
|
- arr2 =parmas.get("type").toString().split(",");
|
|
|
-
|
|
|
- }
|
|
|
if (parmas.get("dates")!=null && parmas.get("dates2")!=null){
|
|
|
- dates=parmas.get("dates").toString();
|
|
|
- dates2 = parmas.get("dates2").toString();
|
|
|
+ dates=parmas.get("dates").toString();
|
|
|
+ dates2 = parmas.get("dates2").toString();
|
|
|
+ }
|
|
|
+ if (parmas.get("hazard")!=null ){
|
|
|
+ arr2=parmas.get("hazard").toString().split(",");
|
|
|
}
|
|
|
PageList<EmsSafeinfo> list = emsSafeinfoService.queryForPage2(dates,dates2,arr2,arr, pageNum, pageSize);
|
|
|
return success(list);
|
|
@@ -102,7 +102,7 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
|
|
|
String selectmaxid = emsSafeinfoMapper.selectmaxid();
|
|
|
if(selectmaxid == null){
|
|
|
- String qqq="AQ"+DateUtils.getCurrentTime("yyyyMMdd")+"0001";
|
|
|
+ String qqq="AQ"+ DateUtils.getCurrentTime("yyyyMMdd")+"0001";
|
|
|
model.setId(qqq);
|
|
|
}else {
|
|
|
String id1 = selectmaxid.substring(10,14);
|
|
@@ -112,45 +112,42 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
String newmaxid ="AQ"+DateUtils.getCurrentTime("yyyyMMdd")+ String.format("%04d", maxid2);
|
|
|
model.setId(newmaxid);
|
|
|
}
|
|
|
-
|
|
|
- model.setCreatetime(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
|
|
|
- model.setCreateman(JwtUtil.getUseridByToken());
|
|
|
+ model.setDates(DateUtils.getCurrentTime("yyyy-MM-dd"));
|
|
|
+// model.setCreateman(JwtUtil.getUseridByToken());
|
|
|
EmsSafeinfo emsSafeinfo = emsSafeinfoService.add(model);
|
|
|
return success(emsSafeinfo);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
|
|
|
- @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short")
|
|
|
+ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
|
|
|
//@RequiresPermissions("emssafeinfo:view")
|
|
|
@GetMapping(value = "/{id}")
|
|
|
- public RESTfulResult get(@PathVariable Short id){
|
|
|
+ public RESTfulResult get(@PathVariable String id){
|
|
|
EmsSafeinfo emsSafeinfo = emsSafeinfoService.getById(id);
|
|
|
return success(emsSafeinfo);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsSafeinfo信息来更新详细信息")
|
|
|
@ApiImplicitParams({
|
|
|
- @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short"),
|
|
|
+ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
|
|
|
@ApiImplicitParam(name = "emsSafeinfo", value = "详细实体emsSafeinfo", required = true, dataType = "EmsSafeinfo")
|
|
|
})
|
|
|
//@RequiresPermissions("emssafeinfo:update")
|
|
|
@PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
|
|
|
public RESTfulResult update(@PathVariable String id, @RequestBody EmsSafeinfo model){
|
|
|
model.setId(id);
|
|
|
- model.setUpdateman(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
|
|
|
- model.setUpdatetime(JwtUtil.getUseridByToken());
|
|
|
EmsSafeinfo emsSafeinfo = emsSafeinfoService.modify(model);
|
|
|
return success(emsSafeinfo);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="删除", notes="根据url的id来指定删除对象")
|
|
|
- @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short")
|
|
|
+ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
|
|
|
//@RequiresPermissions("emssafeinfo:delete")
|
|
|
- @DeleteMapping(value = "/{id}")//Short
|
|
|
+ @DeleteMapping(value = "/{id}")//String
|
|
|
public RESTfulResult delete(@PathVariable String id){
|
|
|
List<String> list = Arrays.asList(id.split(","));
|
|
|
if(ListUtils.isNotEmpty(list)) {
|
|
|
- List<Short> ids = ListUtils.convertList(list);
|
|
|
+ List<String> ids = ListUtils.convertList(list);
|
|
|
emsSafeinfoService.delete(ids);
|
|
|
}
|
|
|
return success();
|
|
@@ -160,143 +157,182 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
@ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "Short")
|
|
|
@PostMapping("/insertExcel")
|
|
|
public RESTfulResult insertExcel (String fileName, MultipartFile file) throws Exception {
|
|
|
- RESTfulResult R = new RESTfulResult();
|
|
|
List<EmsSafeinfo> list = emsSafeinfoService.batchImport(fileName, file);
|
|
|
List<EmsSafeinfo> list2 = new ArrayList<>();
|
|
|
+ EmsSafeinfo res = null;
|
|
|
for (EmsSafeinfo e: list
|
|
|
- ) {
|
|
|
- e.setId("AQ"+IDutils.getImageName());
|
|
|
- e.setCreateman(JwtUtil.getUseridByToken());
|
|
|
- e.setCreatetime(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
|
|
|
- list2.add(e);
|
|
|
+ ) {
|
|
|
+ String selectmaxid = emsSafeinfoMapper.selectmaxid();
|
|
|
+ if(selectmaxid == null){
|
|
|
+ String qqq="AQ"+ DateUtils.getCurrentTime("yyyyMMdd")+"0001";
|
|
|
+ e.setId(qqq);
|
|
|
+ }else {
|
|
|
+ String id1 = selectmaxid.substring(10,14);
|
|
|
+
|
|
|
+ int maxid = Integer.parseInt(id1);
|
|
|
+ int maxid2=maxid+1;
|
|
|
+ String newmaxid ="AQ"+DateUtils.getCurrentTime("yyyyMMdd")+ String.format("%04d", maxid2);
|
|
|
+ e.setId(newmaxid);
|
|
|
+ }
|
|
|
+ res= emsSafeinfoService.add(e);
|
|
|
+
|
|
|
+// e.setCreateman(JwtUtil.getUseridByToken());
|
|
|
+// e.setCreatetime(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
|
|
|
+
|
|
|
}
|
|
|
- int res = emsSafeinfoService.batchAdd(list2);
|
|
|
- if (res>0){
|
|
|
- R.setCode("200");
|
|
|
- return success(R);
|
|
|
+ if (res!=null){
|
|
|
+ return success();
|
|
|
}else {
|
|
|
return failed();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@GetMapping("/downloadExcel")
|
|
|
- public void downloadExcel(HttpServletResponse response,@RequestParam HashMap parmas) throws IOException {
|
|
|
- List<EmsSafeinfo> list = emsSafeinfoService.getList(parmas);
|
|
|
+ public void downloadExcel(HttpServletResponse response, @RequestParam HashMap parmas) throws IOException {
|
|
|
+ String[] arr= null;
|
|
|
+ String[] arr2= null;
|
|
|
+ String dates=null;
|
|
|
+ String dates2=null;
|
|
|
+ if (parmas.get("process")!=null){
|
|
|
+ arr =parmas.get("process").toString().split(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parmas.get("dates")!=null && parmas.get("dates2")!=null){
|
|
|
+ dates=parmas.get("dates").toString();
|
|
|
+ dates2 = parmas.get("dates2").toString();
|
|
|
+ }
|
|
|
+ if (parmas.get("hazard")!=null ){
|
|
|
+ arr2=parmas.get("hazard").toString().split(",");
|
|
|
+ }
|
|
|
+ List<EmsSafeinfo> list = emsSafeinfoMapper.selectByParameters2( dates, dates2, arr2,arr);
|
|
|
|
|
|
- if (list.size()>0){
|
|
|
- OutputStream out = null;
|
|
|
- InputStream is = null;
|
|
|
- //创建Excel文件
|
|
|
- Workbook wb = new XSSFWorkbook();
|
|
|
- //生成sheet
|
|
|
- Sheet sheet = wb.createSheet("sheet1");
|
|
|
- //创建行
|
|
|
- Row row = null;
|
|
|
- //创建列
|
|
|
- Cell cell = null;
|
|
|
- //创建表头单元格样式
|
|
|
- CellStyle cs_header = wb.createCellStyle();
|
|
|
- //设置字体样式
|
|
|
- Font boldFont = wb.createFont();
|
|
|
- //设置文字类型
|
|
|
- boldFont.setFontName("宋体");
|
|
|
- //设置加粗
|
|
|
- boldFont.setBold(true);
|
|
|
- //设置文字大小
|
|
|
- boldFont.setFontHeightInPoints((short) 16);
|
|
|
- //应用设置的字体
|
|
|
- cs_header.setFont(boldFont);
|
|
|
- //设置边框下、左、右、上
|
|
|
- cs_header.setBorderBottom(BorderStyle.THIN);
|
|
|
- cs_header.setBorderLeft(BorderStyle.THIN);
|
|
|
- cs_header.setBorderRight(BorderStyle.THIN);
|
|
|
- cs_header.setBorderTop(BorderStyle.THIN);
|
|
|
- //水平居中
|
|
|
- cs_header.setAlignment(HorizontalAlignment.CENTER);
|
|
|
- //垂直居中
|
|
|
- cs_header.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
- //前景填充色
|
|
|
- cs_header.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
|
|
|
- //设置前景填充样式
|
|
|
- cs_header.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
- //设置标题
|
|
|
- row = sheet.createRow(0);
|
|
|
- //设置单元格行高
|
|
|
- row.setHeightInPoints(24);
|
|
|
- //设置标题
|
|
|
- String[] headers=new String[]{
|
|
|
- "日期","类型","地点","ID","内容","创建时间","创建人","修改时间","修改人","备注"
|
|
|
- };
|
|
|
- //逐个设置标题样式
|
|
|
- for (int i = 0; i < headers.length; i++) {
|
|
|
- //创建单元格
|
|
|
- cell = row.createCell(i);
|
|
|
- //设置单元格内容
|
|
|
- cell.setCellValue(headers[i]);
|
|
|
- //设置单元格样式
|
|
|
- cell.setCellStyle(cs_header);
|
|
|
- }
|
|
|
- //创建文本单元格样式
|
|
|
- CellStyle cs_text = wb.createCellStyle();
|
|
|
- //创建文字设置
|
|
|
- Font textFont = wb.createFont();
|
|
|
- //设置文字类型
|
|
|
- textFont.setFontName("Consolas");
|
|
|
- //设置文字大小
|
|
|
- textFont.setFontHeightInPoints((short) 10);
|
|
|
- //应用设置
|
|
|
- cs_text.setFont(textFont);
|
|
|
- //设置边框
|
|
|
- cs_text.setBorderBottom(BorderStyle.THIN);
|
|
|
- cs_text.setBorderLeft(BorderStyle.THIN);
|
|
|
- cs_text.setBorderRight(BorderStyle.THIN);
|
|
|
- cs_text.setBorderTop(BorderStyle.THIN);
|
|
|
- //水平居中
|
|
|
- cs_text.setAlignment(HorizontalAlignment.CENTER);
|
|
|
- //垂直居中
|
|
|
- cs_text.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
- //调取数据
|
|
|
+ if (list.size()>0){
|
|
|
+ OutputStream out = null;
|
|
|
+ InputStream is = null;
|
|
|
+ //创建Excel文件
|
|
|
+ Workbook wb = new XSSFWorkbook();
|
|
|
+ //生成sheet
|
|
|
+ Sheet sheet = wb.createSheet("sheet1");
|
|
|
+ //创建行
|
|
|
+ Row row = null;
|
|
|
+ //创建列
|
|
|
+ Cell cell = null;
|
|
|
+ //创建表头单元格样式
|
|
|
+ CellStyle cs_header = wb.createCellStyle();
|
|
|
+ //设置字体样式
|
|
|
+ Font boldFont = wb.createFont();
|
|
|
+ //设置文字类型
|
|
|
+ boldFont.setFontName("宋体");
|
|
|
+ //设置加粗
|
|
|
+ boldFont.setBold(true);
|
|
|
+ //设置文字大小
|
|
|
+ boldFont.setFontHeightInPoints((short) 16);
|
|
|
+ //应用设置的字体
|
|
|
+ cs_header.setFont(boldFont);
|
|
|
+ //设置边框下、左、右、上
|
|
|
+ cs_header.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cs_header.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cs_header.setBorderRight(BorderStyle.THIN);
|
|
|
+ cs_header.setBorderTop(BorderStyle.THIN);
|
|
|
+ //水平居中
|
|
|
+ cs_header.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ //垂直居中
|
|
|
+ cs_header.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ //前景填充色
|
|
|
+ cs_header.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
|
|
|
+ //设置前景填充样式
|
|
|
+ cs_header.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ //设置标题
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ //设置单元格行高
|
|
|
+ row.setHeightInPoints(24);
|
|
|
+ //设置标题
|
|
|
+ String[] headers=new String[]{
|
|
|
+ "检查日期","被查单位","ID","隐患内容","检查人","整改措施","整改期限","整改责任人","整改结果","整改日期","验证人","资金","预案","隐患分级","备注"
|
|
|
+ //"日期","类型","地点","ID","内容","创建时间","创建人","修改时间","修改人","备注"
|
|
|
+ };
|
|
|
+ //逐个设置标题样式
|
|
|
+ for (int i = 0; i < headers.length; i++) {
|
|
|
+ //创建单元格
|
|
|
+ cell = row.createCell(i);
|
|
|
+ //设置单元格内容
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
+ //设置单元格样式
|
|
|
+ cell.setCellStyle(cs_header);
|
|
|
+ }
|
|
|
+ //创建文本单元格样式
|
|
|
+ CellStyle cs_text = wb.createCellStyle();
|
|
|
+ //创建文字设置
|
|
|
+ Font textFont = wb.createFont();
|
|
|
+ //设置文字类型
|
|
|
+ textFont.setFontName("Consolas");
|
|
|
+ //设置文字大小
|
|
|
+ textFont.setFontHeightInPoints((short) 10);
|
|
|
+ //应用设置
|
|
|
+ cs_text.setFont(textFont);
|
|
|
+ //设置边框
|
|
|
+ cs_text.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cs_text.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cs_text.setBorderRight(BorderStyle.THIN);
|
|
|
+ cs_text.setBorderTop(BorderStyle.THIN);
|
|
|
+ //水平居中
|
|
|
+ cs_text.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ //垂直居中
|
|
|
+ cs_text.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ //调取数据
|
|
|
|
|
|
- //记录总共多少列(由于接口查询出来的实体类集合,所以不好循环,使用)
|
|
|
- Integer cellSum = 10;
|
|
|
- //将数据写入表格
|
|
|
- for(int i=0; i<list.size(); i++){
|
|
|
- //将实体类集合转成string数组,通过‘,’,获取总共多少列
|
|
|
+ //记录总共多少列(由于接口查询出来的实体类集合,所以不好循环,使用)
|
|
|
+ Integer cellSum = 15;
|
|
|
+ //将数据写入表格
|
|
|
+ for(int i=0; i<list.size(); i++){
|
|
|
+ //将实体类集合转成string数组,通过‘,’,获取总共多少列
|
|
|
// String[] split = list.get(i).toString().split(",");
|
|
|
// cellSum=split.length;
|
|
|
- //创建行,由于0行是标题,所以+1
|
|
|
- row = sheet.createRow(i+1);
|
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS");
|
|
|
- //实体类集合不太好循环,所以逐一设置,如果是其他则可使用for循环
|
|
|
- EmsSafeinfo wpa = (EmsSafeinfo) list.get(i);
|
|
|
- row.createCell(0).setCellValue(wpa.getDates()!=null?wpa.getDates():df.format(Calendar.getInstance().getTime()));
|
|
|
- row.createCell(1).setCellValue(wpa.getType()!=null?wpa.getType():"暂无");
|
|
|
- row.createCell(2).setCellValue(wpa.getProcess()!=null?wpa.getProcess():"暂无");
|
|
|
- row.createCell(3).setCellValue(wpa.getId()!=null?wpa.getId():"暂无");
|
|
|
- row.createCell(4).setCellValue(wpa.getContent()!=null?wpa.getContent():"暂无");
|
|
|
- row.createCell(5).setCellValue(wpa.getCreatetime()!=null?wpa.getCreatetime():"暂无");
|
|
|
- row.createCell(6).setCellValue(wpa.getCreateman()!=null?wpa.getCreateman():"暂无");
|
|
|
- row.createCell(7).setCellValue(wpa.getUpdatetime()!=null?wpa.getUpdatetime():"暂无");
|
|
|
- row.createCell(8).setCellValue(wpa.getUpdateman()!=null?wpa.getUpdateman():"暂无");
|
|
|
- row.createCell(9).setCellValue(wpa.getMemo()!=null?wpa.getMemo():"暂无");
|
|
|
- //为每一个单元格设置样式
|
|
|
- for (int j=0;j<cellSum;j++){
|
|
|
- row.getCell(j).setCellStyle(cs_text);
|
|
|
- }
|
|
|
- }
|
|
|
- //合并单元格,横向
|
|
|
- sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 11, 12));
|
|
|
- sheet.addMergedRegionUnsafe(new CellRangeAddress(1,1,3,4));
|
|
|
- //竖着合并
|
|
|
- sheet.addMergedRegionUnsafe(new CellRangeAddress(1,list.size(),4,4));
|
|
|
- //设置单元格宽度自适应
|
|
|
- for (int i = 0; i <= cellSum; i++)
|
|
|
- {
|
|
|
- sheet.autoSizeColumn((short)i,true); //自动调整列宽
|
|
|
- }
|
|
|
- //设置中文文件名称
|
|
|
- int year = Calendar.getInstance().get(Calendar.YEAR);
|
|
|
- String fileName = year+"";
|
|
|
+ //创建行,由于0行是标题,所以+1
|
|
|
+ row = sheet.createRow(i+1);
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS");
|
|
|
+ //实体类集合不太好循环,所以逐一设置,如果是其他则可使用for循环
|
|
|
+ EmsSafeinfo wpa = (EmsSafeinfo) list.get(i);
|
|
|
+ if (wpa.getMoney()== null ||wpa.getMoney().equals("")){
|
|
|
+ wpa.setMoney(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ row.createCell(0).setCellValue(wpa.getCreatetime()!=null?wpa.getCreatetime():"检查日期");
|
|
|
+ row.createCell(1).setCellValue(wpa.getProcess()!=null?wpa.getProcess():"被查单位");
|
|
|
+ row.createCell(2).setCellValue(wpa.getId()!=null?wpa.getId():"ID");
|
|
|
+ row.createCell(3).setCellValue(wpa.getContent()!=null?wpa.getContent():"隐患内容");
|
|
|
+ row.createCell(4).setCellValue(wpa.getCreateman()!=null?wpa.getCreateman():"检查人");
|
|
|
+ row.createCell(5).setCellValue(wpa.getMeasure()!=null?wpa.getMeasure():"整改措施");
|
|
|
+ row.createCell(6).setCellValue(wpa.getUpdatetime()!=null?wpa.getUpdatetime():"整改期限");
|
|
|
+ row.createCell(7).setCellValue(wpa.getUpdateman()!=null?wpa.getUpdateman():"整改责任人");
|
|
|
+ row.createCell(8).setCellValue(wpa.getFilename()!=null?wpa.getFilename():"整改结果");
|
|
|
+ row.createCell(9).setCellValue(wpa.getRectificationdate()!=null?wpa.getRectificationdate():"整改日期");
|
|
|
+ row.createCell(10).setCellValue(wpa.getVerify()!=null?wpa.getVerify():"验证人");
|
|
|
+ row.createCell(11).setCellValue(wpa.getMoney().toString()!=null?wpa.getMoney().toString():"资金");
|
|
|
+ row.createCell(12).setCellValue(wpa.getPlan()!=null?wpa.getPlan():"预案");
|
|
|
+ row.createCell(13).setCellValue(wpa.getHazard()!=null?wpa.getHazard():"隐患分级");
|
|
|
+ row.createCell(14).setCellValue(wpa.getMemo()!=null?wpa.getMemo():"备注");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //为每一个单元格设置样式
|
|
|
+ for (int j=0;j<cellSum;j++){
|
|
|
+ row.getCell(j).setCellStyle(cs_text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //合并单元格,横向
|
|
|
+ // sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 11, 12));
|
|
|
+ // sheet.addMergedRegionUnsafe(new CellRangeAddress(1,1,3,4));
|
|
|
+ //竖着合并
|
|
|
+ //sheet.addMergedRegionUnsafe(new CellRangeAddress(1,list.size(),4,4));
|
|
|
+ //设置单元格宽度自适应
|
|
|
+ for (int i = 0; i <= cellSum; i++)
|
|
|
+ {
|
|
|
+ sheet.autoSizeColumn((short)i,true); //自动调整列宽
|
|
|
+ }
|
|
|
+ //设置中文文件名称
|
|
|
+ int year = Calendar.getInstance().get(Calendar.YEAR);
|
|
|
+ String fileName = year+"";
|
|
|
// response.reset();
|
|
|
// //浏览器默认服务器传过去的是html,不是excel文件
|
|
|
// //设置响应类型:传输内容是流,并支持中文
|
|
@@ -307,25 +343,24 @@ public class EmsSafeinfoController extends BaseRESTfulController {
|
|
|
// //输出流对象
|
|
|
// wb.write(out);
|
|
|
// wb.close();
|
|
|
- String transferName = new String(fileName.getBytes(Charsets.UTF_8),Charsets.ISO_8859_1);
|
|
|
+ String transferName = new String(fileName.getBytes(Charsets.UTF_8),Charsets.ISO_8859_1);
|
|
|
|
|
|
- out = response.getOutputStream();
|
|
|
- response.setCharacterEncoding("UTF-8");
|
|
|
- response.setContentType("multipart/form-data;charset=UTF-8");
|
|
|
- // response.setContentType("application/vnd.ms-excel");
|
|
|
- // response.setHeader("Content-Disposition", "attachment; filename=\"" + transferName + "\"");
|
|
|
- response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("gbk"), "iso8859-1")+".xlsx");
|
|
|
- wb.write(out);
|
|
|
- wb.close();
|
|
|
- out.flush();
|
|
|
- out.close();
|
|
|
+ out = response.getOutputStream();
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("multipart/form-data;charset=UTF-8");
|
|
|
+ // response.setContentType("application/vnd.ms-excel");
|
|
|
+ // response.setHeader("Content-Disposition", "attachment; filename=\"" + transferName + "\"");
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("gbk"), "iso8859-1")+".xlsx");
|
|
|
+ wb.write(out);
|
|
|
+ wb.close();
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
|
|
|
- }else {
|
|
|
- //return failed();
|
|
|
- }
|
|
|
- //强制刷新
|
|
|
+ }else {
|
|
|
+ //return failed();
|
|
|
+ }
|
|
|
+ //强制刷新
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|