update:修复导出

This commit is contained in:
zzy
2021-07-28 10:10:25 +08:00
parent 2428b39e79
commit b3630e8ad6
3 changed files with 60 additions and 24 deletions
@@ -21,6 +21,7 @@ import com.adc.da.base.web.BaseController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@@ -117,14 +118,19 @@ public class SarLawsAttrDetailedListController extends BaseController<SarLawsAtt
@ApiOperation(value = "导出标准信息")
@GetMapping("/ExportLawsById")
public void ExportLawsById(HttpServletResponse response, StandExcelVo standExcelVo){
try {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
if(standExcelVo.getExportName()==null){
standExcelVo.setExportName("标准导出信息");
}
String fileName = URLEncoder.encode(standExcelVo.getExportName(), "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
String fileName = null;
try {
fileName = URLEncoder.encode(standExcelVo.getExportName(), "UTF-8").replaceAll("\\+", "%20");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
List<LawsDto> data = new ArrayList<>();
if (CollectionUtils.isEmpty(standExcelVo.getIds())){
List<String> list= sarLawsAttrDetailedListDao.selectLawsId2(standExcelVo.getId());
@@ -248,10 +254,14 @@ public class SarLawsAttrDetailedListController extends BaseController<SarLawsAtt
}
}
}
try {
EasyExcel.write(response.getOutputStream(), LawsDto.class).useDefaultStyle(false).autoCloseStream(Boolean.FALSE).sheet("sheet1")
.doWrite(data);
} catch (Exception e) {
response.reset();
} catch (IOException e) {
e.printStackTrace();
}
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
try {
@@ -261,6 +271,6 @@ public class SarLawsAttrDetailedListController extends BaseController<SarLawsAtt
}
}
}
}
@@ -26,66 +26,90 @@ import lombok.NoArgsConstructor;
public class LawsDto {
@ApiModelProperty(value = "主键")
private String id;
@ExcelProperty(value = "标准编号")
@ExcelProperty(value = "标准编号", index = 0)
@ApiModelProperty(value = "标准编号")
private String standNumber;
@ExcelProperty(value = "中文名称")
@ExcelProperty(value = "中文名称", index = 1)
@ApiModelProperty(value = "中文名称")
private String standName;
@ExcelProperty(value = "英文名称")
@ExcelProperty(value = "英文名称", index = 2)
@ApiModelProperty(value = "英文名称")
private String standEnName;
@ExcelProperty(value = "适用车型")
@ExcelProperty(value = "适用车型", index = 3)
@ApiModelProperty(value = "适用车型")
private String typeApplicable;
@ExcelProperty(value = "能源类型")
@ExcelProperty(value = "能源类型", index = 4)
@ApiModelProperty(value = "能源类型")
private String NYLX;
@ExcelProperty(value = "标准年份")
@ApiModelProperty(value = "标准年份")
@ExcelProperty(value = "标准年份", index = 5)
private String standYear;
@ExcelProperty(value = "标准类别")
@ApiModelProperty(value = "标准类别")
@ExcelProperty(value = "标准类别", index = 6)
private String standSortShow;
@ApiModelProperty(value = "标准发表日期")
@ExcelProperty(value = "标准发表日期", index = 7)
private String issueTime;
@ColumnWidth(16)
@ExcelProperty(value = "标准实施日期")
@ExcelProperty(value = "标准实施日期", index = 8)
@ApiModelProperty(value = "标准实施日期")
@DateTimeFormat("yyyy年MM月dd日")
private String putTime;
@ColumnWidth(16)
@ExcelProperty(value = "新车型实施日期")
@ExcelProperty(value = "新车型实施日期", index = 9)
@ApiModelProperty(value = "新车型实施日期")
@DateTimeFormat("yyyy年MM月dd日")
private String XCXSSRQGJ;
@ColumnWidth(16)
@ExcelProperty(value = "在产车实施日期")
@ExcelProperty(value = "在产车实施日期", index = 10)
@ApiModelProperty(value = "在产车实施日期")
@DateTimeFormat("yyyy年MM月dd日")
private String ZCCSSRQGJ;
@ExcelProperty(value = "责任部门")
@ExcelProperty(value = "责任部门", index = 11)
@ApiModelProperty(value = "责任部门")
private String ZRBM;
@ColumnWidth(14)
@ExcelProperty(value = "适用产品线")
@ExcelProperty(value = "适用产品线", index = 12)
@ApiModelProperty(value = "适用产品线")
private String SYCPX;
@ColumnWidth(20)
@ExcelProperty(value = "乘用车VPPS编码")
@ExcelProperty(value = "乘用车VPPS编码", index = 13)
@ApiModelProperty(value = "乘用车VPPS编码")
private String CYCVPPSBM;
@ColumnWidth(20)
@ExcelProperty(value = "乘用车vpps中文名称")
@ExcelProperty(value = "乘用车vpps中文名称", index = 14)
@ApiModelProperty(value = "乘用车vpps中文名称")
private String CYCVPPSCN;
@ColumnWidth(20)
@ExcelProperty(value = "卡车VPPS编码")
@ExcelProperty(value = "卡车VPPS编码", index = 15)
@ApiModelProperty(value = "卡车VPPS编码")
private String KCCVPPSBM;
@ColumnWidth(20)
@ExcelProperty(value = "卡车vpps中文名称")
@ExcelProperty(value = "卡车vpps中文名称", index = 16)
@ApiModelProperty(value = "卡车vpps中文名称")
private String KCCVPPSCN;
@ApiModelProperty(value = "责任工程师")
@ExcelProperty(value = "责任工程师")
@ExcelProperty(value = "责任工程师", index = 17)
private String responsibleEngineer;
@ApiModelProperty(value = "1")
private String standType;
}