|
|
@ -8,33 +8,27 @@ import com.gmh.entity.*;
|
|
|
|
import com.gmh.entity.properties.FileServerProperties;
|
|
|
|
import com.gmh.entity.properties.FileServerProperties;
|
|
|
|
import com.gmh.entity.query.ExecuteTemplateQuery;
|
|
|
|
import com.gmh.entity.query.ExecuteTemplateQuery;
|
|
|
|
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.FileService;
|
|
|
|
|
|
|
|
import com.gmh.service.GmhFileLogService;
|
|
|
|
import com.gmh.service.SysBaijiaxingService;
|
|
|
|
import com.gmh.service.SysBaijiaxingService;
|
|
|
|
import com.gmh.utils.StringUtils;
|
|
|
|
|
|
|
|
import com.gmh.utils.POIExcelUtil;
|
|
|
|
import com.gmh.utils.POIExcelUtil;
|
|
|
|
|
|
|
|
import com.gmh.utils.StringUtils;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
|
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
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.HttpServletRequest;
|
|
|
|
import java.io.File;
|
|
|
|
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.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -54,13 +48,20 @@ public class ExcelController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SysBaijiaxingService baijiaxingService;
|
|
|
|
private SysBaijiaxingService baijiaxingService;
|
|
|
|
|
|
|
|
|
|
|
|
private final ExcelInfo excelInfo = new ExcelInfo();
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* HashMap的Key为SessionId
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 通过SessionId为每一个会话保存自己的对象副本
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 不适用于集群环境
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private final Map<String, ExcelInfo> excelInfoMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
private static final String KEY_XINGMING = "姓名";
|
|
|
|
private static final String KEY_XINGMING = "姓名";
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${gmh.upload-path}")
|
|
|
|
|
|
|
|
private String uploadPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/t01")
|
|
|
|
@RequestMapping("/t01")
|
|
|
|
public R test01() {
|
|
|
|
public R test01() {
|
|
|
|
return R.ok("ok");
|
|
|
|
return R.ok("ok");
|
|
|
@ -68,6 +69,7 @@ public class ExcelController {
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/dataSourceImport")
|
|
|
|
@RequestMapping("/dataSourceImport")
|
|
|
|
public R dataSourceImport(MultipartFile file, String dataSourceImportModel) throws IOException {
|
|
|
|
public R dataSourceImport(MultipartFile file, String dataSourceImportModel) throws IOException {
|
|
|
|
|
|
|
|
excelInfoMap.put(request.getSession().getId(), new ExcelInfo());
|
|
|
|
DataSourceImportModel importModel = DataSourceImportModel.findEnum(dataSourceImportModel);
|
|
|
|
DataSourceImportModel importModel = DataSourceImportModel.findEnum(dataSourceImportModel);
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
FileEntity fileEntity = fileService.uploadFile(file);
|
|
|
|
FileEntity fileEntity = fileService.uploadFile(file);
|
|
|
@ -113,6 +115,7 @@ public class ExcelController {
|
|
|
|
readNameVo.setSheetName(sheet.getSheetName());
|
|
|
|
readNameVo.setSheetName(sheet.getSheetName());
|
|
|
|
readNameVoList.add(readNameVo);
|
|
|
|
readNameVoList.add(readNameVo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExcelInfo excelInfo = excelInfoMap.get(request.getSession().getId());
|
|
|
|
excelInfo.setReadNameVoList(readNameVoList);
|
|
|
|
excelInfo.setReadNameVoList(readNameVoList);
|
|
|
|
return R.ok().setData(readNameVoList);
|
|
|
|
return R.ok().setData(readNameVoList);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -155,6 +158,7 @@ public class ExcelController {
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
Workbook workbook = POIExcelUtil.readExcelFromInputStream(file.getInputStream(), file.getOriginalFilename());
|
|
|
|
FileEntity fileEntity = fileService.uploadFile(file);
|
|
|
|
FileEntity fileEntity = fileService.uploadFile(file);
|
|
|
|
gmhFileLogService.recordLog(fileEntity, GmhFileLog.OperateType.TEMPL_IMP);
|
|
|
|
gmhFileLogService.recordLog(fileEntity, GmhFileLog.OperateType.TEMPL_IMP);
|
|
|
|
|
|
|
|
ExcelInfo excelInfo = excelInfoMap.get(request.getSession().getId());
|
|
|
|
excelInfo.setTemplateOriginalFilename(file.getOriginalFilename());
|
|
|
|
excelInfo.setTemplateOriginalFilename(file.getOriginalFilename());
|
|
|
|
excelInfo.setTemplateSheetNum(Integer.parseInt(templateSheetNum) - 1);
|
|
|
|
excelInfo.setTemplateSheetNum(Integer.parseInt(templateSheetNum) - 1);
|
|
|
|
Sheet sheet = workbook.getSheetAt(excelInfo.getTemplateSheetNum());
|
|
|
|
Sheet sheet = workbook.getSheetAt(excelInfo.getTemplateSheetNum());
|
|
|
@ -167,6 +171,7 @@ public class ExcelController {
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/cellNumSearch")
|
|
|
|
@RequestMapping("/cellNumSearch")
|
|
|
|
public R analysisCell(@Validated RowCellNum rowCellNum) {
|
|
|
|
public R analysisCell(@Validated RowCellNum rowCellNum) {
|
|
|
|
|
|
|
|
ExcelInfo excelInfo = excelInfoMap.get(request.getSession().getId());
|
|
|
|
if (excelInfo.getTemplateWorkbook() == null) {
|
|
|
|
if (excelInfo.getTemplateWorkbook() == null) {
|
|
|
|
return R.error("模板文件出问题了,请重新上传");
|
|
|
|
return R.error("模板文件出问题了,请重新上传");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -190,6 +195,7 @@ public class ExcelController {
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/executeTemplate")
|
|
|
|
@PostMapping("/executeTemplate")
|
|
|
|
public R executeTemplate(@RequestBody ExecuteTemplateQuery executeTemplateQuery) throws IOException {
|
|
|
|
public R executeTemplate(@RequestBody ExecuteTemplateQuery executeTemplateQuery) throws IOException {
|
|
|
|
|
|
|
|
// TODO 有表达式和无表达式兼容处理
|
|
|
|
String newCellData = executeTemplateQuery.getNewCellData();
|
|
|
|
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("}"));
|
|
|
@ -197,6 +203,7 @@ public class ExcelController {
|
|
|
|
String sheetName = exprArr[0];
|
|
|
|
String sheetName = exprArr[0];
|
|
|
|
String field = exprArr[1];
|
|
|
|
String field = exprArr[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExcelInfo excelInfo = excelInfoMap.get(request.getSession().getId());
|
|
|
|
Optional<ReadNameVo> first = excelInfo.getReadNameVoList()
|
|
|
|
Optional<ReadNameVo> first = excelInfo.getReadNameVoList()
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|
.filter(item -> item.getSheetName().equalsIgnoreCase(sheetName))
|
|
|
|
.filter(item -> item.getSheetName().equalsIgnoreCase(sheetName))
|
|
|
@ -269,10 +276,13 @@ public class ExcelController {
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/gotoDownload")
|
|
|
|
@GetMapping("/gotoDownload")
|
|
|
|
public R gotoDownload() {
|
|
|
|
public R gotoDownload() {
|
|
|
|
|
|
|
|
ExcelInfo excelInfo = excelInfoMap.get(request.getSession().getId());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
excelInfo.getTemplateWorkbook().close();
|
|
|
|
excelInfo.getTemplateWorkbook().close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
excelInfoMap.remove(request.getSession().getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|