commit a15d10f90b22bd7227ab67f250c7831697d875f4 Author: hupeng <664288600@qq.com> Date: Sun Feb 25 23:27:26 2024 +0800 动态标签——指标 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7115f6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +target/ +bin/ +out/ +log/ +build/ +dist/ +tmp/ + +*.idea +*.iml +*.log \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..db0e142 --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.szr + center + 1.0 + + + com.szr + common + 1.0 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-validation + + + io.springfox + springfox-swagger-ui + ${swagger.ui.version} + + + com.github.xiaoymin + knife4j-openapi2-spring-boot-starter + ${knife4j.version} + + + org.springframework.boot + spring-boot-starter-test + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis.plus.version} + + + + org.projectlombok + lombok + + + com.alibaba.fastjson2 + fastjson2 + ${fastjson2.version} + + + junit + junit + + + + + diff --git a/common/src/main/java/com/common/entity/Scene.java b/common/src/main/java/com/common/entity/Scene.java new file mode 100644 index 0000000..86b8941 --- /dev/null +++ b/common/src/main/java/com/common/entity/Scene.java @@ -0,0 +1,83 @@ +package com.common.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +@TableName(value = "p_scene") +public class Scene { + @TableId + @ApiModelProperty(value = "主键") + private Integer id; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") + @TableField("create_at") + @ApiModelProperty(value = "创建时间") + private Date createAt; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") + @TableField("update_at") + @ApiModelProperty(value = "修改时间") + private Date updateAt; + @TableField("scene_name") + @ApiModelProperty(value = "技能名称") + private String sceneName; + @TableField("scene_remark") + @ApiModelProperty(value = "备注") + private String sceneRemark; + @ApiModelProperty(value = "角色串") + private String roles; + @TableField("model_notes") + @ApiModelProperty(value = "模型说明") + private String modelNotes; + @TableField("file_url") + @ApiModelProperty(value = "文件地址") + private String fileUrl; + @ApiModelProperty(value = "版本") + private String version; + + //------------- 这里加一个空格后期需要去掉 +// @TableField("contribution_name") + @TableField(exist=false) + @ApiModelProperty(value = "贡献者姓名") + private String contributionName; + @TableField("scene_type") + @ApiModelProperty(value = "技能类别 1定制 2永洪 ") + private Short sceneType; + @TableField("scene_url") + @ApiModelProperty(value = "技能URL") + private String sceneUrl; + @TableField("scene_skin") + @ApiModelProperty(value = "场景皮肤") + private String sceneSkin; + @TableField("icon_url") + @ApiModelProperty(value = "icon地址") + private String iconUrl; + @TableField("create_by") + @ApiModelProperty(value = "创建人") + private String createBy; + @TableField("update_by") + @ApiModelProperty(value = "更新人") + private String updateBy; + @ApiModelProperty(value = "删除标记:0-未删除 1-已删除") + private Short deleted; + @TableField("scene_operation") + @ApiModelProperty(value = "技能类型 智能脑,聪明口,灵活手,千里眼") + private String sceneOperation; + @TableField("scene_order") + @ApiModelProperty(value = "排序") + private Integer sceneOrder; + @TableField("scene_code") + @ApiModelProperty(value = "场景编码") + private String sceneCode; + @TableField("scene_tag") + @ApiModelProperty(value = "场景标签") + private String sceneTag; +} diff --git a/common/src/main/java/com/common/entity/User.java b/common/src/main/java/com/common/entity/User.java new file mode 100644 index 0000000..46f5d5d --- /dev/null +++ b/common/src/main/java/com/common/entity/User.java @@ -0,0 +1,66 @@ +package com.common.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.OffsetDateTime; +import java.util.Set; + +@Data +@TableName(value = "p_user") +public class User { + @TableId + @ApiModelProperty(value = "用户主键") + private Integer id; + @TableField("user_id") + @ApiModelProperty(value = "用户编号") + private String userId; + @TableField("login_name") + @ApiModelProperty(value = "用户名(登录账号)") + private String loginName; + @TableField("login_password") + @ApiModelProperty(value = "用户密码(登录密码)") + private String loginPassword; + @TableField("user_name") + @ApiModelProperty(value = "用户姓名") + private String userName; + @TableField("mobile_number") + @ApiModelProperty(value = "手机号") + private String mobileNumber; + @TableField("police_number") + @ApiModelProperty(value = "警员编号(警号)") + private String policeNumber; + @TableField("id_number") + @ApiModelProperty(value = "身份证号") + private String idNumber; + @ApiModelProperty(value = "是否启用 0-未启用 1-启用") + private String effective; + @TableField("department_id") + @ApiModelProperty(value = "所属单位编号") + private String departmentId; + @TableField("job_title") + @ApiModelProperty(value="职称") + private String jobTitle; + @TableField("role_level") + @ApiModelProperty(value="等级:0 系统用户 1 派出所 2 分局") + private String roleLevel; + @ApiModelProperty(value = "用户角色,role id以逗号拼接") + private Set roles; + //与其它实体类型和命名不一致 + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") + @TableField("create_time") + @ApiModelProperty(value="角色列表") + private OffsetDateTime createTime; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") + @TableField("update_time") + @ApiModelProperty(value="角色列表") + private OffsetDateTime updateTime; + +} diff --git a/common/src/main/java/com/common/entity/base/Base.java b/common/src/main/java/com/common/entity/base/Base.java new file mode 100644 index 0000000..a89b4bc --- /dev/null +++ b/common/src/main/java/com/common/entity/base/Base.java @@ -0,0 +1,30 @@ +package com.common.entity.base; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +public class Base { + @TableId(type = IdType.AUTO) + @ApiModelProperty(value = "主键(32),保存不需要赋值id",required = true) + private Integer id; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") + @TableField("create_time") + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") + @TableField("update_time") + @ApiModelProperty(value = "修改时间") + private Date updateTime; +} diff --git a/common/src/main/java/com/common/entity/dic/AppDic.java b/common/src/main/java/com/common/entity/dic/AppDic.java new file mode 100644 index 0000000..f770c40 --- /dev/null +++ b/common/src/main/java/com/common/entity/dic/AppDic.java @@ -0,0 +1,20 @@ +package com.common.entity.dic; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.common.entity.base.Base; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString(callSuper = true) +@TableName(value = "app_dic") +public class AppDic extends Base { + @TableField("app_type") + @ApiModelProperty(value = "模块类型") + private String appType; + @TableField("parent_id") + @ApiModelProperty(value = "父级ID") + private String parentId; +} diff --git a/common/src/main/java/com/common/entity/dic/IndicatorDic.java b/common/src/main/java/com/common/entity/dic/IndicatorDic.java new file mode 100644 index 0000000..1ae2e12 --- /dev/null +++ b/common/src/main/java/com/common/entity/dic/IndicatorDic.java @@ -0,0 +1,20 @@ +package com.common.entity.dic; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.common.entity.base.Base; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString(callSuper = true) +@TableName(value = "indicator_dic") +public class IndicatorDic extends Base { + @TableField("indicator_type") + @ApiModelProperty(value = "指标类型") + private String indicatorType; + @TableField("parent_id") + @ApiModelProperty(value = "父级ID") + private Integer parentId; +} diff --git a/common/src/main/java/com/common/info/CodeMsg.java b/common/src/main/java/com/common/info/CodeMsg.java new file mode 100644 index 0000000..927c711 --- /dev/null +++ b/common/src/main/java/com/common/info/CodeMsg.java @@ -0,0 +1,26 @@ +package com.common.info; + +import lombok.ToString; + +@ToString +public enum CodeMsg { + SUCCESS(200, "成功"), + FAILURE(500, "失败"), + AUTH_FAILURE(401, "认证失败"); + + private Integer code; + private String message; + + CodeMsg(Integer code, String message){ + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/common/src/main/java/com/common/info/Parameter.java b/common/src/main/java/com/common/info/Parameter.java new file mode 100644 index 0000000..e7b6d6d --- /dev/null +++ b/common/src/main/java/com/common/info/Parameter.java @@ -0,0 +1,7 @@ +package com.common.info; + +public class Parameter { + public static final String TOKEN = "userId"; + public static String TABLE_SCHEMA = "public"; + +} diff --git a/common/src/main/java/com/common/tool/EqTool.java b/common/src/main/java/com/common/tool/EqTool.java new file mode 100644 index 0000000..17bf778 --- /dev/null +++ b/common/src/main/java/com/common/tool/EqTool.java @@ -0,0 +1,17 @@ +package com.common.tool; + +import java.lang.reflect.Field; + +public class EqTool { + public static boolean compareObjects(Object obj1, Object obj2) { + Class clazz = obj1.getClass(); // 获取类信息 + Field[] fields = clazz.getDeclaredFields(); // 获取所有字段 + for (Field field : fields) { + field.setAccessible(true); // 设置为可访问 + if (!field.equals(obj2)) { // 判断字段值是否相等 + return false; + } + } + return true; + } +} diff --git a/common/src/main/resources/common.sql b/common/src/main/resources/common.sql new file mode 100644 index 0000000..63b6fb8 --- /dev/null +++ b/common/src/main/resources/common.sql @@ -0,0 +1,103 @@ +drop table if exists public.p_user; +create table public.p_user ( + id int4 generated always as identity primary key, + user_id varchar(32) null, + login_name varchar(500) null, + login_password varchar(500) null, + user_name varchar(500) null, + mobile_number varchar(500) null, + police_number varchar(500) not null, + id_number varchar(500) null, + effective varchar(1) null default 1, + department_id varchar(500) null, + create_time timestamp(6) null default now(), + update_time timestamp(6) null, + job_title varchar(200) null, + role_level varchar(10) not null default 1, + roles varchar(255) null +); +create index idx_dep on public.p_user using btree (department_id); +create index idx_dep_branch on public.p_user using btree (substr((department_id)::text, 1, 6)); +create index idx_dep_station on public.p_user using btree (substr((department_id)::text, 1, 8)); +create index idx_uid on public.p_user using btree (user_id); +comment on tree public.p_user.user_id is '用户编号'; +comment on tree public.p_user.login_name is '用户名(登录账号)'; +comment on tree public.p_user.login_password is '用户密码(登录密码)'; +comment on tree public.p_user.user_name is '用户姓名'; +comment on tree public.p_user.mobile_number is '手机号'; +comment on tree public.p_user.police_number is '警员编号(警号)'; +comment on tree public.p_user.id_number is '身份证号'; +comment on tree public.p_user.effective is '是否启用:0 无效 1有效 默认 1'; +comment on tree public.p_user.department_id is '所属单位编号'; +comment on tree public.p_user.create_time is '创建时间'; +comment on tree public.p_user.update_time is '更新时间'; +comment on tree public.p_user.job_title is '职称'; +comment on tree public.p_user.role_level is '等级:0运营 1派出所 2分局'; +comment on tree public.p_user.roles is 'role id以逗号拼接'; + +drop table if exists public.p_role; +create table public.p_role ( + id int4 generated always as identity primary key, + role_type varchar(10) null, + role_name varchar(255) null, + role_desc varchar(255) null, + create_at date null, + create_by varchar(255) null, + update_at date null, + update_by varchar(255) null, + deleted int2 null, + data_scope int4 null +); +comment on tree public.p_role.role_type is '角色类型-字典表jslx'; +comment on tree public.p_role.role_name is '角色名'; +comment on tree public.p_role.role_desc is '角色描述'; +comment on tree public.p_role.create_at is '创建时间'; +comment on tree public.p_role.create_by is '创建人'; +comment on tree public.p_role.update_at is '修改时间'; +comment on tree public.p_role.update_by is '修改人'; +comment on tree public.p_role.deleted is '删除标记 0-未删除 1-已删除'; +comment on tree public.p_role.data_scope is '数据权限定义 1-全部权限 2-本部门及以下部门 3-本部门 4-本人 5-自定义'; + +drop table if exists public.p_scene; +create table public.p_scene ( + id int4 generated always as identity primary key, + scene_name varchar(255) null, + scene_remark varchar(500) null, + roles varchar(100) null, + model_notes varchar(1000) null, + file_url varchar(255) null, + "version" varchar(20) null, + contribution_name varchar(255) null, + scene_type int2 null, + scene_url varchar(255) null, + scene_skin varchar(16) null, + icon_url varchar(255) null, + create_at date null, + create_by varchar(255) null, + update_at date null, + update_by varchar(255) null, + deleted int2 null, + scene_operation varchar(255) null, + scene_order int4 null, + scene_code varchar(255) null, + scene_tag varchar(200) null +); +comment on tree public.p_scene.scene_name is '场景名称'; +comment on tree public.p_scene.scene_remark is '场景说明'; +comment on tree public.p_scene.roles is '适用角色 逗号拼接串'; +comment on tree public.p_scene.model_notes is '模型逻辑说明'; +comment on tree public.p_scene.file_url is '文件上传路径'; +comment on tree public.p_scene."version" is '版本'; +comment on tree public.p_scene.contribution_name is '贡献者姓名'; +comment on tree public.p_scene.scene_type is '1:定制 2:永洪编排'; +comment on tree public.p_scene.scene_url is '场景url'; +comment on tree public.p_scene.icon_url is 'icon图片地址'; +comment on tree public.p_scene.create_at is '创建时间'; +comment on tree public.p_scene.create_by is '创建人'; +comment on tree public.p_scene.update_at is '修改时间'; +comment on tree public.p_scene.update_by is '更新人'; +comment on tree public.p_scene.deleted is '删除标记:0-未删除 1-已删除'; +comment on tree public.p_scene.scene_operation is '智能脑,聪明口,灵活手,千里眼'; +comment on tree public.p_scene.scene_order is '排序'; +comment on tree public.p_scene.scene_code is '场景编码'; +comment on tree public.p_scene.scene_tag is '技能标签'; diff --git a/common/src/main/resources/tmp b/common/src/main/resources/tmp new file mode 100644 index 0000000..6d64593 --- /dev/null +++ b/common/src/main/resources/tmp @@ -0,0 +1,19 @@ +select exists (select from information_schema.tables where table_name = 'app_dic') as is_exists; +alter table app_dic add column if not exists t_alter varchar(255); +alter table app_dic drop column if exists t_alter; +drop table if exists app_dic; +select * from p_scene where scene_name like '%人%' or scene_remark like '%人%' or model_notes like '%人%'; + +--查询表字段和注释 +select + col_description (pg_attr.attrelid, pg_attr.attnum) as comment, + format_type (pg_attr.atttypid, pg_attr.atttypmod) as type, + pg_attr.attname as name, + pg_attr.attnotnull as notnull +from + pg_class as pg_cla, + pg_attribute as pg_attr +where + pg_cla.relname = 'p_indicator' +and pg_attr.attrelid = pg_cla.oid +and pg_attr.attnum >0 diff --git a/common/src/main/resources/zbsz.sql b/common/src/main/resources/zbsz.sql new file mode 100644 index 0000000..925c9a4 --- /dev/null +++ b/common/src/main/resources/zbsz.sql @@ -0,0 +1,104 @@ +--generated always 默认从1开始 +--字典_指标类型 +drop table if exists indicator_dic; +create table indicator_dic ( + id int4 generated always as identity primary key, + indicator_type varchar(128) not null, + parent_id int4, + create_time timestamp not null, + update_time timestamp +); +comment on column indicator_dic.id is '主键'; +comment on column indicator_dic.indicator_type is '类型'; +comment on column indicator_dic.parent_id is '父级ID'; +comment on column indicator_dic.create_time is '创建时间'; +comment on column indicator_dic.update_time is '修改时间'; +insert into indicator_dic(indicator_type,create_time,update_time) values ('基础指标',current_timestamp,current_timestamp); +insert into indicator_dic(indicator_type,create_time,update_time) values ('逻辑指标',current_timestamp,current_timestamp); +insert into indicator_dic(indicator_type,create_time,update_time) values ('统计指标',current_timestamp,current_timestamp); +--字典_应用类型 +drop table if exists app_dic; +create table app_dic ( + id int4 generated always as identity primary key, + app_type varchar(128) not null, + parent_id int4, + create_time timestamp not null, + update_time timestamp +); +comment on column app_dic.id is '主键'; +comment on column app_dic.app_type is '类型'; +comment on column app_dic.parent_id is '父级ID'; +comment on column app_dic.create_time is '创建时间'; +comment on column app_dic.update_time is '修改时间'; +insert into app_dic(app_type,create_time,update_time) values ('态势感知',current_timestamp,current_timestamp); +insert into app_dic(app_type,create_time,update_time) values ('智能战果分析',current_timestamp,current_timestamp); +insert into app_dic(app_type,parent_id,create_time,update_time) values ('风险人',1,current_timestamp,current_timestamp); +insert into app_dic(app_type,parent_id,create_time,update_time) values ('风险事',1,current_timestamp,current_timestamp); +insert into app_dic(app_type,parent_id,create_time,update_time) values ('风险物',1,current_timestamp,current_timestamp); +insert into app_dic(app_type,parent_id,create_time,update_time) values ('人',2,current_timestamp,current_timestamp); +insert into app_dic(app_type,parent_id,create_time,update_time) values ('事',2,current_timestamp,current_timestamp); +insert into app_dic(app_type,parent_id,create_time,update_time) values ('物',2,current_timestamp,current_timestamp); + +--表_指标 +drop table if exists p_indicator; +create table p_indicator ( + id int4 generated always as identity primary key, + dynamic_table varchar(128) not null, + dynamic_column varchar(128) not null, + scene_id int4, + indicator_dic_id int4, + app_dic_p_id int4, + app_dic_c_id int4, + search_table varchar(255), + search_column varchar(255), + indicator_code varchar(128), + create_time timestamp not null, + update_time timestamp +); +comment on column p_indicator.id is '指标编号'; +comment on column p_indicator.dynamic_table is '动态表名称'; +comment on column p_indicator.dynamic_column is '动态表字段英文名称'; +comment on column p_indicator.scene_id is '关联技能'; +comment on column p_indicator.indicator_dic_id is '指标类型'; +comment on column p_indicator.app_dic_p_id is '关联应用模块'; +comment on column p_indicator.app_dic_c_id is '关联功能'; +comment on column p_indicator.search_table is '关联表名称'; +comment on column p_indicator.search_column is '关联表字段名称'; +comment on column p_indicator.indicator_code is '代码值'; +comment on column p_indicator.create_time is '创建时间'; +comment on column p_indicator.update_time is '修改时间'; +--表_指标_标签 +drop table if exists p_indicator_label; +create table p_indicator_label ( + id int4 generated always as identity primary key, + table_name varchar(128) not null, + label_name varchar(128) not null, + label_level int4 not null, + parent_id int4, + column_name varchar(128), + create_time timestamp not null, + update_time timestamp +); +comment on column p_indicator_label.id is '标签ID'; +comment on column p_indicator_label.table_name is '表名称'; +comment on column p_indicator_label.label_name is '标签名称'; +comment on column p_indicator_label.label_level is '标签等级'; +comment on column p_indicator_label.parent_id is '父级ID'; +comment on column p_indicator_label.column_name is '字段名称'; +comment on column p_indicator_label.create_time is '创建时间'; +comment on column p_indicator_label.update_time is '修改时间'; +--表_指标_标签_中间表 +drop table if exists p_indicator_label_tmp; +create table p_indicator_label_tmp ( + id int4 generated always as identity primary key, + indicator_id int4, + label_id int4, + create_time timestamp not null, + update_time timestamp +); +comment on column p_indicator_label_tmp.id is '标签ID'; +comment on column p_indicator_label_tmp.indicator_id is '指标ID'; +comment on column p_indicator_label_tmp.label_id is '标签id'; +comment on column p_indicator_label_tmp.create_time is '创建时间'; +comment on column p_indicator_label_tmp.update_time is '修改时间'; + diff --git a/common/src/main/resources/指标api.txt b/common/src/main/resources/指标api.txt new file mode 100644 index 0000000..233de49 --- /dev/null +++ b/common/src/main/resources/指标api.txt @@ -0,0 +1,168 @@ +一、indicator api说明 +1、由appDicCId、appDicPId、indicatorDicId、sceneId组成动态表名 +2、由dynamicColumnEn和表名判断字段有没有重复 +3、标签参数说明 + I、保存指标 + 1、初始化多级标签,所有标签id为null,所有标签都会保存,标签id与父节点的id关联,parent id后台自动通过标签id关联 + 2、级联新增标签,标签格式为:父级(必须包含id)+新增标签 + 3、lableList不能为null,最少有一级标签 + II、更新指标(需要通过查询获取标签属性后,在之前的属性上进行修改,只能进行属性更新,关联更新需要删除指标+保存指标处理) + 1、所有标签id不能为null,用于批量或者局部更新(无序、有序标签都可以) + 2、lableList为null,标签不更新,更新指标其它参数 +4、删除指标时,含有兄弟节点的只删除最高级标签 + + +二、indicator api测试 +1、保存indicator +I、创建动态表 indicator_2_1_2_6,字段为id,c1, 标签为:爷爷1 → 儿子1 → 孙子1 +{ + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "c1", + "indicatorDicId": 1, + "lableList": [ + { + "labelLevel": 1, + "labelName": "爷爷1" + },{ + "labelLevel": 2, + "labelName": "儿子1" + },{ + "labelLevel": 3, + "labelName": "孙子1" + } + ], + "sceneId": 2 +} + + +II、更新表indicator_2_1_2_6,新字段为c2, 标签为:爷爷1 → 儿子1 → 孙子1,孙子2 +{ + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "c2", + "indicatorDicId": 1, + "lableList": [ + { + "id": 1, + "labelLevel": 1, + "labelName": "爷爷1" + },{ + "id": 2, + "labelLevel": 2, + "labelName": "儿子1" + },{ + "labelLevel": 3, + "labelName": "孙子2" + } + ], + "sceneId": 2 +} + + + +III、更新表indicator_2_1_2_6,新字段为c3, 标签为:爷爷1 → 儿子1 → 孙子1,孙子2 | 爷爷2 +{ + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "c3", + "indicatorDicId": 1, + "lableList": [ + { + "labelLevel": 1, + "labelName": "爷爷2" + } + ], + "sceneId": 2 +} + + +IV、更新表indicator_2_1_2_6,新字段为c4, 标签为:爷爷1 → 儿子1 → 孙子1,孙子2 | 爷爷2 | 爷爷3 → 儿子1 +{ + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "c4", + "indicatorDicId": 1, + "lableList": [ + { + "labelLevel": 1, + "labelName": "爷爷3" + },{ + "labelLevel": 2, + "labelName": "儿子1" + } + ], + "sceneId": 2 +} + + +V、更新表indicator_2_1_2_6,新字段为c5, 标签为:爷爷1 → 儿子1 → 孙子1,孙子2 | 爷爷2 | 爷爷3 → 儿子1,儿子2 +{ + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "c5", + "indicatorDicId": 1, + "lableList": [ + { + "id": 6, + "labelLevel": 1, + "labelName": "爷爷3" + },{ + "labelLevel": 2, + "labelName": "儿子2" + } + ], + "sceneId": 2 +} + +VI、更新表indicator_2_1_2_6,新字段为c6, 标签为:爷爷1 → 儿子1 → 孙子1,孙子2,孙子3 | 爷爷2 | 爷爷3 → 儿子1,儿子2 +{ + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "c6", + "indicatorDicId": 1, + "lableList": [ + { + "id": 1, + "labelLevel": 1, + "labelName": "爷爷1" + },{ + "id": 2, + "labelLevel": 2, + "labelName": "儿子1" + },{ + "labelLevel": 3, + "labelName": "孙子3" + } + ], + "sceneId": 2 +} + + +2、更新indicator + +I、更新表indicator_2_1_2_6,新字段为c7, id +{ + "id": 7, + "appDicCId": 6, + "appDicPId": 2, + "dynamicColumnEn": "column7", + "indicatorDicId": 1, + "lableList": [ + { + "id": 1, + "labelLevel": 1, + "labelName": "爷爷1" + },{ + "id": 1, + "labelLevel": 2, + "labelName": "儿子2" + },{ + "labelLevel": 3, + "labelName": "孙子1" + } + ], + "sceneId": 2 +} + + diff --git a/indicator/META-INF/MANIFEST.MF b/indicator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..569b441 --- /dev/null +++ b/indicator/META-INF/MANIFEST.MF @@ -0,0 +1,51 @@ +Manifest-Version: 1.0 +Main-Class: com.indicator.Run +Class-Path: spring-plugin-core-2.0.0.RELEASE.jar swagger-annotations-1.6 + .6.jar slf4j-api-1.7.36.jar simpleclient_tracer_otel_agent-0.15.0.jar m + change-commons-java-0.2.19.jar bcutil-jdk15on-1.69.jar spring-context-s + upport-1.0.10.jar spring-plugin-metadata-2.0.0.RELEASE.jar commons-io-2 + .2.jar springfox-swagger-common-2.10.5.jar log4j-to-slf4j-2.17.2.jar ja + vassist-3.25.0-GA.jar spring-cloud-alibaba-commons-2021.1.jar swagger-m + odels-1.6.6.jar httpasyncclient-4.1.5.jar simpleclient_tracer_otel-0.15 + .0.jar logback-core-1.2.12.jar feign-form-3.8.0.jar animal-sniffer-anno + tations-1.14.jar c3p0-0.9.5.5.jar postgresql-42.3.8.jar spring-security + -rsa-1.0.11.RELEASE.jar mybatis-spring-2.1.2.jar spring-boot-starter-2. + 7.12.jar spring-webmvc-5.3.27.jar checker-qual-3.5.0.jar spring-boot-st + arter-aop-2.7.12.jar spring-core-5.3.27.jar simpleclient_tracer_common- + 0.15.0.jar jsr305-1.3.9.jar spring-cloud-openfeign-core-3.1.8.jar sprin + g-boot-devtools-2.7.12.jar spring-boot-starter-web-2.7.12.jar jackson-d + atatype-jdk8-2.13.5.jar spring-security-crypto-5.7.8.jar spring-boot-st + arter-jdbc-2.7.12.jar spring-jcl-5.3.27.jar spring-cloud-starter-3.1.7. + jar spring-boot-autoconfigure-2.7.12.jar protobuf-java-3.11.4.jar tomca + t-embed-core-9.0.75.jar lombok-1.18.22.jar simpleclient-0.15.0.jar myba + tis-plus-core-3.5.5.jar bcpkix-jdk15on-1.69.jar springfox-spi-2.10.5.ja + r jackson-module-parameter-names-2.13.5.jar mybatis-plus-extension-3.5. + 5.jar feign-slf4j-11.10.jar spring-beans-5.3.27.jar springfox-schema-2. + 10.5.jar hibernate-validator-6.2.5.Final.jar httpcore-4.4.16.jar jackso + n-core-2.13.5.jar spring-boot-starter-tomcat-2.7.12.jar mybatis-3.5.15. + jar springfox-spring-webmvc-2.10.5.jar knife4j-openapi2-spring-boot-sta + rter-4.1.0.jar HikariCP-4.0.3.jar spring-web-5.3.27.jar httpcore-nio-4. + 4.16.jar mybatis-plus-boot-starter-3.5.5.jar spring-boot-2.7.12.jar htt + pclient-4.5.14.jar spring-boot-starter-validation-2.7.12.jar nacos-api- + 1.4.1.jar error_prone_annotations-2.1.3.jar springfox-spring-web-2.10.5 + .jar spring-tx-5.3.27.jar jakarta.annotation-api-1.3.5.jar log4j-api-2. + 17.2.jar checker-compat-qual-2.0.0.jar snakeyaml-1.30.jar jakarta.valid + ation-api-2.0.2.jar spring-aop-5.3.27.jar mapstruct-1.3.1.Final.jar fei + gn-form-spring-3.8.0.jar jackson-annotations-2.13.5.jar tomcat-embed-el + -9.0.75.jar tomcat-embed-websocket-9.0.75.jar j2objc-annotations-1.1.ja + r knife4j-core-4.1.0.jar spring-cloud-starter-alibaba-nacos-discovery-2 + 021.1.jar mybatis-plus-annotation-3.5.5.jar bcprov-jdk15on-1.69.jar spr + ingfox-bean-validators-2.10.5.jar jackson-datatype-jsr310-2.13.5.jar cl + assgraph-4.1.7.jar nacos-client-1.4.1.jar byte-buddy-1.12.23.jar spring + -cloud-context-3.1.7.jar aspectjweaver-1.9.7.jar springfox-core-2.10.5. + jar mybatis-plus-3.5.5.jar jboss-logging-3.4.3.Final.jar spring-jdbc-5. + 3.27.jar guava-24.1.1-jre.jar knife4j-openapi2-ui-4.1.0.jar springfox-s + wagger-ui-2.10.5.jar mybatis-plus-spring-boot-autoconfigure-3.5.5.jar s + pring-cloud-commons-3.1.7.jar spring-context-5.3.27.jar commons-fileupl + oad-1.5.jar jul-to-slf4j-1.7.36.jar spring-cloud-starter-openfeign-3.1. + 8.jar nacos-common-1.4.1.jar classmate-1.5.1.jar jsqlparser-4.6.jar log + back-classic-1.2.12.jar fastjson2-2.0.10.jar jackson-databind-2.13.5.ja + r mysql-connector-java-8.0.28.jar spring-boot-starter-json-2.7.12.jar f + eign-core-11.10.jar commons-codec-1.15.jar spring-boot-starter-logging- + 2.7.12.jar springfox-swagger2-2.10.5.jar spring-expression-5.3.27.jar + diff --git a/indicator/pom.xml b/indicator/pom.xml new file mode 100644 index 0000000..fb30c81 --- /dev/null +++ b/indicator/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + com.szr + center + 1.0 + + + com.szr + indicator + 1.0 + + + + + com.szr + common + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + com.mchange + c3p0 + ${c3p0.version} + + + org.postgresql + postgresql + ${postgresql.version} + + + mysql + mysql-connector-java + ${mysql.version} + + + org.springframework.boot + spring-boot-starter-aop + + + + + org.springframework.boot + spring-boot-devtools + true + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.commons + commons-collections4 + 4.4 + test + + + + + + diff --git a/indicator/src/main/java/com/indicator/Run.java b/indicator/src/main/java/com/indicator/Run.java new file mode 100644 index 0000000..34f41ae --- /dev/null +++ b/indicator/src/main/java/com/indicator/Run.java @@ -0,0 +1,17 @@ +package com.indicator; + +import com.indicator.init.CustomInitializer; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + + +@EnableDiscoveryClient +@SpringBootApplication +public class Run { + public static void main(String[] args) { + SpringApplication application = new SpringApplication(Run.class); + application.addInitializers(new CustomInitializer()); + application.run(); + } +} diff --git a/indicator/src/main/java/com/indicator/aop/LogAop.java b/indicator/src/main/java/com/indicator/aop/LogAop.java new file mode 100644 index 0000000..433fff9 --- /dev/null +++ b/indicator/src/main/java/com/indicator/aop/LogAop.java @@ -0,0 +1,46 @@ +package com.indicator.aop; + +import com.alibaba.fastjson2.JSON; +import com.common.info.Parameter; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.*; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +@Aspect +@Component +@Slf4j +public class LogAop { + @Pointcut("execution( * com.indicator.controller..*.*(..))") + public void log() {} + + @Around("log()") + public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { + long startTime=System.currentTimeMillis(); + Object result=joinPoint.proceed(); + log.info("Response:"+ JSON.toJSON(result)); + log.info("耗时:"+(System.currentTimeMillis()-startTime)); + log.info("==================End================="); + return result; + } + + @Before("log()") + public void doBefore(JoinPoint joinPoint) { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + log.info(""); + log.info("==================Start================="); + log.info("URL:" + request.getRequestURL().toString()); + log.info("Header:" +Parameter.TOKEN + " = " + request.getHeader(Parameter.TOKEN)); + log.info("Method:" + request.getMethod().toString()); + log.info("Class Method:" + joinPoint.getSignature().getDeclaringTypeName() + "," + joinPoint.getSignature().getName()); + log.info("客户端IP:" + request.getRemoteAddr()); + log.info("请求参数:" + JSON.toJSON(joinPoint.getArgs())); + } + +} diff --git a/indicator/src/main/java/com/indicator/config/C3P0Config.java b/indicator/src/main/java/com/indicator/config/C3P0Config.java new file mode 100644 index 0000000..9762537 --- /dev/null +++ b/indicator/src/main/java/com/indicator/config/C3P0Config.java @@ -0,0 +1,21 @@ +package com.indicator.config; + +import com.mchange.v2.c3p0.ComboPooledDataSource; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.sql.DataSource; + + +@Configuration +public class C3P0Config { + @Bean("datasource") + @Primary + @ConfigurationProperties(prefix = "c3p0") + public DataSource dataSource(){ + return DataSourceBuilder.create().type(ComboPooledDataSource.class).build(); + } +} diff --git a/indicator/src/main/java/com/indicator/config/PageConfig.java b/indicator/src/main/java/com/indicator/config/PageConfig.java new file mode 100644 index 0000000..79f1238 --- /dev/null +++ b/indicator/src/main/java/com/indicator/config/PageConfig.java @@ -0,0 +1,19 @@ +package com.indicator.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan("com.indicator.mapper") +public class PageConfig { + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL)); + return interceptor; + } +} diff --git a/indicator/src/main/java/com/indicator/config/Swagger2Config.java b/indicator/src/main/java/com/indicator/config/Swagger2Config.java new file mode 100644 index 0000000..f38819b --- /dev/null +++ b/indicator/src/main/java/com/indicator/config/Swagger2Config.java @@ -0,0 +1,62 @@ +package com.indicator.config; + +import com.indicator.filter.TokenInterceptor; +import com.indicator.repository.UserRepository; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +import javax.annotation.Resource; + + +/** + * http://localhost:8601/doc.html + */ +@Configuration +@Import(BeanValidatorPluginsConfiguration.class) +@EnableSwagger2WebMvc +public class Swagger2Config implements WebMvcConfigurer { + @Resource + private UserRepository userRepository; + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(new ApiInfoBuilder() + .title("指标设置 API") + .description("指标设置 API 说明,Token认证添加Header参数设置步骤: 文档管理 > 个性化设置 > 开启请求参数缓存,开启动态请求参数 | 设置完需要刷新页面") + .version("V-1.0") + .build()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.indicator.controller")) + .paths(PathSelectors.any()) + .build(); + } + + //过滤器 + @Override + public void addInterceptors(InterceptorRegistry registry) { + //添加拦截器 + registry.addInterceptor(new TokenInterceptor(userRepository)) + .addPathPatterns("/**") + .excludePathPatterns("/doc.html") + .excludePathPatterns("/swagger-resources/**") + .excludePathPatterns("/webjars/**") + .excludePathPatterns("/v2/**") + .excludePathPatterns("/favicon.ico") + .excludePathPatterns("/swagger-ui.html/**") + .excludePathPatterns("/keyPerson/callBackResult") + .excludePathPatterns("/upload/**") + .excludePathPatterns("/openapi/*");//白名单 + } + +} diff --git a/indicator/src/main/java/com/indicator/controller/IndicatorController.java b/indicator/src/main/java/com/indicator/controller/IndicatorController.java new file mode 100644 index 0000000..43099a3 --- /dev/null +++ b/indicator/src/main/java/com/indicator/controller/IndicatorController.java @@ -0,0 +1,707 @@ +package com.indicator.controller; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.common.entity.Scene; +import com.common.entity.dic.IndicatorDic; +import com.common.entity.dic.AppDic; +import com.common.info.CodeMsg; +import com.indicator.entity.Indicator; +import com.indicator.entity.IndicatorLabel; +import com.indicator.entity.Label; +import com.indicator.info.Result; +import com.indicator.mapper.IndicatorLabelMapper; +import com.indicator.mapper.LabelMapper; +import com.indicator.repository.*; +import com.indicator.vo.IndicatorVo; +import com.indicator.info.Search; +import com.indicator.vo.DynamicTable; +import com.indicator.mapper.IndicatorMapper; +import com.indicator.service.DynamicTableService; +import com.indicator.service.SearchService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@RestController +@RequestMapping("/indicator") +@Api(tags = "服务接口") +public class IndicatorController { + @Resource + private SceneRepository sceneRepository; + @Resource + private IndicatorDicRepository indicatorDicRepository; + @Resource + private AppDicRepository appDicRepository; + @Resource + private IndicatorRepository indicatorRepository; + @Resource + private IndicatorMapper indicatorMapper; + @Resource + private LabelRepository labelRepository; + @Resource + private LabelMapper labelMapper; + @Resource + private IndicatorLabelRepository indicatorLabelRepository; + @Resource + private IndicatorLabelMapper indicatorLabelMapper; + @Resource + private DynamicTableService dynamicTableService; + @Resource + private SearchService searchService; + + + + private void setSuccess(Result result){ + if(result.getCode() == null){ + result.setCode(CodeMsg.SUCCESS.getCode()); + } + if(result.getMsg() == null){ + result.setMsg(CodeMsg.SUCCESS.getMessage()); + } + } + + private void setListSuccess(Result result,List list){ + setSuccess(result); + + if(list != null){ + result.setData(list); + if(result.getTotal() == null){ + result.setTotal((long) list.size()); + } + }else { + result.setTotal(0L); + } + } + + private void setFailure(Result result){ + if(result.getCode() == null){ + result.setCode(CodeMsg.FAILURE.getCode()); + } + if(result.getMsg() == null){ + result.setMsg(CodeMsg.FAILURE.getMessage()); + } + result.setTotal(0L); + } + + private void setExFailure(Result result,Exception e){ + result.setData(e.getMessage()); + setFailure(result); + } + + + /** + * 关联场景查询 + * @return Result + */ + @ApiOperation(value = "获取关联场景",notes = "获取关联场景列表信息") + @GetMapping("get_scenes") + public Result getScenes() { + Result result = new Result(); + try { + List list = sceneRepository.list(); + setListSuccess(result,list); + log.info("-------- 获取关联场景成功 "); + }catch (Exception e){ + log.error("-------- 获取关联场景异常 : "+e.getMessage(),e); + setExFailure(result,e); + } + return result; + } + + /** + * 指标类型查询 + * @return Result + */ + @ApiOperation(value = "获取指标类型",notes = "获取指标类型列表信息") + @GetMapping("get_indicator_dic") + public Result getIndicatorDic() { + Result result = new Result(); + try { + List list = indicatorDicRepository.list(); + setListSuccess(result,list); + log.info("-------- 获取指标类型成功 "); + }catch (Exception e){ + log.error("-------- 获取指标类型异常 : "+e.getMessage(),e); + setExFailure(result,e); + } + return result; + } + + /** + * 关联应用模块类型查询 + * @return Result + */ + @ApiOperation(value = "获取关联应用模块类型",notes = "获取关联应用模块类型列表信息") + @GetMapping("get_app_p_dic") + public Result getAppPDic() { + Result result = new Result(); + try { + List list = appDicRepository.lambdaQuery().isNull(AppDic::getParentId).list(); + setListSuccess(result,list); + log.info("-------- 获取关联应用模块成功 "); + }catch (Exception e){ + log.error("-------- 获取关联应用模块异常 : "+e.getMessage(),e); + setExFailure(result,e); + } + return result; + } + + /** + * 关联功能类型查询 + * @return Result + */ + @ApiOperation(value = "获取关联功能类型",notes = "获取关联功能类型列表信息") + @ApiImplicitParam(name = "p_id",value = "关联应用模块类型 id,Content-Type:application/x-www-form-urlencoded",required = true) + @GetMapping("get_app_c_dic") + public Result getAppCDic(Integer p_id) { + Result result = new Result(); + try { + List list = appDicRepository.lambdaQuery().eq(AppDic::getParentId,p_id).list(); + setListSuccess(result,list); + log.info("-------- 获取联功能成功 "); + }catch (Exception e){ + log.error("-------- 获取联功能异常,p_id : "+p_id,e); + setExFailure(result,e); + } + return result; + } + + + /** + * 关联应用表信息查询 + * @return Result + */ + @ApiOperation(value = "获取关联应用表信息",notes = "获取关联应用表信息") + @GetMapping("get_app_tables") + public Result getAppTables() { + Result result = new Result(); + try { + List list = searchService.getTableNames(); + setListSuccess(result,list); + log.info("-------- 获取关联应用表成功 "); + }catch (Exception e){ + log.error("-------- 获取关联应用表异常 : "+e.getMessage(),e); + setExFailure(result,e); + } + return result; + } + + /** + * 关联应用表信息查询 + * @return Result + */ + @ApiOperation(value = "获取关联应用表字段信息",notes = "获取关联应用表字段信息") + @ApiImplicitParam(name = "tableName",value = "关联应用表名称,Content-Type:application/x-www-form-urlencoded",required = true) + @GetMapping("get_app_table_columns") + public Result getAppTableColumns(String tableName) { + Result result = new Result(); + try { + List list = searchService.getColumns(tableName); + setListSuccess(result,list); + log.info("-------- 获取关联应用表字段成功 "); + }catch (Exception e){ + log.error("-------- 获取关联应用表字段异常 : "+e.getMessage(),e); + setExFailure(result,e); + } + return result; + } + + + /** + * 关联应用模块类型查询 + * @return Result + */ + @ApiOperation(value = "获取一级标签",notes = "获取一级标签列表信息") + @GetMapping("get_p_label") + public Result getPLabel() { + Result result = new Result(); + try { + List