模块管理导入功能,实现交互

dev
lijinyu 1 year ago
parent abf00f0070
commit c99b54e9d4
  1. 20
      ant-design-vue-jeecg/src/views/modulex/ModulexList.vue
  2. 164
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/modulex/service/impl/ModulexServiceImpl.java
  3. 1
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/taskType/controller/TaskTypeController.java

@ -71,7 +71,25 @@
<div class="table-operator"> <div class="table-operator">
<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel"> <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
<a-button type="primary" icon="import">导入模块</a-button> <a-modal
title="正在上传..."
:visible="ModalData.isVisible==='true'"
:confirm-loading="false"
:mask="true"
:maskClosable="false"
:keyboard="false"
:closable="false"
:footer="false"
>
<p>当前状态{{ ModalData.status }}</p>
<p>总记录数{{ ModalData.records }}</p>
<p>已上传{{ ModalData.uploaded }}</p>
<a-progress
:percent="parseInt(String(ModalData.uploaded/ModalData.records*100))"
title="上传进度:"
status="active" :steps="ModalData.records"/>
</a-modal>
<a-button type="primary" icon="import" @click="showProcess">导入模块</a-button>
</a-upload> </a-upload>
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="functionImportExcelUrl" @change="handleImportExcel"> <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="functionImportExcelUrl" @change="handleImportExcel">
<a-button type="primary" icon="import">导入功能</a-button> <a-button type="primary" icon="import">导入功能</a-button>

