Merge remote-tracking branch 'origin/dev_2307' into dev_2307

dev^2
zjh 1 year ago
commit e68b7b4658
  1. 183
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java

@ -3,6 +3,11 @@ package org.jeecg.modules.demo.functionx.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
@ -23,16 +28,16 @@ import org.jeecg.modules.projectUserRole.entity.ProjectUserRole;
import org.jeecg.modules.projectUserRole.service.IProjectUserRoleService; import org.jeecg.modules.projectUserRole.service.IProjectUserRoleService;
import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.tablex.vo.TablexVo;
import org.jeecg.modules.tablex.ws.WebSocketUtils;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service @Service
public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, FunctionxTest> implements FunctionXTestService { public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, FunctionxTest> implements FunctionXTestService {
@ -45,6 +50,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
private IProjectUserRoleService projectUserRoleService; private IProjectUserRoleService projectUserRoleService;
@Autowired @Autowired
private ISysUserService sysUserService; private ISysUserService sysUserService;
@Autowired
private WebSocketUtils webSocketUtils;
@Override @Override
public Result<?> importExcel(MultipartFile file) { public Result<?> importExcel(MultipartFile file) {
@ -53,6 +60,12 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String username = loginUser.getUsername(); String username = loginUser.getUsername();
Map<String, String> message = new HashMap<>();
message.put("isVisible", "true");
message.put("uploaded", "0");
message.put("status", "判断文件结构");
webSocketUtils.sendMessage(loginUser.getId(), message);
//创建输出流对象 //创建输出流对象
Workbook wb; Workbook wb;
/*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/ /*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/
@ -65,6 +78,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
}else if(split[1].equals("xls")){ }else if(split[1].equals("xls")){
wb= new HSSFWorkbook(file.getInputStream()); wb= new HSSFWorkbook(file.getInputStream());
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件格式错误,请上传Excel文件"); return Result.error("文件格式错误,请上传Excel文件");
} }
} catch (IOException e) { } catch (IOException e) {
@ -81,6 +96,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
if(lastRowIndex < 1) { if(lastRowIndex < 1) {
return Result.error("文件无内容或格式错误"); return Result.error("文件无内容或格式错误");
} }
message.put("status", "读取数据中");
webSocketUtils.sendMessage(loginUser.getId(), message);
List<FunctionxTest> listVo = new ArrayList<>(); List<FunctionxTest> listVo = new ArrayList<>();
for (int i=1;i<=lastRowIndex;i++) { for (int i=1;i<=lastRowIndex;i++) {
@ -120,9 +137,14 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
} }
boolean isSuccessSave = this.saveBatch(listVo); boolean isSuccessSave = this.saveBatch(listVo);
if (!isSuccessSave){ if (!isSuccessSave){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件读入失败"); return Result.error("文件读入失败");
} }
message.put("status", "数据校验");
webSocketUtils.sendMessage(loginUser.getId(), message);
//************************具体字段校验****************************** //************************具体字段校验******************************
LambdaQueryWrapper<FunctionxTest> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<FunctionxTest> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(username!=null, FunctionxTest::getCreatName,username); queryWrapper.eq(username!=null, FunctionxTest::getCreatName,username);
@ -166,7 +188,9 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
String moduleName=""; // 模块编码 String moduleName=""; // 模块编码
functionx.setCreateBy(username); //创建人 functionx.setCreateBy(username); //创建人
functionx.setCreateTime(new Date()); //创建日期 functionx.setCreateTime(new Date()); //创建日期
if(StringUtils.isBlank(moduleId)){ // 空和null if(StringUtils.isBlank(moduleId)){ // 空和null{
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("对应模块不能为空"); return Result.error("对应模块不能为空");
} else{ } else{
for(Modulex modulex : modulexList){ for(Modulex modulex : modulexList){
@ -178,35 +202,51 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
} }
} }
if(functionx.getModuleId() == null){ if(functionx.getModuleId() == null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的对应模块"); return Result.error("请输入正确的对应模块");
} }
} }
if(StringUtils.isBlank(functionName)){ // 空和null if(StringUtils.isBlank(functionName)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("中文名称不能为空"); return Result.error("中文名称不能为空");
} else{ } else{
LambdaQueryWrapper<Functionx> queryWrapper1 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Functionx> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(moduleId!=null,Functionx::getModuleId,moduleId); queryWrapper1.eq(moduleId!=null,Functionx::getModuleId,moduleId);
queryWrapper1.eq(Functionx::getFunctionName,functionName); queryWrapper1.eq(Functionx::getFunctionName,"%"+functionName+"%");
int count = functionxService.count(queryWrapper1); List<Functionx> list1 = functionxService.list(queryWrapper1);
if(count>0) if(list1.size()>0){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("中文名称在模块下重复"); return Result.error("中文名称在模块下重复");
}
functionx.setFunctionName(functionName); functionx.setFunctionName(functionName);
} }
if(StringUtils.isBlank(functionEnName)){ // 空和null if(StringUtils.isBlank(functionEnName)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("英文名称不能为空"); return Result.error("英文名称不能为空");
} else{ } else{
LambdaQueryWrapper<Functionx> queryWrapper2 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Functionx> queryWrapper2 = new LambdaQueryWrapper<>();
queryWrapper2.eq(moduleId!=null,Functionx::getModuleId,moduleId); queryWrapper2.eq(moduleId!=null,Functionx::getModuleId,moduleId);
queryWrapper2.eq(Functionx::getFunctionEnName,functionEnName); queryWrapper2.eq(Functionx::getFunctionEnName,functionEnName);
int count = functionxService.count(queryWrapper2); int count = functionxService.count(queryWrapper2);
if(count>0) if(count>0){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("英文名称在模块下重复"); return Result.error("英文名称在模块下重复");
}
functionx.setFunctionEnName(functionEnName); functionx.setFunctionEnName(functionEnName);
} }
// 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99 // 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99
int type; int type;
if(StringUtils.isBlank(functionType)){ // 空和null if(StringUtils.isBlank(functionType)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能类型不能为空"); return Result.error("功能类型不能为空");
} else{ } else{
switch (functionType){ switch (functionType){
@ -218,17 +258,31 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
case "导入": type=5; break; case "导入": type=5; break;
case "导出": type=6; break; case "导出": type=6; break;
case "其它": type=99; break; case "其它": type=99; break;
default: return Result.error("功能类型错误"); default:
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能类型错误");
} }
functionx.setFunctionType(type); functionx.setFunctionType(type);
} }
// 模块编码+功能缩写;自动填充+手动修改 // 模块编码+功能缩写;自动填充+手动修改
if(StringUtils.isBlank(functionCode)){ // 空和null if(StringUtils.isBlank(functionCode)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能编码不能为空"); return Result.error("功能编码不能为空");
} else{ } else{
String str = moduleName+functionType; LambdaQueryWrapper<Modulex> queryWrapperModulex = new LambdaQueryWrapper<>();
if(!str.equals(functionCode)) queryWrapperModulex.eq(Modulex::getModuleName,moduleName);
Modulex modulex = modulexService.getOne(queryWrapperModulex);
String moduleCode = modulex.getModuleCode();
String firstChar = toFirstChar(functionType);
String str = moduleCode+firstChar;
if(!str.equals(functionCode)){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能编码错误"); return Result.error("功能编码错误");
}
functionx.setFunctionCode(functionCode); functionx.setFunctionCode(functionCode);
} }
@ -241,30 +295,53 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
int count = projectUserRoleService.count(queryWrapperUser); int count = projectUserRoleService.count(queryWrapperUser);
if(count>0) if(count>0)
functionx.setUserRole(userRole); functionx.setUserRole(userRole);
else else{
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的用户角色"); return Result.error("请输入正确的用户角色");
} }
}
if(StringUtils.isNotBlank(managerUsers)){ // 责任人 if(StringUtils.isNotBlank(managerUsers)){ // 责任人
String[] splitManager = managerUsers.split("\\s+|,|;|、");
int count = 0;
for (String manager : splitManager){
LambdaQueryWrapper<SysUser> queryWrapperUserName = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> queryWrapperUserName = new LambdaQueryWrapper<>();
queryWrapperUserName.eq(SysUser::getUsername,managerUsers); queryWrapperUserName.eq(!manager.isEmpty(),SysUser::getUsername,manager);
int count = sysUserService.count(queryWrapperUserName); count = sysUserService.count(queryWrapperUserName);
if(count == 0) {
break;
}
}
if(count>0) if(count>0)
functionx.setManagerUsers(managerUsers); functionx.setManagerUsers(managerUsers);
else else{
return Result.error("请输入正确的责任人"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开");
}
} }
// 值:1、2、3、4、5,默认2 // 值:1、2、3、4、5,默认2
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{
int integer = Integer.parseInt(workLevel); int integer = Integer.parseInt(workLevel);
if (integer<1 || integer>5){ if (integer<1 || integer>5){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务等级错误"); return Result.error("任务等级错误");
} }
functionx.setWorkLevel(integer); functionx.setWorkLevel(integer);
} }
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 {
// 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0 // 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0
@ -284,11 +361,15 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Date date; Date date;
Boolean isTime = checkTime(publishTime); Boolean isTime = checkTime(publishTime);
if (!isTime){ if (!isTime){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("发布时间错误,应为"+pattern+"类型"); return Result.error("发布时间错误,应为"+pattern+"类型");
} }
try { try {
date = dateFormat.parse(publishTime); date = dateFormat.parse(publishTime);
} catch (Exception e) { } catch (Exception e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("发布时间错误,应为"+pattern+"类型"); return Result.error("发布时间错误,应为"+pattern+"类型");
} }
functionx.setPublishTime(date); functionx.setPublishTime(date);
@ -298,11 +379,15 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Date date; Date date;
Boolean isTime = checkTime(startTime); Boolean isTime = checkTime(startTime);
if (!isTime){ if (!isTime){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间错误,应为"+pattern+"类型"); return Result.error("开始时间错误,应为"+pattern+"类型");
} }
try { try {
date = dateFormat.parse(startTime); date = dateFormat.parse(startTime);
} catch (Exception e) { } catch (Exception e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间错误,应为"+pattern+"类型"); return Result.error("开始时间错误,应为"+pattern+"类型");
} }
functionx.setStartTime(date); functionx.setStartTime(date);
@ -317,22 +402,32 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Date date; Date date;
Boolean isTime = checkTime(submitTime); Boolean isTime = checkTime(submitTime);
if (!isTime){ if (!isTime){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间时间错误,应为"+pattern+"类型"); return Result.error("提交时间时间错误,应为"+pattern+"类型");
} }
try { try {
date = dateFormat.parse(submitTime); date = dateFormat.parse(submitTime);
} catch (Exception e) { } catch (Exception e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间时间错误,应为"+pattern+"类型"); return Result.error("提交时间时间错误,应为"+pattern+"类型");
} }
functionx.setSubmitTime(date); functionx.setSubmitTime(date);
} }
if(StringUtils.isNotBlank(realDuration)){ if(StringUtils.isNotBlank(realDuration)){
Double aDouble = Double.valueOf(realDuration); Double aDouble = Double.valueOf(realDuration);
if (aDouble<0.1) if (aDouble<0.1){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("实际时长错误"); return Result.error("实际时长错误");
}
functionx.setDuration(aDouble); functionx.setDuration(aDouble);
} }
if(StringUtils.isBlank(status)){ // 空和null if(StringUtils.isBlank(status)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能状态不能为空"); return Result.error("功能状态不能为空");
} else{ } else{
// 值:正常1、停用0、废弃9;默认1 // 值:正常1、停用0、废弃9;默认1
@ -345,6 +440,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
functionx.setStatus(type); functionx.setStatus(type);
} }
if(StringUtils.isBlank(verisonStatus)){ // 空和null if(StringUtils.isBlank(verisonStatus)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态不能为空"); return Result.error("版本状态不能为空");
} else{ } else{
// 值:当前1、历史0;默认1 // 值:当前1、历史0;默认1
@ -356,6 +453,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
functionx.setStatus(type); functionx.setStatus(type);
} }
if(StringUtils.isBlank(verison)){ // 空和null if(StringUtils.isBlank(verison)){ // 空和null
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本号不能为空"); return Result.error("版本号不能为空");
} else{ } else{
Integer integer = Integer.valueOf(verison); Integer integer = Integer.valueOf(verison);
@ -366,7 +465,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
} }
//**************************校验结束****************************** //**************************校验结束******************************
boolean isSuccessInsert = functionxService.saveBatch(listInsert); boolean isSuccessInsert = isSuccessInsert(loginUser, message, listInsert);
if(!isSuccessInsert){ if(!isSuccessInsert){
return Result.OK("插入失败"); return Result.OK("插入失败");
} }
@ -374,6 +473,28 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
return Result.OK("插入成功"); return Result.OK("插入成功");
} }
private boolean isSuccessInsert(LoginUser loginUser, Map<String, String> message, List<Functionx> listInsert) {
message.put("status", "导入数据中");
webSocketUtils.sendMessage(loginUser.getId(), message);
for (int i = 0; i < listInsert.size(); i++){
try {
Thread.sleep(1000L);
message.put("uploaded", String.valueOf(i + 1));
boolean isSuccessInsert = functionxService.save(listInsert.get(i));
if (!isSuccessInsert){
return false;
}
webSocketUtils.sendMessage(loginUser.getId(), message);
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
} finally {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
}
}
return true;
}
/** /**
* 检查时间格式是否有效 * 检查时间格式是否有效
*/ */
@ -403,4 +524,28 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
return true; return true;
} }
/**
* 名称缩写
*/
public static String toFirstChar(String chinese){
String pinyinStr = "";
char[] newChar = chinese.toCharArray(); //转为单个字符
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < newChar.length; i++) {
if (newChar[i] > 128) {
try {
pinyinStr += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0].charAt(0);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
}else{
pinyinStr += newChar[i];
}
}
return pinyinStr;
}
} }

Loading…
Cancel
Save