法规意见收集-评估结果带文件导出接口开发。
This commit is contained in:
+16
-3
@@ -3,6 +3,7 @@ package com.jero.modules.lawsOpinionGather.controller;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -19,7 +20,6 @@ import com.jero.common.system.base.controller.JeroController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
@@ -153,10 +153,23 @@ public class LawsOpinionAssessmentResultEOController extends JeroController<Laws
|
||||
* @param request
|
||||
* @param lawsOpinionAssessmentResultEO
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
/*@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, LawsOpinionAssessmentResultEO lawsOpinionAssessmentResultEO) {
|
||||
return super.exportXls(request, lawsOpinionAssessmentResultEO, LawsOpinionAssessmentResultEO.class, "法规意见收集-评估结果表");
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
* @param response
|
||||
* @param request
|
||||
* @param lawsOpinionAssessmentResultEO
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public void exportXls(HttpServletResponse response,HttpServletRequest request,
|
||||
LawsOpinionAssessmentResultEO lawsOpinionAssessmentResultEO,
|
||||
@RequestParam Map<String,Object> params) {
|
||||
this.lawsOpinionAssessmentResultEOService.exportXls(response,request, lawsOpinionAssessmentResultEO,params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
|
||||
+3
@@ -4,6 +4,7 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
@@ -82,6 +83,8 @@ public class LawsOpinionAssessmentResultEO implements Serializable {
|
||||
@Excel(name = "附件", width = 15)
|
||||
@ApiModelProperty(value = "附件")
|
||||
private String accessoryFile;
|
||||
@TableField(exist = false)
|
||||
private String accessoryFileName;
|
||||
|
||||
/**提出时间*/
|
||||
@Excel(name = "提出时间", width = 15, format = "yyyy-MM-dd")
|
||||
|
||||
+4
@@ -5,7 +5,9 @@ import com.jero.modules.lawsOpinionGather.entity.LawsOpinionAssessmentResultEO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 法规意见收集-评估结果表
|
||||
@@ -67,4 +69,6 @@ public interface ILawsOpinionAssessmentResultEOService extends IService<LawsOpin
|
||||
* @param json
|
||||
*/
|
||||
void insertBatch(JSONObject json);
|
||||
|
||||
void exportXls(HttpServletResponse response, HttpServletRequest request, LawsOpinionAssessmentResultEO lawsOpinionAssessmentResultEO, Map<String,Object> params);
|
||||
}
|
||||
|
||||
+227
-3
@@ -1,23 +1,44 @@
|
||||
package com.jero.modules.lawsOpinionGather.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.utils.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.constant.enums.CutEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.oss.CosBootUtil;
|
||||
import com.jero.modules.lawsOpinionGather.entity.LawsOpinionAssessmentResultEO;
|
||||
import com.jero.modules.lawsOpinionGather.entity.LawsOpinionGatherEO;
|
||||
import com.jero.modules.lawsOpinionGather.mapper.LawsOpinionAssessmentResultEOMapper;
|
||||
import com.jero.modules.lawsOpinionGather.service.ILawsOpinionAssessmentResultEOService;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.system.util.PDFUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @Description: 法规意见收集-评估结果表
|
||||
@@ -28,6 +49,12 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@Service
|
||||
public class LawsOpinionAssessmentResultEOServiceImpl extends ServiceImpl<LawsOpinionAssessmentResultEOMapper, LawsOpinionAssessmentResultEO> implements ILawsOpinionAssessmentResultEOService {
|
||||
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
@Autowired
|
||||
private IOSSFileService iOSSFileService;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
@@ -125,4 +152,201 @@ public class LawsOpinionAssessmentResultEOServiceImpl extends ServiceImpl<LawsOp
|
||||
this.saveBatch(lawsOpinionAssessmentResultEOList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportXls(HttpServletResponse response, HttpServletRequest request, LawsOpinionAssessmentResultEO lawsOpinionAssessmentResultEO, Map<String,Object> params) {
|
||||
|
||||
Integer pageNo = (Integer) params.getOrDefault("pageNo",1);
|
||||
Integer pageSize = (Integer) params.getOrDefault("pageNo",10);
|
||||
String exportAll = (String)params.get("exportAll");
|
||||
String ids = (String)params.get("ids");
|
||||
String cut = (String)params.get("cut");
|
||||
String exportType = (String)params.get("exportType");
|
||||
List<LawsOpinionAssessmentResultEO> exportData = new ArrayList<>();
|
||||
QueryWrapper<LawsOpinionAssessmentResultEO> queryWrapper = QueryGenerator.initQueryWrapper(lawsOpinionAssessmentResultEO, request.getParameterMap());
|
||||
if(StringUtils.isNotEmpty(ids)){
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
queryWrapper.lambda().in(LawsOpinionAssessmentResultEO::getId,idList);
|
||||
}
|
||||
if(StringUtils.equals(exportAll,"yes")){
|
||||
exportData = this.baseMapper.selectList(queryWrapper);
|
||||
}else {
|
||||
Page<LawsOpinionAssessmentResultEO> page = new Page<LawsOpinionAssessmentResultEO>(pageNo, pageSize);
|
||||
IPage<LawsOpinionAssessmentResultEO> pageList = this.page(page, queryWrapper);
|
||||
exportData = pageList.getRecords();
|
||||
}
|
||||
|
||||
this.disposeData(exportData,cut);
|
||||
|
||||
String title = "";
|
||||
String fileName = "";
|
||||
if(StringUtils.equals(cut, CutEnum.CN.getValue())){
|
||||
title = "相关章节,问题/建议,理由,附件,评估人,提出时间";
|
||||
fileName = "评估结果 " + ".xlsx";
|
||||
}else if(StringUtils.equals(cut,CutEnum.EN.getValue())){
|
||||
title = "Related section,IssueOrSuggest,Reason,Accessory,Evaluator,Submit Date";
|
||||
fileName = "Evaluation results " + ".xlsx";
|
||||
}
|
||||
|
||||
OutputStream os = null;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
|
||||
try {
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=" + fileName);
|
||||
response.setContentType("application/force-download");
|
||||
|
||||
HSSFSheet sheet = workbook.createSheet("sheet1");
|
||||
|
||||
CellStyle titleCellStyle = workbook.createCellStyle();
|
||||
titleCellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中
|
||||
titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//水平居中
|
||||
titleCellStyle.setWrapText(true);//自动换行
|
||||
|
||||
Row firstRow = sheet.createRow(0);
|
||||
|
||||
//创建表头
|
||||
String[] titleArr = title.split(",");
|
||||
for (int i=0; i<=5; i++){
|
||||
sheet.setColumnWidth(i,4000);
|
||||
Cell cell = firstRow.createCell(i);
|
||||
cell.setCellStyle(titleCellStyle);
|
||||
cell.setCellValue(titleArr[i]);
|
||||
}
|
||||
|
||||
//设置导出数据
|
||||
if(CollectionUtils.isNotEmpty(exportData)) {
|
||||
for (int dataIndex = 0; dataIndex < exportData.size(); dataIndex++) {
|
||||
Row dataRow = sheet.createRow(dataIndex + 1);
|
||||
dataRow.createCell(0).setCellValue(exportData.get(dataIndex).getRelatedSection());
|
||||
dataRow.createCell(1).setCellValue(exportData.get(dataIndex).getIssueOrSuggest());
|
||||
dataRow.createCell(2).setCellValue(exportData.get(dataIndex).getReason());
|
||||
dataRow.createCell(3).setCellValue(exportData.get(dataIndex).getAccessoryFileName());
|
||||
dataRow.createCell(4).setCellValue(exportData.get(dataIndex).getCreateBy());
|
||||
String submitTimeStr = disposeDate(exportData.get(dataIndex).getSubmitTime());
|
||||
dataRow.createCell(5).setCellValue(submitTimeStr);
|
||||
}
|
||||
}
|
||||
if ("excel".equals(exportType)) {
|
||||
os = response.getOutputStream();
|
||||
workbook.write(os);
|
||||
os.flush();
|
||||
}else {
|
||||
String path = uploadpath + "/tempZip/evaluationResults";
|
||||
File fileTemp = new File(path);
|
||||
if (fileTemp.exists()) {
|
||||
fileTemp.delete();
|
||||
}
|
||||
fileTemp.mkdirs();
|
||||
//excel
|
||||
OutputStream excelOS = new FileOutputStream(path + File.separator + fileName);
|
||||
workbook.write(excelOS);
|
||||
excelOS.flush();
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
|
||||
for (LawsOpinionAssessmentResultEO data : exportData) {
|
||||
String accessoryFile = data.getAccessoryFile();
|
||||
|
||||
List<OSSFile> fileInfosList = iOSSFileService.getFileInfos(accessoryFile);
|
||||
if (fileInfosList.size() != 0) {
|
||||
for (OSSFile ossFile : fileInfosList) {
|
||||
String url = ossFile.getUrl();
|
||||
//判断文件是否存在
|
||||
if(StringUtils.isNotBlank(url)){
|
||||
//判断文件是否存在
|
||||
boolean b = CosBootUtil.doesObjectExist(url);
|
||||
if(b){
|
||||
InputStream download = CosBootUtil.download(url);
|
||||
if(url.endsWith(".pdf") || url.endsWith(".PDF")){
|
||||
String currentTime = sdf.format(new Date());
|
||||
String waterContent = loginUser.getUsername() + " " + currentTime;
|
||||
File newFile = PDFUtils.PDFWatermark(download,uploadpath,ossFile.getFileName(),waterContent);
|
||||
download = new FileInputStream(newFile.getPath());
|
||||
}
|
||||
copyFile(download, path + File.separator + ossFile.getFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ZipUtil.zip(path, path + ".zip");
|
||||
//文件
|
||||
FileInputStream fis = new FileInputStream(path + ".zip");
|
||||
os = response.getOutputStream();
|
||||
|
||||
int len = 0;
|
||||
while ((len = fis.read()) != -1) {
|
||||
os.write(len);
|
||||
}
|
||||
os.flush();
|
||||
fis.close();
|
||||
}
|
||||
|
||||
}catch (IOException ex){
|
||||
if(CutEnum.CN.getValue().equals(cut)){
|
||||
throw new JeroBootException("下载文件失败");
|
||||
}else{
|
||||
throw new JeroBootException("Failed to download file");
|
||||
}
|
||||
}finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
File file = new File(uploadpath + "/tempZip/evaluationResults");
|
||||
FileUtil.deleteContents(file);
|
||||
File fileTemp = new File(uploadpath + "/tempZip/evaluationResults.zip");
|
||||
FileUtil.deleteContents(fileTemp);
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFile(InputStream in, String newFile) throws IOException {
|
||||
File file2 = new File(newFile);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
try (FileOutputStream ou = new FileOutputStream(newFile);) {
|
||||
byte[] bs = new byte[1024];
|
||||
int count = 0;
|
||||
while ((count = in.read(bs, 0, bs.length)) != -1) {
|
||||
ou.write(bs, 0, count);
|
||||
}
|
||||
ou.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("复制文件失败!");
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据
|
||||
* @param datas
|
||||
* @param cut
|
||||
*/
|
||||
public void disposeData(List<LawsOpinionAssessmentResultEO> datas,String cut){
|
||||
if(CollectionUtils.isNotEmpty(datas)){
|
||||
for (LawsOpinionAssessmentResultEO data : datas) {
|
||||
if(StringUtils.isNotEmpty(data.getAccessoryFile())){
|
||||
List<OSSFile> accessoryFileList = iOSSFileService.getFileInfos(data.getAccessoryFile());
|
||||
String accessoryFileName = accessoryFileList.stream().map(OSSFile::getFileName).collect(Collectors.joining(","));
|
||||
data.setAccessoryFileName(accessoryFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String disposeDate(Date date){
|
||||
String result = "";
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
if(date != null){
|
||||
result = sdf.format(date);
|
||||
}
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
log.error("处理日期失败:" +ex.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user