feat():规则引擎模块

master
Saisai Liu 2024-05-03 11:40:33 +08:00
parent 9b76b6fae4
commit 8a33e76f51
33 changed files with 1067 additions and 46 deletions

View File

@ -3,12 +3,16 @@ package com.muyu.common.system.remote;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.constant.ServiceNameConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
import com.muyu.common.system.domain.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
*
@ -37,4 +41,24 @@ public interface RemoteUserService {
*/
@PostMapping("/user/register")
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*
* @param user
* @return
*/
@PostMapping("/user/list")
public Result<List<SysUser>> list (@RequestBody SysUser user, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*
* @param deptId
* @return
*/
@PostMapping(value = "/dept/{deptId}")
public Result<SysDept> getInfo (@PathVariable("deptId") Long deptId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping(value = "/dept/list")
Result<List<SysDept>> list(@RequestBody SysDept dept, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

View File

@ -1,14 +1,17 @@
package com.muyu.common.system.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.RemoteUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import java.util.List;
/**
*
*
@ -31,6 +34,21 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
public Result<Boolean> registerUserInfo(SysUser sysUser, String source) {
return Result.error("注册用户失败:" + throwable.getMessage());
}
@Override
public Result<List<SysUser>> list(SysUser user, String source) {
return Result.error("用户列表获取失败" + throwable.getMessage());
}
@Override
public Result<SysDept> getInfo(Long deptId, String source) {
return Result.error("用户获取失败" + throwable.getMessage());
}
@Override
public Result<List<SysDept>> list(SysDept dept, String source) {
return Result.error("部门列表获取失败" + throwable.getMessage());
}
};
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-ruleEngine</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-ruleEngine-common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-core</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-security</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,61 @@
package com.muyu.engine.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* rule_engine
*
* @author Saisai
* @date 2024-05-03
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class RuleEngine extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(value = "id",type = IdType.AUTO)
private Long id;
/** 规则名称 */
@Excel(name = "规则名称")
private String name;
/** 规则类型 */
@Excel(name = "规则类型")
private String type;
/** 规则作用域 */
@Excel(name = "规则作用域")
private String level;
/** 引擎编码 */
@Excel(name = "引擎编码")
private String code;
/** 描述 */
@Excel(name = "描述")
private String description;
/** 是否激活 */
@Excel(name = "是否激活")
private String isActivate;
/** 规则状态 */
@Excel(name = "规则状态")
private String status;
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-ruleEngine</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-ruleEngine-remote</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-ruleEngine</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>muyu-ruleEngine-service</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.8</version>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-ruleEngine-common</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-datasource</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-datascope</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-log</artifactId>
</dependency>
<!-- MuYu Common Swagger -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-swagger</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 加入maven deploy插件当在deploy时忽略些model-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,98 @@
package com.muyu.engine.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.service.RuleEngineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* Controller
*
* @author Saisai
* @date 2024-05-03
*/
@RestController
@RequestMapping("/engine")
public class RuleEngineController extends BaseController
{
@Autowired
private RuleEngineService ruleEngineService;
/**
*
*/
@RequiresPermissions("engine:engine:list")
@GetMapping("/list")
public Result<TableDataInfo<RuleEngine>> list(RuleEngine ruleEngine)
{
startPage();
List<RuleEngine> list = ruleEngineService.selectRuleEngineList(ruleEngine);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("engine:engine:export")
@Log(title = "规则引擎", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, RuleEngine ruleEngine)
{
List<RuleEngine> list = ruleEngineService.selectRuleEngineList(ruleEngine);
ExcelUtil<RuleEngine> util = new ExcelUtil<RuleEngine>(RuleEngine.class);
util.exportExcel(response, list, "规则引擎数据");
}
/**
*
*/
@RequiresPermissions("engine:engine:query")
@GetMapping(value = "/{id}")
public Result getInfo(@PathVariable("id") Long id)
{
return success(ruleEngineService.selectRuleEngineById(id));
}
/**
*
*/
@RequiresPermissions("engine:engine:add")
@Log(title = "规则引擎", businessType = BusinessType.INSERT)
@PostMapping
public Result add(@RequestBody RuleEngine ruleEngine)
{
return toAjax(ruleEngineService.insertRuleEngine(ruleEngine));
}
/**
*
*/
@RequiresPermissions("engine:engine:edit")
@Log(title = "规则引擎", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody RuleEngine ruleEngine)
{
return toAjax(ruleEngineService.updateRuleEngine(ruleEngine));
}
/**
*
*/
@RequiresPermissions("engine:engine:remove")
@Log(title = "规则引擎", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public Result remove(@PathVariable Long[] ids)
{
return toAjax(ruleEngineService.deleteRuleEngineByIds(ids));
}
}

View File

@ -0,0 +1,63 @@
package com.muyu.engine.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.engine.domain.RuleEngine;
import java.util.List;
/**
* Mapper
*
* @author Saisai
* @date 2024-05-03
*/
public interface RuleEngineMapper extends BaseMapper<RuleEngine>
{
/**
*
*
* @param id
* @return
*/
public RuleEngine selectRuleEngineById(Long id);
/**
*
*
* @param ruleEngine
* @return
*/
public List<RuleEngine> selectRuleEngineList(RuleEngine ruleEngine);
/**
*
*
* @param ruleEngine
* @return
*/
public int insertRuleEngine(RuleEngine ruleEngine);
/**
*
*
* @param ruleEngine
* @return
*/
public int updateRuleEngine(RuleEngine ruleEngine);
/**
*
*
* @param id
* @return
*/
public int deleteRuleEngineById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteRuleEngineByIds(Long[] ids);
}

View File

@ -0,0 +1,63 @@
package com.muyu.engine.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.engine.domain.RuleEngine;
import java.util.List;
/**
* Service
*
* @author Saisai
* @date 2024-05-03
*/
public interface RuleEngineService extends IService<RuleEngine>
{
/**
*
*
* @param id
* @return
*/
public RuleEngine selectRuleEngineById(Long id);
/**
*
*
* @param ruleEngine
* @return
*/
public List<RuleEngine> selectRuleEngineList(RuleEngine ruleEngine);
/**
*
*
* @param ruleEngine
* @return
*/
public int insertRuleEngine(RuleEngine ruleEngine);
/**
*
*
* @param ruleEngine
* @return
*/
public int updateRuleEngine(RuleEngine ruleEngine);
/**
*
*
* @param ids
* @return
*/
public int deleteRuleEngineByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteRuleEngineById(Long id);
}

View File

@ -0,0 +1,100 @@
package com.muyu.engine.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.mapper.RuleEngineMapper;
import com.muyu.engine.service.RuleEngineService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Service
*
* @author Saisai
* @date 2024-05-03
*/
@Service
@Log4j2
public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngine> implements RuleEngineService
{
@Autowired
private RuleEngineMapper ruleEngineMapper;
/**
*
*
* @param id
* @return
*/
@Override
public RuleEngine selectRuleEngineById(Long id)
{
return ruleEngineMapper.selectRuleEngineById(id);
}
/**
*
*
* @param ruleEngine
* @return
*/
@Override
public List<RuleEngine> selectRuleEngineList(RuleEngine ruleEngine)
{
return ruleEngineMapper.selectRuleEngineList(ruleEngine);
}
/**
*
*
* @param ruleEngine
* @return
*/
@Override
public int insertRuleEngine(RuleEngine ruleEngine)
{
ruleEngine.setCreateTime(DateUtils.getNowDate());
return ruleEngineMapper.insertRuleEngine(ruleEngine);
}
/**
*
*
* @param ruleEngine
* @return
*/
@Override
public int updateRuleEngine(RuleEngine ruleEngine)
{
ruleEngine.setUpdateTime(DateUtils.getNowDate());
return ruleEngineMapper.updateRuleEngine(ruleEngine);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteRuleEngineByIds(Long[] ids)
{
return ruleEngineMapper.deleteRuleEngineByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteRuleEngineById(Long id)
{
return ruleEngineMapper.deleteRuleEngineById(id);
}
}

View File

@ -0,0 +1,28 @@
# Tomcat
server:
port: 9206
# Spring
spring:
application:
# 应用名称
name: muyu-engine
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 43.142.100.73:8848
config:
# 配置中心地址
server-addr: 43.142.100.73:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.etl.mapper: DEBUG

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.engine.mapper.RuleEngineMapper">
<resultMap type="com.muyu.engine.domain.RuleEngine" id="RuleEngineResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="level" column="level" />
<result property="code" column="code" />
<result property="description" column="description" />
<result property="isActivate" column="isActivate" />
<result property="status" column="status" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectRuleEngineVo">
select id, name, type, level, code,description, isActivate, status, remark, create_by, create_time, update_by, update_time from rule_engine
</sql>
<select id="selectRuleEngineList" parameterType="com.muyu.engine.domain.RuleEngine" resultMap="RuleEngineResult">
<include refid="selectRuleEngineVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="level != null and level != ''"> and level = #{level}</if>
<if test="code != null and code != ''"> and code = #{code}</if>
<if test="description != null and description != ''"> and description = #{description}</if>
<if test="isActivate != null and isActivate != ''"> and isActivate = #{isActivate}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
</where>
</select>
<select id="selectRuleEngineById" parameterType="Long" resultMap="RuleEngineResult">
<include refid="selectRuleEngineVo"/>
where id = #{id}
</select>
<insert id="insertRuleEngine" parameterType="com.muyu.engine.domain.RuleEngine">
insert into rule_engine
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="type != null">type,</if>
<if test="level != null">level,</if>
<if test="code != null">code,</if>
<if test="description != null">description,</if>
<if test="isActivate != null">isActivate,</if>
<if test="status != null">status,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="type != null">#{type},</if>
<if test="level != null">#{level},</if>
<if test="code != null">#{code},</if>
<if test="description != null">#{description},</if>
<if test="isActivate != null">#{isActivate},</if>
<if test="status != null">#{status},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateRuleEngine" parameterType="com.muyu.engine.domain.RuleEngine">
update rule_engine
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="type != null">type = #{type},</if>
<if test="level != null">level = #{level},</if>
<if test="code != null">code = #{code},</if>
<if test="description != null">description = #{description},</if>
<if test="isActivate != null">isActivate = #{isActivate},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteRuleEngineById" parameterType="Long">
delete from rule_engine where id = #{id}
</delete>
<delete id="deleteRuleEngineByIds" parameterType="String">
delete from rule_engine where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>muyu-modules</artifactId>
<version>3.6.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>muyu-ruleEngine</artifactId>
<packaging>pom</packaging>
<modules>
<module>muyu-ruleEngine-common</module>
<module>muyu-ruleEngine-remote</module>
<module>muyu-ruleEngine-service</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -34,7 +34,7 @@ public class SysDeptController extends BaseController {
*/
@RequiresPermissions("system:dept:list")
@GetMapping("/list")
public Result list (SysDept dept) {
public Result<List<SysDept>> list (SysDept dept) {
List<SysDept> depts = deptService.selectDeptList(dept);
return success(depts);
}

View File

@ -2,6 +2,8 @@ package com.muyu.etl.domain;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -37,7 +39,13 @@ public class AssetImpower extends BaseEntity {
* id
*/
@Excel(name = "部门id")
private Long typeId;
private Long deptId;
/**
* id
*/
@Excel(name = "接入id")
private Long basicId;
/**
* id
@ -45,4 +53,13 @@ public class AssetImpower extends BaseEntity {
@Excel(name = "用户id")
private Long userId;
public static AssetImpower saveAssetImpower(Long deptId,Long userId,AssetImpower assetImpower){
return AssetImpower.builder()
.basicId(assetImpower.getBasicId())
.tableId(assetImpower.getTableId())
.deptId(deptId)
.userId(userId)
.build();
}
}

View File

@ -37,6 +37,11 @@ public class TableInfo extends TreeEntity
@Excel(name = "表备注")
private String tableRemark;
/** 表备注 */
@Excel(name = "数据来源类型")
private String type;
/** 数据量 */
@Excel(name = "数据量")
private Long dataNum;

View File

@ -34,11 +34,17 @@ public class AssetImpowerReq {
@Excel(name = "表id")
private Long tableId;
/**
* id
*/
@Excel(name = "接入id")
private Long basicId;
/**
* id
*/
@Excel(name = "部门id")
private Long typeId;
private Long deptId;
/**
* id

View File

@ -0,0 +1,63 @@
package com.muyu.etl.domain.resp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* --
*
* @ClassName BasicTableInfoResp
* @Description
* @Author SaiSai.Liu
* @Date 2024/4/30 11:58
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class BasicTableInfoResp {
/**
* id
*/
private Long id;
/**
* id
*/
private Long basicId;
/**
*
*/
private String dataResourceName;
/**
*
*/
private String dataSourcesSystemName;
/**
*
*/
private String databaseName;
/**
*
*/
private String tableRemark;
/**
*
*/
private String tableName;
/**
*
*/
private Long totalNum;
}

View File

@ -45,10 +45,14 @@ public class TableInfoStructureResp
/** 数据量 */
@Excel(name = "数据量")
private Long dataNum;
/** 表备注 */
@Excel(name = "数据来源类型")
private String type;
/** 是否核心 'Y'是 'N'不是 */
@Excel(name = "是否核心 'Y'是 'N'不是")
private String center;
private String databaseType;
private List<Structure> structureList;

View File

@ -11,10 +11,18 @@
<artifactId>muyu-etl-remote</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -90,6 +90,7 @@
<artifactId>muyu-common-swagger</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -5,10 +5,12 @@ import com.muyu.common.security.annotation.EnableMyFeignClients;
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableCustomConfig
@EnableCustomSwagger2
@EnableMyFeignClients
@EnableFeignClients
@SpringBootApplication
public class MuYuEtlApplication {
public static void main(String[] args) {

View File

@ -101,4 +101,19 @@ public class AssetImpowerController extends BaseController
{
return toAjax(assetImpowerService.deleteAssetImpowerByIds(ids));
}
/**
*
*/
@RequiresPermissions("etl:impower:list")
@Log(title = "资产赋权", businessType = BusinessType.DELETE)
@DeleteMapping("getPowerByTableId/{tableId}")
public Result getPowerByTableId(@PathVariable Long tableId)
{
return Result.success(assetImpowerService.getPowerByTableId(tableId));
}
}

View File

@ -187,6 +187,18 @@ public class BasicConfigInfoController extends BaseController {
return Result.success(dictInfoService.insertDictInfo(dictInfo));
}
/**
*
*
* @return
*/
@RequiresPermissions("etl:table:list")
@Log(title = "获取具体表的所有基础信息")
@GetMapping("/getBasicTableInfo/{tableId}")
public Result getBasicTableInfo(@PathVariable Long tableId) throws ServletException {
return Result.success(basicConfigInfoService.getBasicTableInfo(tableId));
}
/**
*
*

View File

@ -60,4 +60,6 @@ public interface AssetImpowerService extends IService<AssetImpower>
* @return
*/
public int deleteAssetImpowerById(Long id);
List<AssetImpower> getPowerByTableId(Long tableId);
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.etl.domain.BasicConfigInfo;
import com.muyu.etl.domain.resp.BasicTableInfoResp;
import com.muyu.etl.domain.resp.TableInfoStructureResp;
import com.muyu.etl.domain.resp.TableTreeResp;
@ -73,4 +74,6 @@ public interface BasicConfigInfoService extends IService<BasicConfigInfo>
List<TableTreeResp> getTableTree();
TableInfoStructureResp getTableInfo(Long tableId);
BasicTableInfoResp getBasicTableInfo(Long tableId);
}

View File

@ -1,14 +1,23 @@
package com.muyu.etl.service.impl;
import java.util.List;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.etl.domain.AssetImpower;
import com.muyu.etl.domain.TableInfo;
import com.muyu.etl.mapper.AssetImpowerMapper;
import com.muyu.etl.service.AssetImpowerService;
import com.muyu.etl.service.TableInfoService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.etl.mapper.AssetImpowerMapper;
import com.muyu.etl.domain.AssetImpower;
import com.muyu.etl.service.AssetImpowerService;
import java.util.ArrayList;
import java.util.List;
/**
* Service
@ -17,10 +26,14 @@ import com.muyu.etl.service.AssetImpowerService;
* @date 2024-04-28
*/
@Service
public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,AssetImpower> implements AssetImpowerService
{
@Log4j2
public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper, AssetImpower> implements AssetImpowerService {
@Autowired
private AssetImpowerMapper assetImpowerMapper;
@Autowired
private TableInfoService tableInfoService;
@Autowired
private RemoteUserService remoteUserService;
/**
*
@ -29,8 +42,7 @@ public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,Asse
* @return
*/
@Override
public AssetImpower selectAssetImpowerById(Long id)
{
public AssetImpower selectAssetImpowerById(Long id) {
return assetImpowerMapper.selectAssetImpowerById(id);
}
@ -41,8 +53,7 @@ public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,Asse
* @return
*/
@Override
public List<AssetImpower> selectAssetImpowerList(AssetImpower assetImpower)
{
public List<AssetImpower> selectAssetImpowerList(AssetImpower assetImpower) {
return assetImpowerMapper.selectAssetImpowerList(assetImpower);
}
@ -53,10 +64,58 @@ public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,Asse
* @return
*/
@Override
public int insertAssetImpower(AssetImpower assetImpower)
{
public int insertAssetImpower(AssetImpower assetImpower) {
List<AssetImpower> rows = new ArrayList<>();
assetImpower.setCreateTime(DateUtils.getNowDate());
return assetImpowerMapper.insertAssetImpower(assetImpower);
//创建一个部门容器和用户容器
List<SysDept> deptList = remoteUserService.list(new SysDept(), SecurityConstants.INNER).getData();
System.out.println(remoteUserService.list(new SysDept(), SecurityConstants.INNER));
//单表单个用户赋权
if (assetImpower.getTableId() != null && assetImpower.getUserId() != null) {
rows.add(assetImpower);
}
//单表多用户赋权
if (assetImpower.getTableId() != null) {
//根据id过滤部门
SysDept dept = remoteUserService.getInfo(assetImpower.getDeptId(), SecurityConstants.INNER).getData();
deptList.addAll(getChildSysDept(deptList, dept));
List<AssetImpower> finalRows = rows;
deptList.stream().distinct().forEach(sysDept -> {
//该部门下的用户列表
remoteUserService.list(new SysUser() {{
setDeptId(sysDept.getDeptId());
}}, SecurityConstants.INNER).getData()
.forEach(sysUser -> finalRows.add(AssetImpower.saveAssetImpower(sysDept.getDeptId(), sysUser.getUserId(), assetImpower)));
});
rows = rows.stream().distinct().toList();
}
//多表单用户赋权
if (assetImpower.getUserId() != null) {
List<TableInfo> tableInfoList = tableInfoService.selectTableInfoList(new TableInfo() {{
setBasicId(assetImpower.getBasicId());
}});
List<AssetImpower> finalRows = rows;
tableInfoList.forEach(tableInfo -> finalRows.add(AssetImpower.saveAssetImpower(
assetImpower.getDeptId(), assetImpower.getUserId(), new AssetImpower() {{
setBasicId(assetImpower.getBasicId());
setTableId(tableInfo.getId());
}})));
}
boolean b = this.saveBatch(rows);
return 1;
}
//递归获取子级部门
public List<SysDept> getChildSysDept(List<SysDept> deptList, SysDept sysDept) {
List<SysDept> list = new ArrayList<>();
List<SysDept> deptChildList = new ArrayList<>(deptList);
list.addAll(deptChildList.stream()
.distinct()
.filter(dept -> dept.getParentId().equals(sysDept.getDeptId())).toList());
if (!list.isEmpty()) {
list.forEach(sysDeptChild -> deptChildList.addAll(this.getChildSysDept(deptChildList, sysDeptChild)));
}
return list;
}
/**
@ -66,8 +125,7 @@ public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,Asse
* @return
*/
@Override
public int updateAssetImpower(AssetImpower assetImpower)
{
public int updateAssetImpower(AssetImpower assetImpower) {
assetImpower.setUpdateTime(DateUtils.getNowDate());
return assetImpowerMapper.updateAssetImpower(assetImpower);
}
@ -79,8 +137,7 @@ public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,Asse
* @return
*/
@Override
public int deleteAssetImpowerByIds(Long[] ids)
{
public int deleteAssetImpowerByIds(Long[] ids) {
return assetImpowerMapper.deleteAssetImpowerByIds(ids);
}
@ -91,8 +148,14 @@ public class AssetImpowerServiceImpl extends ServiceImpl<AssetImpowerMapper,Asse
* @return
*/
@Override
public int deleteAssetImpowerById(Long id)
{
public int deleteAssetImpowerById(Long id) {
return assetImpowerMapper.deleteAssetImpowerById(id);
}
@Override
public List<AssetImpower> getPowerByTableId(Long tableId) {
return this.selectAssetImpowerList(new AssetImpower() {{
setTableId(tableId);
}});
}
}

View File

@ -7,6 +7,7 @@ import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.etl.domain.BasicConfigInfo;
import com.muyu.etl.domain.Structure;
import com.muyu.etl.domain.TableInfo;
import com.muyu.etl.domain.resp.BasicTableInfoResp;
import com.muyu.etl.domain.resp.TableInfoStructureResp;
import com.muyu.etl.domain.resp.TableTreeResp;
import com.muyu.etl.mapper.BasicConfigInfoMapper;
@ -116,6 +117,7 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
/**
*
*
* @param basicConfigInfo
* @return
* @throws ServletException
@ -142,6 +144,7 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
.parentId(0L)
.tableRemark("")
.center("Y")
.type("dataSource")
.tableName(basicConfigInfo.getDataSourcesSystemName() + "(" + databaseName + ")")
.createBy(SecurityUtils.getUsername())
.createTime(new Date())
@ -173,6 +176,7 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
//bug点tableRemark为空造成空指针异常
.tableRemark(tableRemark == null ? "" : tableRemark)
.parentId(tableInfo.getId())
.type("dataTable")
.center("Y")
.updateBy(SecurityUtils.getUsername())
.dataNum(rowCount)
@ -223,6 +227,7 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
/**
*
*
* @param conn
* @param databaseName
* @param table
@ -310,12 +315,12 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
}}).stream().map(info -> {
TableInfoStructureResp tableInfoStructureResp = null;
Future<TableInfoStructureResp> submit = threadPool.submit(() -> {
// List<Structure> structureList = structureService.list(new LambdaQueryWrapper<Structure>().eq(Structure::getTableId, info.getId()));
return TableInfoStructureResp.builder()
.id(info.getId())
.tableName(info.getTableName())
.center(info.getCenter())
.tableRemark(info.getTableRemark())
.type(info.getType())
.dataNum(info.getDataNum())
.parentId(info.getParentId())
.databaseType(basicConfigInfo.getDatabaseType())
@ -362,5 +367,44 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
.build();
}
@Override
public BasicTableInfoResp getBasicTableInfo(Long tableId) {
TableInfo tableInfo = tableInfoService.selectTableInfoById(tableId);
BasicConfigInfo basicConfigInfo = this.selectBasicConfigInfoById(tableInfo.getBasicId());
String host = basicConfigInfo.getHost();
String port = basicConfigInfo.getPort();
String databaseName = basicConfigInfo.getDatabaseName();
String databaseType = basicConfigInfo.getDatabaseType();
String url = "jdbc:" + databaseType + "://" + host + ":" + port + "/" + databaseName + "?" + basicConfigInfo.getConnectionParams();
String user = basicConfigInfo.getUsername();
String password = basicConfigInfo.getPassword();
Long totalNum = null;
BasicTableInfoResp basicTableInfoResp = null;
Connection conn = null;
try {
conn = DriverManager.getConnection(url, user, password);
PreparedStatement ps = conn.prepareStatement("select Count(0) from " + tableInfo.getTableName());
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()){
String a = String.valueOf(resultSet.getObject(1));
totalNum = resultSet.getLong(1);
}
basicTableInfoResp = BasicTableInfoResp.builder()
.dataResourceName(basicConfigInfo.getDataResourceName())
.dataSourcesSystemName(basicConfigInfo.getDataSourcesSystemName())
.databaseName(basicConfigInfo.getDatabaseName())
.tableName(tableInfo.getTableName())
.tableRemark(tableInfo.getTableRemark())
.id(tableId)
.basicId(basicConfigInfo.getId())
.totalNum(totalNum)
.build();
ps.close();
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return basicTableInfoResp;
}
}

View File

@ -6,8 +6,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.muyu.etl.domain.AssetImpower" id="AssetImpowerResult">
<result property="id" column="id" />
<result property="basicId" column="basic_id" />
<result property="tableId" column="table_id" />
<result property="typeId" column="type_id" />
<result property="deptId" column="dept_id" />
<result property="userId" column="user_id" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
@ -17,14 +18,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectAssetImpowerVo">
select id, table_id, type_id, user_id, remark, create_by, create_time, update_by, update_time from asset_impower
select id,basic_id , table_id, dept_id, user_id, remark, create_by, create_time, update_by, update_time from asset_impower
</sql>
<select id="selectAssetImpowerList" parameterType="com.muyu.etl.domain.AssetImpower" resultMap="AssetImpowerResult">
<include refid="selectAssetImpowerVo"/>
<where>
<if test="tableId != null "> and table_id = #{tableId}</if>
<if test="typeId != null "> and type_id = #{typeId}</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="userId != null "> and user_id = #{userId}</if>
</where>
</select>
@ -37,8 +38,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertAssetImpower" parameterType="com.muyu.etl.domain.AssetImpower" useGeneratedKeys="true" keyProperty="id">
insert into asset_impower
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="basicId != null">basic_id,</if>
<if test="tableId != null">table_id,</if>
<if test="typeId != null">type_id,</if>
<if test="deptId != null">dept_id,</if>
<if test="userId != null">user_id,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
@ -47,8 +49,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="basicId != null">#{basicId},</if>
<if test="tableId != null">#{tableId},</if>
<if test="typeId != null">#{typeId},</if>
<if test="deptId != null">#{deptId},</if>
<if test="userId != null">#{userId},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
@ -61,8 +64,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateAssetImpower" parameterType="com.muyu.etl.domain.AssetImpower">
update asset_impower
<trim prefix="SET" suffixOverrides=",">
<if test="basicId != null">basic_id = #{basicId},</if>
<if test="tableId != null">table_id = #{tableId},</if>
<if test="typeId != null">type_id = #{typeId},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>

View File

@ -12,6 +12,7 @@
<result property="tableRemark" column="table_remark" />
<result property="dataNum" column="data_num" />
<result property="center" column="center" />
<result property="type" column="type" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
@ -20,7 +21,7 @@
</resultMap>
<sql id="selectTableInfoVo">
select id, parent_id, basic_id,table_name, table_remark, data_num, center, remark, create_by, create_time, update_by, update_time from table_info
select id, parent_id,type, basic_id,table_name, table_remark, data_num, center, remark, create_by, create_time, update_by, update_time from table_info
</sql>
<select id="selectTableInfoList" parameterType="com.muyu.etl.domain.TableInfo" resultMap="TableInfoResult">
@ -42,7 +43,7 @@
<select id="selectTableInfoByName" parameterType="com.muyu.etl.domain.TableInfo" resultMap="TableInfoResult">
select * from table_info
where basic_id = #{basicId} and table_name = #{tableName}
where basic_id = #{basicId} and (table_name = #{tableName} or parent_id = #{parentId})
</select>
@ -51,6 +52,7 @@
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="parentId != null">parent_id,</if>
<if test="basicId != null">basic_id,</if>
<if test="type != null and type != ''">type,</if>
<if test="tableName != null and tableName != ''">table_name,</if>
<if test="tableRemark != null and tableRemark != ''">table_remark,</if>
<if test="dataNum != null">data_num,</if>
@ -64,6 +66,7 @@
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="parentId != null">#{parentId},</if>
<if test="basicId != null">#{basicId},</if>
<if test="type != null and type != ''">#{type},</if>
<if test="tableName != null and tableName != ''">#{tableName},</if>
<if test="tableRemark != null and tableRemark != ''">#{tableRemark},</if>
<if test="dataNum != null">#{dataNum},</if>
@ -81,6 +84,7 @@
<trim prefix="SET" suffixOverrides=",">
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="basicId != null">basic_id = #{basicId},</if>
<if test="type != null">type = #{type},</if>
<if test="tableName != null and tableName != ''">table_name = #{tableName},</if>
<if test="tableRemark != null and tableRemark != ''">table_remark = #{tableRemark},</if>
<if test="dataNum != null">data_num = #{dataNum},</if>

View File

@ -14,6 +14,7 @@
<module>muyu-job</module>
<module>muyu-file</module>
<module>muyv-etl</module>
<module>muyu-ruleEngine</module>
</modules>
<artifactId>muyu-modules</artifactId>

View File

@ -213,6 +213,13 @@
<version>${muyu.version}</version>
</dependency>
<!-- 规则引擎 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-ruleEngine-common</artifactId>
<version>${muyu.version}</version>
</dependency>
</dependencies>
</dependencyManagement>