dev^2
itcast 1 year ago
parent bede9162cc
commit 757a9971c0
  1. 27
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java
  2. 4
      jeecg-boot/jeecg-boot-module-system/src/main/resources/application-dev.yml

@ -18,8 +18,10 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.fieldx.dto.ExcelInfo; import org.jeecg.modules.fieldx.dto.ExcelInfo;
import org.jeecg.modules.fieldx.entity.Fieldx; import org.jeecg.modules.fieldx.entity.Fieldx;
import org.jeecg.modules.fieldx.entity.Fieldx222; import org.jeecg.modules.fieldx.entity.Fieldx222;
@ -34,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.tablex.entity.Tablex; import org.jeecg.modules.tablex.entity.Tablex;
import org.jeecg.modules.tablex.service.ITablexService; import org.jeecg.modules.tablex.service.ITablexService;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.tablex.ws.WebSocketUtils;
import org.jsoup.helper.StringUtil; import org.jsoup.helper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -60,6 +63,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
private ITablexService tablexService; private ITablexService tablexService;
@Autowired @Autowired
private IFieldx222Service fieldx222Service; private IFieldx222Service fieldx222Service;
@Autowired
private WebSocketUtils webSocketUtils;
/** /**
* 分页列表查询 * 分页列表查询
@ -290,12 +295,18 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
/** /**
* 通过excel导入数据 * 通过excel导入数据
* *
* @param request
* @param response
* @return * @return
*/ */
@PostMapping("/importExcel") @PostMapping("/importExcel")
public Result<?> importExcel(@RequestPart MultipartFile file) throws Exception { public Result<?> importExcel(@RequestPart MultipartFile file) throws Exception {
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
Map<String, String> message = new HashMap<>();
message.put("isVisible", "true");
message.put("uploaded", "0");
message.put("status", "判断文件结构");
webSocketUtils.sendMessage(loginUser.getId(), message);
if (file == null) { if (file == null) {
return Result.error("文件上传失败"); return Result.error("文件上传失败");
} }
@ -314,6 +325,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
workbook = new XSSFWorkbook(inputStream); workbook = new XSSFWorkbook(inputStream);
} }
//读取表 //读取表
message.put("status", "数据预读入");
webSocketUtils.sendMessage(loginUser.getId(), message);
List<Fieldx222> list = new ArrayList<>(); List<Fieldx222> list = new ArrayList<>();
//获取excel的所有页 //获取excel的所有页
int numberofSheets= workbook.getNumberOfSheets(); int numberofSheets= workbook.getNumberOfSheets();
@ -393,11 +406,17 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
} }
} }
message.put("status", "数据预读入成功");
webSocketUtils.sendMessage(loginUser.getId(), message);
message.put("status", "正在上传");
webSocketUtils.sendMessage(loginUser.getId(), message);
fieldx222Service.saveBatch(list); fieldx222Service.saveBatch(list);
List<Fieldx222> list222 = fieldx222Service.list(); List<Fieldx222> list222 = fieldx222Service.list();
fieldx222Service.remove(null); fieldx222Service.remove(null);
if(list222==null) if(list222==null)
return Result.error("文件上传失败"); return Result.error("文件上传失败");
List<Fieldx> list1= list222.stream().map((item)->{ List<Fieldx> list1= list222.stream().map((item)->{
Fieldx fieldx=new Fieldx(); Fieldx fieldx=new Fieldx();
String id=item.getId(); String id=item.getId();
@ -424,7 +443,11 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
fieldx.setRule(item.getRull()); fieldx.setRule(item.getRull());
return fieldx; return fieldx;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
//将中间表数据导入数据库
fieldxService.saveBatch(list1); fieldxService.saveBatch(list1);
message.put("status", "上传成功");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.OK("文件上传成功"); return Result.OK("文件上传成功");
} }

@ -137,9 +137,9 @@ spring:
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
# 多数据源配置 # 多数据源配置
#multi-datasource1: #multi-datasource1:
url: jdbc:mysql://182.92.169.222:3306/project_management?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai url: jdbc:mysql://127.0.0.1:3306/project_management?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root username: root
password: ycwl2022. password: root
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
#redis 配置 #redis 配置
redis: redis:

Loading…
Cancel
Save