|
|
|
@ -18,8 +18,10 @@ import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
|
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.entity.Fieldx; |
|
|
|
|
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.service.ITablexService; |
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController; |
|
|
|
|
import org.jeecg.modules.tablex.ws.WebSocketUtils; |
|
|
|
|
import org.jsoup.helper.StringUtil; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
@ -60,6 +63,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
|
private ITablexService tablexService; |
|
|
|
|
@Autowired |
|
|
|
|
private IFieldx222Service fieldx222Service; |
|
|
|
|
@Autowired |
|
|
|
|
private WebSocketUtils webSocketUtils; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 分页列表查询 |
|
|
|
@ -290,12 +295,18 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
|
/** |
|
|
|
|
* 通过excel导入数据 |
|
|
|
|
* |
|
|
|
|
* @param request |
|
|
|
|
* @param response |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/importExcel") |
|
|
|
|
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) { |
|
|
|
|
return Result.error("文件上传失败"); |
|
|
|
|
} |
|
|
|
@ -314,6 +325,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
|
workbook = new XSSFWorkbook(inputStream); |
|
|
|
|
} |
|
|
|
|
//读取表
|
|
|
|
|
message.put("status", "数据预读入"); |
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
|
List<Fieldx222> list = new ArrayList<>(); |
|
|
|
|
//获取excel的所有页
|
|
|
|
|
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); |
|
|
|
|
List<Fieldx222> list222 = fieldx222Service.list(); |
|
|
|
|
fieldx222Service.remove(null); |
|
|
|
|
if(list222==null) |
|
|
|
|
return Result.error("文件上传失败"); |
|
|
|
|
|
|
|
|
|
List<Fieldx> list1= list222.stream().map((item)->{ |
|
|
|
|
Fieldx fieldx=new Fieldx(); |
|
|
|
|
String id=item.getId(); |
|
|
|
@ -424,7 +443,11 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
|
fieldx.setRule(item.getRull()); |
|
|
|
|
return fieldx; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
//将中间表数据导入数据库
|
|
|
|
|
fieldxService.saveBatch(list1); |
|
|
|
|
message.put("status", "上传成功"); |
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
|
return Result.OK("文件上传成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|