|
@@ -1,5 +1,7 @@
|
|
|
package com.boman.report.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.StringUtils;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
@@ -10,15 +12,22 @@ import com.boman.domain.GenTable;
|
|
|
import com.boman.domain.GenTableColumn;
|
|
|
import com.boman.domain.dto.AjaxResult;
|
|
|
import com.boman.domain.dto.ImportExcelDto;
|
|
|
+import com.boman.domain.dto.ImportFileDto;
|
|
|
+import com.boman.domain.entity.StatisticReportPersonnel;
|
|
|
import com.boman.report.mapper.ImportMapper;
|
|
|
import com.boman.report.service.IImportServcie;
|
|
|
+import com.boman.report.service.StatisticReportPersonnelService;
|
|
|
import com.boman.web.core.api.RemoteObjService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -40,25 +49,33 @@ public class ImportServiceImpl implements IImportServcie {
|
|
|
private RedisService redisService;
|
|
|
@Autowired
|
|
|
private RemoteObjService remoteObjService;
|
|
|
+ @Autowired
|
|
|
+ private StatisticReportPersonnelService personnelService;
|
|
|
|
|
|
@Override
|
|
|
- public AjaxResult importData(List<MultipartFile> multipartFiles, String tableName) throws Exception {
|
|
|
- Objects.requireNonNull(multipartFiles, "未上传文件!");
|
|
|
+ @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
|
|
|
+ public AjaxResult importData(ImportFileDto fileDto, Long personnelId, String tableName) throws Exception {
|
|
|
+ Objects.requireNonNull(fileDto, "未上传文件!");
|
|
|
ObjectUtils.requireNonNull(tableName, "表名为空!");
|
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
|
Map<String, GenTableColumn> columnMap = this.genImportColumn(genTable.getColumns());
|
|
|
List<GenTableColumn> columns = genColumData(tableName, columnMap);
|
|
|
this.genBaseData(columns, columnMap);
|
|
|
ExcelUtil<JSONObject> util = new ExcelUtil<>(JSONObject.class);
|
|
|
- List<JSONObject> list = new ArrayList<>();
|
|
|
- for(MultipartFile multipartFile : multipartFiles) {
|
|
|
- list.addAll(util.importCommonExcel("", multipartFile.getInputStream(), columns));
|
|
|
- }
|
|
|
+
|
|
|
+ String realPath = getFileRealPath(fileDto);
|
|
|
+ File file = new File(realPath);
|
|
|
+ List<JSONObject> list = util.importCommonExcel("", new FileInputStream(file), columns);
|
|
|
ImportExcelDto dto = new ImportExcelDto();
|
|
|
dto.setDataList(list);
|
|
|
dto.setTableName(tableName);
|
|
|
remoteObjService.importCommonData(dto);
|
|
|
-
|
|
|
+ // 上传成功后需要修改上报人的状态
|
|
|
+ StatisticReportPersonnel personnel = new StatisticReportPersonnel();
|
|
|
+ personnel.setId(personnelId);
|
|
|
+ personnel.setStatus("2");
|
|
|
+ personnel.setUploadFile(fileDto.toString());
|
|
|
+ personnelService.updateStatus(personnel);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
@@ -165,4 +182,19 @@ public class ImportServiceImpl implements IImportServcie {
|
|
|
columns.add(columnMap.get(UPDATE_BY));
|
|
|
columns.add(columnMap.get(UPDATE_TIME));
|
|
|
}
|
|
|
+
|
|
|
+ private String getFileRealPath(ImportFileDto fileJson) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", "发文表.xlsx");
|
|
|
+ jsonObject.put("name", "发文表.xlsx");
|
|
|
+ jsonObject.put("status", null);
|
|
|
+ jsonObject.put("uid", null);
|
|
|
+ jsonObject.put("absolutePath", "c:\\file/2021/08/25/1629873633185.xlsx");
|
|
|
+ jsonObject.put("originalName", "发文表.xlsx");
|
|
|
+ System.out.println(jsonObject.toJSONString());
|
|
|
+ }
|
|
|
}
|