|
|
@ -1,31 +1,37 @@
|
|
|
|
package com.gmh.controller;
|
|
|
|
package com.gmh.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.gmh.entity.GmhUser;
|
|
|
|
import com.gmh.entity.*;
|
|
|
|
import com.gmh.entity.R;
|
|
|
|
import com.gmh.entity.properties.FileServerProperties;
|
|
|
|
import com.gmh.entity.RowCellNum;
|
|
|
|
import com.gmh.entity.query.ExecuteTemplateQuery;
|
|
|
|
import com.gmh.entity.SysBaijiaxing;
|
|
|
|
|
|
|
|
import com.gmh.entity.vo.ReadNameVo;
|
|
|
|
import com.gmh.entity.vo.ReadNameVo;
|
|
|
|
|
|
|
|
import com.gmh.service.GmhFileLogService;
|
|
|
|
|
|
|
|
import com.gmh.service.FileService;
|
|
|
|
import com.gmh.service.SysBaijiaxingService;
|
|
|
|
import com.gmh.service.SysBaijiaxingService;
|
|
|
|
import com.gmh.utils.CommonUtils;
|
|
|
|
import com.gmh.utils.StringUtils;
|
|
|
|
import com.gmh.utils.POIExcelUtil;
|
|
|
|
import com.gmh.utils.POIExcelUtil;
|
|
|
|
import com.gmh.utils.RedisUtils;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import com.gmh.utils.RedisUtilsDefault;
|
|
|
|
import lombok.Getter;
|
|
|
|
|
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItem;
|
|
|
|
|
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
import org.apache.poi.ss.util.CellReference;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.validation.constraints.Pattern;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
@ -36,11 +42,19 @@ import java.util.stream.Collectors;
|
|
|
|
@RequestMapping("/excel")
|
|
|
|
@RequestMapping("/excel")
|
|
|
|
public class ExcelController {
|
|
|
|
public class ExcelController {
|
|
|
|
|
|
|
|
|
|
|
|
private Integer templateSheetNum = null;
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private FileService fileService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private GmhFileLogService gmhFileLogService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private FileServerProperties fileProperties;
|
|
|
|
|
|
|
|
|
|
|
|
private Workbook templateWorkbook = null;
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SysBaijiaxingService baijiaxingService;
|
|
|
|
|
|
|
|
|
|
|
|
private List<ReadNameVo> readNameVoList = null;
|
|
|
|
private final ExcelInfo excelInfo = new ExcelInfo();
|
|
|
|
|
|
|
|
|
|
|
|
private static final String KEY_XINGMING = "姓名";
|
|
|
|
private static final String KEY_XINGMING = "姓名";
|
|
|
|
|
|
|
|
|
|
|
@ -52,57 +66,68 @@ public class ExcelController {
|
|
|
|
return R.ok("ok");
|
|
|
|
return R.ok("ok");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/readData")
|
|
|
|
@RequestMapping("/dataSourceImport")
|
|
|
|
public R readSourceData(MultipartFile file) throws IOException {
|
|
|
|
public R dataSourceImport(MultipartFile file, String dataSourceImportModel) throws IOException {
|
|
|
|
|
|
|
|
DataSourceImportModel importModel = DataSourceImportModel.findEnum(dataSourceImportModel);
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
readNameVoList = new ArrayList<>();
|
|
|
|
FileEntity fileEntity = fileService.uploadFile(file);
|
|
|
|
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
|
|
|
|
gmhFileLogService.recordLog(fileEntity, GmhFileLog.OperateType.D_S_IMP);
|
|
|
|
ReadNameVo readNameVo = new ReadNameVo();
|
|
|
|
if (DataSourceImportModel.AUTO_NAME.equals(importModel)) {
|
|
|
|
Sheet sheet = workbook.getSheetAt(i);
|
|
|
|
List<ReadNameVo> readNameVoList = new ArrayList<>();
|
|
|
|
List<Map<String, String>> excelMaps = POIExcelUtil.toListMap(sheet);
|
|
|
|
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
|
|
|
|
if (excelMaps.isEmpty()) {
|
|
|
|
ReadNameVo readNameVo = new ReadNameVo();
|
|
|
|
continue;
|
|
|
|
Sheet sheet = workbook.getSheetAt(i);
|
|
|
|
}
|
|
|
|
List<Map<String, String>> excelMaps = POIExcelUtil.toListMap(sheet);
|
|
|
|
Map<String, String> firstElement = excelMaps.get(0);
|
|
|
|
if (excelMaps.isEmpty()) {
|
|
|
|
String xmKey = KEY_XINGMING;
|
|
|
|
continue;
|
|
|
|
for (String key : firstElement.keySet()) {
|
|
|
|
|
|
|
|
if (KEY_XINGMING.equals(firstElement.get(key))) {
|
|
|
|
|
|
|
|
xmKey = key;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<String, String> firstElement = excelMaps.get(0);
|
|
|
|
if (firstElement.containsKey(xmKey)) {
|
|
|
|
String xmKey = KEY_XINGMING;
|
|
|
|
if (!KEY_XINGMING.equals(xmKey)) {
|
|
|
|
for (String key : firstElement.keySet()) {
|
|
|
|
excelMaps.remove(firstElement);
|
|
|
|
if (KEY_XINGMING.equals(firstElement.get(key))) {
|
|
|
|
|
|
|
|
xmKey = key;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
readNameVo = getReadNameDataForNameKey(excelMaps, xmKey);
|
|
|
|
if (firstElement.containsKey(xmKey)) {
|
|
|
|
} else {
|
|
|
|
if (!KEY_XINGMING.equals(xmKey)) {
|
|
|
|
Map<String, Integer> map = new HashMap<>();
|
|
|
|
excelMaps.remove(firstElement);
|
|
|
|
for (Map<String, String> excelMap : excelMaps) {
|
|
|
|
}
|
|
|
|
for (String key : excelMap.keySet()) {
|
|
|
|
readNameVo = getReadNameDataForNameKey(excelMaps, xmKey);
|
|
|
|
String value = excelMap.get(key);
|
|
|
|
} else {
|
|
|
|
if (baijiaxingService.likeChineseName(value)) {
|
|
|
|
Map<String, Integer> map = new HashMap<>();
|
|
|
|
Integer count = map.getOrDefault(key, 0);
|
|
|
|
for (Map<String, String> excelMap : excelMaps) {
|
|
|
|
map.put(key, ++count);
|
|
|
|
for (String key : excelMap.keySet()) {
|
|
|
|
|
|
|
|
String value = excelMap.get(key);
|
|
|
|
|
|
|
|
if (baijiaxingService.likeChineseName(value)) {
|
|
|
|
|
|
|
|
Integer count = map.getOrDefault(key, 0);
|
|
|
|
|
|
|
|
map.put(key, ++count);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Map.Entry<String,Integer>> list = new ArrayList<>(map.entrySet());
|
|
|
|
List<Map.Entry<String,Integer>> list = new ArrayList<>(map.entrySet());
|
|
|
|
|
|
|
|
// list.sort(Comparator.comparingInt(Map.Entry::getValue)); //升序
|
|
|
|
// list.sort(Comparator.comparingInt(Map.Entry::getValue)); //升序
|
|
|
|
list.sort((o1, o2) -> (o2.getValue() - o1.getValue()));
|
|
|
|
list.sort((o1, o2) -> (o2.getValue() - o1.getValue()));
|
|
|
|
String key = list.get(0).getKey();
|
|
|
|
String key = list.get(0).getKey();
|
|
|
|
readNameVo = getReadNameDataForNameKey(excelMaps, key);
|
|
|
|
readNameVo = getReadNameDataForNameKey(excelMaps, key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
readNameVo.setSheetName(sheet.getSheetName());
|
|
|
|
|
|
|
|
readNameVoList.add(readNameVo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
readNameVo.setSheetName(sheet.getSheetName());
|
|
|
|
excelInfo.setReadNameVoList(readNameVoList);
|
|
|
|
readNameVoList.add(readNameVo);
|
|
|
|
return R.ok().setData(readNameVoList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return R.ok().setData(readNameVoList);
|
|
|
|
return R.error();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ReadNameVo getReadNameDataForNameKey(List<Map<String, String>> excelMaps, final String key) {
|
|
|
|
public ReadNameVo getReadNameDataForNameKey(List<Map<String, String>> excelMaps, final String key) {
|
|
|
|
ReadNameVo readNameVo = new ReadNameVo();
|
|
|
|
ReadNameVo readNameVo = new ReadNameVo();
|
|
|
|
// 去重前
|
|
|
|
// 去重前
|
|
|
|
List<GmhUser> oldNameList = excelMaps.stream().map(map -> new GmhUser(map.get(key))).collect(Collectors.toList());
|
|
|
|
List<GmhUser> oldNameList = excelMaps.stream()
|
|
|
|
|
|
|
|
.map(map -> new GmhUser(map.get(key)))
|
|
|
|
|
|
|
|
.filter(item -> StringUtils.isNotBlank(item.getName()))
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
// 去重后
|
|
|
|
// 去重后
|
|
|
|
LinkedHashSet<GmhUser> newNameList = new LinkedHashSet<>(oldNameList);
|
|
|
|
LinkedHashSet<GmhUser> newNameList = new LinkedHashSet<>(oldNameList);
|
|
|
|
readNameVo.setNameList(newNameList);
|
|
|
|
readNameVo.setNameList(newNameList);
|
|
|
@ -118,24 +143,34 @@ public class ExcelController {
|
|
|
|
return readNameVo;
|
|
|
|
return readNameVo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 模板导入
|
|
|
|
|
|
|
|
* @param file excel文件
|
|
|
|
|
|
|
|
* @param templateSheetNum 模板所在Sheet页
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
* @throws IOException
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/template")
|
|
|
|
@RequestMapping("/template")
|
|
|
|
public R templateUpload(MultipartFile file, String templateSheetNum) throws IOException {
|
|
|
|
public R templateUpload(MultipartFile file, String templateSheetNum) throws IOException {
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
this.templateSheetNum = Integer.parseInt(templateSheetNum) - 1;
|
|
|
|
FileEntity fileEntity = fileService.uploadFile(file);
|
|
|
|
Sheet sheet = workbook.getSheetAt(this.templateSheetNum);
|
|
|
|
gmhFileLogService.recordLog(fileEntity, GmhFileLog.OperateType.TEMPL_IMP);
|
|
|
|
|
|
|
|
excelInfo.setTemplateOriginalFilename(file.getOriginalFilename());
|
|
|
|
|
|
|
|
excelInfo.setTemplateSheetNum(Integer.parseInt(templateSheetNum) - 1);
|
|
|
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(excelInfo.getTemplateSheetNum());
|
|
|
|
if (sheet == null) {
|
|
|
|
if (sheet == null) {
|
|
|
|
throw new RuntimeException("sheet页不存在");
|
|
|
|
throw new RuntimeException("sheet页不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.templateWorkbook = workbook;
|
|
|
|
excelInfo.setTemplateWorkbook(workbook);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/cellNumSearch")
|
|
|
|
@RequestMapping("/cellNumSearch")
|
|
|
|
public R analysisCell(@Validated RowCellNum rowCellNum) {
|
|
|
|
public R analysisCell(@Validated RowCellNum rowCellNum) {
|
|
|
|
if (this.templateWorkbook == null) {
|
|
|
|
if (excelInfo.getTemplateWorkbook() == null) {
|
|
|
|
return R.error("模板文件出问题了,请重新上传");
|
|
|
|
return R.error("模板文件出问题了,请重新上传");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Sheet sheet = this.templateWorkbook.getSheetAt(this.templateSheetNum);
|
|
|
|
Sheet sheet = excelInfo.getTemplateWorkbook().getSheetAt(excelInfo.getTemplateSheetNum());
|
|
|
|
rowCellNum = POIExcelUtil.analysisCellRowNum(rowCellNum);
|
|
|
|
rowCellNum = POIExcelUtil.analysisCellRowNum(rowCellNum);
|
|
|
|
Row row = sheet.getRow(rowCellNum.getRowNum());
|
|
|
|
Row row = sheet.getRow(rowCellNum.getRowNum());
|
|
|
|
if (row == null) {
|
|
|
|
if (row == null) {
|
|
|
@ -152,15 +187,17 @@ public class ExcelController {
|
|
|
|
return R.ok().setData(stringCellVal);
|
|
|
|
return R.ok().setData(stringCellVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/executeTemplate")
|
|
|
|
|
|
|
|
public void executeTemplate(String newCellData, String cellRowStr, HttpServletResponse response) throws IOException {
|
|
|
|
@PostMapping("/executeTemplate")
|
|
|
|
|
|
|
|
public R executeTemplate(@RequestBody ExecuteTemplateQuery executeTemplateQuery) throws IOException {
|
|
|
|
|
|
|
|
String newCellData = executeTemplateQuery.getNewCellData();
|
|
|
|
String expr = newCellData.substring(newCellData.indexOf("@{"), newCellData.indexOf("}") + 1);
|
|
|
|
String expr = newCellData.substring(newCellData.indexOf("@{"), newCellData.indexOf("}") + 1);
|
|
|
|
String exprVal = newCellData.substring(newCellData.indexOf("@{") + 2, newCellData.indexOf("}"));
|
|
|
|
String exprVal = newCellData.substring(newCellData.indexOf("@{") + 2, newCellData.indexOf("}"));
|
|
|
|
String[] exprArr = exprVal.split("\\.");
|
|
|
|
String[] exprArr = exprVal.split("\\.");
|
|
|
|
String sheetName = exprArr[0];
|
|
|
|
String sheetName = exprArr[0];
|
|
|
|
String field = exprArr[1];
|
|
|
|
String field = exprArr[1];
|
|
|
|
|
|
|
|
|
|
|
|
Optional<ReadNameVo> first = readNameVoList
|
|
|
|
Optional<ReadNameVo> first = excelInfo.getReadNameVoList()
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|
.filter(item -> item.getSheetName().equalsIgnoreCase(sheetName))
|
|
|
|
.filter(item -> item.getSheetName().equalsIgnoreCase(sheetName))
|
|
|
|
.findFirst();
|
|
|
|
.findFirst();
|
|
|
@ -168,45 +205,77 @@ public class ExcelController {
|
|
|
|
throw new RuntimeException("未找到sheet页,可能是表达式错误");
|
|
|
|
throw new RuntimeException("未找到sheet页,可能是表达式错误");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReadNameVo readNameVo = first.get();
|
|
|
|
ReadNameVo readNameVo = first.get();
|
|
|
|
POIExcelUtil.removeModelSheet(this.templateWorkbook, this.templateSheetNum);
|
|
|
|
POIExcelUtil.removeModelSheet(excelInfo.getTemplateWorkbook(), excelInfo.getTemplateSheetNum());
|
|
|
|
POIExcelUtil.batchCloneSheet(this.templateWorkbook, this.templateSheetNum, readNameVo.getNameList().size());
|
|
|
|
POIExcelUtil.batchCloneSheet(excelInfo.getTemplateWorkbook(), excelInfo.getTemplateSheetNum(), readNameVo.getNameList().size());
|
|
|
|
ArrayList<GmhUser> gmhUsers = new ArrayList<>(readNameVo.getNameList());
|
|
|
|
ArrayList<GmhUser> gmhUsers = new ArrayList<>(readNameVo.getNameList());
|
|
|
|
RowCellNum rowCellNum = POIExcelUtil.analysisCellRowNum(cellRowStr);
|
|
|
|
RowCellNum rowCellNum = POIExcelUtil.analysisCellRowNum(executeTemplateQuery.getCellRowStr());
|
|
|
|
for (int i = 0; i < this.templateWorkbook.getNumberOfSheets(); i++) {
|
|
|
|
for (int i = 0; i < excelInfo.getTemplateWorkbook().getNumberOfSheets(); i++) {
|
|
|
|
Sheet sheet = templateWorkbook.getSheetAt(i);
|
|
|
|
Sheet sheet = excelInfo.getTemplateWorkbook().getSheetAt(i);
|
|
|
|
if (sheet == null) {
|
|
|
|
if (sheet == null) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Row row = sheet.getRow(rowCellNum.getRowNum());
|
|
|
|
Row row = sheet.getRow(rowCellNum.getRowNum());
|
|
|
|
Cell cell = row.getCell(rowCellNum.getCellNum());
|
|
|
|
Cell cell = row.getCell(rowCellNum.getCellNum());
|
|
|
|
cell.setCellValue(newCellData.replace(expr, CommonUtils.nameFormat(gmhUsers.get(i).getName())));
|
|
|
|
cell.setCellValue(newCellData.replace(expr, StringUtils.nameFormat(gmhUsers.get(i).getName())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO 文件保存到本地,文件信息入库
|
|
|
|
// TODO 文件保存到本地,文件信息入库
|
|
|
|
|
|
|
|
String localPath = fileProperties.getLocal().getPath();
|
|
|
|
|
|
|
|
File parentFile = new File(localPath);
|
|
|
|
|
|
|
|
if (!parentFile.exists()) {
|
|
|
|
|
|
|
|
if (!parentFile.mkdirs()) {
|
|
|
|
|
|
|
|
throw new RuntimeException("创建保存路径失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
FileEntity fileEntity = new FileEntity();
|
|
|
|
|
|
|
|
String extName = FileUtil.extName(excelInfo.getTemplateOriginalFilename());
|
|
|
|
|
|
|
|
String originalFilename;
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(executeTemplateQuery.getResultExcelName())) {
|
|
|
|
|
|
|
|
originalFilename = excelInfo.getTemplateOriginalFilename();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
originalFilename = executeTemplateQuery.getResultExcelName() + "." + extName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fileEntity.setContentType(MediaType.ALL_VALUE)
|
|
|
|
|
|
|
|
.setOriginalFilename(originalFilename)
|
|
|
|
|
|
|
|
.setFileSize(2222L);
|
|
|
|
|
|
|
|
fileEntity.setFileType(fileProperties.getType());
|
|
|
|
|
|
|
|
String nowDate = DateUtil.format(new Date(), "yyyyMMddHHmmss");
|
|
|
|
|
|
|
|
fileEntity.setFileName(nowDate + "." + extName);
|
|
|
|
|
|
|
|
File dest = new File(localPath + File.separator + fileEntity.getFileName());
|
|
|
|
|
|
|
|
fileEntity.setFilePath(localPath + File.separator + fileEntity.getFileName());
|
|
|
|
|
|
|
|
FileOutputStream fout = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fout = new FileOutputStream(dest);
|
|
|
|
|
|
|
|
excelInfo.getTemplateWorkbook().write(fout);
|
|
|
|
|
|
|
|
fileService.save(fileEntity);
|
|
|
|
|
|
|
|
gmhFileLogService.recordLog(fileEntity, GmhFileLog.OperateType.TEMPL_EXP);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
assert fout != null;
|
|
|
|
|
|
|
|
fout.close();
|
|
|
|
|
|
|
|
// excelInfo.getTemplateWorkbook().close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
|
|
|
|
|
|
|
|
// 输出Excel文件
|
|
|
|
// 输出Excel文件 下载出去
|
|
|
|
OutputStream output = response.getOutputStream();
|
|
|
|
// OutputStream output = response.getOutputStream();
|
|
|
|
response.reset();
|
|
|
|
// response.reset();
|
|
|
|
// 设置文件头
|
|
|
|
// // 设置文件头
|
|
|
|
response.setHeader("Content-Disposition",
|
|
|
|
// response.setHeader("Content-Disposition",
|
|
|
|
"attchement;filename=" + new String((sheetName + ".xls").getBytes("gb2312"), "ISO8859-1"));
|
|
|
|
// "attchement;filename=" + new String((sheetName + ".xls").getBytes("gb2312"), "ISO8859-1"));
|
|
|
|
response.setContentType("application/msexcel");
|
|
|
|
// response.setContentType("application/msexcel");
|
|
|
|
this.templateWorkbook.write(output);
|
|
|
|
// excelInfo.getTemplateWorkbook().write(fout);
|
|
|
|
this.templateWorkbook.close();
|
|
|
|
// excelInfo.getTemplateWorkbook().close();
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// FileOutputStream out = new FileOutputStream("C:\\Users\\admin\\Desktop\\tempfile\\output\\out的222.xls");
|
|
|
|
|
|
|
|
// out.flush();
|
|
|
|
|
|
|
|
// templateWorkbook.write(out);
|
|
|
|
|
|
|
|
// out.close();
|
|
|
|
|
|
|
|
// System.out.println("文件输出完成");
|
|
|
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@GetMapping("/gotoDownload")
|
|
|
|
private SysBaijiaxingService baijiaxingService;
|
|
|
|
public R gotoDownload() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
excelInfo.getTemplateWorkbook().close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isChinaName(String val) {
|
|
|
|
private boolean isChinaName(String val) {
|
|
|
|
QueryWrapper<SysBaijiaxing> queryWrapper = new QueryWrapper<>();
|
|
|
|
QueryWrapper<SysBaijiaxing> queryWrapper = new QueryWrapper<>();
|
|
|
@ -270,4 +339,27 @@ public class ExcelController {
|
|
|
|
// return R.ok().setData(readNameList);
|
|
|
|
// return R.ok().setData(readNameList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 数据源导入模式枚举
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
|
|
|
public enum DataSourceImportModel {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AUTO_NAME("0", "自动识别姓名"),
|
|
|
|
|
|
|
|
ALL("1", "全部导入");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String value;
|
|
|
|
|
|
|
|
private final String remark;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DataSourceImportModel findEnum(String value) {
|
|
|
|
|
|
|
|
for (DataSourceImportModel item : values()) {
|
|
|
|
|
|
|
|
if (value.equals(item.getValue())) {
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new RuntimeException("没有找到对应的枚举");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|