2024年7月8日 新增导入后直接生成导出内容
This commit is contained in:
parent
373be9bd89
commit
8fa0a8c0ac
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.modules.demo.blStuAnswer.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -12,6 +13,8 @@ import org.jeecg.common.system.base.controller.JeecgController;
|
|||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.modules.demo.blStuAnswer.entity.BlStuAnswer;
|
||||
import org.jeecg.modules.demo.blStuAnswer.service.IBlStuAnswerService;
|
||||
import org.jeecg.modules.demo.blStuInfo.entity.BlStuInfo;
|
||||
import org.jeecg.modules.demo.blStuInfo.service.IBlStuInfoService;
|
||||
import org.jeecg.modules.tools.word.ExportWord;
|
||||
import org.jeecg.modules.tools.word.WordOperator;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
|
@ -40,10 +43,15 @@ import java.util.Map;
|
|||
@RequestMapping("/blStuAnswer/blStuAnswer")
|
||||
@Slf4j
|
||||
public class BlStuAnswerController extends JeecgController<BlStuAnswer, IBlStuAnswerService> {
|
||||
|
||||
@Autowired
|
||||
private IBlStuAnswerService blStuAnswerService;
|
||||
|
||||
/**
|
||||
|
||||
@Autowired
|
||||
private IBlStuInfoService blStuInfoService;
|
||||
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param blStuAnswer
|
||||
|
@ -175,9 +183,7 @@ public class BlStuAnswerController extends JeecgController<BlStuAnswer, IBlStuAn
|
|||
params.setNeedSave(true);
|
||||
try {
|
||||
List<BlStuAnswer> list = ExcelImportUtil.importExcel(file.getInputStream(), BlStuAnswer.class, params);
|
||||
list.forEach(x->{
|
||||
x.setMainId(id);
|
||||
});
|
||||
list.forEach(x-> x.setMainId(id));
|
||||
//update-begin-author:taoyan date:20190528 for:批量插入数据
|
||||
long start = System.currentTimeMillis();
|
||||
service.saveBatch(list);
|
||||
|
@ -188,8 +194,14 @@ public class BlStuAnswerController extends JeecgController<BlStuAnswer, IBlStuAn
|
|||
//直接导出附件
|
||||
WordOperator wo = service.createWordTjfx(id);
|
||||
//保存到本地附件里
|
||||
// String exportWordPath = ExportWord.wordPathToLocalFile(wo,"学生问卷详细信息.docx", "exportWords");
|
||||
//保存到主表里
|
||||
// var updateWp = new UpdateWrapper<BlStuInfo>();
|
||||
// updateWp.lambda().eq(BlStuInfo::getId, id);
|
||||
// updateWp.lambda().set()
|
||||
// blStuInfoService.update(updateWp);
|
||||
|
||||
|
||||
ExportWord.download_by_is();
|
||||
//update-end-author:taoyan date:20190528 for:批量插入数据
|
||||
return Result.ok("文件导入成功!数据行数:" + list.size());
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -3,22 +3,26 @@ package org.jeecg.modules.tools.word;
|
|||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.util.CommonUtils;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.tools.FileUtils;
|
||||
import org.jeecg.modules.tools.Global;
|
||||
import org.jeecg.modules.tools.IdGen;
|
||||
import org.jeecg.modules.tools.pdf.PDFUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -26,6 +30,7 @@ import java.util.List;
|
|||
* 导出word工具类
|
||||
* @author binzec
|
||||
*/
|
||||
@Slf4j
|
||||
public class ExportWord {
|
||||
|
||||
private static Global global = SpringContextUtils.getBean(Global.class);
|
||||
|
@ -73,10 +78,6 @@ public class ExportWord {
|
|||
return new WordOperator(is);
|
||||
}
|
||||
|
||||
// public static String getWordPathToLocalFile(String biz){
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* 下载生成的word文档
|
||||
* @param request 请求
|
||||
|
@ -449,6 +450,48 @@ public class ExportWord {
|
|||
}
|
||||
}
|
||||
|
||||
//返回个附件地址,文档吐到此处
|
||||
public static String wordPathToLocalFile(WordOperator wordOperator, String name, String bizPath){
|
||||
OutputStream os = null;
|
||||
try {
|
||||
String ctxPath = global.uploadPath;
|
||||
String fileName;
|
||||
File file = new File(ctxPath + File.separator + bizPath + File.separator );
|
||||
if (!file.exists()) {
|
||||
// 创建文件根目录
|
||||
file.mkdirs();
|
||||
}
|
||||
// 获取文件名
|
||||
String orgName = name;
|
||||
orgName = CommonUtils.getFileName(orgName);
|
||||
if(orgName.contains(SymbolConstant.SPOT)){
|
||||
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
|
||||
}else{
|
||||
fileName = orgName+ "_" + System.currentTimeMillis();
|
||||
}
|
||||
String savePath = file.getPath() + File.separator + fileName;
|
||||
File savefile = new File(savePath);
|
||||
//FileCopyUtils.copy(mf.getBytes(), savefile);
|
||||
os = FileUtil.getOutputStream(savefile);
|
||||
wordOperator.write(os);
|
||||
String dbpath;
|
||||
if(oConvertUtils.isNotEmpty(bizPath)){
|
||||
dbpath = bizPath + File.separator + fileName;
|
||||
}else{
|
||||
dbpath = fileName;
|
||||
}
|
||||
if (dbpath.contains(SymbolConstant.DOUBLE_BACKSLASH)) {
|
||||
dbpath = dbpath.replace(SymbolConstant.DOUBLE_BACKSLASH, SymbolConstant.SINGLE_SLASH);
|
||||
}
|
||||
return dbpath;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
IoUtil.close(os);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String mergeDocx(List<String> fileNames) throws Exception {
|
||||
return MergeDoc.mergeDocx(fileNames,global.getTmpDickPath());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue