dev
吱屋 1 year ago
commit 44dfc3e854
  1. 67
      ant-design-vue-jeecg/src/views/modulex/ModulexList.vue
  2. 16
      ant-design-vue-jeecg/src/views/requiremententity/RequirementEntityList.vue
  3. 1
      jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  4. 27
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/requiremententity/controller/RequirementEntityController.java
  5. 239
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/controller/RulexController.java
  6. 3
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/IRulexService.java
  7. 27
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/impl/RulexServiceImpl.java
  8. 81
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/controller/TablexController.java
  9. 6
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/service/ITablexService.java
  10. 27
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/service/impl/TablexServiceImpl.java
  11. 63
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/ws/MyWebSocket.java
  12. 53
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/tablex/ws/WebSocketUtils.java

@ -77,10 +77,49 @@
<a-button type="primary" icon="import">导入功能</a-button> <a-button type="primary" icon="import">导入功能</a-button>
</a-upload> </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" @click="showProcess">导入规则</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-upload> </a-upload>
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="tablexImportExcelUrl" @change="handleImportExcel">
<a-button type="primary" icon="import">导入实体</a-button> <a-upload name="file" :showUploadList="false" :multiple="false"
:headers="tokenHeader" :action="tablexImportExcelUrl" @change="handleImportExcel">
<a-button type="primary" icon="import" @click="showProcess">导入实体</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-upload> </a-upload>
<a-button @click="fanhui" type="primary" icon="rollback">返回</a-button> <a-button @click="fanhui" type="primary" icon="rollback">返回</a-button>
@ -212,6 +251,13 @@ export default {
}, },
data () { data () {
return { return {
ModalData:{
uploaded: '0',
isVisible: 'false',
records: '0',
status: '判断文件结构'
},
visible:false,
description: '模块管理管理页面', description: '模块管理管理页面',
// //
columns: [ columns: [
@ -427,6 +473,7 @@ export default {
this.loginRole(usercode) this.loginRole(usercode)
//console.log('userole1',this.userRole1) //console.log('userole1',this.userRole1)
this.getSuperFieldList() this.getSuperFieldList()
this.showProcess()
}, },
computed: { computed: {
importExcelUrl: function () { importExcelUrl: function () {
@ -450,6 +497,20 @@ export default {
}, },
}, },
methods: { methods: {
//
showProcess(){
let userId = store.getters.userInfo.id
let base_url = window._CONFIG['domianURL']
base_url = base_url.replace('http', 'ws')
let ws = new WebSocket(`${base_url}/uploadProcess/${userId}`)
ws.onmessage = (e) =>{
this.ModalData=JSON.parse(e.data)
if (this.visible===false) {
// this.getList()
console.log("重新获取列表")
}
}
},
// //
checkChange (checked) { checkChange (checked) {
// name // name

@ -95,15 +95,14 @@
<span slot="action" slot-scope="text, record"> <span slot="action" slot-scope="text, record">
<a @click="handleEdit(record)">编辑</a> <a @click="handleEdit(record)">编辑</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a @click="handleDetail(record)">详情</a> <a @click="handleDetail(record)">详情</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a @click="fq(record.id)">废弃</a> <a @click="fq(record.id)">废弃</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a @click="zh(record)">转化</a> <a :disabled="record.entityStatus!=9" @click="updateEntityStatus(record.id)">撤销</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a :disabled="record.entityStatus!=9" @click="updateEntityStatus(record,'9')">撤销</a> <a @click="zh(record)">转化</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"> <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
<a>删除</a> <a>删除</a>
@ -194,6 +193,7 @@
importExcelUrl: "requiremententity/requirementEntity/importExcel", importExcelUrl: "requiremententity/requirementEntity/importExcel",
fq:"/requiremententity/requirementEntity/fq", fq:"/requiremententity/requirementEntity/fq",
hb:"/requiremententity/requirementEntity/hb", hb:"/requiremententity/requirementEntity/hb",
cx:"/requiremententity/requirementEntity/cx",
}, },
dictOptions:{}, dictOptions:{},
@ -209,6 +209,16 @@
}, },
}, },
methods: { methods: {
updateEntityStatus(id){
getAction(this.url.cx,{id:id}).then((res)=>{
if (res.success) {
this.$message.success(res.message);
this.loadData();
}else{
this.$message.warning(res.message);
}
});
},
hb(hbsj){ hb(hbsj){
console.log(hbsj) console.log(hbsj)
if(hbsj.length<2){ if(hbsj.length<2){

@ -72,6 +72,7 @@ public class ShiroConfig {
} }
// 配置不会被拦截的链接 顺序判断 // 配置不会被拦截的链接 顺序判断
filterChainDefinitionMap.put("/createtp/createtp/maketupu","anon"); // 知识图谱排除 filterChainDefinitionMap.put("/createtp/createtp/maketupu","anon"); // 知识图谱排除
filterChainDefinitionMap.put("/uploadProcess/**", "anon"); //上传进度条
filterChainDefinitionMap.put("/sys/cas/client/validateLogin", "anon"); //cas验证登录 filterChainDefinitionMap.put("/sys/cas/client/validateLogin", "anon"); //cas验证登录
filterChainDefinitionMap.put("/sys/randomImage/**", "anon"); //登录验证码接口排除 filterChainDefinitionMap.put("/sys/randomImage/**", "anon"); //登录验证码接口排除
filterChainDefinitionMap.put("/sys/checkCaptcha", "anon"); //登录验证码接口排除 filterChainDefinitionMap.put("/sys/checkCaptcha", "anon"); //登录验证码接口排除

@ -200,6 +200,26 @@ public class RequirementEntityController extends JeecgController<RequirementEnti
return Result.OK("已废弃"); return Result.OK("已废弃");
} }
/**
* 撤销废除
*
* @param id
* @return
*/
@AutoLog(value = "撤销废除")
@ApiOperation(value="撤销废除", notes="撤销废除")
@GetMapping(value = "/cx")
public Result<?> cx(@RequestParam(name="id",required=true) String id) {
RequirementEntity requirementEntity = requirementEntityService.getById(id);
if(requirementEntity==null) {
return Result.error("未找到对应数据");
}else{
requirementEntity.setEntityStatus(0);
requirementEntityService.updateById(requirementEntity);
}
return Result.OK("已撤销废除");
}
/** /**
* 合并 * 合并
* *
@ -210,6 +230,10 @@ public class RequirementEntityController extends JeecgController<RequirementEnti
@ApiOperation(value="合并", notes="合并") @ApiOperation(value="合并", notes="合并")
@DeleteMapping(value = "/hb") @DeleteMapping(value = "/hb")
public Result<?> hb(@RequestParam(name="ids",required=true) String ids,@RequestParam(name="id",required=true) String id) { public Result<?> hb(@RequestParam(name="ids",required=true) String ids,@RequestParam(name="id",required=true) String id) {
RequirementEntity requirementEntity1 = requirementEntityService.getById(id);
if(requirementEntity1.getEntityStatus()==9){
return Result.error("该实体已废弃,需撤回废弃后再保留");
}else{
List<String> listids = Arrays.asList(ids.split(",")); List<String> listids = Arrays.asList(ids.split(","));
for (int i = 0 ; i < listids.size(); i++){ for (int i = 0 ; i < listids.size(); i++){
if(!id.equals(listids.get(i))){ if(!id.equals(listids.get(i))){
@ -218,12 +242,13 @@ public class RequirementEntityController extends JeecgController<RequirementEnti
requirementEntityService.updateById(requirementEntity); requirementEntityService.updateById(requirementEntity);
} }
} }
RequirementEntity requirementEntity1 = requirementEntityService.getById(id);
requirementEntity1.setEntityStatus(2); requirementEntity1.setEntityStatus(2);
requirementEntityService.updateById(requirementEntity1); requirementEntityService.updateById(requirementEntity1);
return Result.OK("成功"); return Result.OK("成功");
} }
}
/** /**
* 导出excel * 导出excel
* *

@ -1,17 +1,18 @@
package org.jeecg.modules.demo.rulex.controller; package org.jeecg.modules.demo.rulex.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
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.functionx.service.IFunctionxService; import org.jeecg.modules.demo.functionx.service.IFunctionxService;
@ -20,53 +21,43 @@ import org.jeecg.modules.demo.rulex.entity.Rulex;
import org.jeecg.modules.demo.rulex.mapper.RulexMapper; import org.jeecg.modules.demo.rulex.mapper.RulexMapper;
import org.jeecg.modules.demo.rulex.service.IRuleVoService; 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.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.rulex.util.DateValidator; import org.jeecg.modules.demo.rulex.util.DateValidator;
import org.jeecg.modules.demo.rulex.util.DateValidatorUsingDateFormat; import org.jeecg.modules.demo.rulex.util.DateValidatorUsingDateFormat;
import org.jeecg.modules.fieldx.entity.Fieldx; import org.jeecg.modules.fieldx.entity.Fieldx;
import org.jeecg.modules.fieldx.service.IFieldxService; import org.jeecg.modules.fieldx.service.IFieldxService;
import org.jeecg.modules.modulex.entity.Modulex; import org.jeecg.modules.modulex.entity.Modulex;
import org.jeecg.modules.modulex.service.IModulexService; import org.jeecg.modules.modulex.service.IModulexService;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysDictItem; import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.mapper.SysDictItemMapper; import org.jeecg.modules.system.mapper.SysDictItemMapper;
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.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
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.context.ApplicationContext;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
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.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
/** import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Description: 规则管理 * @Description: 规则管理
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2023-04-10 * @Date: 2023-04-10
* @Version: V1.0 * @Version: V1.0
*/ */
@Api(tags="规则管理") @Api(tags = "规则管理")
@RestController @RestController
@RequestMapping("/rulex/rulex") @RequestMapping("/rulex/rulex")
@Slf4j @Slf4j
public class RulexController extends JeecgController<Rulex, IRulexService> { public class RulexController extends JeecgController<Rulex, IRulexService> {
@Autowired
private IRulexService rulexService;
@Autowired
private IRuleVoService iRuleVoService;
@Autowired @Autowired
FunctionxMapper functionxMapper; FunctionxMapper functionxMapper;
@Autowired @Autowired
@ -79,13 +70,18 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
ITablexService iTablexService; ITablexService iTablexService;
@Autowired @Autowired
IModulexService iModulexService; IModulexService iModulexService;
@Autowired @Autowired
RulexController rulexController; RulexController rulexController;
@Autowired
private IRulexService rulexService;
@Autowired
private IRuleVoService iRuleVoService;
@Autowired @Autowired
private SysDictItemMapper sysDictItemMapper; private SysDictItemMapper sysDictItemMapper;
@Autowired
private WebSocketUtils webSocketUtils;
/** /**
* 分页列表查询 * 分页列表查询
@ -97,24 +93,24 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
* @return * @return
*/ */
@AutoLog(value = "规则管理-分页列表查询") @AutoLog(value = "规则管理-分页列表查询")
@ApiOperation(value="规则管理-分页列表查询", notes="规则管理-分页列表查询") @ApiOperation(value = "规则管理-分页列表查询", notes = "规则管理-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<?> queryPageList(Rulex rulex, public Result<?> queryPageList(Rulex rulex,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
// QueryWrapper<Rulex> queryWrapper = QueryGenerator.initQueryWrapper(rulex, req.getParameterMap()); // QueryWrapper<Rulex> queryWrapper = QueryGenerator.initQueryWrapper(rulex, req.getParameterMap());
QueryWrapper<Rulex> queryWrapper=new QueryWrapper<>(); QueryWrapper<Rulex> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("function_id",rulex.getFunctionId()); queryWrapper.eq("function_id", rulex.getFunctionId());
queryWrapper.orderByDesc("work_level"); queryWrapper.orderByDesc("work_level");
if(rulex.getRuleCode()!=null){ if (rulex.getRuleCode() != null) {
queryWrapper.eq("rule_code",rulex.getRuleCode()); queryWrapper.eq("rule_code", rulex.getRuleCode());
} }
if(rulex.getTableId()!=null){ if (rulex.getTableId() != null) {
queryWrapper.eq("table_id",rulex.getTableId()); queryWrapper.eq("table_id", rulex.getTableId());
} }
if(rulex.getFieldId()!=null){ if (rulex.getFieldId() != null) {
queryWrapper.eq("field_id",rulex.getFieldId()); queryWrapper.eq("field_id", rulex.getFieldId());
} }
Page<Rulex> page = new Page<Rulex>(pageNo, pageSize); Page<Rulex> page = new Page<Rulex>(pageNo, pageSize);
IPage<Rulex> pageList = rulexService.page(page, queryWrapper); IPage<Rulex> pageList = rulexService.page(page, queryWrapper);
@ -128,20 +124,20 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
* @return * @return
*/ */
@AutoLog(value = "规则管理-添加") @AutoLog(value = "规则管理-添加")
@ApiOperation(value="规则管理-添加", notes="规则管理-添加") @ApiOperation(value = "规则管理-添加", notes = "规则管理-添加")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result<?> add(@RequestBody Rulex rulex) { public Result<?> add(@RequestBody Rulex rulex) {
if(rulex.getFunctionId()==null){ if (rulex.getFunctionId() == null) {
return Result.error("功能点错误!!!"); return Result.error("功能点错误!!!");
} }
Functionx functionx = functionxMapper.selectById(rulex.getFunctionId()); Functionx functionx = functionxMapper.selectById(rulex.getFunctionId());
if(functionx.getStartTime()!=null){ if (functionx.getStartTime() != null) {
rulex.setStartTime(functionx.getStartTime()); rulex.setStartTime(functionx.getStartTime());
} }
if(functionx.getSubmitTime()!=null){ if (functionx.getSubmitTime() != null) {
rulex.setSubmitTime(functionx.getSubmitTime()); rulex.setSubmitTime(functionx.getSubmitTime());
} }
if(functionx.getRealDuration()!=null){ if (functionx.getRealDuration() != null) {
rulex.setRealDuration(functionx.getRealDuration()); rulex.setRealDuration(functionx.getRealDuration());
} }
rulex.setManagerUsers(functionx.getManagerUsers()); rulex.setManagerUsers(functionx.getManagerUsers());
@ -157,7 +153,7 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
* @return * @return
*/ */
@AutoLog(value = "规则管理-编辑") @AutoLog(value = "规则管理-编辑")
@ApiOperation(value="规则管理-编辑", notes="规则管理-编辑") @ApiOperation(value = "规则管理-编辑", notes = "规则管理-编辑")
@PutMapping(value = "/edit") @PutMapping(value = "/edit")
public Result<?> edit(@RequestBody Rulex rulex) { public Result<?> edit(@RequestBody Rulex rulex) {
rulexService.updateById(rulex); rulexService.updateById(rulex);
@ -171,9 +167,9 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
* @return * @return
*/ */
@AutoLog(value = "规则管理-通过id删除") @AutoLog(value = "规则管理-通过id删除")
@ApiOperation(value="规则管理-通过id删除", notes="规则管理-通过id删除") @ApiOperation(value = "规则管理-通过id删除", notes = "规则管理-通过id删除")
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) { public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
rulexService.removeById(id); rulexService.removeById(id);
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }
@ -185,9 +181,9 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
* @return * @return
*/ */
@AutoLog(value = "规则管理-批量删除") @AutoLog(value = "规则管理-批量删除")
@ApiOperation(value="规则管理-批量删除", notes="规则管理-批量删除") @ApiOperation(value = "规则管理-批量删除", notes = "规则管理-批量删除")
@DeleteMapping(value = "/deleteBatch") @DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) { public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
this.rulexService.removeByIds(Arrays.asList(ids.split(","))); this.rulexService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!"); return Result.OK("批量删除成功!");
} }
@ -199,11 +195,11 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
* @return * @return
*/ */
@AutoLog(value = "规则管理-通过id查询") @AutoLog(value = "规则管理-通过id查询")
@ApiOperation(value="规则管理-通过id查询", notes="规则管理-通过id查询") @ApiOperation(value = "规则管理-通过id查询", notes = "规则管理-通过id查询")
@GetMapping(value = "/queryById") @GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name="id",required=true) String id) { public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
Rulex rulex = rulexService.getById(id); Rulex rulex = rulexService.getById(id);
if(rulex==null) { if (rulex == null) {
return Result.error("未找到对应数据"); return Result.error("未找到对应数据");
} }
return Result.OK(rulex); return Result.OK(rulex);
@ -223,27 +219,39 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
/** /**
* 通过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 rulexController.preImportAndExcel(request); return rulexController.preImportAndExcel(file);
} }
@Transactional @Transactional
public Result<?> preImportAndExcel(HttpServletRequest request) { public Result<?> preImportAndExcel(MultipartFile file) {
//return super.importExcel(request, response, ScTeams.class);
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); Map<String, String> message = new HashMap<>();
message.put("isVisible", "true");
message.put("uploaded", "0");
message.put("status", "判断文件结构");
webSocketUtils.sendMessage(loginUser.getId(), message);
// 判断文件是否是表格
String originalFilename = file.getOriginalFilename();
if (StringUtils.isBlank(originalFilename) ||
(!originalFilename.endsWith("xls") &&
!originalFilename.endsWith("xlsx"))) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件格式不正确");
}
//校验时间 //校验时间
final DateValidator validator = new DateValidatorUsingDateFormat("yyyy-MM-dd hh:mm:ss"); final DateValidator validator = new DateValidatorUsingDateFormat("yyyy-MM-dd hh:mm:ss");
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
System.err.println("----------------------------------------------"); if (file == null) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
if (file==null){
return Result.error("文件上传失败,请重新上传"); return Result.error("文件上传失败,请重新上传");
} }
ImportParams params = new ImportParams(); ImportParams params = new ImportParams();
@ -251,13 +259,14 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
params.setHeadRows(1);//表头行数,默认1 params.setHeadRows(1);//表头行数,默认1
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
try { try {
// List<ScTeamsDr> list = ExcelImportUtil.importExcel(file.getInputStream(), ScTeamsDr.class, params); message.put("status", "数据预读入");
webSocketUtils.sendMessage(loginUser.getId(), message);
List<RuleVo> list = ExcelImportUtil.importExcel(file.getInputStream(), RuleVo.class, params); List<RuleVo> list = ExcelImportUtil.importExcel(file.getInputStream(), RuleVo.class, params);
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("文件导入失败:模板中暂无数据");
} }
System.err.println("----------------------------------------------");
System.out.println("List<ScTeams> list = ExcelImportUtil.importExcel: " + list);
int num = 0; int num = 0;
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if ( if (
@ -277,28 +286,34 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
// list.get(i).getManagerUsers() == null && // list.get(i).getManagerUsers() == null &&
// list.get(i).getDuration() == null && // list.get(i).getDuration() == null &&
// list.get(i).getSubmitTime() == null && // list.get(i).getSubmitTime() == null &&
list.get(i).getRealDuration() == null&& list.get(i).getRealDuration() == null &&
list.get(i).getStatus() == null|| list.get(i).getStatus() == null ||
list.get(i).getVerisonStatus() == null|| list.get(i).getVerisonStatus() == null ||
list.get(i).getVerison() == null) { list.get(i).getVerison() == null) {
continue; continue;
} }
num++; num++;
if (num == 0) { if (num == 0) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:导入模板不匹配"); return Result.error("文件导入失败:导入模板不匹配");
// } else if (num!=list.size()) { // } else if (num!=list.size()) {
// return Result.error("文件导入失败:请检查填写文字"); // return Result.error("文件导入失败:请检查填写文字");
} }
iRuleVoService.save(list.get(i)); iRuleVoService.save(list.get(i));
} }
}catch (Exception e) { } catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg, e); log.error(msg, e);
//if(msg!=null && msg.contains("Duplicate entry")) //if(msg!=null && msg.contains("Duplicate entry"))
if (msg != null && msg.indexOf("Duplicate entry") >= 0) { if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:有重复数据!"); return Result.error("文件导入失败:有重复数据!");
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:" + e.getMessage()); return Result.error("文件导入失败:" + e.getMessage());
} }
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示 //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
@ -309,11 +324,17 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
List<RuleVo> ruleVoList = iRuleVoService.list(); List<RuleVo> ruleVoList = iRuleVoService.list();
if (ruleVoList.size()<=0||ruleVoList==null){ if (ruleVoList.size() <= 0 || ruleVoList == null) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败,模板不匹配"); return Result.error("文件导入失败,模板不匹配");
} }
// 将总的记录数传递给前端
message.put("records", String.valueOf(ruleVoList.size()));
webSocketUtils.sendMessage(loginUser.getId(), message);
for (int i = 0; i < ruleVoList.size(); i++) { for (int i = 0; i < ruleVoList.size(); i++) {
Rulex rulex = new Rulex(); Rulex rulex = new Rulex();
RuleVo ruleVo = ruleVoList.get(i); RuleVo ruleVo = ruleVoList.get(i);
@ -324,6 +345,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
Fieldx byId = iFieldxService.getOne(rulexLambdaQueryWrapper); Fieldx byId = iFieldxService.getOne(rulexLambdaQueryWrapper);
if (byId == null) { if (byId == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("字段输入错误,请核对"); return Result.error("字段输入错误,请核对");
} }
rulex.setFieldId(byId.getId()); rulex.setFieldId(byId.getId());
@ -334,6 +357,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
Functionx byId1 = functionxService.getOne(functionxLambdaQueryWrapper); Functionx byId1 = functionxService.getOne(functionxLambdaQueryWrapper);
if (byId1 == null) { if (byId1 == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能输入错误,请核对"); return Result.error("功能输入错误,请核对");
} }
rulex.setFunctionId(byId1.getId()); rulex.setFunctionId(byId1.getId());
@ -343,6 +368,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
modulexLambdaQueryWrapper.eq(Modulex::getModuleName, moduleName); modulexLambdaQueryWrapper.eq(Modulex::getModuleName, moduleName);
Modulex byId2 = iModulexService.getOne(modulexLambdaQueryWrapper); Modulex byId2 = iModulexService.getOne(modulexLambdaQueryWrapper);
if (byId2 == null) { if (byId2 == null) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
iRuleVoService.remove(null); iRuleVoService.remove(null);
return Result.error("模块输入错误,请核对"); return Result.error("模块输入错误,请核对");
@ -354,6 +381,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
tableLambdaQueryWrapper.eq(Tablex::getTableName, tableId); tableLambdaQueryWrapper.eq(Tablex::getTableName, tableId);
Tablex byId3 = iTablexService.getOne(tableLambdaQueryWrapper); Tablex byId3 = iTablexService.getOne(tableLambdaQueryWrapper);
if (byId3 == null) { if (byId3 == null) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
iRuleVoService.remove(null); iRuleVoService.remove(null);
return Result.error("实体输入错误,请核对"); return Result.error("实体输入错误,请核对");
@ -366,7 +395,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
rulex.setDuration(aDouble); rulex.setDuration(aDouble);
} catch (Exception e) { } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务时长输入错误,请核对"); return Result.error("任务时长输入错误,请核对");
} }
@ -375,7 +405,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
d = Double.valueOf(ruleVo.getRealDuration()); d = Double.valueOf(ruleVo.getRealDuration());
} catch (Exception e) { } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("实际时长输入错误,请核对"); return Result.error("实际时长输入错误,请核对");
} }
rulex.setRealDuration(d); rulex.setRealDuration(d);
@ -384,16 +415,19 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
integer = Integer.valueOf(ruleVo.getWorkLevel()); integer = Integer.valueOf(ruleVo.getWorkLevel());
} catch (Exception e) { } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务等级输入错误,请核对"); return Result.error("任务等级输入错误,请核对");
} }
rulex.setWorkLevel(integer); rulex.setWorkLevel(integer);
String workStatus = ruleVo.getWorkStatus(); String workStatus = ruleVo.getWorkStatus();
LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDictItemLambdaQueryWrapper.eq(SysDictItem::getItemText, workStatus).eq(SysDictItem::getDictId,"1645268542514421762"); sysDictItemLambdaQueryWrapper.eq(SysDictItem::getItemText, workStatus).eq(SysDictItem::getDictId, "1645268542514421762");
SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper); SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper);
if (sysDictItem == null){ if (sysDictItem == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态输入错误,请核对"); return Result.error("任务状态输入错误,请核对");
} }
@ -401,10 +435,12 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
String status = ruleVo.getStatus(); String status = ruleVo.getStatus();
LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
sysDictItemLambdaQueryWrapper2.eq(SysDictItem::getItemText, status).eq(SysDictItem::getDictId,"1645264493205491713"); sysDictItemLambdaQueryWrapper2.eq(SysDictItem::getItemText, status).eq(SysDictItem::getDictId, "1645264493205491713");
SysDictItem sysDictItem2 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper2); SysDictItem sysDictItem2 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper2);
if (sysDictItem2 == null){ if (sysDictItem2 == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("规则状态输入错误,请核对"); return Result.error("规则状态输入错误,请核对");
} }
@ -416,6 +452,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
SysDictItem sysDictItem3 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper3); SysDictItem sysDictItem3 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper3);
if (sysDictItem3 == null) { if (sysDictItem3 == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态输入错误,请核对"); return Result.error("版本状态输入错误,请核对");
} }
@ -427,23 +465,23 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
try { try {
String startTime = ruleVo.getStartTime(); String startTime = ruleVo.getStartTime();
if (startTime != null) if (startTime != null)
if (!validator.isValid(startTime)){ if (!validator.isValid(startTime)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间输入错误"); return Result.error("开始时间输入错误");
} } else {
else {
Date date = simpleDateFormat.parse(startTime); Date date = simpleDateFormat.parse(startTime);
rulex.setStartTime(date); rulex.setStartTime(date);
} }
String submitTime = ruleVo.getSubmitTime(); String submitTime = ruleVo.getSubmitTime();
if (submitTime != null) if (submitTime != null)
if (!validator.isValid(submitTime)){ if (!validator.isValid(submitTime)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间输入错误"); return Result.error("提交时间输入错误");
} } else {
else {
Date date1 = simpleDateFormat.parse(submitTime); Date date1 = simpleDateFormat.parse(submitTime);
rulex.setSubmitTime(date1); rulex.setSubmitTime(date1);
} }
@ -456,6 +494,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
List<String> list = rulexMapper.checkRuleNo(byId1.getId()); List<String> list = rulexMapper.checkRuleNo(byId1.getId());
if (list.contains(ruleNo)) { if (list.contains(ruleNo)) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("规则序号已存在"); return Result.error("规则序号已存在");
} }
rulex.setRuleNo(ruleNo); rulex.setRuleNo(ruleNo);
@ -480,7 +520,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
integer1 = Integer.valueOf(ruleVo.getVerison()); integer1 = Integer.valueOf(ruleVo.getVerison());
} catch (Exception e) { } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本号输入错误,请核对"); return Result.error("版本号输入错误,请核对");
} }
rulex.setVerison(String.valueOf(integer1)); rulex.setVerison(String.valueOf(integer1));
@ -488,16 +529,20 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
String managerUsers = ruleVo.getManagerUsers(); String managerUsers = ruleVo.getManagerUsers();
if (managerUsers != null) if (managerUsers != null)
rulex.setManagerUsers(managerUsers); rulex.setManagerUsers(managerUsers);
message.put("status", "正在读取数据");
webSocketUtils.sendMessage(loginUser.getId(), message);
//存入真实表 //存入真实表
rulexService.save(rulex); rulexService.saveRule(rulex,loginUser,message,i+1);
iRuleVoService.remove(null); iRuleVoService.remove(null);
} }
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.ok("文件导入成功!"); return Result.ok("文件导入成功!");
} }
@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);
} }
} }

@ -1,11 +1,13 @@
package org.jeecg.modules.demo.rulex.service; package org.jeecg.modules.demo.rulex.service;
import org.jeecg.common.api.vo.Result; 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.Functionx;
import org.jeecg.modules.demo.rulex.entity.Rulex; import org.jeecg.modules.demo.rulex.entity.Rulex;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @Description: 规则管理 * @Description: 规则管理
@ -20,6 +22,7 @@ public interface IRulexService extends IService<Rulex> {
List<Rulex> queryRuleListByFunctionId(Functionx functionx); List<Rulex> queryRuleListByFunctionId(Functionx functionx);
void saveRule(Rulex rulex, LoginUser loginUser, Map<String, String> message,int i);
void saveRulex(Functionx functionx); void saveRulex(Functionx functionx);
} }

@ -5,20 +5,24 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; 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.Functionx;
import org.jeecg.modules.demo.rulex.entity.Rulex; import org.jeecg.modules.demo.rulex.entity.Rulex;
import org.jeecg.modules.demo.rulex.mapper.RulexMapper; import org.jeecg.modules.demo.rulex.mapper.RulexMapper;
import org.jeecg.modules.demo.rulex.service.IRulexService; import org.jeecg.modules.demo.rulex.service.IRulexService;
import org.jeecg.modules.fieldx.entity.Fieldx; import org.jeecg.modules.fieldx.entity.Fieldx;
import org.jeecg.modules.fieldx.service.IFieldxService; import org.jeecg.modules.fieldx.service.IFieldxService;
import org.jeecg.modules.message.controller.SysMessageTemplateController;
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.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @Description: 规则管理 * @Description: 规则管理
@ -34,6 +38,9 @@ public class RulexServiceImpl extends ServiceImpl<RulexMapper, Rulex> implements
@Autowired @Autowired
RulexMapper rulexMapper; RulexMapper rulexMapper;
@Autowired
private WebSocketUtils webSocketUtils;
@Autowired @Autowired
private ITablexService iTablexService; private ITablexService iTablexService;
@ -70,6 +77,26 @@ public class RulexServiceImpl extends ServiceImpl<RulexMapper, Rulex> implements
return this.list(ruleWrapper); return this.list(ruleWrapper);
} }
@Override
public void saveRule(Rulex rulex, LoginUser loginUser, Map<String, String> message,int i) {
try {
Thread.sleep(1000L);
this.save(rulex);
message.put("uploaded", String.valueOf(i ));
webSocketUtils.sendMessage(loginUser.getId(), message);
} catch (InterruptedException e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
log.error(e.getMessage(), e);
}
}
/** /**
* 功能管理新增规则操作时如果功能类型是新增修改自动根据实体对应的字段自动生成若干条记录根据实体的字段生成多条规则 * 功能管理新增规则操作时如果功能类型是新增修改自动根据实体对应的字段自动生成若干条记录根据实体的字段生成多条规则
* *

@ -37,12 +37,14 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.tablex.service.ITablexVoService; import org.jeecg.modules.tablex.service.ITablexVoService;
import org.jeecg.modules.tablex.vo.TablexVo; import org.jeecg.modules.tablex.vo.TablexVo;
import org.jeecg.modules.tablex.ws.WebSocketUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams; 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.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.BeanUtils;
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;
@ -81,6 +83,9 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
@Autowired @Autowired
private IRequirementEntityService requirementEntityService; private IRequirementEntityService requirementEntityService;
@Autowired
private WebSocketUtils webSocketUtils;
/** /**
* 分页列表查询 * 分页列表查询
* *
@ -269,14 +274,23 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
*/ */
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(MultipartFile file) { public Result<?> importExcel(MultipartFile file) {
try {
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);
try {
// 判断文件是否是表格 // 判断文件是否是表格
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
if (StringUtils.isBlank(originalFilename) || if (StringUtils.isBlank(originalFilename) ||
(!originalFilename.endsWith("xls") && (!originalFilename.endsWith("xls") &&
!originalFilename.endsWith("xlsx"))) { !originalFilename.endsWith("xlsx"))) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件格式不正确"); return Result.error("文件格式不正确");
} }
@ -286,17 +300,25 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
params.setHeadRows(1);//表头行数,默认1 params.setHeadRows(1);//表头行数,默认1
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
List<TablexVo> list = null; List<TablexVo> list = null;
message.put("status", "读取数据中");
webSocketUtils.sendMessage(loginUser.getId(), message);
try { try {
//读取excel数据 //读取excel数据
list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params); list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params);
} catch (Exception e) { } catch (Exception e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件读取失败"); return Result.error("文件读取失败");
} }
//判断文件中是否存在数据 //判断文件中是否存在数据
if (list == null || list.size() == 0) { if (list == null || list.size() == 0) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("Excel数据为空"); return Result.error("Excel数据为空");
} }
message.put("status", "数据预读入");
webSocketUtils.sendMessage(loginUser.getId(), message);
for (TablexVo tablexVo : list) { for (TablexVo tablexVo : list) {
//判断当前存入行是否为空值 //判断当前存入行是否为空值
if (tablexVo.getModuleId() == null && if (tablexVo.getModuleId() == null &&
@ -307,13 +329,17 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
tablexVo.getStatus() == null && tablexVo.getStatus() == null &&
tablexVo.getVerisonStatus() == null && tablexVo.getVerisonStatus() == null &&
tablexVo.getVerison() == null) continue; tablexVo.getVerison() == null) continue;
// 将总的记录数传递给前端
message.put("records", String.valueOf(list.size()));
webSocketUtils.sendMessage(loginUser.getId(), message);
//判断版本号长度 //判断版本号长度
String verison = tablexVo.getVerison(); String verison = tablexVo.getVerison();
if (verison.length() > 5) { if (verison.length() > 5) {
return Result.error("导入失败,版本号格式错误"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("预读入失败,版本号格式错误");
} }
//存入临时表中 //存入临时表中
tablexVoService.save(tablexVo); tablexVoService.save(tablexVo);
} }
@ -324,20 +350,30 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
tablexVoService.removeAll(voList); tablexVoService.removeAll(voList);
if (voList.size() == 0) { if (voList.size() == 0) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,数据为空"); return Result.error("导入失败,数据为空");
} }
Tablex tablex = new Tablex(); message.put("status", "开始数据校验");
webSocketUtils.sendMessage(loginUser.getId(), message);
for (int i = 0; i < voList.size(); i++) { for (int i = 0; i < voList.size(); i++) {
List<Tablex> tablexList = new ArrayList<>();
Tablex tablex = new Tablex();
String moduleId = voList.get(i).getModuleId(); String moduleId = voList.get(i).getModuleId();
if (moduleId == null || moduleId.equals("")){ if (moduleId == null || moduleId.equals("")){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("对应模块填写不能为空"); return Result.error("对应模块填写不能为空");
} }
LambdaQueryWrapper<Modulex> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Modulex> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Modulex::getId,moduleId); queryWrapper.eq(Modulex::getId,moduleId);
Modulex modulex = modulexService.getOne(queryWrapper); Modulex modulex = modulexService.getOne(queryWrapper);
if(modulex == null){ if(modulex == null){
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("对应模块填写错误"); return Result.error("对应模块填写错误");
} }
String modulexId = modulex.getId(); String modulexId = modulex.getId();
@ -346,9 +382,9 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
String verisonStatus = voList.get(i).getVerisonStatus(); String verisonStatus = voList.get(i).getVerisonStatus();
//判断实体状态 //判断实体状态
int statusInt = status.equals("正常") ? 1 : status.equals("停用") ? 0 : status.equals("废弃") ? 9 : 3; //int statusInt = status.equals("正常") ? 1 : status.equals("停用") ? 0 : status.equals("废弃") ? 9 : 3;
//判断版本状态 //判断版本状态
int verisonStatusInt = verisonStatus.equals("当前") ? 1 : verisonStatus.equals("历史") ? 0 : 3; //int verisonStatusInt = verisonStatus.equals("当前") ? 1 : verisonStatus.equals("历史") ? 0 : 3;
//判断对应模块 //判断对应模块
if (modulexId != null && voList.get(i).getModuleId() != null && !voList.get(i).getModuleId().equals("")) { if (modulexId != null && voList.get(i).getModuleId() != null && !voList.get(i).getModuleId().equals("")) {
@ -357,9 +393,9 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
//判断英文名称 //判断英文名称
if (voList.get(i).getTableEnName() != null && !voList.get(i).getTableEnName().equals("") && !voList.get(i).getTableEnName().equals(modulex.getModuleEnName())) { if (voList.get(i).getTableEnName() != null && !voList.get(i).getTableEnName().equals("") && !voList.get(i).getTableEnName().equals(modulex.getModuleEnName())) {
//判断实体状态 //判断实体状态
if (statusInt == 1 || statusInt == 0 || statusInt == 9) { if (status.equals("1") || status.equals("0") || status.equals("9")) {
//判断版本状态 //判断版本状态
if (verisonStatusInt == 1 || verisonStatusInt == 0) { if (verisonStatus.equals("1") || verisonStatus.equals("0")) {
//判断版本号 //判断版本号
if (voList.get(i).getVerison() != null && !voList.get(i).getVerison().equals("")) { if (voList.get(i).getVerison() != null && !voList.get(i).getVerison().equals("")) {
tablex.setModuleId(voList.get(i).getModuleId()); tablex.setModuleId(voList.get(i).getModuleId());
@ -368,36 +404,53 @@ public class TablexController extends JeecgController<Tablex, ITablexService> {
tablex.setTableStructure(voList.get(i).getTableStructure()); tablex.setTableStructure(voList.get(i).getTableStructure());
tablex.setStructuralDiagram(voList.get(i).getStructuralDiagram()); tablex.setStructuralDiagram(voList.get(i).getStructuralDiagram());
tablex.setCreateBy(loginUser.getRealname()); tablex.setCreateBy(loginUser.getRealname());
tablex.setStatus(statusInt); tablex.setStatus(Integer.valueOf(voList.get(i).getStatus()));
tablex.setVerisonStatus(verisonStatusInt); tablex.setVerisonStatus(Integer.valueOf(voList.get(i).getVerisonStatus()));
tablex.setVerison(Integer.valueOf(voList.get(i).getVerison())); tablex.setVerison(Integer.valueOf(voList.get(i).getVerison()));
//保存到真实表中 tablexList.add(tablex);
tablexService.save(tablex);
//单条保存到真实表中
tablexService.saveSingleBatch(tablexList,loginUser,message);
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!"); return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!");
} }
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!"); return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!");
} }
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!"); return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!");
} }
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!"); return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!");
} }
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!"); return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!");
} }
} else { } else {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!"); return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!");
} }
} }
} catch (Exception e) { } catch (Exception e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败"); return Result.error("文件导入失败");
} }
return Result.OK("文件导入成功!"); message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.ok("文件导入成功!");
} }
} }

