|
|
@ -37,12 +37,14 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
|
|
import org.jeecg.modules.tablex.service.ITablexVoService; |
|
|
|
import org.jeecg.modules.tablex.service.ITablexVoService; |
|
|
|
import org.jeecg.modules.tablex.vo.TablexVo; |
|
|
|
import org.jeecg.modules.tablex.vo.TablexVo; |
|
|
|
|
|
|
|
import org.jeecg.modules.tablex.ws.WebSocketUtils; |
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil; |
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil; |
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams; |
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
|
|
|
import org.jeecg.common.system.base.controller.JeecgController; |
|
|
|
import org.jeecg.common.system.base.controller.JeecgController; |
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
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.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
@ -81,6 +83,9 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IRequirementEntityService requirementEntityService; |
|
|
|
private IRequirementEntityService requirementEntityService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private WebSocketUtils webSocketUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 分页列表查询 |
|
|
|
* 分页列表查询 |
|
|
|
* |
|
|
|
* |
|
|
@ -269,14 +274,23 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
public Result<?> importExcel(MultipartFile file) { |
|
|
|
public Result<?> importExcel(MultipartFile file) { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 判断文件是否是表格
|
|
|
|
// 判断文件是否是表格
|
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
if (StringUtils.isBlank(originalFilename) || |
|
|
|
if (StringUtils.isBlank(originalFilename) || |
|
|
|
(!originalFilename.endsWith("xls") && |
|
|
|
(!originalFilename.endsWith("xls") && |
|
|
|
!originalFilename.endsWith("xlsx"))) { |
|
|
|
!originalFilename.endsWith("xlsx"))) { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("文件格式不正确"); |
|
|
|
return Result.error("文件格式不正确"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -286,17 +300,25 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
params.setHeadRows(1);//表头行数,默认1
|
|
|
|
params.setHeadRows(1);//表头行数,默认1
|
|
|
|
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
|
|
|
|
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
|
|
|
|
List<TablexVo> list = null; |
|
|
|
List<TablexVo> list = null; |
|
|
|
|
|
|
|
message.put("status", "数据预读入"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
try { |
|
|
|
try { |
|
|
|
//读取excel数据
|
|
|
|
//读取excel数据
|
|
|
|
list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params); |
|
|
|
list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("文件读取失败"); |
|
|
|
return Result.error("文件读取失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
//判断文件中是否存在数据
|
|
|
|
//判断文件中是否存在数据
|
|
|
|
if (list == null || list.size() == 0) { |
|
|
|
if (list == null || list.size() == 0) { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("Excel数据为空"); |
|
|
|
return Result.error("Excel数据为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message.put("status", "数据预读入"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
for (TablexVo tablexVo : list) { |
|
|
|
for (TablexVo tablexVo : list) { |
|
|
|
//判断当前存入行是否为空值
|
|
|
|
//判断当前存入行是否为空值
|
|
|
|
if (tablexVo.getModuleId() == null && |
|
|
|
if (tablexVo.getModuleId() == null && |
|
|
@ -307,13 +329,17 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
tablexVo.getStatus() == null && |
|
|
|
tablexVo.getStatus() == null && |
|
|
|
tablexVo.getVerisonStatus() == null && |
|
|
|
tablexVo.getVerisonStatus() == null && |
|
|
|
tablexVo.getVerison() == null) continue; |
|
|
|
tablexVo.getVerison() == null) continue; |
|
|
|
|
|
|
|
// 将总的记录数传递给前端
|
|
|
|
|
|
|
|
message.put("records", String.valueOf(list.size())); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
|
|
|
|
|
|
|
|
//判断版本号长度
|
|
|
|
//判断版本号长度
|
|
|
|
String verison = tablexVo.getVerison(); |
|
|
|
String verison = tablexVo.getVerison(); |
|
|
|
if (verison.length() > 5) { |
|
|
|
if (verison.length() > 5) { |
|
|
|
return Result.error("导入失败,版本号格式错误"); |
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
|
|
|
|
return Result.error("预读入失败,版本号格式错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//存入临时表中
|
|
|
|
//存入临时表中
|
|
|
|
tablexVoService.save(tablexVo); |
|
|
|
tablexVoService.save(tablexVo); |
|
|
|
} |
|
|
|
} |
|
|
@ -324,20 +350,30 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
tablexVoService.removeAll(voList); |
|
|
|
tablexVoService.removeAll(voList); |
|
|
|
|
|
|
|
|
|
|
|
if (voList.size() == 0) { |
|
|
|
if (voList.size() == 0) { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,数据为空"); |
|
|
|
return Result.error("导入失败,数据为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Tablex tablex = new Tablex(); |
|
|
|
message.put("status", "开始数据校验"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
for (int i = 0; i < voList.size(); i++) { |
|
|
|
for (int i = 0; i < voList.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Tablex> tablexList = new ArrayList<>(); |
|
|
|
|
|
|
|
Tablex tablex = new Tablex(); |
|
|
|
|
|
|
|
|
|
|
|
String moduleId = voList.get(i).getModuleId(); |
|
|
|
String moduleId = voList.get(i).getModuleId(); |
|
|
|
if (moduleId == null || moduleId.equals("")){ |
|
|
|
if (moduleId == null || moduleId.equals("")){ |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("对应模块填写不能为空"); |
|
|
|
return Result.error("对应模块填写不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
LambdaQueryWrapper<Modulex> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
LambdaQueryWrapper<Modulex> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(Modulex::getId,moduleId); |
|
|
|
queryWrapper.eq(Modulex::getId,moduleId); |
|
|
|
Modulex modulex = modulexService.getOne(queryWrapper); |
|
|
|
Modulex modulex = modulexService.getOne(queryWrapper); |
|
|
|
if(modulex == null){ |
|
|
|
if(modulex == null){ |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("对应模块填写错误"); |
|
|
|
return Result.error("对应模块填写错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
String modulexId = modulex.getId(); |
|
|
|
String modulexId = modulex.getId(); |
|
|
@ -346,9 +382,9 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
String verisonStatus = voList.get(i).getVerisonStatus(); |
|
|
|
String verisonStatus = voList.get(i).getVerisonStatus(); |
|
|
|
|
|
|
|
|
|
|
|
//判断实体状态
|
|
|
|
//判断实体状态
|
|
|
|
int statusInt = status.equals("正常") ? 1 : status.equals("停用") ? 0 : status.equals("废弃") ? 9 : 3; |
|
|
|
//int statusInt = status.equals("正常") ? 1 : status.equals("停用") ? 0 : status.equals("废弃") ? 9 : 3;
|
|
|
|
//判断版本状态
|
|
|
|
//判断版本状态
|
|
|
|
int verisonStatusInt = verisonStatus.equals("当前") ? 1 : verisonStatus.equals("历史") ? 0 : 3; |
|
|
|
//int verisonStatusInt = verisonStatus.equals("当前") ? 1 : verisonStatus.equals("历史") ? 0 : 3;
|
|
|
|
|
|
|
|
|
|
|
|
//判断对应模块
|
|
|
|
//判断对应模块
|
|
|
|
if (modulexId != null && voList.get(i).getModuleId() != null && !voList.get(i).getModuleId().equals("")) { |
|
|
|
if (modulexId != null && voList.get(i).getModuleId() != null && !voList.get(i).getModuleId().equals("")) { |
|
|
@ -357,47 +393,64 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
//判断英文名称
|
|
|
|
//判断英文名称
|
|
|
|
if (voList.get(i).getTableEnName() != null && !voList.get(i).getTableEnName().equals("") && !voList.get(i).getTableEnName().equals(modulex.getModuleEnName())) { |
|
|
|
if (voList.get(i).getTableEnName() != null && !voList.get(i).getTableEnName().equals("") && !voList.get(i).getTableEnName().equals(modulex.getModuleEnName())) { |
|
|
|
//判断实体状态
|
|
|
|
//判断实体状态
|
|
|
|
if (statusInt == 1 || statusInt == 0 || statusInt == 9) { |
|
|
|
if (status.equals("1") || status.equals("0") || status.equals("9")) { |
|
|
|
//判断版本状态
|
|
|
|
//判断版本状态
|
|
|
|
if (verisonStatusInt == 1 || verisonStatusInt == 0) { |
|
|
|
if (verisonStatus.equals("1") || verisonStatus.equals("0")) { |
|
|
|
//判断版本号
|
|
|
|
//判断版本号
|
|
|
|
if (voList.get(i).getVerison() != null && !voList.get(i).getVerison().equals("")) { |
|
|
|
if (voList.get(i).getVerison() != null && !voList.get(i).getVerison().equals("")) { |
|
|
|
tablex.setModuleId(voList.get(i).getModuleId()); |
|
|
|
tablex.setModuleId(voList.get(i).getModuleId()); |
|
|
|
tablex.setTableName(voList.get(i).getTableName()); |
|
|
|
tablex.setTableName(voList.get(i).getTableName()); |
|
|
|
tablex.setTableEnName(voList.get(i).getTableEnName()); |
|
|
|
tablex.setTableEnName(voList.get(i).getTableEnName()); |
|
|
|
tablex.setTableStructure(voList.get(i).getTableStructure()); |
|
|
|
tablex.setTableStructure(voList.get(i).getTableStructure()); |
|
|
|
tablex.setStructuralDiagram(voList.get(i).getStructuralDiagram()); |
|
|
|
tablex.setStructuralDiagram(voList.get(i).getStructuralDiagram()); |
|
|
|
tablex.setCreateBy(loginUser.getRealname()); |
|
|
|
tablex.setCreateBy(loginUser.getRealname()); |
|
|
|
tablex.setStatus(statusInt); |
|
|
|
tablex.setStatus(Integer.valueOf(voList.get(i).getStatus())); |
|
|
|
tablex.setVerisonStatus(verisonStatusInt); |
|
|
|
tablex.setVerisonStatus(Integer.valueOf(voList.get(i).getVerisonStatus())); |
|
|
|
tablex.setVerison(Integer.valueOf(voList.get(i).getVerison())); |
|
|
|
tablex.setVerison(Integer.valueOf(voList.get(i).getVerison())); |
|
|
|
|
|
|
|
|
|
|
|
//保存到真实表中
|
|
|
|
tablexList.add(tablex); |
|
|
|
tablexService.save(tablex); |
|
|
|
|
|
|
|
|
|
|
|
//单条保存到真实表中
|
|
|
|
|
|
|
|
tablexService.saveSingleBatch(tablexList,loginUser,message); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("文件导入失败"); |
|
|
|
return Result.error("文件导入失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
message.put("isVisible", "false"); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.OK("文件导入成功!"); |
|
|
|
return Result.OK("文件导入成功!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|