diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/controller/FunctionxController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/controller/FunctionxController.java index ab5d776..bbde1a4 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/controller/FunctionxController.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/controller/FunctionxController.java @@ -28,6 +28,7 @@ import org.jeecg.modules.demo.requirementfun.entity.RequirementFun; 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.service.IRulexService; import org.jeecg.modules.modulex.entity.Modulex; import org.jeecg.modules.modulex.service.IModulexService; import org.jeecgframework.poi.excel.ExcelImportUtil; @@ -66,6 +67,9 @@ public class FunctionxController extends JeecgController { Result sort(String id); List queryRuleListByFunctionId(Functionx functionx); + + void saveRulex(Functionx functionx); } diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/impl/RulexServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/impl/RulexServiceImpl.java index 8b3babc..126b80e 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/impl/RulexServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/impl/RulexServiceImpl.java @@ -1,16 +1,23 @@ package org.jeecg.modules.demo.rulex.service.impl; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.demo.functionx.entity.Functionx; import org.jeecg.modules.demo.rulex.entity.Rulex; import org.jeecg.modules.demo.rulex.mapper.RulexMapper; import org.jeecg.modules.demo.rulex.service.IRulexService; +import org.jeecg.modules.fieldx.entity.Fieldx; +import org.jeecg.modules.fieldx.service.IFieldxService; +import org.jeecg.modules.tablex.entity.Tablex; +import org.jeecg.modules.tablex.service.ITablexService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; - +import java.util.Date; import java.util.List; /** @@ -19,39 +26,86 @@ import java.util.List; * @Date: 2023-04-10 * @Version: V1.0 */ + +@Slf4j @Service public class RulexServiceImpl extends ServiceImpl implements IRulexService { - @Autowired - RulexMapper rulexMapper; - - @Override - public Result sort(String id) { - String sort = rulexMapper.sort(id); - String functioncode = rulexMapper.find(id); - if (sort == null) { - return Result.OK("001" + functioncode); - } else { - int i = Integer.parseInt(sort); - i++; - String s = Integer.toString(i); - while (s.length() < 3) { - s = "0" + s; - } - return Result.OK(s + functioncode); + @Autowired + RulexMapper rulexMapper; + + @Autowired + private ITablexService iTablexService; + + @Autowired + private IFieldxService iFieldxService; + + @Override + public Result sort(String id) { + String sort = rulexMapper.sort(id); + String functioncode = rulexMapper.find(id); + if (sort == null) { + return Result.OK("001" + functioncode); + } else { + int i = Integer.parseInt(sort); + i++; + String s = Integer.toString(i); + while (s.length() < 3) { + s = "0" + s; + } + return Result.OK(s + functioncode); + } + } + + /** + * 根据功能id查询对应的规则 + * + * @param functionx functionx + * @return {@link List}<{@link Rulex}> + */ + @Override + public List queryRuleListByFunctionId(Functionx functionx) { + LambdaQueryWrapper ruleWrapper = new LambdaQueryWrapper<>(); + ruleWrapper.eq(Rulex::getFunctionId, functionx.getId()); + return this.list(ruleWrapper); + } + + /** + * 功能管理新增规则操作时,如果功能类型是‘新增’和‘修改’,自动根据实体对应的字段,自动生成若干条记录(根据实体的字段生成多条规则) + * + * @param functionx + */ + @Override + public void saveRulex(Functionx functionx) { + int functionType = functionx.getFunctionType().intValue(); + if (1 == functionType || 3 == functionType) { + String moduleId = functionx.getModuleId(); + Tablex tablex = iTablexService.getOne(new LambdaQueryWrapper().eq(Tablex::getModuleId, moduleId)); + if (!ObjectUtils.isEmpty(tablex)) { + List fieldxList = iFieldxService.list(new LambdaQueryWrapper().eq(Fieldx::getTableId, tablex.getId())); + if (!ObjectUtils.isEmpty(fieldxList)) { + fieldxList.stream().forEach(o -> { + //主键字段不创建规则 + if (0 == o.getIsPk()) { + Rulex rulex = new Rulex(); + rulex.setModuleId(moduleId); + rulex.setTableId(tablex.getId()); + rulex.setFunctionId(functionx.getId()); + rulex.setFieldId(o.getId()); + rulex.setCreateTime(new Date()); + Result result = this.sort(functionx.getId()); + String roleCodeStr = result.getResult().toString(); + log.info("-----------------the roleCodeStr:{}", roleCodeStr); + String ruleNo = roleCodeStr.substring(0, 3); + String ruleCode = roleCodeStr.substring(3) + ruleNo; + rulex.setRuleNo(ruleNo); + rulex.setRuleCode(ruleCode); + rulex.setPmDescribe(JSON.toJSONString(o)); + this.save(rulex); + } + }); + } + } + } } - } - - /** - * 根据功能id查询对应的规则 - * - * @param functionx functionx - * @return {@link List}<{@link Rulex}> - */ - @Override - public List queryRuleListByFunctionId(Functionx functionx) { - LambdaQueryWrapper ruleWrapper = new LambdaQueryWrapper<>(); - ruleWrapper.eq(Rulex::getFunctionId, functionx.getId()); - return this.list(ruleWrapper); - } }