导入规则开发

dev
zjh 1 year ago
parent 5c765d5946
commit 5cc8cba26a
  1. 209
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/controller/RulexController.java

@ -3,22 +3,15 @@ package org.jeecg.modules.demo.rulex.controller;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
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.mapper.FunctionxMapper; import org.jeecg.modules.demo.functionx.mapper.FunctionxMapper;
import org.jeecg.modules.demo.requirementfun.entity.RequirementFun; import org.jeecg.modules.demo.rulex.entity.RuleVo;
import org.jeecg.modules.demo.requirementfun.service.IRequirementFunService;
import org.jeecg.modules.demo.requirementitem.entity.RequirementItem;
import org.jeecg.modules.demo.requirementitem.service.IRequirementItemService;
import org.jeecg.modules.demo.rulex.entity.Rulex; import org.jeecg.modules.demo.rulex.entity.Rulex;
import org.jeecg.modules.demo.rulex.service.IRuleVoService;
import org.jeecg.modules.demo.rulex.service.IRulexService; import org.jeecg.modules.demo.rulex.service.IRulexService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -26,18 +19,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.fieldx.entity.Fieldx;
import org.jeecg.modules.fieldx.service.IFieldxService;
import org.jeecg.modules.modulex.entity.Modulex;
import org.jeecg.modules.modulex.service.IModulexService;
import org.jeecg.modules.tablex.entity.Tablex;
import org.jeecg.modules.tablex.service.ITablexService;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
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.jeecg.common.system.base.controller.JeecgController; 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.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.aspect.annotation.AutoLog;
@ -55,12 +50,17 @@ import org.jeecg.common.aspect.annotation.AutoLog;
public class RulexController extends JeecgController<Rulex, IRulexService> { public class RulexController extends JeecgController<Rulex, IRulexService> {
@Autowired @Autowired
private IRulexService rulexService; private IRulexService rulexService;
@Autowired
private IRuleVoService iRuleVoService;
@Autowired @Autowired
FunctionxMapper functionxMapper; FunctionxMapper functionxMapper;
@Autowired @Autowired
private IRequirementFunService requirementFunService; IFieldxService iFieldxService;
@Autowired @Autowired
private IRequirementItemService requirementItemService; ITablexService iTablexService;
@Autowired
IModulexService iModulexService;
/** /**
@ -126,43 +126,6 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
/**
* 转化规则
*
* @param rulex
* @return
*/
@AutoLog(value = "转化规则")
@ApiOperation(value="转化规则", notes="转化规则")
@PostMapping(value = "/zhgz")
public Result<?> zhgz(@RequestBody Rulex rulex) {
if(rulex.getFunctionId()==null){
return Result.error("功能点错误!!!");
}
Functionx functionx = functionxMapper.selectById(rulex.getFunctionId());
if(functionx.getStartTime()!=null){
rulex.setStartTime(functionx.getStartTime());
}
if(functionx.getSubmitTime()!=null){
rulex.setSubmitTime(functionx.getSubmitTime());
}
if(functionx.getRealDuration()!=null){
rulex.setRealDuration(functionx.getRealDuration());
}
rulex.setManagerUsers(functionx.getManagerUsers());
rulex.setWorkStatus(functionx.getWorkStatus());
rulexService.save(rulex);
RequirementItem requirementItem = requirementItemService.getById(rulex.getModuleId());
requirementItem.setRequirementStatus(2);
requirementItemService.updateById(requirementItem);
RequirementFun requirementFun1 = new RequirementFun();
requirementFun1.setRequirementId(rulex.getModuleId());
requirementFun1.setFunId(rulex.getId());
requirementFun1.setFunLevel(4);
requirementFunService.save(requirementFun1);
return Result.OK("添加成功!");
}
/** /**
* 编辑 * 编辑
* *
@ -244,7 +207,149 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, Rulex.class); return super.importExcel(request, response, Rulex.class);
} }
public Result<?> preImportAndExcel(HttpServletRequest request) {
//return super.importExcel(request, response, ScTeams.class);
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
System.err.println("----------------------------------------------");
// 获取上传文件对象
MultipartFile file = entity.getValue();
if (file==null){
return Result.error("文件上传失败,请重新上传");
}
ImportParams params = new ImportParams();
params.setTitleRows(2);//表格标题行数,默认0
params.setHeadRows(1);//表头行数,默认1
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
try {
// List<ScTeamsDr> list = ExcelImportUtil.importExcel(file.getInputStream(), ScTeamsDr.class, params);
List<RuleVo> list = ExcelImportUtil.importExcel(file.getInputStream(), RuleVo.class, params);
if (list == null || list.size() <= 0) {
return Result.error("文件导入失败:模板中暂无数据");
}
System.err.println("----------------------------------------------");
System.out.println("List<ScTeams> list = ExcelImportUtil.importExcel: " + list);
int num = 0;
for (int i = 0; i < list.size(); i++) {
if (list.size() > 0 &&
list.get(i).getRuleNo() == null &&
list.get(i).getRuleCode() == null &&
list.get(i).getPmDescribe() == null &&
list.get(i).getModuleId() == null &&
list.get(i).getFunctionId() == null &&
list.get(i).getDiagrams() == null &&
list.get(i).getTableId() == null &&
list.get(i).getFieldId() == null &&
list.get(i).getManagerUsers() == null &&
list.get(i).getWorkLevel() == null &&
list.get(i).getWorkStatus() == null &&
list.get(i).getStartTime() == null &&
list.get(i).getManagerUsers() == null &&
list.get(i).getDuration() == null &&
list.get(i).getSubmitTime() == null &&
list.get(i).getRealDuration() == null&&
list.get(i).getStatus() == null&&
list.get(i).getVerisonStatus() == null&&
list.get(i).getVerison() == null) {
continue;
}
iRuleVoService.save(list.get(i));
if (num == 0) {
return Result.error("文件导入失败:导入模板不匹配");
} else {
return Result.ok("文件导入成功!");
}
}
}catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage();
log.error(msg, e);
//if(msg!=null && msg.contains("Duplicate entry"))
if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
return Result.error("文件导入失败:有重复数据!");
} else {
return Result.error("文件导入失败:" + e.getMessage());
}
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
List<RuleVo> ruleVoList = iRuleVoService.list();
if (ruleVoList.size()<=0||ruleVoList==null){
return Result.error("文件导入失败");
}
for (int i = 0; i < ruleVoList.size(); i++) {
RuleVo ruleVo = ruleVoList.get(i);
//对应字段
String fieldId = ruleVo.getFieldId();
Fieldx byId = iFieldxService.getById(fieldId);
if (byId==null){
return Result.error("字段输入错误,请核对");
}
//对应功能
String functionId = ruleVo.getFunctionId();
Fieldx byId1 = iFieldxService.getById(functionId);
if (byId1==null){
return Result.error("功能输入错误,请核对");
}
//对应模块
String moduleId = ruleVo.getModuleId();
Modulex byId2 = iModulexService.getById(moduleId);
if (byId2==null){
return Result.error("模块输入错误,请核对");
}
//对应实体
String tableId = ruleVo.getTableId();
Tablex byId3 = iTablexService.getById(tableId);
if (byId3==null){
return Result.error("实体输入错误,请核对");
}
try {
Double.valueOf(ruleVo.getDuration());
}catch (Exception e){
return Result.error("任务时长输入错误,请核对");
}
try {
Integer.valueOf(ruleVo.getRealDuration());
}catch (Exception e){
return Result.error("实际时长输入错误,请核对");
}
try {
Integer.valueOf(ruleVo.getWorkLevel());
}catch (Exception e){
return Result.error("任务等级输入错误,请核对");
}
try {
Double.valueOf(ruleVo.getWorkStatus());
}catch (Exception e){
return Result.error("任务状态输入错误,请核对");
}
try {
Integer.valueOf(ruleVo.getStatus());
}catch (Exception e){
return Result.error("规则输入错误,请核对");
}
try {
Double.valueOf(ruleVo.getVerisonStatus());
}catch (Exception e){
return Result.error("版本状态输入错误,请核对");
}
}
return Result.error("文件导入失败!");
}
@GetMapping(value = "/sort") @GetMapping(value = "/sort")
public Result<?> sort(@RequestParam(name="id",required=true) String id) { public Result<?> sort(@RequestParam(name="id",required=true) String id) {
return rulexService.sort(id); return rulexService.sort(id);

Loading…
Cancel
Save