From fd4cc1135ceb9cc7e5d4986d64c76bb821c09178 Mon Sep 17 00:00:00 2001 From: guilongma <3307671311@qq.com> Date: Mon, 24 Jul 2023 09:11:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AF=BC=E5=85=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8A=9F=E8=83=BD=E7=BC=96=E7=A0=81=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=BF=9B=E5=BA=A6=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/FunctionXTestServiceImpl.java | 183 ++++++++++++++++-- 1 file changed, 164 insertions(+), 19 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java index b11e5fb..7e66324 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java +++ b/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.toolkit.StringUtils; 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.ss.usermodel.Cell; 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.system.entity.SysUser; 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.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; @Service public class FunctionXTestServiceImpl extends ServiceImpl implements FunctionXTestService { @@ -45,6 +50,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl importExcel(MultipartFile file) { @@ -53,6 +60,12 @@ public class FunctionXTestServiceImpl extends ServiceImpl message = new HashMap<>(); + message.put("isVisible", "true"); + message.put("uploaded", "0"); + message.put("status", "判断文件结构"); + webSocketUtils.sendMessage(loginUser.getId(), message); + //创建输出流对象 Workbook wb; /*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/ @@ -65,6 +78,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl listVo = new ArrayList<>(); for (int i=1;i<=lastRowIndex;i++) { @@ -120,9 +137,14 @@ public class FunctionXTestServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(username!=null, FunctionxTest::getCreatName,username); @@ -166,7 +188,9 @@ public class FunctionXTestServiceImpl extends ServiceImpl queryWrapper1 = new LambdaQueryWrapper<>(); queryWrapper1.eq(moduleId!=null,Functionx::getModuleId,moduleId); - queryWrapper1.eq(Functionx::getFunctionName,functionName); - int count = functionxService.count(queryWrapper1); - if(count>0) + queryWrapper1.eq(Functionx::getFunctionName,"%"+functionName+"%"); + List list1 = functionxService.list(queryWrapper1); + if(list1.size()>0){ + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("中文名称在模块下重复"); + } + functionx.setFunctionName(functionName); } if(StringUtils.isBlank(functionEnName)){ // 空和null + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("英文名称不能为空"); } else{ LambdaQueryWrapper queryWrapper2 = new LambdaQueryWrapper<>(); queryWrapper2.eq(moduleId!=null,Functionx::getModuleId,moduleId); queryWrapper2.eq(Functionx::getFunctionEnName,functionEnName); int count = functionxService.count(queryWrapper2); - if(count>0) + if(count>0){ + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("英文名称在模块下重复"); + } + functionx.setFunctionEnName(functionEnName); } // 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99 int type; if(StringUtils.isBlank(functionType)){ // 空和null + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("功能类型不能为空"); } else{ switch (functionType){ @@ -218,17 +258,31 @@ public class FunctionXTestServiceImpl extends ServiceImpl queryWrapperModulex = new LambdaQueryWrapper<>(); + 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("功能编码错误"); + } + functionx.setFunctionCode(functionCode); } @@ -241,30 +295,53 @@ public class FunctionXTestServiceImpl extends ServiceImpl0) functionx.setUserRole(userRole); - else + else{ + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("请输入正确的用户角色"); } + + } if(StringUtils.isNotBlank(managerUsers)){ // 责任人 + String[] splitManager = managerUsers.split("\\s+|,|;|、"); + + int count = 0; + for (String manager : splitManager){ LambdaQueryWrapper queryWrapperUserName = new LambdaQueryWrapper<>(); - queryWrapperUserName.eq(SysUser::getUsername,managerUsers); - int count = sysUserService.count(queryWrapperUserName); + queryWrapperUserName.eq(!manager.isEmpty(),SysUser::getUsername,manager); + count = sysUserService.count(queryWrapperUserName); + if(count == 0) { + break; + } + } + if(count>0) functionx.setManagerUsers(managerUsers); - else - return Result.error("请输入正确的责任人"); + else{ + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开"); + } + } // 值:1、2、3、4、5,默认2 if(StringUtils.isBlank(workLevel)){ // 任务等级 + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("任务等级不能为空"); } else{ int integer = Integer.parseInt(workLevel); if (integer<1 || integer>5){ + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("任务等级错误"); } functionx.setWorkLevel(integer); } if(StringUtils.isBlank(workStatus)){ + message.put("isVisible", "false"); + webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("任务状态不能为空"); } else { // 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0 @@ -284,11 +361,15 @@ public class FunctionXTestServiceImpl extends ServiceImpl message, List 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 128) { + try { + pinyinStr += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0].charAt(0); + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + }else{ + pinyinStr += newChar[i]; + } + } + return pinyinStr; + } + }