@ -1,7 +1,12 @@
package org.jeecg.modules.tablex.service; package org.jeecg.modules.tablex.service;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.tablex.entity.Tablex; import org.jeecg.modules.tablex.entity.Tablex;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.tablex.vo.TablexVo;
import java.util.List;
import java.util.Map;
/** /**
* @Description: 实体表 * @Description: 实体表
@ -15,4 +20,5 @@ public interface ITablexService extends IService<Tablex> {
void updateVersion(String tableId, int i); void updateVersion(String tableId, int i);
void saveSingleBatch(List<Tablex> tablexList, LoginUser loginUser, Map<String, String> message);
} }

@ -1,13 +1,19 @@
package org.jeecg.modules.tablex.service.impl; package org.jeecg.modules.tablex.service.impl;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.tablex.entity.Tablex; import org.jeecg.modules.tablex.entity.Tablex;
import org.jeecg.modules.tablex.mapper.TablexMapper; import org.jeecg.modules.tablex.mapper.TablexMapper;
import org.jeecg.modules.tablex.service.ITablexService; import org.jeecg.modules.tablex.service.ITablexService;
import org.jeecg.modules.tablex.vo.TablexVo;
import org.jeecg.modules.tablex.ws.WebSocketUtils;
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;
/** /**
* @Description: 实体表 * @Description: 实体表
* @Author: jeecg-boot * @Author: jeecg-boot
@ -20,6 +26,9 @@ public class TablexServiceImpl extends ServiceImpl<TablexMapper, Tablex> impleme
@Autowired @Autowired
private TablexMapper tablexMapper; private TablexMapper tablexMapper;
@Autowired
private WebSocketUtils webSocketUtils;
@Override @Override
public void updateSql(String tableId, String sql) { public void updateSql(String tableId, String sql) {
tablexMapper.updateSql(tableId,sql); tablexMapper.updateSql(tableId,sql);
@ -29,4 +38,22 @@ public class TablexServiceImpl extends ServiceImpl<TablexMapper, Tablex> impleme
public void updateVersion(String tableId, int i) { public void updateVersion(String tableId, int i) {
tablexMapper.updateVersion(tableId,i); tablexMapper.updateVersion(tableId,i);
} }
@Override
public void saveSingleBatch(List<Tablex> tablexList, LoginUser loginUser, Map<String, String> message) {
for (int i = 0; i < tablexList.size(); i++){
try {
Thread.sleep(1000L);
message.put("uploaded", String.valueOf(i + 1));
this.save(tablexList.get(i));
webSocketUtils.sendMessage(loginUser.getId(), message);
} catch (InterruptedException e) {
message.put("isVisible", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
log.error(e.getMessage(), e);
}
}
}
} }

@ -0,0 +1,63 @@
package org.jeecg.modules.tablex.ws;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
@ServerEndpoint(value = "/uploadProcess/{val}")
public class MyWebSocket {
/**
* 已经建立连接的对话ConcurrentHashMap是一个线程安全的Map
*/
private static final Map<String, Session> sessionPool =
new ConcurrentHashMap<>();
/**
* 连接建立成功触发
*
* @param session 会话
*/
@OnOpen
public void onOpen(Session session, EndpointConfig endpointConfig,
@PathParam("val") String key) {
// 将session进行保存
sessionPool.put(key, session);
log.info("创建一个连接,当前连接的连接数量是:{}", sessionPool.size());
}
/**
* 发送消息
*
* @param info 信息
*/
@OnMessage
public void onMessage(String info) {
log.info("接受到的消息是:{}", info);
}
public Map<String, Session> getSessionPool() {
return sessionPool;
}
/**
* 关闭连接时触发
*
* @param session 会话
*/
@OnClose
public void onClose(Session session, @PathParam("val") String key) {
sessionPool.remove(key);
log.info("关闭一个连接,当前剩余连接数为:{}", sessionPool.size());
}
}

@ -0,0 +1,53 @@
package org.jeecg.modules.tablex.ws;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.websocket.Session;
import java.util.Map;
@Slf4j
@Component
public class WebSocketUtils {
@Autowired
MyWebSocket webSocket;
private static Map<String, Session> sessionPool;
@PostConstruct
private void init() {
sessionPool = webSocket.getSessionPool();
}
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public void sendMessage(String key, Map<String, String> message) {
Session session = sessionPool.get(key);
try {
session.getBasicRemote()
.sendText(OBJECT_MAPPER
.writeValueAsString(message));
} catch (Exception e) {
log.error(e.getMessage());
}
}
public void sendAllMessage(Map<String, String> message) {
sessionPool.values().forEach(session -> {
try {
session.getBasicRemote()
.sendText(OBJECT_MAPPER
.writeValueAsString(message));
} catch (Exception e) {
log.error(e.getMessage());
}
});
}
}
Loading…
Cancel
Save