@ -42,6 +42,7 @@ import org.jeecg.modules.system.service.ISysRoleService;
import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.system.service.ISysUserService;
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.modules.tablex.ws.WebSocketUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -101,6 +102,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
@Autowired @Autowired
private IProjectxService projectxService; private IProjectxService projectxService;
@Autowired
private WebSocketUtils webSocketUtils;
@ -326,13 +330,22 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
public Result<?> importExcel(MultipartFile file) throws Exception { public Result<?> importExcel(MultipartFile file) throws Exception {
// 获取当前操作用户 // 获取当前操作用户
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);
String username = loginUser.getUsername(); String username = loginUser.getUsername();
if (file.isEmpty()) { if (file.isEmpty()) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("上传为空"); return Result.error("上传为空");
} }
String filename = file.getOriginalFilename(); String filename = file.getOriginalFilename();
String fileSuffix = filename.substring(filename.lastIndexOf(".")); String fileSuffix = filename.substring(filename.lastIndexOf("."));
if (!fileSuffix.equals(".xls") && !fileSuffix.equals(".xlsx")) { if (!fileSuffix.equals(".xls") && !fileSuffix.equals(".xlsx")) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件类型不对"); return Result.error("文件类型不对");
} }
List<ModulexTemplate> modulexVoList = new ArrayList<>(); List<ModulexTemplate> modulexVoList = new ArrayList<>();
@ -345,6 +358,8 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
} }
List<String> propertyNames = new ArrayList<>(); List<String> propertyNames = new ArrayList<>();
// 获取excel的sheet页 // 获取excel的sheet页
message.put("status", "读取数据中");
webSocketUtils.sendMessage(loginUser.getId(), message);
int numberOfSheets = wb.getNumberOfSheets(); int numberOfSheets = wb.getNumberOfSheets();
for (int i = 0; i < numberOfSheets; i++) { for (int i = 0; i < numberOfSheets; i++) {
Sheet sheet = wb.getSheetAt(i); Sheet sheet = wb.getSheetAt(i);
@ -380,24 +395,32 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
break; break;
case 1: case 1:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "项目名称为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "项目名称为空");
} }
modulexVo.setProjectId(value); modulexVo.setProjectId(value);
break; break;
case 2: case 2:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "中文名称为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "中文名称为空");
} }
modulexVo.setModuleName(value); modulexVo.setModuleName(value);
break; break;
case 3: case 3:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "英文名称为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "英文名称为空");
} }
modulexVo.setModuleEnName(value); modulexVo.setModuleEnName(value);
break; break;
case 4: case 4:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "模块编码为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "模块编码为空");
} }
modulexVo.setModuleCode(value); modulexVo.setModuleCode(value);
@ -410,12 +433,16 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
break; break;
case 7: case 7:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "任务等级为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "任务等级为空");
} }
modulexVo.setWorkLevel(value); modulexVo.setWorkLevel(value);
break; break;
case 8: case 8:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "开发状态为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "开发状态为空");
} }
modulexVo.setWorkStatus(value); modulexVo.setWorkStatus(value);
@ -425,6 +452,8 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
break; break;
case 10: case 10:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "任务时长为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "任务时长为空");
} }
modulexVo.setDuration(value); modulexVo.setDuration(value);
@ -437,6 +466,8 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
break; break;
case 13: case 13:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "实际时长为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "实际时长为空");
} }
modulexVo.setRealDuration(value); modulexVo.setRealDuration(value);
@ -455,26 +486,36 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
break; break;
case 18: case 18:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "模块状态为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "模块状态为空");
} }
modulexVo.setStatus(value); modulexVo.setStatus(value);
break; break;
case 19: case 19:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "版本状态为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "版本状态为空");
} }
modulexVo.setVerisonStatus(value); modulexVo.setVerisonStatus(value);
break; break;
case 20: case 20:
if (value == null || value == "") { if (value == null || value == "") {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "版本号为空"); return Result.error("第" + (j + 1) + "行" + propertyNames.get(k) + "版本号为空");
}else if(value.length()<=0||value.length()>50){ }else if(value.length()<=0||value.length()>50){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本号不符合规范"); return Result.error("版本号不符合规范");
}else { }else {
modulexVo.setVerison(value); modulexVo.setVerison(value);
} }
break; break;
default: default:
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("未知错误"); return Result.error("未知错误");
} }
modulexVo.setUploadPerson(username); modulexVo.setUploadPerson(username);
@ -484,11 +525,15 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
} }
} }
modulexTemplateService.saveBatch(modulexVoList); modulexTemplateService.saveBatch(modulexVoList);
List<Modulex> modulexList = new ArrayList<>(); List<Modulex> modulexList = new ArrayList<>();
List<ModulexTemplate> modulexTemplates = this.SelectModulex(); List<ModulexTemplate> modulexTemplates = this.SelectModulex();
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
if(modulexTemplates==null||modulexTemplates.size()==0){ if(modulexTemplates==null||modulexTemplates.size()==0){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,预读数据失败,获取不到表格中的数据,请重新导入");
} }
else { else {
for (ModulexTemplate modulexTemplate : modulexTemplates) { for (ModulexTemplate modulexTemplate : modulexTemplates) {
@ -497,8 +542,11 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
} }
boolean isTure = modulexTemplateService.removeByIds(ids); boolean isTure = modulexTemplateService.removeByIds(ids);
if(!isTure){ if(!isTure){
return Result.error("临时表删除失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("预读数据删除失败,请重新导入");
} }
message.put("status", "导入数据中");
for (ModulexTemplate modulexTemplate : modulexTemplates) { for (ModulexTemplate modulexTemplate : modulexTemplates) {
Modulex modulex = new Modulex(); Modulex modulex = new Modulex();
String pid = modulexTemplate.getPid(); String pid = modulexTemplate.getPid();
@ -509,26 +557,36 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
queryWrapper.eq(Modulex::getModuleName,pid); queryWrapper.eq(Modulex::getModuleName,pid);
List<Modulex> list = this.list(queryWrapper); List<Modulex> list = this.list(queryWrapper);
if(list==null ||list.size()==0){ if(list==null ||list.size()==0){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,此模块不存在上级"); return Result.error("导入失败,此模块不存在上级");
} }
Modulex one =list.get(0); Modulex one =list.get(0);
if(one==null){ if(one==null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,此模块不存在上级"); return Result.error("导入失败,此模块不存在上级");
}String pid1 = one.getId(); }String pid1 = one.getId();
if(pid1==null){ if(pid1==null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,此模块不存在上级"); return Result.error("导入失败,此模块不存在上级");
} }
modulex.setPid(pid1); modulex.setPid(pid1);
} }
String projectId = modulexTemplate.getProjectId(); String projectId = modulexTemplate.getProjectId();
if(projectId==null){ if(projectId==null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,项目名称不能为空"); return Result.error("导入失败,项目名称不能为空");
}else { }else {
LambdaQueryWrapper<Projectx> projectxLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Projectx> projectxLambdaQueryWrapper = new LambdaQueryWrapper<>();
projectxLambdaQueryWrapper.eq(Projectx::getProjectName,projectId); projectxLambdaQueryWrapper.eq(Projectx::getProjectName,projectId);
Projectx projectx = projectxService.getOne(projectxLambdaQueryWrapper); Projectx projectx = projectxService.getOne(projectxLambdaQueryWrapper);
if(projectx==null){ if(projectx==null){
return Result.error("项目名称不存在"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,项目名称不存在");
} else { } else {
String projectxId = projectx.getId(); String projectxId = projectx.getId();
modulex.setProjectId(projectxId); modulex.setProjectId(projectxId);
@ -537,6 +595,8 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
String moduleName = modulexTemplate.getModuleName(); String moduleName = modulexTemplate.getModuleName();
String pid1 = modulex.getPid(); String pid1 = modulex.getPid();
if(moduleName==null){ if(moduleName==null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,中文名称不能为空"); return Result.error("导入失败,中文名称不能为空");
}else if(pid1==null){ }else if(pid1==null){
modulex.setModuleName(moduleName); modulex.setModuleName(moduleName);
@ -545,14 +605,20 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
modulexLambdaQueryWrapper.eq(Modulex::getPid,pid1).eq(Modulex::getModuleName,moduleName); modulexLambdaQueryWrapper.eq(Modulex::getPid,pid1).eq(Modulex::getModuleName,moduleName);
Modulex modulex1 = this.getOne(modulexLambdaQueryWrapper); Modulex modulex1 = this.getOne(modulexLambdaQueryWrapper);
if(modulex1!=null){ if(modulex1!=null){
return Result.error("相同的上级模块不能重名"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,相同的上级模块不能重名");
}modulex.setModuleName(moduleName); }modulex.setModuleName(moduleName);
String moduleEnName = modulexTemplate.getModuleEnName(); String moduleEnName = modulexTemplate.getModuleEnName();
if(moduleEnName==null){ if(moduleEnName==null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,英文名称不能为空"); return Result.error("导入失败,英文名称不能为空");
}modulex.setModuleEnName(moduleEnName); }modulex.setModuleEnName(moduleEnName);
String moduleCode = modulexTemplate.getModuleCode(); String moduleCode = modulexTemplate.getModuleCode();
if(moduleCode==null||moduleCode.length()>30){ if(moduleCode==null||moduleCode.length()>30){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,模块编码不能为空或者模块编码过长"); return Result.error("导入失败,模块编码不能为空或者模块编码过长");
} }
modulex.setModuleCode(moduleCode); modulex.setModuleCode(moduleCode);
@ -568,10 +634,14 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
sysUserLambdaQueryWrapper.eq(SysUser::getUsername,managerUsers); sysUserLambdaQueryWrapper.eq(SysUser::getUsername,managerUsers);
SysUser iSysUserServiceOne = iSysUserService.getOne(sysUserLambdaQueryWrapper); SysUser iSysUserServiceOne = iSysUserService.getOne(sysUserLambdaQueryWrapper);
if(iSysUserServiceOne==null){ if(iSysUserServiceOne==null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,责任人信息查询不到"); return Result.error("导入失败,责任人信息查询不到");
}else { }else {
String id = iSysUserServiceOne.getId(); String id = iSysUserServiceOne.getId();
if (id == null) { if (id == null) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,责任人信息查询不到"); return Result.error("导入失败,责任人信息查询不到");
} }
modulex.setManagerUsers(id); modulex.setManagerUsers(id);
@ -579,17 +649,23 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
} }
String workLevel = modulexTemplate.getWorkLevel(); String workLevel = modulexTemplate.getWorkLevel();
if(StringUtils.isBlank(workLevel)){ if(StringUtils.isBlank(workLevel)){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,任务等级不能为空"); return Result.error("导入失败,任务等级不能为空");
} }
else { else {
Integer integer = Integer.valueOf(workLevel); Integer integer = Integer.valueOf(workLevel);
if(integer<=0&&integer>=6){ if(integer<=0&&integer>=6){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,任务等级不规范"); return Result.error("导入失败,任务等级不规范");
} }
modulex.setWorkLevel(integer); modulex.setWorkLevel(integer);
} }
String workStatus = modulexTemplate.getWorkStatus(); String workStatus = modulexTemplate.getWorkStatus();
if(StringUtils.isBlank(workStatus)){ if(StringUtils.isBlank(workStatus)){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,工作状态不能为空"); return Result.error("导入失败,工作状态不能为空");
}else { }else {
Integer integer = 100; Integer integer = 100;
@ -607,6 +683,8 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
case "已取出": integer = 9; case "已取出": integer = 9;
break; break;
default: default:
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,开发状态不规范"); return Result.error("导入失败,开发状态不规范");
} }
modulex.setWorkStatus(integer); modulex.setWorkStatus(integer);
@ -617,7 +695,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
}else { }else {
Boolean result = this.checkTime(publishTime); Boolean result = this.checkTime(publishTime);
if(!result){ if(!result){
return Result.error("日期格式不规范"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,日期格式不规范");
}else { }else {
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(publishTime); Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(publishTime);
modulex.setPublishTime(date); modulex.setPublishTime(date);
@ -625,7 +705,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
} }
String duration = modulexTemplate.getDuration(); String duration = modulexTemplate.getDuration();
if(StringUtils.isBlank(duration)){ if(StringUtils.isBlank(duration)){
return Result.error("任务时长不能为空"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,任务时长不能为空");
}else { }else {
double parseDouble = Double.parseDouble(duration); double parseDouble = Double.parseDouble(duration);
modulex.setDuration(parseDouble); modulex.setDuration(parseDouble);
@ -636,7 +718,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
}else { }else {
Boolean result = this.checkTime(startTime); Boolean result = this.checkTime(startTime);
if(!result){ if(!result){
return Result.error("开始时间不规范"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,开始时间不规范");
}else { }else {
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime); Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime);
modulex.setStartTime(date); modulex.setStartTime(date);
@ -648,7 +732,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
}else { }else {
Boolean result = this.checkTime(submitTime); Boolean result = this.checkTime(submitTime);
if(!result){ if(!result){
return Result.error("提交时间不规范"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,提交时间不规范");
}else { }else {
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(submitTime); Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(submitTime);
modulex.setSubmitTime(date); modulex.setSubmitTime(date);
@ -656,11 +742,15 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
} }
String realDuration = modulexTemplate.getRealDuration(); String realDuration = modulexTemplate.getRealDuration();
if(StringUtils.isBlank(realDuration)){ if(StringUtils.isBlank(realDuration)){
return Result.error("实际时长不能为空"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,实际时长不能为空");
}else { }else {
double parseDouble = Double.parseDouble(realDuration); double parseDouble = Double.parseDouble(realDuration);
if(parseDouble<0.1){ if(parseDouble<0.1){
return Result.error("最小时间0.1小时"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,最小时间0.1小时");
} }
modulex.setRealDuration(parseDouble); modulex.setRealDuration(parseDouble);
} }
@ -672,11 +762,15 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
sysRoleLambdaQueryWrapper.eq(SysRole::getRoleName,userRole); sysRoleLambdaQueryWrapper.eq(SysRole::getRoleName,userRole);
SysRole one = iSysRoleService.getOne(sysRoleLambdaQueryWrapper); SysRole one = iSysRoleService.getOne(sysRoleLambdaQueryWrapper);
if(one==null){ if(one==null){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,用户角色不存在");
} }
String useRole = one.getId(); String useRole = one.getId();
if(useRole==null){ if(useRole==null){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,用户角色不存在");
} modulex.setUserRole(useRole); } modulex.setUserRole(useRole);
} }
String relatedBean = modulexTemplate.getRelatedBean(); String relatedBean = modulexTemplate.getRelatedBean();
@ -685,6 +779,8 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
}else { }else {
Boolean extracted = extracted(modulex, relatedBean); Boolean extracted = extracted(modulex, relatedBean);
if(!extracted){ if(!extracted){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("关联实体不存在"); return Result.error("关联实体不存在");
} }
} }
@ -698,7 +794,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
}modulex.setDiagrams(diagrams); }modulex.setDiagrams(diagrams);
String status = modulexTemplate.getStatus(); String status = modulexTemplate.getStatus();
if(StringUtils.isBlank(status)){ if(StringUtils.isBlank(status)){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,模块状态不能为空");
}else { }else {
Integer integer = 100; Integer integer = 100;
switch (status){ switch (status){
@ -709,13 +807,17 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
case "废弃": integer = 9; case "废弃": integer = 9;
break; break;
default: default:
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,模块状态不规范匹配不到");
} }
modulex.setStatus(integer); modulex.setStatus(integer);
} }
String verisonStatus = modulexTemplate.getVerisonStatus(); String verisonStatus = modulexTemplate.getVerisonStatus();
if(StringUtils.isBlank(verisonStatus)){ if(StringUtils.isBlank(verisonStatus)){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,版本状态不能为空");
}else { }else {
Integer integer = 100; Integer integer = 100;
switch (verisonStatus){ switch (verisonStatus){
@ -724,23 +826,31 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
case "历史": integer = 0; case "历史": integer = 0;
break; break;
default: default:
Result.error("未知错误"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
Result.error("导入失败,版本状态不规范,匹配失败");
} }
modulex.setVerisonStatus(integer); modulex.setVerisonStatus(integer);
} }
String verison = modulexTemplate.getVerison(); String verison = modulexTemplate.getVerison();
if(StringUtils.isBlank(verison)){ if(StringUtils.isBlank(verison)){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,版本号不能为空");
}else { }else {
int parseInt = Integer.parseInt(verison); int parseInt = Integer.parseInt(verison);
modulex.setVerison(parseInt); modulex.setVerison(parseInt);
} }
modulexList.add(modulex); modulexList.add(modulex);
} }
boolean result = this.saveBatch(modulexList); boolean result = this.saveSingleBatch(modulexList, loginUser, message);
if(!result){ if(!result){
return Result.error("导入失败"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("未知错误导入失败,请重新导入");
} }
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.OK("导入成功"); return Result.OK("导入成功");
} }
} }
@ -798,6 +908,22 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
List<ModulexTemplate> modulexTemplateList = modulexTemplateService.list(queryWrapper); List<ModulexTemplate> modulexTemplateList = modulexTemplateService.list(queryWrapper);
return modulexTemplateList; return modulexTemplateList;
} }
@Transactional
public boolean saveSingleBatch(List<Modulex> modulexList, LoginUser loginUser, Map<String, String> message) throws InterruptedException {
Boolean isTrue;
for (int i = 0; i < modulexList.size(); i++){
Thread.sleep(1000L);
message.put("uploaded", String.valueOf(i + 1));
isTrue = this.save(modulexList.get(i));
if(!isTrue){
webSocketUtils.sendMessage(loginUser.getId(), message);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return false;
}
}
return true;
}
private void handleStatus(String id, Integer a) { private void handleStatus(String id, Integer a) {

@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import javafx.util.Pair;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;

Loading…
Cancel
Save