提交 fead13d8 作者: 方治民

feat: 补充用户表字段、新增部门/岗位/视频/定位标签/定位日志/定位信标/围栏数据表

上级 1ea64067
...@@ -30,3 +30,5 @@ ...@@ -30,3 +30,5 @@
- [x] 通用文件上传模块 - [x] 通用文件上传模块
- [ ] 通用字典管理模块 - [ ] 通用字典管理模块
- [ ] XXL-JOB 定时任务模块 - [ ] XXL-JOB 定时任务模块
- [x] @Convert 处理 Raw JSON 数据格式转换
- [ ] 扩展 PostgresDialect 实现时序查询函数
...@@ -8,12 +8,16 @@ bootJar { ...@@ -8,12 +8,16 @@ bootJar {
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
// 💬 Mock/Test Env // 💬 Mock/Test Env
runtimeOnly 'com.h2database:h2' runtimeOnly 'com.h2database:h2'
// 💬 Prod/Dev Env // 💬 Prod/Dev Env
// runtimeOnly 'mysql:mysql-connector-java' // runtimeOnly 'mysql:mysql-connector-java'
runtimeOnly 'org.postgresql:postgresql' runtimeOnly 'org.postgresql:postgresql'
// 本地依赖
implementation fileTree(dir: project.rootDir.getPath() + '\\libs', includes: ['*jar'])
implementation project(":basic-common:core") implementation project(":basic-common:core")
implementation project(":basic-common:util") implementation project(":basic-common:util")
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.config.converter;
import com.alibaba.fastjson.JSONArray;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/**
* JSONArray JPA 类型转换
*
* @author Jim
* @version 0.1
* 2022/4/7 18:03
*/
@Converter
public class JSONArrayConverter implements AttributeConverter<JSONArray, String> {
@Override
public String convertToDatabaseColumn(JSONArray json) {
return json.toJSONString();
}
@Override
public JSONArray convertToEntityAttribute(String s) {
return JSONArray.parseArray(s);
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.config.converter;
import com.alibaba.fastjson.JSONObject;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/**
* JSONObject JPA 类型转换
*
* @author Jim
* @version 0.1
* 2022/4/7 18:03
*/
@Converter
public class JSONObjectConverter implements AttributeConverter<JSONObject, String> {
@Override
public String convertToDatabaseColumn(JSONObject json) {
return json.toJSONString();
}
@Override
public JSONObject convertToEntityAttribute(String s) {
return JSONObject.parseObject(s);
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.config.dialect;
import org.hibernate.spatial.dialect.postgis.PostgisPG10Dialect;
/**
* Postgres 方言
* TODO: 扩展 TimescaleDB 查询函数相关
*
* @author Jim
* @version 0.1
* 2022/4/7 16:11
*/
@SuppressWarnings({ "unused" })
public class PostgresDialect extends PostgisPG10Dialect {
private static final long serialVersionUID = 187383913873678550L;
public PostgresDialect() {
super();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.yiring.common.annotation.FieldMapping;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Point;
/**
* 定位信标
* 引用:
* 1. 查询地图分区(定位系统), https://nl.yz-cloud.com/position/area/list
* 2. 查询信标点(定位系统), https://nl.yz-cloud.com/position/config/point/list
*
* @author Jim
* @version 0.1
* 2022/4/7 11:02
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(
name = "BS_LOCATION_BEACON",
indexes = { @Index(columnList = "linkId"), @Index(columnList = "code", unique = true) }
)
@Comment("定位信标")
public class LocationBeacon implements Serializable {
private static final long serialVersionUID = 5419734189897829250L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 定位信标】
* 作用: 用于双向联动进行数据同步
*/
@FieldMapping("id")
@Comment("外链主键")
Long linkId;
@Comment("地图 ID")
Long areaId;
/**
* 前缀: BTI
* 后缀: 8 位数字
*/
@FieldMapping("deviceId")
@Comment("编号")
@Column(unique = true, nullable = false)
String code;
@Comment("x")
BigDecimal x;
@Comment("y")
BigDecimal y;
@Comment("z")
BigDecimal z;
@Comment("距离(米)")
Double distance;
@Comment("坐标点信息")
Point point;
@FieldMapping
@Comment("电量")
Integer volt;
@FieldMapping
@Comment("电量单位")
String voltUnit;
@FieldMapping(value = "time", desc = "更新时间戳", type = Long.class)
@Comment("更新时间")
LocalDateTime updateTime;
@Comment("创建时间")
LocalDateTime createTime;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LocationBeacon that = (LocationBeacon) o;
return id != null && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.yiring.common.annotation.FieldMapping;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Geometry;
/**
* 围栏
* 引用: 定位平台接口规范V3.0.1 #7.1
*
* @author Jim
* @version 0.1
* 2022/4/7 16:26
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_LOCATION_FENCE", indexes = { @Index(columnList = "linkId"), @Index(columnList = "mode") })
@Comment("围栏")
public class LocationFence implements Serializable {
private static final long serialVersionUID = 4155868702188991300L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 电子围栏】
* 作用: 用于双向联动进行数据同步
*/
@FieldMapping("id")
@Comment("外链主键")
Long linkId;
@Comment("地图 ID")
Long areaId;
@FieldMapping("entityTypes")
@Comment("围栏模型")
@Enumerated(EnumType.STRING)
Mode mode;
@Comment("坐标信息(x,y,r)")
@Column(columnDefinition = "JSON")
String shape;
@Comment("形状信息(circle: 圆形, polygon: 多边形)")
String shapeType;
@Comment("空间信息")
Geometry geometry;
@Comment("半径,米/单位(圆形围栏)")
Double radius;
@Comment("超时时间(秒)")
Integer overtime;
@Comment("消抖时间(秒)")
Integer threshold;
@Comment("创建时间")
LocalDateTime createTime;
@SuppressWarnings({ "unused" })
public enum Mode {
NORMAL("标准"),
DANGER("危险区域");
@Getter
final String text;
Mode(String text) {
this.text = text;
}
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.yiring.auth.domain.user.User;
import com.yiring.common.annotation.FieldMapping;
import java.io.Serializable;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* 围栏规则
* TODO: 规则待梳理
*
* @author Jim
* @version 0.1
* 2022/4/7 18:25
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_LOCATION_FENCE_RULE", indexes = {})
@Comment("围栏规则")
public class LocationFenceRule implements Serializable {
private static final long serialVersionUID = -6683465582430417205L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("围栏")
@ManyToOne
@JoinColumn(name = "fence_id")
LocationFence fence;
@FieldMapping("entityTypes")
@Comment("规则模型")
@Enumerated(EnumType.STRING)
Mode mode;
@Comment("规则名称")
String name;
@Comment("规则描述")
String describe;
@Comment("最小值(人数)")
Integer minValue;
@Comment("最大值(人数)")
Integer maxValue;
@Comment("规则生效开始时间")
LocalTime minTime;
@Comment("规则生效结束时间")
LocalTime maxTime;
@Comment("允许的用户(人员)")
@OneToMany
@Builder.Default
@ToString.Exclude
Set<User> includes = new HashSet<>(0);
@Comment("不允许的用户(人员)")
@OneToMany
@Builder.Default
@ToString.Exclude
Set<User> excludes = new HashSet<>(0);
@SuppressWarnings({ "unused" })
public enum Mode {
STAFF("人员"),
NUMBER("数量");
@Getter
final String text;
Mode(String text) {
this.text = text;
}
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.alibaba.fastjson.JSONObject;
import com.yiring.app.config.converter.JSONObjectConverter;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Point;
/**
* 定位数据
* 引用: 定位平台接口规范V3.0.1 #6
*
* @author Jim
* @version 0.1
* 2022/4/7 10:21
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_LOCATION_LOG", indexes = { @Index(columnList = "time"), @Index(columnList = "silent") })
@Comment("定位数据")
public class LocationLog implements Serializable {
private static final long serialVersionUID = 3467455881020691989L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("标签")
@ManyToOne
LocationTag tag;
@Comment("时间")
@Column(nullable = false)
LocalDateTime time;
@Comment("经度")
BigDecimal lon;
@Comment("纬度")
BigDecimal lat;
@Comment("海拔高度(m)")
BigDecimal altitude;
@Comment("坐标点信息")
Point point;
@Comment("信标集合")
@Builder.Default
@OneToMany
@ToString.Exclude
Set<LocationBeacon> beacons = new HashSet<>(0);
@Comment("围栏集合")
@Builder.Default
@OneToMany
@ToString.Exclude
Set<LocationFence> fences = new HashSet<>(0);
@Comment("静止/运动")
Boolean silent;
@Comment("电量")
Integer volt;
@Comment("电量单位")
String voltUnit;
@Comment("原始数据")
@Convert(converter = JSONObjectConverter.class)
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(columnDefinition = "JSON")
@ToString.Exclude
JSONObject raw;
@Comment("创建时间")
LocalDateTime createTime;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LocationLog locationLog = (LocationLog) o;
return id != null && Objects.equals(id, locationLog.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import com.yiring.auth.domain.user.User;
import com.yiring.common.annotation.FieldMapping;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* 定位标签
* 引用:
* 1. 定位平台接口规范V3.0.1 #4.3
* 2. 真源定位系统后台管理模块
*
* @author Jim
* @version 0.1
* 2022/4/7 11:02
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(
name = "BS_LOCATION_TAG",
indexes = {
@Index(columnList = "linkId"),
@Index(columnList = "type"),
@Index(columnList = "used"),
@Index(columnList = "user_id"),
@Index(columnList = "code", unique = true),
}
)
@Comment("定位标签")
public class LocationTag implements Serializable {
private static final long serialVersionUID = 5419734189897829250L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 定位标签】
* 作用: 用于双向联动进行数据同步
*/
@FieldMapping("id")
@Comment("外链主键")
Long linkId;
@FieldMapping
@Comment("IMEI 设备标识码")
String imei;
/**
* 前缀: BTT
* 后缀: 8 位数字
*/
@FieldMapping("tagId")
@Comment("编号")
@Column(unique = true, nullable = false)
String code;
@FieldMapping("tagCode")
@Comment("型号")
@Enumerated(EnumType.STRING)
Type type;
@FieldMapping
@Comment("静止/运动")
Boolean silent;
@OneToOne
@JoinColumn(name = "user_id")
@Comment("绑定用户")
User user;
@FieldMapping
@Comment("使用/闲置")
Boolean used;
@FieldMapping
@Comment("电量")
Integer volt;
@FieldMapping
@Comment("电量单位")
String voltUnit;
@FieldMapping(value = "raiseTimestamp", desc = "更新时间戳", type = Long.class)
@Comment("更新时间")
LocalDateTime updateTime;
@Comment("创建时间")
LocalDateTime createTime;
@SuppressWarnings({ "unused" })
public enum Type {
BTT01("蓝牙人员定位卡"),
BTT02("蓝牙车辆定位器"),
BTT11("蓝牙人员定位卡(超薄)");
final String text;
Type(String text) {
this.text = text;
}
public String text() {
return this.text;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LocationTag that = (LocationTag) o;
return id != null && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.video;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
import org.locationtech.jts.geom.Point;
/**
* 监控视频
*
* @author Jim
* @version 0.1
* 2022/4/8 10:17
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "BS_VIDEO", indexes = { @Index(columnList = "online"), @Index(columnList = "enable") })
@Comment("监控视频")
public class Video implements Serializable {
private static final long serialVersionUID = -4382898847143469396L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("坐标点信息")
Point point;
@Comment("分类")
String type;
@Comment("标识")
String uuid;
/**
* rtsp 地址
*/
@Comment("rtsp 媒体地址")
String rtsp;
@Comment("m3u8 地址")
String m3u8;
@Comment("是否在线")
Boolean online;
@Comment("是否启用")
Boolean enable;
@Comment("创建时间")
LocalDateTime createTime;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.video;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author Jim
* @version 0.1
* 2022/4/8 10:25
*/
@Repository
public interface VideoRepository extends JpaRepository<Video, Serializable> {}
...@@ -8,7 +8,7 @@ spring: ...@@ -8,7 +8,7 @@ spring:
username: postgres username: postgres
password: 123456 password: 123456
jpa: jpa:
database-platform: org.hibernate.spatial.dialect.postgis.PostgisPG10Dialect database-platform: com.yiring.app.config.dialect.PostgresDialect
open-in-view: true open-in-view: true
hibernate: hibernate:
ddl-auto: update ddl-auto: update
......
...@@ -8,7 +8,7 @@ spring: ...@@ -8,7 +8,7 @@ spring:
name: "kshg-api" name: "kshg-api"
profiles: profiles:
include: auth include: auth
active: dev active: mock
# DEBUG # DEBUG
debug: false debug: false
/* (C) 2022 YiRing, Inc. */
package com.yiring.auth.domain.dept;
import com.yiring.auth.domain.post.Post;
import com.yiring.auth.domain.user.User;
import com.yiring.common.annotation.FieldMapping;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* 部门
*
* @author ifzm
* 2018/9/3 17:08
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Comment("系统部门")
@Table(name = "SYS_DEPARTMENT", indexes = { @Index(columnList = "pid"), @Index(columnList = "tree") })
public class Department implements Serializable {
private static final long serialVersionUID = -5402731145404250150L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
/**
* 数据来源于【真源人员定位系统 - 部门】
* 作用: 用于双向联动进行数据同步
*/
@FieldMapping("id")
@Comment("外链主键")
Long linkId;
@Comment("名称")
String name;
@Comment("描述")
String describe;
@ManyToOne
@JoinColumn(name = "leader_id")
@Comment("负责人")
User leader;
@Comment("序号")
Integer serial;
@Comment("层级")
Integer level;
@Comment("是否启用")
Boolean enable;
@Comment("是否删除")
Boolean deleted;
@Comment("父级ID")
Long pid;
@Comment("树节点标识")
String tree;
@Comment("岗位集合")
@Builder.Default
@ToString.Exclude
@ManyToMany
@JoinTable(
name = "SYS_DEPARTMENT_POSTS",
joinColumns = { @JoinColumn(name = "department_id") },
inverseJoinColumns = { @JoinColumn(name = "post_id") }
)
Set<Post> posts = new HashSet<>(0);
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
Department that = (Department) o;
return id != null && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.auth.domain.dept;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author Jim
* @version 0.1
* 2022/4/8 8:52
*/
@Repository
public interface DepartmentRepository extends JpaRepository<Department, Serializable> {}
...@@ -4,10 +4,12 @@ package com.yiring.auth.domain.permission; ...@@ -4,10 +4,12 @@ package com.yiring.auth.domain.permission;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import javax.persistence.*; import javax.persistence.*;
import lombok.*; import lombok.*;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment; import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId; import org.hibernate.snowflake.SnowflakeId;
...@@ -19,7 +21,9 @@ import org.hibernate.snowflake.SnowflakeId; ...@@ -19,7 +21,9 @@ import org.hibernate.snowflake.SnowflakeId;
* 2018/9/3 17:08 * 2018/9/3 17:08
*/ */
@Data @Getter
@Setter
@ToString
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
...@@ -128,4 +132,17 @@ public class Permission implements Serializable { ...@@ -128,4 +132,17 @@ public class Permission implements Serializable {
return meta; return meta;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
Permission that = (Permission) o;
return id != null && Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
} }
/* (C) 2022 YiRing, Inc. */
package com.yiring.auth.domain.post;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId;
/**
* 岗位
*
* @author ifzm
* 2018/9/3 15:45
*/
@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Comment("系统岗位")
@Table(name = "SYS_POST")
public class Post implements Serializable {
private static final long serialVersionUID = 3744892781714515997L;
@Comment("主键")
@Id
@GeneratedValue(generator = SnowflakeId.GENERATOR)
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id;
@Comment("名称")
String name;
@Comment("描述")
String describe;
@Comment("是否启用")
Boolean enable;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.auth.domain.post;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author Jim
* @version 0.1
* 2022/4/8 8:52
*/
@Repository
public interface PostRepository extends JpaRepository<Post, Serializable> {}
...@@ -6,11 +6,13 @@ import com.yiring.auth.domain.permission.Permission; ...@@ -6,11 +6,13 @@ import com.yiring.auth.domain.permission.Permission;
import com.yiring.auth.domain.user.User; import com.yiring.auth.domain.user.User;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import lombok.*; import lombok.*;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment; import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId; import org.hibernate.snowflake.SnowflakeId;
...@@ -22,7 +24,9 @@ import org.hibernate.snowflake.SnowflakeId; ...@@ -22,7 +24,9 @@ import org.hibernate.snowflake.SnowflakeId;
* 2018/9/3 15:45 * 2018/9/3 15:45
*/ */
@Data @Getter
@Setter
@ToString
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
...@@ -52,6 +56,7 @@ public class Role implements Serializable { ...@@ -52,6 +56,7 @@ public class Role implements Serializable {
@Builder.Default @Builder.Default
@Comment("权限集合") @Comment("权限集合")
@ManyToMany @ManyToMany
@ToString.Exclude
private Set<Permission> permissions = new HashSet<>(); private Set<Permission> permissions = new HashSet<>();
@JsonIgnore @JsonIgnore
...@@ -66,4 +71,17 @@ public class Role implements Serializable { ...@@ -66,4 +71,17 @@ public class Role implements Serializable {
inverseJoinColumns = { @JoinColumn(name = "user_id") } inverseJoinColumns = { @JoinColumn(name = "user_id") }
) )
private Set<User> users = new HashSet<>(); private Set<User> users = new HashSet<>();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
Role role = (Role) o;
return id != null && Objects.equals(id, role.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
} }
...@@ -2,15 +2,20 @@ ...@@ -2,15 +2,20 @@
package com.yiring.auth.domain.user; package com.yiring.auth.domain.user;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yiring.auth.domain.dept.Department;
import com.yiring.auth.domain.post.Post;
import com.yiring.auth.domain.role.Role; import com.yiring.auth.domain.role.Role;
import com.yiring.common.annotation.FieldMapping;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import lombok.*; import lombok.*;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import org.hibernate.Hibernate;
import org.hibernate.annotaions.Comment; import org.hibernate.annotaions.Comment;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.snowflake.SnowflakeId; import org.hibernate.snowflake.SnowflakeId;
...@@ -22,7 +27,9 @@ import org.hibernate.snowflake.SnowflakeId; ...@@ -22,7 +27,9 @@ import org.hibernate.snowflake.SnowflakeId;
* 2018/9/3 15:27 * 2018/9/3 15:27
*/ */
@Data @Getter
@Setter
@ToString
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
...@@ -32,6 +39,7 @@ import org.hibernate.snowflake.SnowflakeId; ...@@ -32,6 +39,7 @@ import org.hibernate.snowflake.SnowflakeId;
@Table( @Table(
name = "SYS_USER", name = "SYS_USER",
indexes = { indexes = {
@Index(columnList = "uuid", unique = true),
@Index(columnList = "mobile", unique = true), @Index(columnList = "mobile", unique = true),
@Index(columnList = "username", unique = true), @Index(columnList = "username", unique = true),
@Index(columnList = "email", unique = true), @Index(columnList = "email", unique = true),
...@@ -50,6 +58,21 @@ public class User implements Serializable { ...@@ -50,6 +58,21 @@ public class User implements Serializable {
@GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG) @GenericGenerator(name = SnowflakeId.GENERATOR, strategy = SnowflakeId.Strategy.LONG)
Long id; Long id;
/**
* 数据来源于【真源人员定位系统 - 定位信标】
* 作用: 用于双向联动进行数据同步
*/
@FieldMapping("id")
@Comment("外链主键")
Long linkId;
@Comment("厂区 ID")
Long orgId;
@Comment("工号(唯一标识)")
@Column(unique = true)
String uuid;
@Comment("真实姓名") @Comment("真实姓名")
String realName; String realName;
...@@ -74,6 +97,17 @@ public class User implements Serializable { ...@@ -74,6 +97,17 @@ public class User implements Serializable {
@Comment("头像") @Comment("头像")
String avatar; String avatar;
@Comment("职称")
String title;
@Comment("岗位")
@ManyToOne
@JoinColumn(name = "post_id")
Post post;
@Comment("性别(1: 男, 2: 女)")
Integer gender;
@Comment("是否启用") @Comment("是否启用")
Boolean enabled; Boolean enabled;
...@@ -89,7 +123,24 @@ public class User implements Serializable { ...@@ -89,7 +123,24 @@ public class User implements Serializable {
joinColumns = { @JoinColumn(name = "user_id") }, joinColumns = { @JoinColumn(name = "user_id") },
inverseJoinColumns = { @JoinColumn(name = "role_id") } inverseJoinColumns = { @JoinColumn(name = "role_id") }
) )
private Set<Role> roles = new HashSet<>(); Set<Role> roles = new HashSet<>();
@Comment("所属部门")
@ManyToOne
@JoinColumn(name = "department_id")
Department department;
@Comment("用户类型")
@Enumerated(EnumType.STRING)
Type type;
@Comment("单位(外部)")
String unit;
@Comment("状态")
@Builder.Default
@Enumerated(EnumType.STRING)
Status status = Status.DEFAULT;
@Comment("最后登录IP地址") @Comment("最后登录IP地址")
String lastLoginIp; String lastLoginIp;
...@@ -97,6 +148,57 @@ public class User implements Serializable { ...@@ -97,6 +148,57 @@ public class User implements Serializable {
@Comment("最后登录时间") @Comment("最后登录时间")
LocalDateTime lastLoginTime; LocalDateTime lastLoginTime;
@Comment("更新时间")
LocalDateTime updateTime;
@Comment("创建时间") @Comment("创建时间")
LocalDateTime createTime; LocalDateTime createTime;
@SuppressWarnings({ "unused" })
public enum Type {
EMPLOYEES("员工"),
GUEST("访客");
final String text;
Type(String text) {
this.text = text;
}
public String text() {
return this.text;
}
}
@SuppressWarnings({ "unused" })
public enum Status {
DEFAULT("默认"),
REST("休息"),
WORK("工作"),
INSPECTION("巡检"),
SPECIAL_JOB("特殊作业");
final String text;
Status(String text) {
this.text = text;
}
public String text() {
return this.text;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
User user = (User) o;
return id != null && Objects.equals(id, user.id);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
} }
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.annotation;
import java.lang.annotation.*;
/**
* 字段映射
* 用于记录并处理数据表字段与外部系统的字段映射关系,便于进行数据同步转换处理
*
* @author Jim
* @version 0.1
* 2022/4/7 15:21
*/
@SuppressWarnings({ "unused" })
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FieldMapping {
/**
* 映射字段
*/
String value() default "";
/**
* 描述信息
*/
String desc() default "";
/**
* 映射类型
*/
Class<?> type() default Object.class;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论