diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/blStuAnswer/controller/BlStuAnswerController.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/blStuAnswer/controller/BlStuAnswerController.java index 41a230b..77e3bd1 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/blStuAnswer/controller/BlStuAnswerController.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/blStuAnswer/controller/BlStuAnswerController.java @@ -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 { + @Autowired private IBlStuAnswerService blStuAnswerService; - - /** + + @Autowired + private IBlStuInfoService blStuInfoService; + + + /** * 分页列表查询 * * @param blStuAnswer @@ -175,9 +183,7 @@ public class BlStuAnswerController extends JeecgController 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(); +// 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) { diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/tools/word/ExportWord.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/tools/word/ExportWord.java index c5ac178..62a5fe0 100644 --- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/tools/word/ExportWord.java +++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/tools/word/ExportWord.java @@ -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 fileNames) throws Exception { return MergeDoc.mergeDocx(fileNames,global.getTmpDickPath()); } diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml index 2c6cf06..d519e8f 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml @@ -329,7 +329,7 @@ libreOffice: webDriver: driverName: webdriver.chrome.driver # 浏览器完整路径 - webExamplePath: 'C:/Users/86170/AppData/Local/Google/Chrome/Application/chrome.exe' + webExamplePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe' # 驱动地址 driverPath: web/webDriver/126.0.6478.127/chromedriver.exe # html地址