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

dev
shiji 1 year ago
commit f2c7e246f7
  1. 6
      ant-design-vue-jeecg/src/views/modulex/ModulexList.vue
  2. 12
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functiontemplate/controller/FunctionTemplateController.java
  3. 98
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functiontemplate/entity/FunctionTemplateTest.java
  4. 9
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functiontemplate/mapper/FunctionTemplateTestMapper.java
  5. 10
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functiontemplate/service/FunctionTemplateTestService.java
  6. 323
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functiontemplate/service/impl/FunctionTemplateTestServiceImpl.java
  7. 17
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/controller/FunctionxController.java
  8. 127
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/entity/FunctionxTest.java
  9. 8
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/mapper/FunctionxTestMapper.java
  10. 10
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/FunctionXTestService.java
  11. 411
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java

@ -71,7 +71,9 @@
<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-button type="primary" icon="import">导入模块</a-button> <a-button type="primary" icon="import">导入模块</a-button>
<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>
</a-upload>
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="ruleImportExcelUrl" @change="handleImportExcel"> <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="ruleImportExcelUrl" @change="handleImportExcel">
<a-button type="primary" icon="import">导入规则</a-button> <a-button type="primary" icon="import">导入规则</a-button>
</a-upload> </a-upload>
@ -397,6 +399,7 @@ export default {
deleteBatch: "/modulex/modulex/deleteBatch", deleteBatch: "/modulex/modulex/deleteBatch",
exportXlsUrl: "/modulex/modulex/exportXls", exportXlsUrl: "/modulex/modulex/exportXls",
importExcelUrl: "modulex/modulex/importExcel", importExcelUrl: "modulex/modulex/importExcel",
functionImportExcelUrl: "/functionx/functionx/importExcel",
tablexImportExcelUrl: "tablex/tablex/importExcel", tablexImportExcelUrl: "tablex/tablex/importExcel",
ruleImportExcelUrl: "rulex/rulex/importExcel", ruleImportExcelUrl: "rulex/rulex/importExcel",
}, },
@ -424,6 +427,9 @@ export default {
checkColumn: function () { checkColumn: function () {
return this.columns.map(item => item.title) return this.columns.map(item => item.title)
}, },
functionImportExcelUrl: function(){
return `${window._CONFIG['domianURL']}/${this.url.functionImportExcelUrl}`;
},
tablexImportExcelUrl: function(){ tablexImportExcelUrl: function(){
return `${window._CONFIG['domianURL']}/${this.url.tablexImportExcelUrl}`; return `${window._CONFIG['domianURL']}/${this.url.tablexImportExcelUrl}`;
}, },

@ -11,6 +11,7 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.functiontemplate.entity.FunctionTemplate; import org.jeecg.modules.demo.functiontemplate.entity.FunctionTemplate;
import org.jeecg.modules.demo.functiontemplate.service.FunctionTemplateTestService;
import org.jeecg.modules.demo.functiontemplate.service.IFunctionTemplateService; import org.jeecg.modules.demo.functiontemplate.service.IFunctionTemplateService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -23,6 +24,7 @@ import org.jeecg.common.system.base.controller.JeecgController;
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.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -41,6 +43,8 @@ import org.jeecg.common.aspect.annotation.AutoLog;
public class FunctionTemplateController extends JeecgController<FunctionTemplate, IFunctionTemplateService> { public class FunctionTemplateController extends JeecgController<FunctionTemplate, IFunctionTemplateService> {
@Autowired @Autowired
private IFunctionTemplateService functionTemplateService; private IFunctionTemplateService functionTemplateService;
@Autowired
private FunctionTemplateTestService templateTestService;
/** /**
* 分页列表查询 * 分页列表查询
@ -192,13 +196,13 @@ public class FunctionTemplateController extends JeecgController<FunctionTemplate
/** /**
* 通过excel导入数据 * 通过excel导入数据
* *
* @param request
* @param response
* @return * @return
*/ */
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { public Result<?> importExcel(MultipartFile file) {
return super.importExcel(request, response, FunctionTemplate.class);
return templateTestService.importExcel(file);
// return super.importExcel(request, response, FunctionTemplate.class); // 原始代码
} }
} }

@ -0,0 +1,98 @@
package org.jeecg.modules.demo.functiontemplate.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
*
* @TableName function_template_test
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FunctionTemplateTest implements Serializable {
/**
*
*/
private Long id;
/**
* 模块模板类型
*/
private String modulextypename;
/**
* 中文名称
*/
private String functiontemplatename;
/**
* 英文名称
*/
private String functiontemplateenname;
/**
* 功能编码
*/
private String functiontemplatecode;
/**
* 功能类型
*/
private String functiontemplatetype;
/**
* 功能描述
*/
private String functiontemplatedescribe;
/**
* 分析图
*/
private String diagrams;
/**
* 用户角色
*/
private String userrole;
/**
* 责任人
*/
private String managerusers;
/**
* 任务等级
*/
private String worklevel;
/**
* 任务状态
*/
private String workstatus;
/**
* 发布时间
*/
private String publishtime;
/**
* 开始时间
*/
private String starttime;
/**
* 任务时长
*/
private String duration;
/**
* 创建人
*/
private String createname;
}

@ -0,0 +1,9 @@
package org.jeecg.modules.demo.functiontemplate.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.jeecg.modules.demo.functiontemplate.entity.FunctionTemplateTest;
@Mapper
public interface FunctionTemplateTestMapper extends BaseMapper<FunctionTemplateTest> {
}

@ -0,0 +1,10 @@
package org.jeecg.modules.demo.functiontemplate.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.demo.functiontemplate.entity.FunctionTemplateTest;
import org.springframework.web.multipart.MultipartFile;
public interface FunctionTemplateTestService extends IService<FunctionTemplateTest> {
Result<?> importExcel(MultipartFile file);
}

@ -0,0 +1,323 @@
package org.jeecg.modules.demo.functiontemplate.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 lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.demo.functiontemplate.entity.FunctionTemplate;
import org.jeecg.modules.demo.functiontemplate.entity.FunctionTemplateTest;
import org.jeecg.modules.demo.functiontemplate.mapper.FunctionTemplateTestMapper;
import org.jeecg.modules.demo.functiontemplate.service.FunctionTemplateTestService;
import org.jeecg.modules.demo.functiontemplate.service.IFunctionTemplateService;
import org.jeecg.modules.demo.moduletype.entity.ModuleType;
import org.jeecg.modules.demo.moduletype.service.IModuleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
@Slf4j
public class FunctionTemplateTestServiceImpl extends ServiceImpl<FunctionTemplateTestMapper, FunctionTemplateTest> implements FunctionTemplateTestService {
@Autowired
private IFunctionTemplateService functionTemplateService;
@Autowired
private IModuleTypeService moduleTypeService;
/**
* 导入excel
*
* @param file 文件
* @return {@link Result}<{@link ?}>
*/
@Override
@Transactional
public Result<?> importExcel(MultipartFile file) {
List<FunctionTemplateTest> listVo = new ArrayList<>();
// 获取当前操作用户
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String username = loginUser.getUsername();
Map<Integer, List<String>> fileMap = new HashMap<>();
//创建输出流对象
Workbook wb=null;
/*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/
String[] split = file.getOriginalFilename().split("\\.");
try {
if(split[1].equals("xlsx")){
wb= new XSSFWorkbook(file.getInputStream());
}else if(split[1].equals("xls")){
wb= new HSSFWorkbook(file.getInputStream());
} else {
return Result.error("文件格式错误,请上传Excel文件");
}
} catch (IOException e) {
throw new RuntimeException("请上传正确格式文件");
}
//获取工作表页数据
//读取第1页的数据
Sheet sheet=wb.getSheetAt(0);
//获取工作表页中行数据
//读取的总的行数
int lastRowIndex=sheet.getLastRowNum();
if(lastRowIndex < 1) {
return Result.error("文件无内容或格式错误");
}
for (int i=1;i<=lastRowIndex;i++) {
Row row = sheet.getRow(i);
if(row!=null){
short lastCellNum = row.getLastCellNum();
List<String> list = new ArrayList<>();
for (int j=0;j<lastCellNum;j++){
Cell cell = row.getCell(j);
String cellValue = cell.getStringCellValue();
list.add(cellValue);
}
FunctionTemplateTest fun = new FunctionTemplateTest();
fun.setModulextypename(list.get(0));
fun.setFunctiontemplatename(list.get(1));
fun.setFunctiontemplateenname(list.get(2));
fun.setFunctiontemplatecode(list.get(3));
fun.setFunctiontemplatetype(list.get(4));
fun.setFunctiontemplatedescribe(list.get(5)); // 功能描述
fun.setDiagrams(list.get(6)); // 分析图
fun.setUserrole(list.get(7)); // 用户角色
fun.setManagerusers(list.get(8)); // 责任人
fun.setWorklevel(list.get(9)); // 任务等级
fun.setWorkstatus(list.get(10)); //任务状态
fun.setPublishtime(list.get(11)); // 发布时间
fun.setStarttime(list.get(12)); // 开始时间
fun.setDuration(list.get(13)); // 任务时长
fun.setCreatename(username);
listVo.add(fun);
}
}
boolean isSuccessSave = this.saveBatch(listVo);
if (!isSuccessSave){
return Result.error("文件读入失败");
}
// ------------------------------字段具体校验----------------------------------
LambdaQueryWrapper<FunctionTemplateTest> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(username!=null,FunctionTemplateTest::getCreatename,username);
List<FunctionTemplateTest> list = this.list(queryWrapper);
boolean remove = this.remove(queryWrapper);
if (!remove){
log.error("临时表删除错误!");
}
List<FunctionTemplate> listInsert = new ArrayList<>(); // 正式插入
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
for (FunctionTemplateTest function :list){
FunctionTemplate functionTemplate = new FunctionTemplate();
String modulextypename = function.getModulextypename(); // 模块模板类型
String functiontemplatename = function.getFunctiontemplatename(); // 中文名称
String functiontemplateenname = function.getFunctiontemplateenname(); // 英文名称
String functiontemplatecode = function.getFunctiontemplatecode(); // 功能编码
String functiontemplatetype = function.getFunctiontemplatetype(); // 功能类型
String functiontemplatedescribe = function.getFunctiontemplatedescribe(); // 任务描述
String diagrams = function.getDiagrams();// 分析图
String userrole = function.getUserrole(); // 用户角色
String managerUsers = function.getManagerusers(); // 责任人
String worklevel = function.getWorklevel(); // 任务等级
String workstatus = function.getWorkstatus(); // 任务状态
String publishtime = function.getPublishtime(); // 发布时间
String starttime = function.getStarttime(); // 开始时间
String duration = function.getDuration(); // 任务时长
if(StringUtils.isBlank(modulextypename)){ // 空和null
return Result.error("模块模板类型不能为空");
} else{
LambdaQueryWrapper<ModuleType> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(ModuleType::getModulextypeName,modulextypename);
ModuleType one = moduleTypeService.getOne(queryWrapper1);
if(one==null)
return Result.error("请输入正确的模块模板类型");
else
functionTemplate.setModulextypeId(one.getId());
}
if(StringUtils.isBlank(functiontemplatename)){ // 空和null
return Result.error("中文名称不能为空");
} else{
LambdaQueryWrapper<FunctionTemplate> queryWrapperCh = new LambdaQueryWrapper<>();
// queryWrapperCh.eq()
functionTemplate.setFunctionTemplateName(functiontemplatename);
}
if(StringUtils.isBlank(functiontemplateenname)){
return Result.error("英文名称不能为空");
} else {
functionTemplate.setFunctionTemplateEnName(functiontemplateenname);
}
Integer type=100;
if(StringUtils.isBlank(functiontemplatetype)){
// 模块编码+功能缩写;自动填充+手动修改
return Result.error("功能类型不能为空");
} else {
// 值:列表0、新增1、删除2、修改3、查看4、导入5、导出6、其它99;默认99
switch (functiontemplatetype){
case "列表": type=0; break;
case "新增": type=1; break;
case "删除": type=2; break;
case "修改": type=3; break;
case "查看": type=4; break;
case "导入": type=5; break;
case "导出": type=6; break;
case "其它": type=99; break;
default: return Result.error("功能类型错误");
}
functionTemplate.setFunctionTemplateType(type);
}
if(StringUtils.isBlank(functiontemplatecode)){
return Result.error("功能编码不能为空");
} else {
if (type!=100){
String str = "后期替换"+functiontemplatetype;
if(!str.equals(functiontemplatecode))
return Result.error("功能编码错误");
}
functionTemplate.setFunctionTemplateCode(functiontemplatecode);
}
if(StringUtils.isNotBlank(functiontemplatedescribe)){
functionTemplate.setFunctionTemplateDescribe(functiontemplatedescribe);
}
if(StringUtils.isNotBlank(diagrams)){
functionTemplate.setDiagrams(diagrams);
}
if(StringUtils.isNotBlank(userrole)){
functionTemplate.setUserRole(userrole);
}
if(StringUtils.isNotBlank(managerUsers)){
functionTemplate.setManagerUsers(managerUsers);
}
if(StringUtils.isBlank(worklevel)){ // 空和null
return Result.error("任务等级不能为空");
} else{
Integer level = Integer.valueOf(worklevel);
if(level<0 || level>6){
return Result.error("任务等级不符范围");
}
functionTemplate.setWorkLevel(level);
}
if(StringUtils.isBlank(workstatus)){
return Result.error("任务状态不能为空");
} else {
// 预制值:未发布0、已发布1、开发中2、已完成3、已审核4、DEBUG9;默认0
type=10;
switch (workstatus){
case "未发布": type=0; break;
case "已发布": type=1; break;
case "开发中": type=2; break;
case "已完成": type=3; break;
case "已审核": type=4; break;
case "DEBUG": type=9; break;
default: return Result.error("任务状态错误");
}
functionTemplate.setWorkStatus(type);
}
if(StringUtils.isNotBlank(publishtime)){
Date date;
Boolean isTime = checkTime(publishtime);
if (!isTime){
return Result.error("发布日期错误,应为"+pattern+"类型");
}
try {
date = dateFormat.parse(publishtime);
} catch (Exception e) {
return Result.error("发布日期错误,应为"+pattern+"类型");
}
functionTemplate.setPublishTime(date);
}
if(StringUtils.isNotBlank(starttime)){
Date date;
Boolean isTime = checkTime(starttime);
if (!isTime){
return Result.error("开始日期错误,应为"+pattern+"类型");
}
try {
date = dateFormat.parse(starttime);
} catch (Exception e) {
return Result.error("开始日期错误,应为"+pattern+"类型");
}
functionTemplate.setPublishTime(date);
}
if(StringUtils.isNotBlank(duration)){
Double dura = Double.valueOf(duration);
functionTemplate.setDuration(dura);
}
functionTemplate.setCreateBy(username);
functionTemplate.setCreateTime(new Date());
listInsert.add(functionTemplate);
}
// -------------------------------校验结束--------------------------------------
boolean isSuccess = functionTemplateService.saveBatch(listInsert);
if(!isSuccess){
return Result.OK("插入失败");
}
return Result.OK("插入成功");
}
/**
* 检查时间格式是否有效
*/
private Boolean checkTime(String date){
// 使用日期解析方式校验日期逻辑有效性
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date parsedDate = dateFormat.parse(date);
// 检查年份是否合法(例如:不能小于1900)
Calendar calendar = Calendar.getInstance();
calendar.setTime(parsedDate);
int year = calendar.get(Calendar.YEAR);
if (year < 1900) {
return false;
}
// 检查日期的逻辑有效性(例如:2月30日是无效的)
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH) + 1;
int maxDayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
if (dayOfMonth > maxDayOfMonth) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
}

@ -17,6 +17,7 @@ import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.functionx.entity.Functionx; import org.jeecg.modules.demo.functionx.entity.Functionx;
import org.jeecg.modules.demo.functionx.entity.RoleConstant; import org.jeecg.modules.demo.functionx.entity.RoleConstant;
import org.jeecg.modules.demo.functionx.service.FunctionXTestService;
import org.jeecg.modules.demo.functionx.service.IFunctionxService; import org.jeecg.modules.demo.functionx.service.IFunctionxService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -70,6 +71,9 @@ public class FunctionxController extends JeecgController<Functionx, IFunctionxSe
@Autowired @Autowired
private IRulexService iRulexService; private IRulexService iRulexService;
@Autowired
private FunctionXTestService functionXTestService;
/** /**
* 分页列表查询 * 分页列表查询
@ -241,16 +245,9 @@ public class FunctionxController extends JeecgController<Functionx, IFunctionxSe
return super.exportXls(request, functionx, Functionx.class, "功能管理"); return super.exportXls(request, functionx, Functionx.class, "功能管理");
} }
/** @PostMapping("/importExcel")
* 通过excel导入数据 public Result<?> importExcel(MultipartFile file) {
* return functionXTestService.importExcel(file);
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, Functionx.class);
} }
//获得模块管理的编码,填充给功能编码 //获得模块管理的编码,填充给功能编码

@ -0,0 +1,127 @@
package org.jeecg.modules.demo.functionx.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName functionx_test
*/
@TableName(value ="functionx_test")
@Data
public class FunctionxTest implements Serializable {
/**
*
*/
@TableId
private String id;
/**
* 对应模块
*/
private String moduleName;
/**
* 中文名称
*/
private String functionName;
/**
* 英文名称
*/
private String functionEnName;
/**
* 功能编码
*/
private String functionCode;
/**
* 功能类型
*/
private String functionType;
/**
* 功能描述
*/
private String pmDescribe;
/**
* 分析图
*/
private String diagrams;
/**
* 用户角色
*/
private String userRole;
/**
* 责任人
*/
private String managerUsers;
/**
* 任务等级
*/
private String workLevel;
/**
* 任务状态
*/
private String workStatus;
/**
* 发布时间
*/
private String publishTime;
/**
* 开始时间
*/
private String startTime;
/**
* 任务时长
*/
private String duration;
/**
* 提交时间
*/
private String submitTime;
/**
* 实际时长
*/
private String realDuration;
/**
* 功能状态
*/
private String status;
/**
* 版本状态
*/
private String verisonStatus;
/**
* 版本号
*/
private String verison;
/**
* 创建人
*/
private String creatName;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,8 @@
package org.jeecg.modules.demo.functionx.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.jeecg.modules.demo.functionx.entity.FunctionxTest;
@Mapper
public interface FunctionxTestMapper extends BaseMapper<FunctionxTest> {
}

@ -0,0 +1,10 @@
package org.jeecg.modules.demo.functionx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.demo.functionx.entity.FunctionxTest;
import org.springframework.web.multipart.MultipartFile;
public interface FunctionXTestService extends IService<FunctionxTest> {
Result<?> importExcel(MultipartFile file);
}

@ -0,0 +1,411 @@
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 org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.demo.functionx.entity.Functionx;
import org.jeecg.modules.demo.functionx.entity.FunctionxTest;
import org.jeecg.modules.demo.functionx.mapper.FunctionxTestMapper;
import org.jeecg.modules.demo.functionx.service.FunctionXTestService;
import org.jeecg.modules.demo.functionx.service.IFunctionxService;
import org.jeecg.modules.modulex.entity.Modulex;
import org.jeecg.modules.modulex.service.IModulexService;
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.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;
@Service
public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, FunctionxTest> implements FunctionXTestService {
@Autowired
private IModulexService modulexService;
@Autowired
private IFunctionxService functionxService;
@Autowired
private IProjectUserRoleService projectUserRoleService;
@Autowired
private ISysUserService sysUserService;
@Override
public Result<?> importExcel(MultipartFile file) {
// 获取当前操作用户
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String username = loginUser.getUsername();
//创建输出流对象
Workbook wb;
/*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/
String[] split = file.getOriginalFilename().split("\\.");
try {
if(split[1].equals("xlsx")){
wb= new XSSFWorkbook(file.getInputStream());
}else if(split[1].equals("xls")){
wb= new HSSFWorkbook(file.getInputStream());
} else {
return Result.error("文件格式错误,请上传Excel文件");
}
} catch (IOException e) {
return Result.error("请上传正确格式文件");
}
//获取工作表页数据
//读取第1页的数据
Sheet sheet=wb.getSheetAt(0);
//获取工作表页中行数据
//读取的总的行数
int lastRowIndex=sheet.getLastRowNum();
if(lastRowIndex < 1) {
return Result.error("文件无内容或格式错误");
}
List<FunctionxTest> listVo = new ArrayList<>();
for (int i=1;i<=lastRowIndex;i++) {
Row row = sheet.getRow(i); // 行
if(row!=null){
short lastCellNum = row.getLastCellNum();
List<String> list = new ArrayList<>();
for (int j=0;j<lastCellNum;j++){
Cell cell = row.getCell(j); // 单元格
String cellValue = cell.getStringCellValue();
list.add(cellValue);
}
//------------接收-------------
FunctionxTest fun = new FunctionxTest();
fun.setModuleName(list.get(0)); // 对应模块
fun.setFunctionName(list.get(1)); // 中文名称
fun.setFunctionEnName(list.get(2)); // 英文名称
fun.setFunctionCode(list.get(3)); // 功能编码
fun.setFunctionType(list.get(4)); // 功能类型
fun.setPmDescribe(list.get(5)); // 功能描述
fun.setDiagrams(list.get(6)); // 分析图
fun.setUserRole(list.get(7)); // 用户角色
fun.setManagerUsers(list.get(8)); // 责任人
fun.setWorkLevel(list.get(9)); // 任务等级
fun.setWorkStatus(list.get(10)); // 任务状态
fun.setPublishTime(list.get(11)); // 发布时间
fun.setStartTime(list.get(12)); // 开始时间
fun.setDuration(list.get(13)); // 任务时长
fun.setSubmitTime(list.get(14)); // 提交时间
fun.setRealDuration(list.get(15)); // 实际时长
fun.setStatus(list.get(16)); // 功能状态
fun.setVerisonStatus(list.get(17)); // 版本状态
fun.setVerison(list.get(18)); // 版本号
fun.setCreatName(username);
listVo.add(fun);
}
}
boolean isSuccessSave = this.saveBatch(listVo);
if (!isSuccessSave){
return Result.error("文件读入失败");
}
//************************具体字段校验******************************
LambdaQueryWrapper<FunctionxTest> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(username!=null, FunctionxTest::getCreatName,username);
List<FunctionxTest> list = this.list(queryWrapper);
boolean remove = this.remove(queryWrapper);
if (!remove){
log.error("临时表删除错误!");
}
// 对应模块校验
List<Modulex> modulexList = modulexService.list();
List<Functionx> listInsert = new ArrayList<>(); // 正式插入
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
for(FunctionxTest function : list){
Functionx functionx = new Functionx();
String moduleId = function.getModuleName();
String functionName = function.getFunctionName();
String functionEnName = function.getFunctionEnName();
String functionCode = function.getFunctionCode();
String functionType = function.getFunctionType();
String pmDescribe = function.getPmDescribe();
String diagrams = function.getDiagrams();
String userRole = function.getUserRole();
String managerUsers = function.getManagerUsers();
String workLevel = function.getWorkLevel();
String workStatus = function.getWorkStatus();
String publishTime = function.getPublishTime();
String startTime = function.getStartTime();
String duration = function.getDuration();
String submitTime = function.getSubmitTime();
String realDuration = function.getRealDuration();
String status = function.getStatus();
String verisonStatus = function.getVerisonStatus();
String verison = function.getVerison();
String moduleName=""; // 模块编码
functionx.setCreateBy(username); //创建人
functionx.setCreateTime(new Date()); //创建日期
if(StringUtils.isBlank(moduleId)){ // 空和null
return Result.error("对应模块不能为空");
} else{
for(Modulex modulex : modulexList){
if (modulex.getModuleName().equals(moduleId)){
functionx.setModuleId(modulex.getId());
moduleId = modulex.getId();
moduleName=modulex.getModuleName();
break;
}
}
if(functionx.getModuleId() == null){
return Result.error("请输入正确的对应模块");
}
}
if(StringUtils.isBlank(functionName)){ // 空和null
return Result.error("中文名称不能为空");
} else{
LambdaQueryWrapper<Functionx> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(moduleId!=null,Functionx::getModuleId,moduleId);
queryWrapper1.eq(Functionx::getFunctionName,functionName);
int count = functionxService.count(queryWrapper1);
if(count>0)
return Result.error("中文名称在模块下重复");
functionx.setFunctionName(functionName);
}
if(StringUtils.isBlank(functionEnName)){ // 空和null
return Result.error("英文名称不能为空");
} else{
LambdaQueryWrapper<Functionx> queryWrapper2 = new LambdaQueryWrapper<>();
queryWrapper2.eq(moduleId!=null,Functionx::getModuleId,moduleId);
queryWrapper2.eq(Functionx::getFunctionEnName,functionEnName);
int count = functionxService.count(queryWrapper2);
if(count>0)
return Result.error("英文名称在模块下重复");
functionx.setFunctionEnName(functionEnName);
}
// 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99
int type;
if(StringUtils.isBlank(functionType)){ // 空和null
return Result.error("功能类型不能为空");
} else{
switch (functionType){
case "列表": type=0; break;
case "新增": type=1; break;
case "删除": type=2; break;
case "修改": type=3; break;
case "查看": type=4; break;
case "导入": type=5; break;
case "导出": type=6; break;
case "其它": type=99; break;
default: return Result.error("功能类型错误");
}
functionx.setFunctionType(type);
}
// 模块编码+功能缩写;自动填充+手动修改
if(StringUtils.isBlank(functionCode)){ // 空和null
return Result.error("功能编码不能为空");
} else{
String str = moduleName+functionType;
if(!str.equals(functionCode))
return Result.error("功能编码错误");
functionx.setFunctionCode(functionCode);
}
if(StringUtils.isNotBlank(pmDescribe)){ // 功能描述
functionx.setPmDescribe(pmDescribe);
}
if(StringUtils.isNotBlank(diagrams)){ // 分析图
functionx.setDiagrams(diagrams);
}
if(StringUtils.isNotBlank(userRole)){ // 用户角色
LambdaQueryWrapper<ProjectUserRole> queryWrapperUser = new LambdaQueryWrapper<>();
queryWrapperUser.eq(ProjectUserRole::getUserRole,userRole); // 是否匹配项目id?
int count = projectUserRoleService.count(queryWrapperUser);
if(count>0)
functionx.setUserRole(userRole);
else
return Result.error("请输入正确的用户角色");
}
if(StringUtils.isNotBlank(managerUsers)){ // 责任人
LambdaQueryWrapper<SysUser> queryWrapperUserName = new LambdaQueryWrapper<>();
queryWrapperUserName.eq(SysUser::getUsername,managerUsers);
int count = sysUserService.count(queryWrapperUserName);
if(count>0)
functionx.setManagerUsers(managerUsers);
else
return Result.error("请输入正确的责任人");
}
// 值:1、2、3、4、5,默认2
if(StringUtils.isBlank(workLevel)){ // 任务等级
return Result.error("任务等级不能为空");
} else{
int integer = Integer.parseInt(workLevel);
if (integer<1 || integer>5){
return Result.error("任务等级错误");
}
functionx.setWorkLevel(integer);
}
if(StringUtils.isBlank(workStatus)){
return Result.error("任务状态不能为空");
} else {
// 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0
switch (workStatus){
case "未发布": type=0; break;
case "已发布": type=1; break;
case "开发中": type=2; break;
case "已完成": type=3; break;
case "已撤回": type=4; break;
case "已取消": type=9; break;
default: return Result.error("任务状态错误");
}
functionx.setWorkStatus(type);
}
if(StringUtils.isNotBlank(publishTime)){
Date date;
Boolean isTime = checkTime(publishTime);
if (!isTime){
return Result.error("发布时间错误,应为"+pattern+"类型");
}
try {
date = dateFormat.parse(publishTime);
} catch (Exception e) {
return Result.error("发布时间错误,应为"+pattern+"类型");
}
functionx.setPublishTime(date);
}
if(StringUtils.isNotBlank(startTime)){
Date date;
Boolean isTime = checkTime(startTime);
if (!isTime){
return Result.error("开始时间错误,应为"+pattern+"类型");
}
try {
date = dateFormat.parse(startTime);
} catch (Exception e) {
return Result.error("开始时间错误,应为"+pattern+"类型");
}
functionx.setStartTime(date);
}
if(StringUtils.isNotBlank(duration)){
Double aDouble = Double.valueOf(duration);
functionx.setDuration(aDouble);
}
if(StringUtils.isNotBlank(submitTime)){
Date date;
Boolean isTime = checkTime(submitTime);
if (!isTime){
return Result.error("提交时间时间错误,应为"+pattern+"类型");
}
try {
date = dateFormat.parse(submitTime);
} catch (Exception e) {
return Result.error("提交时间时间错误,应为"+pattern+"类型");
}
functionx.setSubmitTime(date);
}
if(StringUtils.isNotBlank(realDuration)){
Double aDouble = Double.valueOf(realDuration);
if (aDouble<0.1)
return Result.error("实际时长错误");
functionx.setDuration(aDouble);
}
if(StringUtils.isBlank(status)){ // 空和null
return Result.error("功能状态不能为空");
} else{
// 值:正常1、停用0、废弃9;默认1
switch (status){
case "正常": type=1; break;
case "停用": type=0; break;
case "废弃": type=9; break;
default: return Result.error("任务状态错误");
}
functionx.setStatus(type);
}
if(StringUtils.isBlank(verisonStatus)){ // 空和null
return Result.error("版本状态不能为空");
} else{
// 值:当前1、历史0;默认1
switch (verisonStatus){
case "当前": type=1; break;
case "历史": type=0; break;
default: return Result.error("版本状态错误");
}
functionx.setStatus(type);
}
if(StringUtils.isBlank(verison)){ // 空和null
return Result.error("版本号不能为空");
} else{
Integer integer = Integer.valueOf(verison);
functionx.setStatus(integer);
}
listInsert.add(functionx);
}
//**************************校验结束******************************
boolean isSuccessInsert = functionxService.saveBatch(listInsert);
if(!isSuccessInsert){
return Result.OK("插入失败");
}
return Result.OK("插入成功");
}
/**
* 检查时间格式是否有效
*/
private Boolean checkTime(String date){
// 使用日期解析方式校验日期逻辑有效性
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date parsedDate = dateFormat.parse(date);
// 检查年份是否合法(例如:不能小于1900)
Calendar calendar = Calendar.getInstance();
calendar.setTime(parsedDate);
int year = calendar.get(Calendar.YEAR);
if (year < 1900) {
return false;
}
// 检查日期的逻辑有效性(例如:2月30日是无效的)
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int maxDayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
if (dayOfMonth > maxDayOfMonth) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
}
Loading…
Cancel
Save