1、查询公共模块设计 50%
This commit is contained in:
parent
cd70412e5d
commit
a3fc5e216e
|
@ -1,5 +1,6 @@
|
|||
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,
|
||||
|
@ -13,9 +14,7 @@ create table public.p_user (
|
|||
update_time timestamp(6) null,
|
||||
job_title varchar(200) null,
|
||||
role_level varchar(10) not null default 1,
|
||||
id int8 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
|
||||
roles varchar(255) null,
|
||||
constraint p_user_pkey primary key (id)
|
||||
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));
|
||||
|
@ -38,7 +37,7 @@ comment on column public.p_user.roles is 'role id以逗号拼接';
|
|||
|
||||
drop table if exists public.p_role;
|
||||
create table public.p_role (
|
||||
id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
|
||||
id int4 generated always as identity primary key,
|
||||
role_type varchar(10) null,
|
||||
role_name varchar(255) null,
|
||||
role_desc varchar(255) null,
|
||||
|
@ -61,7 +60,7 @@ comment on column public.p_role.data_scope is '数据权限定义 1-全部权限
|
|||
|
||||
drop table if exists public.p_scene;
|
||||
create table public.p_scene (
|
||||
id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
|
||||
id int4 generated always as identity primary key,
|
||||
scene_name varchar(255) null,
|
||||
scene_remark varchar(500) null,
|
||||
roles varchar(100) null,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
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 '%人%';
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
--generated always 默认从0开始
|
||||
--generated always 默认从1开始
|
||||
--字典_指标类型
|
||||
drop table if exists indicator_dic;
|
||||
create table indicator_dic (
|
||||
id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
|
||||
id int4 generated always as identity primary key,
|
||||
indicator_type varchar(128) not null,
|
||||
parent_id int4,
|
||||
create_time timestamp not null,
|
||||
|
@ -19,7 +19,7 @@ insert into indicator_dic(indicator_type,create_time) values ('统计指标',cur
|
|||
--字典_应用类型
|
||||
drop table if exists app_dic;
|
||||
create table app_dic (
|
||||
id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
|
||||
id int4 generated always as identity primary key,
|
||||
app_type varchar(128) not null,
|
||||
parent_id int4,
|
||||
create_time timestamp not null,
|
||||
|
@ -41,13 +41,15 @@ insert into app_dic(app_type,parent_id,create_time) values ('物',1,current_time
|
|||
--表_指标
|
||||
drop table if exists p_indicator;
|
||||
create table p_indicator (
|
||||
id int4 not null generated always as identity( minvalue 0 no maxvalue start 0 no cycle),
|
||||
id int4 generated always as identity primary key,
|
||||
indicator_name varchar(128) not null,
|
||||
indicator_en_name varchar(128) not null,
|
||||
indicator_dic_id int4,
|
||||
scene_id int4,
|
||||
app_dic_p_id int4,
|
||||
app_dic_c_id int4,
|
||||
indicator_table_name varchar(255),
|
||||
indicator_column varchar(255),
|
||||
indicator_code varchar(128),
|
||||
create_time timestamp not null,
|
||||
update_time timestamp
|
||||
|
@ -59,29 +61,8 @@ comment on column p_indicator.indicator_dic_id is '指标类型';
|
|||
comment on column p_indicator.scene_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.indicator_code is '关联功能';
|
||||
comment on column p_indicator.indicator_table_name is '关联表名称';
|
||||
comment on column p_indicator.indicator_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 '修改时间';
|
||||
|
||||
|
||||
|
||||
--触发器,根据增删改动态增加删除字段
|
||||
create or replace function trigger_function() returns trigger as $$
|
||||
begin
|
||||
-- 判断当前操作类型为 insert、update 还是 delete
|
||||
if (tg_op = 'insert' or tg_op = 'delete') then
|
||||
-- 如果是 insert 或 delete 操作,则删除指定字段
|
||||
execute format('alter table %i drop column column_name', tg_table_name);
|
||||
elsif (tg_op = 'update') then
|
||||
-- 如果是 update 操作,则添加新字段
|
||||
execute format('alter table %i add column new_column_name data_type', tg_table_name);
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- 创建 after insert/update/delete 触发器
|
||||
create trigger trigger_name
|
||||
after insert or update or delete on table_name
|
||||
for each row
|
||||
execute procedure trigger_function();
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.zbsz.Run
|
||||
Class-Path: spring-boot-starter-logging-2.7.12.jar springfox-swagger2-2.
|
||||
10.5.jar aspectjweaver-1.9.7.jar springfox-spring-web-2.10.5.jar mybati
|
||||
s-plus-3.5.5.jar jackson-annotations-2.13.5.jar jackson-datatype-jdk8-2
|
||||
.13.5.jar spring-plugin-core-2.0.0.RELEASE.jar spring-boot-devtools-2.7
|
||||
.12.jar mchange-commons-java-0.2.19.jar springfox-spi-2.10.5.jar jackso
|
||||
n-module-parameter-names-2.13.5.jar postgresql-42.3.8.jar spring-boot-s
|
||||
tarter-validation-2.7.12.jar mybatis-plus-extension-3.5.5.jar snakeyaml
|
||||
-1.30.jar classmate-1.5.1.jar spring-boot-autoconfigure-2.7.12.jar spri
|
||||
ng-boot-starter-tomcat-2.7.12.jar jackson-core-2.13.5.jar tomcat-embed-
|
||||
websocket-9.0.75.jar swagger-annotations-1.6.6.jar hibernate-validator-
|
||||
6.2.5.Final.jar jackson-datatype-jsr310-2.13.5.jar jsqlparser-4.6.jar s
|
||||
pringfox-swagger-common-2.10.5.jar springfox-spring-webmvc-2.10.5.jar s
|
||||
pring-webmvc-5.3.27.jar c3p0-0.9.5.5.jar mapstruct-1.3.1.Final.jar jul-
|
||||
to-slf4j-1.7.36.jar spring-core-5.3.27.jar mybatis-plus-annotation-3.5.
|
||||
5.jar fastjson2-2.0.10.jar logback-classic-1.2.12.jar mysql-connector-j
|
||||
ava-8.0.28.jar log4j-api-2.17.2.jar springfox-bean-validators-2.10.5.ja
|
||||
r springfox-schema-2.10.5.jar classgraph-4.1.7.jar checker-qual-3.5.0.j
|
||||
ar spring-aop-5.3.27.jar jackson-databind-2.13.5.jar tomcat-embed-core-
|
||||
9.0.75.jar spring-context-5.3.27.jar spring-boot-starter-2.7.12.jar pro
|
||||
tobuf-java-3.11.4.jar spring-boot-starter-jdbc-2.7.12.jar spring-plugin
|
||||
-metadata-2.0.0.RELEASE.jar slf4j-api-1.7.36.jar tomcat-embed-el-9.0.75
|
||||
.jar spring-boot-starter-json-2.7.12.jar springfox-core-2.10.5.jar byte
|
||||
-buddy-1.12.23.jar mybatis-plus-core-3.5.5.jar mybatis-spring-2.1.2.jar
|
||||
spring-boot-starter-web-2.7.12.jar javassist-3.25.0-GA.jar swagger-mod
|
||||
els-1.6.6.jar knife4j-core-4.1.0.jar jakarta.annotation-api-1.3.5.jar j
|
||||
boss-logging-3.4.3.Final.jar mybatis-plus-boot-starter-3.5.5.jar logbac
|
||||
k-core-1.2.12.jar spring-tx-5.3.27.jar spring-boot-starter-aop-2.7.12.j
|
||||
ar spring-beans-5.3.27.jar HikariCP-4.0.3.jar mybatis-plus-spring-boot-
|
||||
autoconfigure-3.5.5.jar knife4j-openapi2-ui-4.1.0.jar spring-boot-2.7.1
|
||||
2.jar spring-web-5.3.27.jar knife4j-openapi2-spring-boot-starter-4.1.0.
|
||||
jar spring-jdbc-5.3.27.jar spring-jcl-5.3.27.jar lombok-1.18.22.jar myb
|
||||
atis-3.5.15.jar log4j-to-slf4j-2.17.2.jar spring-expression-5.3.27.jar
|
||||
springfox-swagger-ui-2.10.5.jar jakarta.validation-api-2.0.2.jar
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.zbsz.config;
|
||||
|
||||
import com.zbsz.filter.TokenInterceptor;
|
||||
import com.zbsz.repository.UserService;
|
||||
import com.zbsz.repository.UserRepository;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
@ -26,7 +26,7 @@ import javax.annotation.Resource;
|
|||
@EnableSwagger2WebMvc
|
||||
public class Swagger2Config implements WebMvcConfigurer {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
|
@ -46,7 +46,7 @@ public class Swagger2Config implements WebMvcConfigurer {
|
|||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
//添加拦截器
|
||||
registry.addInterceptor(new TokenInterceptor(userService))
|
||||
registry.addInterceptor(new TokenInterceptor(userRepository))
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/doc.html")
|
||||
.excludePathPatterns("/swagger-resources/**")
|
||||
|
|
|
@ -6,10 +6,12 @@ import com.common.entity.dic.AppDic;
|
|||
import com.common.info.CodeMsg;
|
||||
import com.zbsz.entity.Indicator;
|
||||
import com.zbsz.info.Result;
|
||||
import com.zbsz.repository.IndicatorDicService;
|
||||
import com.zbsz.repository.AppDicService;
|
||||
import com.zbsz.repository.IndicatorService;
|
||||
import com.zbsz.repository.SceneService;
|
||||
import com.zbsz.repository.IndicatorDicRepository;
|
||||
import com.zbsz.repository.AppDicRepository;
|
||||
import com.zbsz.repository.IndicatorRepository;
|
||||
import com.zbsz.repository.SceneRepository;
|
||||
import com.zbsz.service.DynamicTableService;
|
||||
import com.zbsz.service.SearchService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
@ -26,13 +28,17 @@ import java.util.List;
|
|||
@Api(tags = "服务接口")
|
||||
public class IndicatorController {
|
||||
@Resource
|
||||
private SceneService sceneService;
|
||||
private SceneRepository sceneRepository;
|
||||
@Resource
|
||||
private IndicatorDicService indicatorDicService;
|
||||
private IndicatorDicRepository indicatorDicRepository;
|
||||
@Resource
|
||||
private AppDicService appDicService;
|
||||
private AppDicRepository appDicRepository;
|
||||
@Resource
|
||||
private IndicatorService indicatorService;
|
||||
private IndicatorRepository indicatorRepository;
|
||||
@Resource
|
||||
private DynamicTableService dynamicTableService;
|
||||
@Resource
|
||||
private SearchService searchService;
|
||||
|
||||
private void setSuccessInfo(Result result){
|
||||
result.setCode(CodeMsg.SUCCESS.getCode());
|
||||
|
@ -76,7 +82,7 @@ public class IndicatorController {
|
|||
public Result getScenes() {
|
||||
Result result = new Result();
|
||||
try {
|
||||
List<Scene> list = sceneService.list();
|
||||
List<Scene> list = sceneRepository.list();
|
||||
setSuccessListInfo(result,list);
|
||||
log.info("-------- 获取关联场景成功 ");
|
||||
}catch (Exception e){
|
||||
|
@ -95,7 +101,7 @@ public class IndicatorController {
|
|||
public Result getIndicatorDic() {
|
||||
Result result = new Result();
|
||||
try {
|
||||
List<IndicatorDic> list = indicatorDicService.list();
|
||||
List<IndicatorDic> list = indicatorDicRepository.list();
|
||||
setSuccessListInfo(result,list);
|
||||
log.info("-------- 获取指标类型成功 ");
|
||||
}catch (Exception e){
|
||||
|
@ -114,7 +120,7 @@ public class IndicatorController {
|
|||
public Result getAppPDic() {
|
||||
Result result = new Result();
|
||||
try {
|
||||
List<AppDic> list = appDicService.lambdaQuery().isNull(AppDic::getParentId).list();
|
||||
List<AppDic> list = appDicRepository.lambdaQuery().isNull(AppDic::getParentId).list();
|
||||
setSuccessListInfo(result,list);
|
||||
log.info("-------- 获取关联应用模块成功 ");
|
||||
}catch (Exception e){
|
||||
|
@ -131,22 +137,61 @@ public class IndicatorController {
|
|||
@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(Long p_id) {
|
||||
public Result getAppCDic(Integer p_id) {
|
||||
Result result = new Result();
|
||||
try {
|
||||
List<AppDic> list = appDicService.lambdaQuery().eq(AppDic::getParentId,p_id).list();
|
||||
List<AppDic> list = appDicRepository.lambdaQuery().eq(AppDic::getParentId,p_id).list();
|
||||
setSuccessListInfo(result,list);
|
||||
log.info("-------- 获取联功能成功 ");
|
||||
}catch (Exception e){
|
||||
log.error("-------- 获取联功能异常 : "+e.getMessage(),e);
|
||||
log.error("-------- 获取联功能异常,p_id : "+p_id,e);
|
||||
setFailureEInfo(result,e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联应用表信息查询
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation(value = "获取关联应用表信息",notes = "获取关联应用表信息")
|
||||
@GetMapping("get_app_tables")
|
||||
public Result getAppTables() {
|
||||
Result result = new Result();
|
||||
try {
|
||||
List<String> list = searchService.getTableNames();
|
||||
setSuccessListInfo(result,list);
|
||||
log.info("-------- 获取关联应用表成功 ");
|
||||
}catch (Exception e){
|
||||
log.error("-------- 获取关联应用表异常 : "+e.getMessage(),e);
|
||||
setFailureEInfo(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<String> list = searchService.getTableColumns(tableName);
|
||||
setSuccessListInfo(result,list);
|
||||
log.info("-------- 获取关联应用表字段成功 ");
|
||||
}catch (Exception e){
|
||||
log.error("-------- 获取关联应用表字段异常 : "+e.getMessage(),e);
|
||||
setFailureEInfo(result,e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean validEnName(Indicator indicator){
|
||||
List<Indicator> list=indicatorService.lambdaQuery()
|
||||
List<Indicator> list= indicatorRepository.lambdaQuery()
|
||||
.eq(Indicator::getSceneId,indicator.getSceneId())
|
||||
.eq(Indicator::getIndicatorDicId,indicator.getIndicatorDicId())
|
||||
.eq(Indicator::getAppDicPId,indicator.getAppDicPId())
|
||||
|
@ -177,7 +222,7 @@ public class IndicatorController {
|
|||
log.info("-------- 指标英文名称可用,name :"+indicator.getIndicatorEnName());
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("-------- 获取联功能异常 : "+e.getMessage(),e);
|
||||
log.error("-------- 获取联功能异常,indicator : "+indicator,e);
|
||||
setFailureEInfo(result,e);
|
||||
}
|
||||
return result;
|
||||
|
@ -185,7 +230,7 @@ public class IndicatorController {
|
|||
|
||||
|
||||
/**
|
||||
* 保存指标
|
||||
* 保存修改指标
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation(value = "保存指标",notes = "保存指标")
|
||||
|
@ -203,22 +248,70 @@ public class IndicatorController {
|
|||
return result;
|
||||
}
|
||||
|
||||
boolean flag = indicatorService.save(indicator);
|
||||
if(flag){
|
||||
boolean save_indicator_flag = indicatorRepository.saveOrUpdate(indicator);
|
||||
boolean save_dynamic_table_flag = true;
|
||||
if(save_indicator_flag){
|
||||
switch (indicator.getAppDicPId()) {
|
||||
case 1:
|
||||
//动态表
|
||||
|
||||
//智能战果分析时,创建动态表
|
||||
case 2:
|
||||
save_dynamic_table_flag = dynamicTableService.createTable(indicator);
|
||||
break;
|
||||
}
|
||||
if(save_dynamic_table_flag){
|
||||
setSuccessFlagInfo(result,true);
|
||||
log.info("-------- 保存指标成功 ");
|
||||
}else {
|
||||
result.setData("动态创建表失败");
|
||||
setFailureInfo(result);
|
||||
log.error("-------- 动态创建表异常,indicator : "+indicator);
|
||||
}
|
||||
|
||||
setSuccessFlagInfo(result,true);
|
||||
log.info("-------- 保存指标成功 ");
|
||||
}else {
|
||||
result.setData("保存指标失败");
|
||||
setFailureInfo(result);
|
||||
log.error("-------- 保存指标异常");
|
||||
log.error("-------- 保存指标异常,indicator : "+indicator);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("-------- 保存指标异常 : "+e.getMessage(),e);
|
||||
log.error("-------- 保存指标异常,indicator : "+indicator,e);
|
||||
setFailureEInfo(result,e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指标
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation(value = "删除指标",notes = "删除指标")
|
||||
@PostMapping("delete_indicator")
|
||||
@Transactional
|
||||
public Result delete_Indicator(@RequestBody Indicator indicator) {
|
||||
Result result = new Result();
|
||||
try {
|
||||
boolean delete_indicator_flag = indicatorRepository.removeById(indicator);
|
||||
boolean delete_dynamic_table_flag = true;
|
||||
if(delete_indicator_flag){
|
||||
switch (indicator.getAppDicPId()) {
|
||||
//智能战果分析时,创建动态表
|
||||
case 2:
|
||||
delete_dynamic_table_flag = dynamicTableService.deleteTable(indicator);
|
||||
break;
|
||||
}
|
||||
if(delete_dynamic_table_flag){
|
||||
setSuccessFlagInfo(result,true);
|
||||
log.info("-------- 删除指标成功 ");
|
||||
}else {
|
||||
result.setData("动态删除表失败");
|
||||
setFailureInfo(result);
|
||||
log.error("-------- 动态删除表异常,indicator : "+indicator);
|
||||
}
|
||||
}else {
|
||||
result.setData("删除指标失败");
|
||||
setFailureInfo(result);
|
||||
log.error("-------- 删除指标异常,indicator : "+indicator);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("-------- 删除指标异常,indicator : "+indicator,e);
|
||||
setFailureEInfo(result,e);
|
||||
}
|
||||
return result;
|
||||
|
@ -227,5 +320,4 @@ public class IndicatorController {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.zbsz.controller;
|
|||
|
||||
import com.common.info.CodeMsg;
|
||||
import com.common.entity.User;
|
||||
import com.zbsz.info.LoginInfo;
|
||||
import com.zbsz.info.Login;
|
||||
import com.zbsz.info.Result;
|
||||
import com.zbsz.repository.UserService;
|
||||
import com.zbsz.repository.UserRepository;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -21,7 +21,7 @@ import javax.annotation.Resource;
|
|||
@Api(tags = "服务接口")
|
||||
public class OpenApiController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private UserRepository userRepository;
|
||||
|
||||
/**
|
||||
* 登录表单需要校验字段是否含有 or 1=1
|
||||
|
@ -30,10 +30,10 @@ public class OpenApiController {
|
|||
*/
|
||||
@ApiOperation(value = "登录",notes = "登录服务")
|
||||
@PostMapping("login")
|
||||
public Result login(@RequestBody LoginInfo info) {
|
||||
public Result login(@RequestBody Login info) {
|
||||
Result result = new Result();
|
||||
try {
|
||||
User user = userService.lambdaQuery().eq(User::getLoginName,info.getUserName()).eq(User::getLoginPassword,info.getPassWord()).one();
|
||||
User user = userRepository.lambdaQuery().eq(User::getLoginName,info.getUserName()).eq(User::getLoginPassword,info.getPassWord()).one();
|
||||
if(user!=null){
|
||||
result.setCode(CodeMsg.SUCCESS.getCode());
|
||||
result.setMsg(CodeMsg.SUCCESS.getMessage());
|
||||
|
|
|
@ -28,6 +28,12 @@ public class Indicator extends Base {
|
|||
@TableField("app_dic_c_id")
|
||||
@ApiModelProperty(value = "关联功能(32)")
|
||||
private Integer appDicCId;
|
||||
@TableField("indicator_table_name")
|
||||
@ApiModelProperty(value = "关联表名称(255)")
|
||||
private String indicatorTableName;
|
||||
@TableField("indicator_column")
|
||||
@ApiModelProperty(value = "关联表字段名称(255)")
|
||||
private String indicatorColumn;
|
||||
@TableField("indicator_code")
|
||||
@ApiModelProperty(value = "代码值(32)")
|
||||
private String indicatorCode;
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
import com.common.entity.User;
|
||||
import com.common.info.CodeMsg;
|
||||
import com.zbsz.info.Result;
|
||||
import com.zbsz.repository.UserService;
|
||||
import com.zbsz.repository.UserRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
@ -16,10 +16,10 @@ import java.io.PrintWriter;
|
|||
@Slf4j
|
||||
public class TokenInterceptor implements HandlerInterceptor {
|
||||
|
||||
private UserService userService;
|
||||
private UserRepository userRepository;
|
||||
|
||||
public TokenInterceptor(UserService userService){
|
||||
this.userService=userService;
|
||||
public TokenInterceptor(UserRepository userRepository){
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||
String userId = request.getHeader("userId");
|
||||
log.info("获取到用户信息 userId : " + userId);
|
||||
if(userId!=null){
|
||||
User user = userService.lambdaQuery().eq(User::getUserId,userId).one();
|
||||
User user = userRepository.lambdaQuery().eq(User::getUserId,userId).one();
|
||||
if(user!=null){
|
||||
return true;
|
||||
}else{
|
||||
|
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
|||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class LoginInfo {
|
||||
public class Login {
|
||||
@NotBlank(message = "用户不能为空")
|
||||
private String userName;//操作人名称
|
||||
@NotBlank(message = "密码不能为空")
|
|
@ -0,0 +1,39 @@
|
|||
package com.zbsz.info;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Search {
|
||||
@ApiModelProperty(value = "字段内容,可以为空")
|
||||
private String columnValue;
|
||||
@ApiModelProperty(value = "当前页码,(小于等于1) = 1, 页码从1开始,2为第2页",required = true)
|
||||
private Integer currentPage;
|
||||
@ApiModelProperty(value = "每页返回行数(每页展示最大多少行)",required = true)
|
||||
private Integer pageSize;
|
||||
@ApiModelProperty(value = "表名称,可以为空")
|
||||
private String tableName;
|
||||
@ApiModelProperty(value = "过滤字段列表,可以为空")
|
||||
private List<String> columnNameList;
|
||||
@ApiModelProperty(value = "合并表名称列表,可以为空")
|
||||
private List<String> leftJoinTableNameList;
|
||||
@ApiModelProperty(value = "时间过滤字段,默认为create_time,不为空的时候覆盖create_time,可以为空")
|
||||
private String timeName;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
|
||||
@ApiModelProperty(value = "开始时间,时间格式为 :yyyy-MM-dd HH:mm:ss,可以为空")
|
||||
private Date startTime;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
|
||||
@ApiModelProperty(value = "结束时间,时间格式为 :yyyy-MM-dd HH:mm:ss,可以为空")
|
||||
private Date endTime;
|
||||
@ApiModelProperty(value = "排序字段,默认为create_time,可以为空")
|
||||
private String orderBy;
|
||||
@ApiModelProperty(value = "排序类型,默认为desc,备注(desc:降序 asc:升序),可以为空")
|
||||
private String descOrAsc;
|
||||
}
|
|
@ -6,5 +6,5 @@ import com.zbsz.mapper.AppDicMapper;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AppDicService extends ServiceImpl<AppDicMapper, AppDic> {
|
||||
public class AppDicRepository extends ServiceImpl<AppDicMapper, AppDic> {
|
||||
}
|
|
@ -6,5 +6,5 @@ import com.zbsz.mapper.IndicatorDicMapper;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class IndicatorDicService extends ServiceImpl<IndicatorDicMapper, IndicatorDic> {
|
||||
public class IndicatorDicRepository extends ServiceImpl<IndicatorDicMapper, IndicatorDic> {
|
||||
}
|
|
@ -6,5 +6,5 @@ import com.zbsz.mapper.IndicatorMapper;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class IndicatorService extends ServiceImpl<IndicatorMapper, Indicator> {
|
||||
public class IndicatorRepository extends ServiceImpl<IndicatorMapper, Indicator> {
|
||||
}
|
|
@ -6,5 +6,5 @@ import com.zbsz.mapper.SceneMapper;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SceneService extends ServiceImpl<SceneMapper, Scene> {
|
||||
public class SceneRepository extends ServiceImpl<SceneMapper, Scene> {
|
||||
}
|
|
@ -6,5 +6,5 @@ import com.zbsz.mapper.UserMapper;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserService extends ServiceImpl<UserMapper, User> {
|
||||
public class UserRepository extends ServiceImpl<UserMapper, User> {
|
||||
}
|
|
@ -1,39 +1,136 @@
|
|||
package com.zbsz.service;
|
||||
|
||||
import com.zbsz.entity.Indicator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DynamicTableService {
|
||||
@Autowired
|
||||
private DataSource dataSource; // 注入DataSource对象
|
||||
@Resource
|
||||
private DataSource dataSource;
|
||||
|
||||
private String getTableName(Indicator indicator){
|
||||
String tablename = "indicator_"+indicator.getSceneId()
|
||||
+"_"+indicator.getIndicatorDicId()
|
||||
+"_"+indicator.getAppDicPId()
|
||||
+"_"+indicator.getAppDicCId()
|
||||
+"_"+indicator.getIndicatorEnName()
|
||||
;
|
||||
return tablename;
|
||||
}
|
||||
|
||||
public void createTable(){
|
||||
public boolean createTable(Indicator indicator) throws Exception{
|
||||
Connection conn = null;
|
||||
Statement stm = null;
|
||||
String tableName = null;
|
||||
try {
|
||||
tableName = getTableName(indicator);
|
||||
conn = dataSource.getConnection();
|
||||
|
||||
|
||||
stm = conn.createStatement();
|
||||
String exists_sql = "select exists (select from information_schema.tables where table_name = '"+tableName+"') as is_exists";
|
||||
String create_sql = "create table "+tableName+" (id int4 generated always as identity primary key,"+indicator.getIndicatorEnName()+" varchar(255) not null)";
|
||||
String alter_sql = "alter table "+tableName+" add column if not exists "+indicator.getIndicatorEnName()+" varchar(255)";
|
||||
log.info("---------- 查询表是否存在 sql:"+exists_sql);
|
||||
ResultSet rs = stm.executeQuery(exists_sql);
|
||||
boolean flag = true;
|
||||
while(rs.next()){
|
||||
flag = rs.getBoolean("is_exists");
|
||||
}
|
||||
int result = 0;
|
||||
if(flag){
|
||||
log.info("---------- 创建表 sql:"+exists_sql);
|
||||
result = stm.executeUpdate(create_sql);
|
||||
}else {
|
||||
log.info("---------- 添加表字段 sql:"+exists_sql);
|
||||
result = stm.executeUpdate(alter_sql);
|
||||
}
|
||||
if(result>0){
|
||||
return true;
|
||||
}else {
|
||||
log.error("创建表,table name : "+tableName+"失败");
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e){
|
||||
|
||||
throw new Exception("创建动态表失败,table name : "+tableName,e);
|
||||
}finally {
|
||||
try {
|
||||
if(conn!=null) conn.close();
|
||||
if(stm != null) stm.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("stm.close() 异常!");
|
||||
}
|
||||
try {
|
||||
if(conn != null) conn.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("conn.close() 异常!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteTable(Indicator indicator) throws Exception{
|
||||
Connection conn = null;
|
||||
Statement stm = null;
|
||||
String tableName = null;
|
||||
try {
|
||||
List<String> columnList = new ArrayList();
|
||||
tableName = getTableName(indicator);
|
||||
conn = dataSource.getConnection();
|
||||
stm = conn.createStatement();
|
||||
String exists_sql = "select exists (select from information_schema.tables where table_name = '"+tableName+"') as is_exists";
|
||||
ResultSet rs = stm.executeQuery(exists_sql);
|
||||
boolean flag = true;
|
||||
while(rs.next()){
|
||||
flag = rs.getBoolean("is_exists");
|
||||
}
|
||||
if(!flag){
|
||||
throw new Exception("删除动态表失败,table name : "+tableName+" 不存在!!!");
|
||||
}
|
||||
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
ResultSet resultSet = metaData.getColumns(null,null,tableName,null);
|
||||
while (resultSet.next()) {
|
||||
columnList.add(resultSet.getString("COLUMN_NAME"));
|
||||
}
|
||||
|
||||
String alter_sql = "alter table "+tableName+" drop column if exists "+indicator.getIndicatorEnName();
|
||||
String drop_sql = "drop table if exists"+tableName;
|
||||
|
||||
int result = 0;
|
||||
if(columnList.size()>1){
|
||||
log.info("---------- 删除表字段 sql:"+alter_sql);
|
||||
result = stm.executeUpdate(alter_sql);
|
||||
}else {
|
||||
log.info("---------- 删除表 sql:"+drop_sql);
|
||||
result = stm.executeUpdate(drop_sql);
|
||||
}
|
||||
|
||||
if(result>0){
|
||||
return true;
|
||||
}else {
|
||||
log.error("删除动态表失败,table name : "+tableName);
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new Exception("删除动态表失败,table name : "+tableName,e);
|
||||
}finally {
|
||||
try {
|
||||
if(stm != null) stm.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("stm.close() 异常!");
|
||||
}
|
||||
try {
|
||||
if(conn != null) conn.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("conn.close() 异常!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package com.zbsz.service;
|
||||
|
||||
import com.zbsz.entity.Indicator;
|
||||
import com.zbsz.info.Search;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SearchService {
|
||||
@Resource
|
||||
private DataSource dataSource;
|
||||
|
||||
public List<String> getTableNames() throws Exception{
|
||||
Connection conn = null;
|
||||
try {
|
||||
List<String> list = new ArrayList();
|
||||
conn = dataSource.getConnection();
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
ResultSet resultSet = metaData.getTables(null, null, null, new String[]{"TABLE"});
|
||||
while (resultSet.next()) {
|
||||
list.add(resultSet.getString("TABLE_NAME"));
|
||||
}
|
||||
return list;
|
||||
}catch (Exception e){
|
||||
throw new Exception("获取数据库列表失败!",e);
|
||||
}finally {
|
||||
try {
|
||||
if(conn != null) conn.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("获取数据库列表失败,conn.close() 异常!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> getTableColumns(String tableName) throws Exception{
|
||||
Connection conn = null;
|
||||
try {
|
||||
List<String> list = new ArrayList();
|
||||
conn = dataSource.getConnection();
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
ResultSet resultSet = metaData.getColumns(null,null,tableName,null);
|
||||
while (resultSet.next()) {
|
||||
//1、COLUMN_NAME:column name and size 2、TYPE_NAME:data type name
|
||||
list.add(resultSet.getString("COLUMN_NAME"));
|
||||
}
|
||||
return list;
|
||||
}catch (Exception e){
|
||||
throw new Exception("获取数据库列表失败!",e);
|
||||
}finally {
|
||||
try {
|
||||
if(conn != null) conn.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("获取数据库列表失败,conn.close() 异常!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List searchIndicator(Search search) throws Exception{
|
||||
Connection conn = null;
|
||||
Statement stm = null;
|
||||
//需要上一层设置
|
||||
String tableName = search.getTableName();
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
stm = conn.createStatement();
|
||||
String left_join_sql = "select * from "+tableName+" left join ";
|
||||
log.info("---------- 左连接合并表 sql:"+left_join_sql);
|
||||
|
||||
}catch (Exception e){
|
||||
throw new Exception("创建动态表失败,table name : "+tableName,e);
|
||||
}finally {
|
||||
try {
|
||||
if(stm != null) stm.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("stm.close() 异常!");
|
||||
}
|
||||
try {
|
||||
if(conn != null) conn.close();
|
||||
}catch (Exception e){
|
||||
throw new Exception("conn.close() 异常!");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -3,7 +3,11 @@ package com.zbsz;
|
|||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.common.entity.dic.IndicatorDic;
|
||||
import com.zbsz.repository.IndicatorDicService;
|
||||
import com.zbsz.entity.Indicator;
|
||||
import com.zbsz.repository.IndicatorDicRepository;
|
||||
import com.zbsz.service.DynamicTableService;
|
||||
import com.zbsz.service.SearchService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
@ -11,13 +15,20 @@ import javax.annotation.Resource;
|
|||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class IndicatorTest {
|
||||
@Resource
|
||||
private IndicatorDicService indicatorDicService;
|
||||
private IndicatorDicRepository indicatorDicRepository;
|
||||
@Resource
|
||||
private SearchService searchService;
|
||||
@Resource
|
||||
private DynamicTableService dynamicTableService;
|
||||
|
||||
|
||||
@Test
|
||||
public void testPage(){
|
||||
Page<IndicatorDic> page = new Page(1, 2);
|
||||
indicatorDicService.page(page);
|
||||
Page<IndicatorDic> page = new Page(9, 2);
|
||||
indicatorDicRepository.page(page);
|
||||
List<IndicatorDic> list = page.getRecords();
|
||||
for (IndicatorDic indicatorDic : list) {
|
||||
System.out.println("|||||||||| : "+ JSON.toJSON(indicatorDic));
|
||||
|
@ -30,4 +41,27 @@ public class IndicatorTest {
|
|||
System.out.println("-------- : "+page.hasNext());
|
||||
System.out.println("-------- : "+page.hasPrevious());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchTable() throws Exception{
|
||||
System.out.println(searchService.getTableNames());
|
||||
System.out.println(searchService.getTableColumns("app_dic"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDynamicTable() {
|
||||
Indicator indicator = new Indicator();
|
||||
indicator.setSceneId(3);
|
||||
indicator.setIndicatorDicId(0);
|
||||
indicator.setAppDicPId(1);
|
||||
indicator.setAppDicCId(0);
|
||||
indicator.setIndicatorEnName("p_user");
|
||||
try {
|
||||
dynamicTableService.createTable(indicator);
|
||||
} catch (Exception e) {
|
||||
log.error("创建动态表异常,",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue