一. 数据库设计
走失人员表和丢失物品表是主要的业务表
对这两个表进行数据添加时,往消息表中增加数据
对这两个表进行数据修改时,同时修改消息表
对这两个表进行删除时,消息表的数据也删除(逻辑删除),签阅表和签阅历史表的数据删除
办结消息后要修改消息表对应数据状态删除签阅表对应的数据
取消办结消息后要修改消息表对应数据状态,从历史签约表中查出该数据并插入到签阅表中
所有未读消息是消息表中有,签阅表中没有的数据
全部标记已读是查出所有未读的消息插入到签阅表中
二. 项目
1. 导入依赖
<dependencyManagement>
<dependencies>
<!-- 导入duceap 2.1 POM定义-->
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--web开发基础包-->
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-boot-starter-web</artifactId>
</dependency>
<!--flyway模块-->
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-boot-starter-flyway</artifactId>
</dependency>
<!--swagger-->
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-boot-starter-swagger</artifactId>
</dependency>
<!--表码模块-->
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-boot-starter-code</artifactId>
</dependency>
<!--上传组件模块-->
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-boot-starter-uploader</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
</dependency>
<dependency>
<groupId>com.dragonsoft</groupId>
<artifactId>duceap-security-dcuc</artifactId>
</dependency>
</dependencies>
<!--指定仓库地址-->
<repositories>
<repository>
<id>duceap-releases</id>
<name>Team Nexus Release Repository</name>
<url>http://192.168.6.13:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
2. 配置文件
application.properties
spring.datasource.url=jdbc:oracle:thin:@20.20.30.112:1521:ORCL
spring.datasource.username=bmxft_tj
spring.datasource.password=dragon
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.max-idle=10
#spring.datasource.max-wait=10000
#spring.datasource.min-idle=5
#spring.datasource.initial-size=5
server.port=8082
server.servlet.context-path=/bmxft
#打印sql日志
spring.jpa.show-sql=true
##配置登陆方式,dids、dssoac、dcuc
#duceap.security.type=dcuc
##dcuc登录配置#
##单点登录服务器地址
##duceap.security.dcuc.casServerUrlPrefix=http://114.112.161.157:8877/dcucserver
#duceap.security.dcuc.casServerUrlPrefix=http://192.168.10.2:8877/dcucserver
##对接系统地址(ip+port即可)
#duceap.security.dcuc.serverName=http://20.20.32.132:1645
##duceap.security.dcuc.serverName=http://192.168.150.113:1645
##无须登录过滤的资源(如js,css等静态资源),多个用“|”隔开
#duceap.security.dcuc.ignorePattern=/js/*|/img/*|/css/*|/dcuclogin/*|/authorizationPage.html|/importAuthorizationFile.html|/license/LicenseManagerServlet|/authorizationFile/|/v2/|/v1/home/|/v1/dict/|/api/file/|/v1/txry/|/ueditor/|/pathImage/
##应用代码
#duceap.security.dcuc.appCode=bmxft
##用户中心服务接口地址
##duceap.security.dcuc.ApiUrl=http://114.112.161.157:8870/dcuc
#duceap.security.dcuc.ApiUrl=http://192.168.10.2:8870/dcuc
#
##设置文件上传大小,springboot默认的最大上传大小是1MB
#spring.servlet.multipart.max-file-size=1024MB
#spring.servlet.multipart.max-request-size=1024MB
##设置服务端存储路径
#duceap.uploader.store.strategy=fileSystem
#duceap.uploader.store.fileSystem.path=file:/D:/upload/
#授权
duceap.license.enabled=false
#flyway
duceap.flyway.enabled=false
#数据表空间
duceap.flyway.placeholders.TABLESPACE_DATA=USERS
##索引表空间
duceap.flyway.placeholders.TABLESPACE_INDEX=USERS
##大字段表空间
duceap.flyway.placeholders.TABLESPACE_LOB=USERS
#
##默认根据驱动名进行自动匹配
flyway.dbtype=oracle
#
##当没有配置flyway脚本扫描器类,默认加载此目录下flyway脚本
duceap.flyway.locations=classpath:/sql/BMXFT
duceap.flyway.placeholderPrefix=#{
duceap.flyway.placeholderSuffix=}
duceap.flyway.outOfOrder=true
duceap.flyway.initOnMigrate=true
duceap.flyway.initVersion=0.5.0
duceap.flyway.ignoreFailedFutureMigration=false
#swagger开关
duceap.swagger.enabled = true
#swagger扫描包路径 默认com.dragonsoft
duceap.swagger.packagePath =com.dragonsoft.bmxft
swagger路径
http://20.20.32.132:8082/bmxft/v2/api-docs
flyway脚本
V1.0.0__InitTable.sql
/*==============================================================*/
/* Table: T_LOST_PEOPLE */
/*==============================================================*/
create table T_LOST_PEOPLE
(
ID varchar2(32) not null,
TITLE varchar2(150) not null,
PEOPLE_TYPE_CODE varchar2(10) not null,
PEOPLE_NAME varchar2(30),
UNKNOWN_NAME varchar2(10) default '0' not null,
SEX_CODE varchar2(10) not null,
ID_CARD varchar2(20),
HEIGHT_CODE varchar2(10),
SHAPE_CODE varchar2(10),
HAIRSTYLE_CODE varchar2(10),
HAIRCOLOR_CODE varchar2(10),
PEOPLE_TYPE varchar2(10),
AGE_CODE varchar2(10),
HEADWEAR VARCHAR2(150),
JACKET VARCHAR2(150),
TROUSERS VARCHAR2(150),
SHOES VARCHAR2(150),
BELONGINGS VARCHAR2(300),
SOMATOTYPE_MARKER VARCHAR2(150),
ACCENT VARCHAR2(90),
FIND_ADDRESS VARCHAR2(210),
OTHER_FEATURES VARCHAR2(900),
PHOTOS VARCHAR2(2000),
PREVIEW_PHOTO VARCHAR2(200),
REPORTER_NAME VARCHAR2(30),
REPORTER_TEL VARCHAR2(30),
REPORTER_ID_CARD VARCHAR2(20),
FIND_TIME DATE,
LOST_STATE varchar2(10) default '0',
FINISH_REMARK VARCHAR2(50),
UNFINISH_TIME DATE,
FUZZY_SEARCH VARCHAR2(3000),
CREATE_TIME DATE default SYSDATE not null,
CREATE_USER VARCHAR2(50),
CREATE_USERNAME VARCHAR2(30),
CREATE_DEPT VARCHAR2(50),
CREATE_DEPTNAME VARCHAR2(150),
CREATER_TEL VARCHAR2(30),
HIDE_CREATER_TEL varchar2(10) default '0' not null,
DELETED varchar2(10) default '0' not null,
DELETE_TIME DATE,
constraint PK_T_LOST_PEOPLE primary key (ID)
);
comment on table T_LOST_PEOPLE is
'走失人员表';
comment on column T_LOST_PEOPLE.ID is
'主键';
comment on column T_LOST_PEOPLE.TITLE is
'标题';
comment on column T_LOST_PEOPLE.PEOPLE_TYPE_CODE is
'人员类型【代码】';
comment on column T_LOST_PEOPLE.PEOPLE_NAME is
'人员姓名,不详直接不设置';
comment on column T_LOST_PEOPLE.UNKNOWN_NAME is
'是否人员姓名不详,1:是,0:否';
comment on column T_LOST_PEOPLE.SEX_CODE is
'性别【代码】';
comment on column T_LOST_PEOPLE.ID_CARD is
'身份证号';
comment on column T_LOST_PEOPLE.HEIGHT_CODE is
'人员身高【代码】';
comment on column T_LOST_PEOPLE.SHAPE_CODE is
'人员体型【代码】';
comment on column T_LOST_PEOPLE.HAIRSTYLE_CODE is
'发型【代码】';
comment on column T_LOST_PEOPLE.HAIRCOLOR_CODE is
'头发颜色【代码】';
comment on column T_LOST_PEOPLE.PEOPLE_TYPE is
'人员类型【代码】';
comment on column T_LOST_PEOPLE.AGE_CODE is
'人员年龄【代码】';
comment on column T_LOST_PEOPLE.HEADWEAR is
'头饰';
comment on column T_LOST_PEOPLE.JACKET is
'上衣';
comment on column T_LOST_PEOPLE.TROUSERS is
'裤子';
comment on column T_LOST_PEOPLE.SHOES is
'鞋子';
comment on column T_LOST_PEOPLE.BELONGINGS is
'随时物品';
comment on column T_LOST_PEOPLE.SOMATOTYPE_MARKER is
'体型标记';
comment on column T_LOST_PEOPLE.ACCENT is
'口音';
comment on column T_LOST_PEOPLE.FIND_ADDRESS is
'发现地点,通常用于尸体类型';
comment on column T_LOST_PEOPLE.OTHER_FEATURES is
'其他特征';
comment on column T_LOST_PEOPLE.PHOTOS is
'相关照片(id/url,多个),JSON格式,字符串数组,例如:["A","B","C"]';
comment on column T_LOST_PEOPLE.PREVIEW_PHOTO is
'预览图';
comment on column T_LOST_PEOPLE.REPORTER_NAME is
'报案人姓名';
comment on column T_LOST_PEOPLE.REPORTER_TEL is
'报案人电话';
comment on column T_LOST_PEOPLE.REPORTER_ID_CARD is
'报案人身份证号';
comment on column T_LOST_PEOPLE.FIND_TIME is
'发现时间';
comment on column T_LOST_PEOPLE.LOST_STATE is
'走失状态,1:办结,0:办理中';
comment on column T_LOST_PEOPLE.FINISH_REMARK is
'办结备注';
comment on column T_LOST_PEOPLE.UNFINISH_TIME is
'取消办结时间';
comment on column T_LOST_PEOPLE.FUZZY_SEARCH is
'模糊搜索信息';
comment on column T_LOST_PEOPLE.CREATE_TIME is
'创建时间';
comment on column T_LOST_PEOPLE.CREATE_USER is
'创建用户ID';
comment on column T_LOST_PEOPLE.CREATE_USERNAME is
'创建用户名';
comment on column T_LOST_PEOPLE.CREATE_DEPT is
'创建部门ID';
comment on column T_LOST_PEOPLE.CREATE_DEPTNAME is
'创建部门名称';
comment on column T_LOST_PEOPLE.CREATER_TEL is
'创建人手机号';
comment on column T_LOST_PEOPLE.HIDE_CREATER_TEL is
'是否隐藏创建人联系电话,1:隐藏,0:显示';
comment on column T_LOST_PEOPLE.DELETED is
'逻辑删除标记,1:删除,0:未删除';
comment on column T_LOST_PEOPLE.DELETE_TIME is
'删除时间';
/*==============================================================*/
/* Index: IDX_PEOPLE_STATE__CREATE_TIME */
/*==============================================================*/
create index IDX_PEOPLE_STATE__CREATE_TIME on T_LOST_PEOPLE (
LOST_STATE ASC,
CREATE_TIME ASC
);
/*==============================================================*/
/* Table: T_LOST_THINGS */
/*==============================================================*/
create table T_LOST_THINGS
(
ID varchar2(32) not null,
TITLE varchar2(150) not null,
THINGS_TYPE_CODE varchar2(10) not null,
OTHER_THINGS_TYPE varchar2(10) default '0',
OTHER_THINGS_TYPE_NAME VARCHAR2(90),
BRAND varchar2(100),
UNKNOWN_BRAND varchar2(10) default '0' not null,
MODEL VARCHAR2(100),
UNKNOWN_MODEL varchar2(10) default '0',
COLOR VARCHAR2(50),
SOURCE VARCHAR2(300),
OTHER_FEATURES VARCHAR2(900),
PHOTOS VARCHAR2(2000),
PREVIEW_PHOTO VARCHAR2(200),
REPORTER_NAME VARCHAR2(30),
REPORTER_TEL VARCHAR2(30),
REPORTER_ID_CARD VARCHAR2(20),
FIND_TIME DATE,
LOST_STATE varchar2(10) default '0',
FINISH_REMARK VARCHAR2(50),
UNFINISH_TIME DATE,
FUZZY_SEARCH VARCHAR2(3000),
CREATE_TIME DATE default SYSDATE not null,
CREATE_USER VARCHAR2(50),
CREATE_USERNAME VARCHAR2(30),
CREATE_DEPT VARCHAR2(50),
CREATE_DEPTNAME VARCHAR2(150),
CREATER_TEL VARCHAR2(30),
HIDE_CREATER_TEL varchar2(10) default '0' not null,
DELETED varchar2(10) default '0' not null,
DELETE_TIME DATE,
constraint PK_T_LOST_THINGS primary key (ID)
);
comment on table T_LOST_THINGS is
'丢失物品表';
comment on column T_LOST_THINGS.ID is
'主键';
comment on column T_LOST_THINGS.TITLE is
'标题';
comment on column T_LOST_THINGS.THINGS_TYPE_CODE is
'物品类型【代码】';
comment on column T_LOST_THINGS.OTHER_THINGS_TYPE is
'是其他物品类型,1:是,0:否(默认)';
comment on column T_LOST_THINGS.OTHER_THINGS_TYPE_NAME is
'其他物品类型名称';
comment on column T_LOST_THINGS.BRAND is
'品牌';
comment on column T_LOST_THINGS.UNKNOWN_BRAND is
'品牌是否不详,1:是,0:否';
comment on column T_LOST_THINGS.MODEL is
'型号';
comment on column T_LOST_THINGS.UNKNOWN_MODEL is
'型号是否不详,1:是,0:否';
comment on column T_LOST_THINGS.COLOR is
'颜色';
comment on column T_LOST_THINGS.SOURCE is
'物品来源';
comment on column T_LOST_THINGS.OTHER_FEATURES is
'其他特征';
comment on column T_LOST_THINGS.PHOTOS is
'相关照片(id/url,多个),JSON格式,字符串数组,例如:["A","B","C"]';
comment on column T_LOST_THINGS.PREVIEW_PHOTO is
'预览图';
comment on column T_LOST_THINGS.REPORTER_NAME is
'报案人姓名';
comment on column T_LOST_THINGS.REPORTER_TEL is
'报案人电话';
comment on column T_LOST_THINGS.REPORTER_ID_CARD is
'报案人身份证号';
comment on column T_LOST_THINGS.FIND_TIME is
'发现丢失时间';
comment on column T_LOST_THINGS.LOST_STATE is
'寻找状态,1:办结,0:办理中';
comment on column T_LOST_THINGS.FINISH_REMARK is
'办结备注';
comment on column T_LOST_THINGS.UNFINISH_TIME is
'取消办结时间';
comment on column T_LOST_THINGS.FUZZY_SEARCH is
'模糊搜索信息';
comment on column T_LOST_THINGS.CREATE_TIME is
'创建时间';
comment on column T_LOST_THINGS.CREATE_USER is
'创建用户ID';
comment on column T_LOST_THINGS.CREATE_USERNAME is
'创建用户名';
comment on column T_LOST_THINGS.CREATE_DEPT is
'创建部门ID';
comment on column T_LOST_THINGS.CREATE_DEPTNAME is
'创建部门名称';
comment on column T_LOST_THINGS.CREATER_TEL is
'创建人手机号';
comment on column T_LOST_THINGS.HIDE_CREATER_TEL is
'是否隐藏创建人联系电话,1:隐藏,0:显示';
comment on column T_LOST_THINGS.DELETED is
'逻辑删除标记,1:删除,0:未删除';
comment on column T_LOST_THINGS.DELETE_TIME is
'删除时间';
/*==============================================================*/
/* Index: IDX_THINGS_STATE */
/*==============================================================*/
create index IDX_THINGS_STATE on T_LOST_THINGS (
LOST_STATE ASC
);
/*==============================================================*/
/* Table: T_MESSAGE */
/*==============================================================*/
create table T_MESSAGE
(
ID VARCHAR2(32) not null,
MESSAGE_TYPE VARCHAR2(32) not null,
DATA_ID VARCHAR2(32),
MESSAGE_TITLE VARCHAR2(210) not null,
CREATE_TIME DATE not null,
LOST_TIME DATE,
LOST_STATE VARCHAR2(32) default '0' not null,
CREATE_USER_ID VARCHAR2(50) not null,
DELETED VARCHAR2(2) default '0',
constraint PK_T_MESSAGE primary key (ID)
);
comment on table T_MESSAGE is
'消息表,这个表保存所有数据,并且必须根据办结状态进行筛选';
comment on column T_MESSAGE.ID is
'主键';
comment on column T_MESSAGE.MESSAGE_TYPE is
'消息类型,1:人员消息,2:物品消息';
comment on column T_MESSAGE.DATA_ID is
'物品/人员表数据ID';
comment on column T_MESSAGE.MESSAGE_TITLE is
'消息标题';
comment on column T_MESSAGE.CREATE_TIME is
'创建时间/发布时间';
comment on column T_MESSAGE.LOST_TIME is
'丢失时间';
comment on column T_MESSAGE.LOST_STATE is
'办结状态,1:已办结(无须再查询),0:未办结(默认)';
comment on column T_MESSAGE.CREATE_USER_ID is
'创建用户ID';
comment on column T_MESSAGE.DELETED is
'逻辑删除标识,1:删除,0:未删除';
/*==============================================================*/
/* Index: IDX_ST__MSG_TYPE__DATA_ID */
/*==============================================================*/
create index IDX_ST__MSG_TYPE__DATA_ID on T_MESSAGE (
LOST_STATE ASC,
MESSAGE_TYPE ASC,
DATA_ID ASC
);
/*==============================================================*/
/* Table: T_MESSAGE_READ */
/*==============================================================*/
create table T_MESSAGE_READ
(
USER_ID VARCHAR2(50) not null,
MESSAGE_ID VARCHAR2(32) not null,
READ_TIME DATE default SYSDATE,
constraint PK_T_MESSAGE_READ primary key (MESSAGE_ID, USER_ID)
);
comment on table T_MESSAGE_READ is
'未办结消息签阅表,这个表的数据只保留待办结的消息签约状态';
comment on column T_MESSAGE_READ.USER_ID is
'阅读用户ID';
comment on column T_MESSAGE_READ.MESSAGE_ID is
'消息ID';
comment on column T_MESSAGE_READ.READ_TIME is
'阅读时间';
/*==============================================================*/
/* Index: IDX_MSG_TYPE2 */
/*==============================================================*/
create index IDX_MSG_TYPE2 on T_MESSAGE_READ (
MESSAGE_ID ASC
);
/*==============================================================*/
/* Table: T_MESSAGE_READ_HISTORY */
/*==============================================================*/
create table T_MESSAGE_READ_HISTORY
(
USER_ID VARCHAR2(50) T_MESSAGE not null,
MESSAGE_ID VARCHAR2(32) not null,
READ_TIME DATE default SYSDATE,
constraint PK_T_MESSAGE_READ_HISTORY primary key (MESSAGE_ID, USER_ID)
);
comment on table T_MESSAGE_READ_HISTORY is
'消息签阅历史表,这个表的数据永久存储';
comment on column T_MESSAGE_READ_HISTORY.USER_ID is
'阅读用户ID';
comment on column T_MESSAGE_READ_HISTORY.MESSAGE_ID is
'消息ID';
comment on column T_MESSAGE_READ_HISTORY.READ_TIME is
'阅读时间';
/*==============================================================*/
/* Index: IDX_MSG_TYPE3 */
/*==============================================================*/
create index IDX_MSG_TYPE3 on T_MESSAGE_READ_HISTORY (
MESSAGE_ID ASC
);
V1.0.1__CodeData.sql
INSERT INTO "DM_SYS_CODE" VALUES ('1', '走失人口消息', 'DM_PEOPLE_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '迷途人员消息', 'DM_PEOPLE_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('3', '无名尸体消息', 'DM_PEOPLE_TYPE_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_PEOPLE_TYPE_CODE', NULL, '消息类型', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL, 'CODE_ID=''DM_PEOPLE_TYPE_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('1', '160cm以下', 'DM_HEIGHT_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('2', '161-170cm', 'DM_HEIGHT_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('3', '171-175cm', 'DM_HEIGHT_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('4', '175-180cm', 'DM_HEIGHT_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('5', '181cm以上', 'DM_HEIGHT_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_HEIGHT_CODE', NULL, '身高', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_HEIGHT_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('1', '中等',
'DM_SHAPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '微瘦',
'DM_SHAPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('3', '瘦',
'DM_SHAPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('4', '微胖',
'DM_SHAPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('5', '胖',
'DM_SHAPE_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_SHAPE_CODE', NULL, '人员体型', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_SHAPE_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('1', '光头',
'DM_HAIRSTYLE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '短发',
'DM_HAIRSTYLE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('3', '中长发',
'DM_HAIRSTYLE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('4', '长发',
'DM_HAIRSTYLE_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_HAIRSTYLE_CODE', NULL, '人员发型', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_HAIRSTYLE_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('1', '黑色',
'DM_HAIRCOLOR_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '白色',
'DM_HAIRCOLOR_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('3', '灰白色',
'DM_HAIRCOLOR_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('4', '棕色',
'DM_HAIRCOLOR_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('5', '其他',
'DM_HAIRCOLOR_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_HAIRCOLOR_CODE', NULL, '人员头发颜色', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_HAIRCOLOR_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('1', '精神病',
'DM_PEOPLE_TYPE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '老年人',
'DM_PEOPLE_TYPE');
INSERT INTO "DM_SYS_CODE" VALUES ('3', '儿童',
'DM_PEOPLE_TYPE');
INSERT INTO "DM_SYS_CODE" VALUES ('4', '无行为能力',
'DM_PEOPLE_TYPE');
INSERT INTO "DM_SYS_CODE" VALUES ('5', '其他',
'DM_PEOPLE_TYPE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_PEOPLE_TYPE', NULL, '人员类型', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_PEOPLE_TYPE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('1', '10岁以下', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('2', '11-20岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('3', '21-30岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('4', '31-40岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('5', '41-50岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('6', '51-60岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('7', '61-70岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('8', '71-80岁', 'DM_AGE_CODE');
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('9', '80岁以上', 'DM_AGE_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_AGE_CODE', NULL, '人员年龄', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_AGE_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('1', '寻找中',
'DM_LOST_STATE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '已办结',
'DM_LOST_STATE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_LOST_STATE', NULL, '消息状态', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_LOST_STATE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('1', '手机',
'DM_THINGS_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('2', '钱包',
'DM_THINGS_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('3', '背包',
'DM_THINGS_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('4', '挎包',
'DM_THINGS_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('5', '行李箱',
'DM_THINGS_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('6', '文件',
'DM_THINGS_TYPE_CODE');
INSERT INTO "DM_SYS_CODE" VALUES ('7', '其他(填写)',
'DM_THINGS_TYPE_CODE');
INSERT INTO "T_MD_SYS_CODE_DIC" VALUES ('DM_THINGS_TYPE_CODE', NULL, '物品类型', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL,
'CODE_ID=''DM_THINGS_TYPE_CODE''', '1', NULL);
INSERT INTO "DM_SYS_CODE" VALUES ('3', '未知',
'DM_SEX');
INSERT INTO "T_MD_SYS_CODE_DIC" ("CODE_ID", "DATASOURCE_ID", "NAME", "ENTITY_NAME", "CODE_FIELD", "NAME_FIELD", "PY_FIELD", "WB_FIELD", "ORDER_FIELD", "SEGMENT_RULE", "VIEW_SQL", "LOAD_TYPE", "PARENT_CODE_FIELD") VALUES ('T_ORG_INFO', NULL, '机构信息', 'T_ORG_INFO', 'CODE', 'FULL_NAME', NULL, NULL, NULL, NULL, NULL, '1', NULL);
INSERT INTO "T_MD_SYS_CODE_DIC" ("CODE_ID", "DATASOURCE_ID", "NAME", "ENTITY_NAME", "CODE_FIELD", "NAME_FIELD", "PY_FIELD", "WB_FIELD", "ORDER_FIELD", "SEGMENT_RULE", "VIEW_SQL", "LOAD_TYPE", "PARENT_CODE_FIELD") VALUES ('WebsiteVisiteUrl', NULL, '请求服务器地址', 'DM_SYS_CODE', 'CODE', 'VALUE', NULL, NULL, NULL, NULL, 'CODE_ID=''WebsiteVisiteUrl''', '1', NULL);
INSERT INTO "DM_SYS_CODE" ("CODE", "VALUE", "CODE_ID") VALUES ('http://20.20.32.130:8082/bmxft', '图片地址path', 'WebsiteVisiteUrl');
3. 自动生成实体类
生成后直接复制进项目
全局搜索字段在实体类的get方法中进行拼接用来进行模糊查询
private static String nvl(String str){
return str == null ? "" : str ;
}
@Column(name=FUZZY_SEARCH, nullable=true, length=3000)
public String getFuzzySearch() {
return nvl(this.getPeopleName()) +
nvl(this.getTitle()) +
nvl(this.getIdCard()) +
nvl(this.getHeadwear()) +
nvl(this.getJacket()) +
nvl(this.getTrousers()) +
nvl(this.getShoes())+
nvl(this.getBelongings())+
nvl(this.getSomatotypeMarker())+
nvl(this.getAccent())+
nvl(this.getFindAddress())+
nvl(this.getOtherFeatures())+
nvl(this.getReporterIdCard())+
nvl(this.getReporterName())+
nvl(this.getReporterTel())+
nvl(this.getCreateDeptname())+
nvl(this.getCreateUsername())+
nvl(this.getCreaterTel());
}
4. 走失人员业务
4.1 LostPeopleController
人员走失的相关接口
- 查询所有走失人员数据
- 发布/编辑人员走失消息
- 全局搜索人员信息
- swagger注释的使用
@RestController
@Api(value = "人员走失相关接口")
@RequestMapping(value = "/v1/lostpeople")
public class LostPeopleController extends BaseRestController<LostPeople, String> {
private ILostPeopleService lostPeopleService;
public LostPeopleController(ILostPeopleService lostPeopleService){
super(lostPeopleService);
this.lostPeopleService = lostPeopleService;
}
/**
* 查询所有走失人员数据
* @param
* @return
*/
@ApiOperation(value = "查询所有的走失人员数据")
@PostMapping(value = "/findList")
public Page<LostPeople> findList(Searchable searchCondition) {
Page<LostPeople> page = lostPeopleService.findList(searchCondition);
return page;
}
/**
* 发布/编辑人员走失消息
* @param lostPeople
* @return
*/
@ApiOperation(value = "发布/编辑人员走失消息")
@PostMapping(value = "/releaseOrEditPeopleMessage")
public ResponseResult releaseOrEditPeopleMessage(@RequestBody LostPeople lostPeople){
LostPeople people = lostPeopleService.releaseOrEditPeopleMessage(lostPeople);
return ResponseResult.newInstance(people);
}
/**
* 全局搜索人物信息
* @param searchable
* @return
*/
@ApiOperation(value = "全局搜索人物信息")
@PostMapping(value = "/globalSearchPeople")
public Page<LostPeople> globalSearch(Searchable searchable){
Page<LostPeople> page = lostPeopleService.globalSearch(searchable);
return page;
}
}
4.2 LostPeopleService
注意点
-
查询列表时对时间条件进行处理,默认查询近一个月的数据
if(!StringUtils.isEmpty(condition)){//时间条件处理 String str = condition.getValue().toString(); JSONArray jsonArray = JSONArray.parseArray(str); searchable.removeSearchFilter("createTime", SearchOperator.eq); try { searchable.addSearchFilter("createTime", SearchOperator.ge, (DateUtils.getDate(String.valueOf(jsonArray.get(0)), DateConst.HYPHEN_DISPLAY_DATE.getLabel()))); searchable.addSearchFilter("createTime", SearchOperator.le, (DateUtils.getDate(String.valueOf(jsonArray.get(1)), DateConst.HYPHEN_DISPLAY_DATE.getLabel()))); }catch (ParseException e){ e.printStackTrace(); } }else { //默认查近一个月的数据 searchable.removeSearchFilter("createTime", SearchOperator.eq); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1); searchable.addSearchFilter("createTime", SearchOperator.ge, cal.getTime()); searchable.addSearchFilter("createTime", SearchOperator.le, DateUtils.getDate()); searchable.addSort(Sort.Direction.DESC, "createTime"); }
-
消息类型是多选框,自己需要进行判断用or拼接条件
if(!StringUtils.isEmpty(peopleTypeCode)){ String value = (String)peopleTypeCode.getValue(); List<String> codes = Arrays.asList(value.split(",")); searchable.removeSearchFilter("peopleTypeCode", SearchOperator.eq); if(codes.size() == 1) { searchable.addSearchFilter( SearchFilterHelper.or( SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(0)))); }else if(codes.size() == 2) { searchable.addSearchFilter( SearchFilterHelper.or( SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(0)), SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(1)))); }else if(codes.size() == 3){ searchable.addSearchFilter( SearchFilterHelper.or( SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(0)), SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(1)), SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(2)))); } }
发布/编辑操作根据有无ID进行判断操作类型,发布/编辑人员表的同时添加/修改消息表对应的数据
@Service
@Transactional
public class LostPeopleService extends BaseService<LostPeople, String> implements ILostPeopleService {
private LostPeopleRepository lostPeopleRepository;
@Autowired
private MessageRepository messageRepository;
public LostPeopleService(LostPeopleRepository lostPeopleRepository){
super(lostPeopleRepository);
this.lostPeopleRepository=lostPeopleRepository;
}
@Override
public Page<LostPeople> findList(Searchable searchable) {
LostThingsService.searchInfo(searchable);
Page<LostPeople> paging = lostPeopleRepository.paging(searchable);
return paging;
}
/**
* 人员表+数据,消息表+数据
* @param lostPeople
*/
@Override
public LostPeople releaseOrEditPeopleMessage(LostPeople lostPeople) {
String id = lostPeople.getId();
if(StringUtils.isEmpty(id)) {
/**
* 发布操作
*/
lostPeople.setId(UUID.randomUUID().toString().replaceAll("-",""));
SecurityUser securityUser = SessionUtils.getUserInfo();
if(securityUser != null) {
Object dw = securityUser.getExtendtions().get("orgName");
Object dwId = securityUser.getExtendtions().get("orgCode");
lostPeople.setCreateDeptname(dw!=null ? String.valueOf(dw) : "便民寻访调查局");//创建单位
lostPeople.setCreateDept(dwId!=null ? String.valueOf(dwId) : "");//單位ID
lostPeople.setCreateUser(SessionUtils.getUserInfo().getId());
}else {
lostPeople.setCreateDept("dept0000000000");
lostPeople.setCreateDeptname("便民寻访调查局");
lostPeople.setCreateUser("user0000000000");
}
lostPeople.setCreateTime(new Date());
lostPeople.setDeleted("0");
lostPeople.setFuzzySearch(lostPeople.getFuzzySearch());
lostPeople.setLostState(LostPeopleEnum.XZZ.getCode());//寻找中
LostPeople lp = lostPeopleRepository.save(lostPeople);
//往消息表中插入
Message message = new Message();
message.setCreateTime(new Date());
message.setId(UUID.randomUUID().toString().replaceAll("-",""));
message.setMessageType(MessageEnum.RYXX.getCode());
message.setDataId(lp.getId());
message.setMessageTitle(lp.getCreateDeptname()+"发布"+lp.getTitle());
message.setLostTime(lp.getFindTime());
message.setLostState(lp.getLostState());
message.setCreateUserId(lp.getCreateUser());
message.setDeleted("0");
messageRepository.save(message);
return lp;
}else {
/**
* 编辑操作
*/
LostPeople one = this.findOne(id);
lostPeople.setCreateUser(one.getCreateUser());
lostPeople.setCreateTime(one.getCreateTime());
lostPeople.setCreateDept(one.getCreateDept());
LostPeople update = lostPeopleRepository.update(lostPeople);
//消息表也要修改
Message message = messageRepository.findByDataId(id);
message.setLostTime(update.getFindTime());
message.setMessageType(update.getPeopleTypeCode());
message.setCreateTime(update.getCreateTime());
message.setCreateUserId(update.getCreateUser());
message.setLostState(update.getLostState());
message.setMessageTitle(update.getCreateDeptname() + "发布" + update.getTitle());
messageRepository.update(message);
return update;
}
}
@Override
public Page<LostPeople> globalSearch(Searchable searchable) {
searchable.addSort(Sort.Direction.DESC,"createTime");
Page<LostPeople> paging = this.paging(searchable);
return paging;
}
4.3 LostPeopleEnum
public enum LostPeopleEnum {
URL("URL", "/api/file/view/"),
XZZ("1","寻找中"),
YBJ("2","已办结");
private final String code;
private final String desc;
private LostPeopleEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public String getCode() {
return this.code;
}
public String getDesc() {
return this.desc;
}
}
5. 丢失物品业务
5.1 LostThingsController
相关接口
- 查询所有物品丢失数据
- 发布/编辑物品丢失消息
- 全局搜索物品信息
@RestController
@RequestMapping(value = "/v1/lostthings")
public class LostThingsController extends BaseRestController<LostThings, String> {
private ILostThingsService lostThingsService;
public LostThingsController(ILostThingsService lostThingsService){
super(lostThingsService);
this.lostThingsService = lostThingsService;
}
/**
* 查询所有物品丢失数据
* @param
* @return
*/
@ApiOperation(value = "查询所有的物品丢失数据")
@PostMapping(value = "/findList")
public Page<LostThings> findList(Searchable searchCondition) {
Page<LostThings> page = lostThingsService.findList(searchCondition);
return page;
}
/**
* 发布/编辑物品丢失消息
* @param lostThings
* @return
*/
@ApiOperation(value = "发布/编辑物品丢失消息")
@PostMapping(value = "/releaseOrEditPeopleMessage")
public ResponseResult releaseOrEditThingsMessage(@RequestBody LostThings lostThings){
LostThings things = lostThingsService.releaseOrEditThingsMessage(lostThings);
return ResponseResult.newInstance(things);
}
/**
* 全局搜索物品信息
* @param searchable
* @return
*/
@ApiOperation(value = "全局搜索物品信息")
@PostMapping(value = "/globalSearchThings")
public Page<LostThings> globalSearchThings(Searchable searchable){
Page<LostThings> page = lostThingsService.globalSearchThings(searchable);
return page;
}
}
5.2 LostThingsService
@Service
@Transactional
public class LostThingsService extends BaseService<LostThings, String> implements ILostThingsService {
private LostThingsRepository lostThingsRepository;
@Autowired
private MessageRepository messageRepository;
public LostThingsService(LostThingsRepository lostThingsRepository){
super(lostThingsRepository);
this.lostThingsRepository=lostThingsRepository;
}
@Override
public Page<LostThings> findList(Searchable searchable) {
searchInfo(searchable);
Page<LostThings> paging = this.paging(searchable);
return paging;
}
@Override
public LostThings releaseOrEditThingsMessage(LostThings lostThings) {
String id = lostThings.getId();
if(StringUtils.isEmpty(id)){
/**
* 发布操作
*/
lostThings.setId(UUID.randomUUID().toString().replaceAll("-",""));
SecurityUser securityUser = SessionUtils.getUserInfo();
if(securityUser != null) {
Object dw = securityUser.getExtendtions().get("orgName");
Object dwId = securityUser.getExtendtions().get("orgCode");
lostThings.setCreateDeptname(dw!=null ? String.valueOf(dw) : "便民寻访调查局");//创建单位
lostThings.setCreateDept(dwId!=null ? String.valueOf(dwId) : "");//單位ID
lostThings.setCreateUser(SessionUtils.getUserInfo().getId());
}else {
lostThings.setCreateDept("dept0000000000");
lostThings.setCreateDeptname("便民寻访调查局");
lostThings.setCreateUser("user0000000000");
}
lostThings.setCreateTime(new Date());
lostThings.setDeleted("0");
lostThings.setFuzzySearch(lostThings.getFuzzySearch());
lostThings.setLostState(LostThingsEnum.XZZ.getCode());//寻找中
LostThings newLostThings = lostThingsRepository.save(lostThings);
//消息表中同时增加数据
Message message = new Message();
message.setId(UUID.randomUUID().toString().replaceAll("-",""));
message.setCreateTime(new Date());
message.setMessageType(MessageEnum.WPXX.getCode());
message.setDataId(newLostThings.getId());
message.setMessageTitle(newLostThings.getCreateDeptname()+"发布"+newLostThings.getTitle());
message.setLostTime(newLostThings.getFindTime());
message.setLostState(newLostThings.getLostState());
message.setCreateUserId(newLostThings.getCreateUser());
message.setDeleted("0");
messageRepository.save(message);
return newLostThings;
}else {
/**
* 编辑操作
*/
LostThings one = this.findOne(id);
lostThings.setCreateUser(one.getCreateUser());
lostThings.setCreateTime(one.getCreateTime());
lostThings.setCreateDept(one.getCreateDept());
lostThings.setDeleted("0");
LostThings updateThings = lostThingsRepository.update(lostThings);
//修改消息表
Message message = messageRepository.findByDataId(id);
message.setLostTime(updateThings.getFindTime());
message.setMessageType(updateThings.getThingsTypeCode());
message.setCreateTime(updateThings.getCreateTime());
message.setCreateUserId(updateThings.getCreateUser());
message.setLostState(updateThings.getLostState());
message.setMessageTitle(updateThings.getCreateDeptname() + "发布" + updateThings.getTitle());
messageRepository.update(message);
return updateThings;
}
}
@Override
public Page<LostThings> globalSearchThings(Searchable searchable) {
searchable.addSort(Sort.Direction.DESC,"createTime");
Page<LostThings> paging = this.paging(searchable);
return paging;
}
public static void searchInfo(Searchable searchable) {
searchable.addSearchFilter("deleted", SearchOperator.eq,"0");
Condition condition = searchable.getSearchFilter("createTime", SearchOperator.eq);
Condition peopleTypeCode = searchable.getSearchFilter("peopleTypeCode", SearchOperator.eq);
if(!StringUtils.isEmpty(peopleTypeCode)){
String value = (String)peopleTypeCode.getValue();
List<String> codes = Arrays.asList(value.split(","));
searchable.removeSearchFilter("peopleTypeCode", SearchOperator.eq);
if(codes.size() == 1) {
searchable.addSearchFilter(
SearchFilterHelper.or(
SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(0))));
}else if(codes.size() == 2) {
searchable.addSearchFilter(
SearchFilterHelper.or(
SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(0)),
SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(1))));
}else if(codes.size() == 3){
searchable.addSearchFilter(
SearchFilterHelper.or(
SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(0)),
SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(1)),
SearchFilterHelper.newCondition("peopleTypeCode", SearchOperator.eq, codes.get(2))));
}
}
if(!StringUtils.isEmpty(condition)){//时间条件处理
String str = condition.getValue().toString();
JSONArray jsonArray = JSONArray.parseArray(str);
searchable.removeSearchFilter("createTime", SearchOperator.eq);
try {
searchable.addSearchFilter("createTime", SearchOperator.ge, (DateUtils.getDate(String.valueOf(jsonArray.get(0)), DateConst.HYPHEN_DISPLAY_DATE.getLabel())));
searchable.addSearchFilter("createTime", SearchOperator.le, (DateUtils.getDate(String.valueOf(jsonArray.get(1)), DateConst.HYPHEN_DISPLAY_DATE.getLabel())));
}catch (ParseException e){
e.printStackTrace();
}
}else {
//默认查近一个月的数据
searchable.removeSearchFilter("createTime", SearchOperator.eq);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
searchable.addSearchFilter("createTime", SearchOperator.ge, cal.getTime());
searchable.addSearchFilter("createTime", SearchOperator.le, DateUtils.getDate());
searchable.addSort(Sort.Direction.DESC, "createTime");
}
}
}
6. 消息业务
6.1 MessageController
消息相关接口
- 查询所有消息列表
- 查询未读数
- 全部标记已读
- 消息详情
- 删除信息
- 办结消息操作
- 取消办结消息操作
- 将图片与业务表关联
@RestController
@RequestMapping(value = "/v1/message")
public class MessageController extends BaseRestController<Message, String> {
private IMessageService messageService;
public MessageController(IMessageService messageService){
super(messageService);
this.messageService = messageService;
}
/**
* 查询所有消息列表
* @param
* @return
*/
@ApiOperation(value = "查询所有消息列表")
@PostMapping(value = "/findList")
public ResponseResult findList(Searchable searchable) {
Page<Message> messageVoList = messageService.findList(searchable);
return ResponseResult.newInstance(messageVoList);
}
/**
* 查询未读数
* @return
*/
@ApiOperation(value = "查询未读数")
@PostMapping(value = "/unReadCount")
public ResponseResult unReadCount(){
Integer count = messageService.findUnReadCount();
return ResponseResult.newInstance(count);
}
/**
* 全部标记已读
*/
@ApiOperation(value = "全部标记已读")
@PostMapping(value = "/allRead")
public ResponseResult allRead(){
messageService.allRead();
return ResponseResult.newInstance("全部已读");
}
/**
* 消息详情
* @return
*/
@ApiOperation(value = "消息详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "messageId", value = "所选消息ID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "messageType", value = "所选消息类型:1人员消息|2物品消息", dataType = "String", required = true)
})
@PostMapping(value = "/messageInfo")
public ResponseResult messageInfo(String messageId,String messageType){
if(MessageEnum.RYXX.getCode().equals(messageType)){//人员信息
LostPeople lostPeople = messageService.findPeopleInfoByMessageId(messageId);
return ResponseResult.newInstance(lostPeople);
}
LostThings lostThings = messageService.findThingsInfoByMessageId(messageId);
return ResponseResult.newInstance(lostThings);
}
/**
* 删除信息
* @param lostId
* @param messageType
* @return
*/
@ApiOperation(value = "删除信息")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "lostId", value = "所选数据ID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "messageType", value = "所选消息类型:1人员消息|2物品消息", dataType = "String", required = true)
})
@DeleteMapping(value = "/deleteMessage")
public ResponseResult deleteMessage(String lostId,String messageType){
messageService.deleteMessage(lostId,messageType);
return ResponseResult.newInstance("删除成功");
}
/**
* 办结消息
* @param lostId
* @param messageType
* @return
*/
@ApiOperation(value = "办结消息操作")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "lostId", value = "所选数据ID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "messageType", value = "所选消息类型:1人员消息|2物品消息", dataType = "String", required = true)
})
@PostMapping(value = "/finishMessage")
public ResponseResult finishMessage(String lostId,String messageType){
messageService.finishMessage(lostId,messageType);
return ResponseResult.newInstance("办结成功");
}
@ApiOperation(value = "取消办结消息操作")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "lostId", value = "所选数据ID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "messageType", value = "所选消息类型:1人员消息|2物品消息", dataType = "String", required = true)
})
@PostMapping(value = "/cancelFinishMessage")
public ResponseResult cancelFinishMessage(String lostId,String messageType){
messageService.cancelFinishMessage(lostId,messageType);
return ResponseResult.newInstance("取消办结成功");
}
@ApiOperation(value = "将图片与业务表关联")
@PostMapping(value = "/relatedBusiness")
public ResponseResult relatedBusiness(@RequestBody RequestFileVo requestFileVo){
messageService.updateImage(requestFileVo.getBusId(),requestFileVo.getImageIds(),requestFileVo.getType());
return ResponseResult.newInstance("操作成功");
}
}
6.2 MessageService
查询消息列表
消息列表从消息表中查询创建者不是自己并且状态是未办结的消息按照创建时间倒序排
查询未读数
消息表和签阅表联查 查消息表中有签阅表中没有并且消息表中创建人不是自己的数据
全部已读
查询所有没读的消息ID和查未读数类似,通过消息ID往签阅表和历史签阅表填数据
删除消息
根据消息类型判断是人员表还是物品表来进行逻辑删除,同时逻辑删除消息表的数据,删除签阅表和历史签阅表的数据
办结消息
修改人员或物品的状态为已办结,同时也修改消息表的状态已办结,删除签阅表中的数据
取消办结
修改人员或物品的状态为寻找中,同时也修改消息表的状态寻找中,从历史签阅表中查出数据存入签阅表中
查看消息详情
如果消息的创建人不是当前登录用户,状态不是已办结,签阅表中没有当前登录用户查看这个消息的记录,那么往签阅表和历史签阅表中添加数据
将图片与业务表关联
从码表中查出配置的服务器路径,删除该业务与附件的关联,用“,”分割图片ID进行业务和图片的关联操作,拼接字符串:服务器地址+api+文件ID,存入业务表的图片字段中进行修改
@Service
@Transactional
public class MessageService extends BaseService<Message, String> implements IMessageService {
private MessageRepository messageRepository;
@Autowired
private ILostPeopleService lostPeopleService;
@Autowired
private ILostThingsService lostThingsService;
public MessageService(MessageRepository messageRepository){
super(messageRepository);
this.messageRepository=messageRepository;
}
@Override
public Page<Message> findList(Searchable searchable) {
SecurityUser securityUser = SessionUtils.getUserInfo();
String userId = "user0000000000";
if(securityUser != null) {
userId = SessionUtils.getUserInfo().getId();
}
searchable.addSearchFilter("deleted", SearchOperator.eq,"0");
searchable.addSearchFilter("createUserId", SearchOperator.ne,userId);
searchable.addSearchFilter("lostState",SearchOperator.eq,Integer.parseInt(LostPeopleEnum.XZZ.getCode()));
searchable.addSort(Sort.Direction.DESC,"createTime");
Page<Message> paging = this.paging(searchable);
return paging;
}
/**
* 查询消息签阅表和消息表,签阅表中没有,消息表中有的数据
* @return
*/
@Override
public Integer findUnReadCount() {
SecurityUser securityUser = SessionUtils.getUserInfo();
String userId = "user0000000000";
if(securityUser != null) {
userId = SessionUtils.getUserInfo().getId();
}
String sql = "SELECT " +
"COUNT (1) " +
"FROM " +
"T_MESSAGE tm " +
"LEFT JOIN T_MESSAGE_READ tmr ON TM. ID = TMR.MESSAGE_ID " +
"WHERE " +
"TMR.MESSAGE_ID IS NULL and tm.CREATE_USER_ID != ?";
Integer count = PersistentFactory.getJdbcDao().queryForInt(sql,new Object[]{userId});
return count;
}
@Override
public void allRead() {
SecurityUser securityUser = SessionUtils.getUserInfo();
String userId = "user0000000000";
if(securityUser != null) {
userId = SessionUtils.getUserInfo().getId();
}
String sql = "SELECT " +
"tm.id " +
"FROM " +
"T_MESSAGE tm " +
"LEFT JOIN T_MESSAGE_READ tmr ON TM. ID = TMR.MESSAGE_ID " +
"WHERE " +
"TMR.MESSAGE_ID IS NULL and tm.CREATE_USER_ID != ?";
List<Map<String, Object>> ids = PersistentFactory.getJdbcDao().queryForList(sql, new Object[]{userId});
for(Map<String,Object> id : ids){//消息ID
InsertReadAndHistory((String)id.get("ID"));
}
}
@Override
public LostPeople findPeopleInfoById(String lostId) {
isRead(lostId);
return lostPeopleService.findOne(lostId);
}
@Override
public LostThings findThingsInfoById(String lostId) {
isRead(lostId);
return lostThingsService.findOne(lostId);
}
private void isRead(String lostId) {
SecurityUser securityUser = SessionUtils.getUserInfo();
String userId = "user0000000000";
if (securityUser != null) {
userId = SessionUtils.getUserInfo().getId();
}
Message message = messageRepository.findByDataId(lostId);
//如果消息是自己发布的不往签阅表里加数据
if(!userId.equals(message.getCreateUserId())) {
//如果消息状态是寻找中
if (LostPeopleEnum.XZZ.getCode().equals(message.getLostState())) {
String findMessageRead = "SELECT * from T_MESSAGE_READ where USER_ID = '" + userId + "' and MESSAGE_ID = '" + message.getId() + "'";
List<Map<String, Object>> maps = PersistentFactory.getJdbcDao().queryForList(findMessageRead);
//如果签约表中没有数据
if (CollectionUtils.isEmpty(maps)) {
InsertReadAndHistory(message.getId());
}
}
}
}
/**
* 根据消息ID往签约表及历史签约表中加数据
* @param messageId
* @return
*/
private void InsertReadAndHistory(String messageId) {
SecurityUser securityUser = SessionUtils.getUserInfo();
String userId = "user0000000000";
if(securityUser != null) {
userId = SessionUtils.getUserInfo().getId();
}
String insertMessageRead = "insert into T_MESSAGE_READ (USER_ID,MESSAGE_ID,READ_TIME) values ('" + userId + "','" + messageId + "',sysdate)";
String insertMessageHistory = "insert into T_MESSAGE_READ_HISTORY (USER_ID,MESSAGE_ID,READ_TIME) values ('" + userId + "','" + messageId + "',sysdate)";
PersistentFactory.getJdbcDao().execute(insertMessageRead);
PersistentFactory.getJdbcDao().execute(insertMessageHistory);
}
/**
* 删除消息 逻辑删除物品人员表,逻辑删除消息表 ,删除签阅表和签阅历史表
* @param id
* @param messageType
*/
@Override
public void deleteMessage(String id, String messageType) {
if(MessageEnum.RYXX.getCode().equals(messageType)){//人员信息
//逻辑删除
LostPeople one = lostPeopleService.findOne(id);
one.setDeleted("1");
one.setDeleteTime(new Date());
lostPeopleService.update(one);
}else if(MessageEnum.WPXX.getCode().equals(messageType)){//物品信息
LostThings one = lostThingsService.findOne(id);
one.setDeleted("1");
one.setDeleteTime(new Date());
lostThingsService.update(one);
}
//逻辑删除消息表的信息
Message message = messageRepository.findByDataId(id);
message.setDeleted("1");
messageRepository.update(message);
//删除签阅表和签阅历史表的数据
messageRepository.delReadHistoryByMessageId(message.getId());
messageRepository.delReadByMessageId(message.getId());
}
/**
* 办结消息 修改人员|物品状态为已办结 修改消息表办结状态
* @param lostId
* @param messageType
*/
@Override
public void finishMessage(String lostId, String messageType) {
if(MessageEnum.RYXX.getCode().equals(messageType)){//人员
LostPeople lostPeople = lostPeopleService.findOne(lostId);
lostPeople.setLostState(LostPeopleEnum.YBJ.getCode());
//修改人员表状态已办结
lostPeopleService.update(lostPeople);
}else if(MessageEnum.WPXX.getCode().equals(messageType)){//物品
LostThings lostThings = lostThingsService.findOne(lostId);
lostThings.setLostState(LostPeopleEnum.YBJ.getCode());
lostThingsService.update(lostThings);
}
//修改消息表办结状态,删除签阅表数据
Message message = messageRepository.findByDataId(lostId);
updateMessageStateAndDeleteReadInfo(message);
}
/**
* 进行办结操作后
* 根据消息ID修改办结状态为以办结,删除签阅表数据
* @param message 消息ID
*/
private void updateMessageStateAndDeleteReadInfo(Message message) {
message.setLostState(LostPeopleEnum.YBJ.getCode());
messageRepository.update(message);
String deleteReadById = "delete from T_MESSAGE_READ where MESSAGE_ID = '" + message.getId() + "'";
PersistentFactory.getJdbcDao().execute(deleteReadById);
}
/**
* 取消办结 修改人员|物品表的状态为寻找中,
* @param lostId
* @param messageType
*/
@Override
public void cancelFinishMessage(String lostId, String messageType) {
if(MessageEnum.RYXX.getCode().equals(messageType)) {//人员
LostPeople lostPeople = lostPeopleService.findOne(lostId);
lostPeople.setLostState(LostPeopleEnum.XZZ.getCode());
//修改人员表状态寻找中
lostPeopleService.update(lostPeople);
}else if(MessageEnum.WPXX.getCode().equals(messageType)) {//物品
LostThings lostThings = lostThingsService.findOne(lostId);
lostThings.setLostState(LostPeopleEnum.XZZ.getCode());
lostThingsService.update(lostThings);
}
//修改消息表状态寻找中
Message message = messageRepository.findByDataId(lostId);
updateMessageStateAndInsertRead(message);
}
@Override
public void updateImage(String busId, String imageIds, String type) {
List<CodeRecord> list = CodeInfoUtils.getCodeListByCodeDicId(SysEnum.QQSH.getCode());
//先删除改业务与附件的关联,用于编辑操作
messageRepository.updateDelFile(busId);
if(!StringUtils.isEmpty(imageIds)){
List<String> strings = Arrays.asList(imageIds.split(","));
for(String imageId : strings){
messageRepository.updateFile(busId,imageId,type);
}
List<UploaderFile> fileList = messageRepository.findFileByBusinessId(busId);
String apis = "";
for(UploaderFile file : fileList){
apis += list.get(0).getValue()+LostPeopleEnum.URL.getDesc()+file.getId()+",";
}
String substring = apis.substring(0, apis.length() - 1);
if(MessageEnum.RYTP.getCode().equals(type)){//图片类型为人员图片
LostPeople one = lostPeopleService.findOne(busId);
one.setPhotos(substring);
lostPeopleService.update(one);
}else if(MessageEnum.WPTP.getCode().equals(type)){
LostThings one = lostThingsService.findOne(busId);
one.setPhotos(substring);
lostThingsService.update(one);
}
}
}
/**
* 进行取消办结操作后
* 把消息表的状态改变并且通过消息ID从历史签阅表中查出数据存入签阅表中
* @param message
*/
private void updateMessageStateAndInsertRead(Message message) {
message.setLostState(LostPeopleEnum.XZZ.getCode());
messageRepository.update(message);
//从历史签阅表中查出数据存入签阅表里
String insertReadByHistoryData = "INSERT INTO T_MESSAGE_READ " +
"SELECT * FROM T_MESSAGE_READ_HISTORY " +
"WHERE MESSAGE_ID = '" + message.getId() + "'";
PersistentFactory.getJdbcDao().execute(insertReadByHistoryData);
}
}
6.3 MessageRepository
- 通过业务ID查询消息对象
- 删除业务与附件的关联
- 将业务与附件关联
- 通过消息ID删除消息表数据
- 通过消息ID删除签约表数据
- 根据业务类型获取业务附件
public interface MessageRepository extends BaseRepository<Message, String> {
Message findByDataId(String id);
/**
* 删除业务与附件的关联
* @param
*/
@Modifying
@NativeQuery("UPDATE T_UPLOADER_FILE SET BUSINESS_ID = '', BUSINESS_TYPE = '' WHERE BUSINESS_ID = :busId")
void updateDelFile(@Param("busId") String busId);
/**
* 将业务与附件做关联
* @param
*/
@Modifying
@NativeQuery("UPDATE T_UPLOADER_FILE SET BUSINESS_ID = :busId, BUSINESS_TYPE = :type WHERE ID = :imageId")
void updateFile(@Param("busId") String busId,@Param("imageId") String imageId,@Param("type") String type);
/**
* 通过消息ID删除消息表数据
* @param id
*/
@Modifying
@NativeQuery("delete from T_MESSAGE_READ_HISTORY where MESSAGE_ID = :id")
void delReadHistoryByMessageId(@Param("id") String id);
/**
* 通过消息ID删除签约表的数据
* @param id
*/
@Modifying
@NativeQuery("delete from T_MESSAGE_READ where MESSAGE_ID = :id")
void delReadByMessageId(@Param("id") String id);
/**
* 根据业务类型获取业务附件
* @return
*/
@NativeQuery(value = "SELECT * from T_UPLOADER_FILE WHERE BUSINESS_ID =:busId ORDER by GENERATE_TIME ASC")
List<UploaderFile> findFileByBusinessId(@Param("busId") String busId);
}
6.4 RequestFileVo
public class RequestFileVo {
private String busId;
private String type;
private String imageIds;
public String getBusId() {
return busId;
}
public void setBusId(String busId) {
this.busId = busId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getImageIds() {
return imageIds;
}
public void setImageIds(String imageIds) {
this.imageIds = imageIds;
}
}
7. 系统通用
7.1 DictController
查询码表数据的接口
@RestController
@RequestMapping(value = "/v1/dict")
public class DictController extends BaseRestController<Object,String> {
/**
* 查询字典项
* @param
* @return
*/
@PostMapping(value = "/findDictList")
public ResponseResult findDictList(@RequestParam(value="codeDicId") String codeDicId) {
List<CodeRecord> list = CodeInfoUtils.getCodeListByCodeDicId(codeDicId);
return ResponseResult.newInstance(list);
}
}
7.2 SysEnum
public enum SysEnum {
QQSH("WebsiteVisiteUrl", "请求方式"),
;
private final String code;
private final String desc;
private SysEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public String getCode() {
return this.code;
}
public String getDesc() {
return this.desc;
}
}