main主干首次提交,包含用户认证模块
This commit is contained in:
40
src/main/resources/application.yml
Normal file
40
src/main/resources/application.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
server:
|
||||
port: 18082
|
||||
servlet:
|
||||
context-path: /label
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: lablesys-backend
|
||||
datasource:
|
||||
url: ${DB_URL:jdbc:postgresql://39.107.112.174:5432/lablesystem}
|
||||
username: ${DB_USERNAME:postgres}
|
||||
password: ${DB_PASSWORD:postgres!Pw}
|
||||
driver-class-name: org.postgresql.Driver
|
||||
data:
|
||||
redis:
|
||||
host: ${REDIS_HOST:39.107.227.165}
|
||||
port: ${REDIS_PORT:6379}
|
||||
password: ${REDIS_PASSWORD:jsti@2024}
|
||||
timeout: 5s
|
||||
sql:
|
||||
init:
|
||||
mode: never
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:mapper/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html
|
||||
|
||||
labelsys:
|
||||
session:
|
||||
ttl: PT2H
|
||||
store-type: redis
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.labelsys.backend: DEBUG
|
||||
35
src/main/resources/logback.xml
Normal file
35
src/main/resources/logback.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds">
|
||||
|
||||
<property name="LOG_PATH" value="${LOG_PATH:-logs}"/>
|
||||
<property name="APP_NAME" value="label-backend"/>
|
||||
<property name="LOG_PATTERN"
|
||||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出(Docker 日志采集依赖 stdout) -->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder charset="UTF-8">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 滚动文件:60 MB / 个,按日分组,保留 30 天,总上限 3 GB -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_PATH}/${APP_NAME}.log</file>
|
||||
<encoder charset="UTF-8">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/${APP_NAME}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>60MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
<totalSizeCap>3GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
40
src/main/resources/mapper/BizDataRecordMapper.xml
Normal file
40
src/main/resources/mapper/BizDataRecordMapper.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.labelsys.backend.mapper.BizDataRecordMapper">
|
||||
<resultMap id="BizDataRecordResultMap" type="com.labelsys.backend.entity.BizDataRecord">
|
||||
<id column="id" property="id"/>
|
||||
<result column="company_id" property="companyId"/>
|
||||
<result column="creator_id" property="creatorId"/>
|
||||
<result column="creator_role" property="creatorRole"/>
|
||||
<result column="record_name" property="recordName"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="RecordColumns">
|
||||
id, company_id, creator_id, creator_role, record_name, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
<select id="listVisibleByEmployee" resultMap="BizDataRecordResultMap">
|
||||
select <include refid="RecordColumns"/>
|
||||
from biz_data_record
|
||||
where company_id = #{companyId}
|
||||
and creator_id = #{creatorId}
|
||||
order by id
|
||||
</select>
|
||||
|
||||
<select id="listVisibleByManager" resultMap="BizDataRecordResultMap">
|
||||
select <include refid="RecordColumns"/>
|
||||
from biz_data_record
|
||||
where company_id = #{companyId}
|
||||
and creator_role in ('EMPLOYEE', 'MANAGER')
|
||||
order by id
|
||||
</select>
|
||||
|
||||
<select id="listVisibleByEngineer" resultMap="BizDataRecordResultMap">
|
||||
select <include refid="RecordColumns"/>
|
||||
from biz_data_record
|
||||
where company_id = #{companyId}
|
||||
order by id
|
||||
</select>
|
||||
</mapper>
|
||||
59
src/main/resources/mapper/SysCompanyMapper.xml
Normal file
59
src/main/resources/mapper/SysCompanyMapper.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.labelsys.backend.mapper.SysCompanyMapper">
|
||||
<resultMap id="SysCompanyResultMap" type="com.labelsys.backend.entity.SysCompany">
|
||||
<id column="id" property="id"/>
|
||||
<result column="company_code" property="companyCode"/>
|
||||
<result column="company_name" property="companyName"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="CompanyColumns">
|
||||
id, company_code, company_name, status, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="com.labelsys.backend.entity.SysCompany">
|
||||
insert into sys_company (id, company_code, company_name, status, created_at, updated_at)
|
||||
values (#{id}, #{companyCode}, #{companyName}, #{status}, current_timestamp, current_timestamp)
|
||||
</insert>
|
||||
|
||||
<select id="findById" resultMap="SysCompanyResultMap">
|
||||
select <include refid="CompanyColumns"/>
|
||||
from sys_company
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findByCompanyCode" resultMap="SysCompanyResultMap">
|
||||
select <include refid="CompanyColumns"/>
|
||||
from sys_company
|
||||
where company_code = #{companyCode}
|
||||
</select>
|
||||
|
||||
<select id="findEnabledCompaniesByPhone" resultMap="SysCompanyResultMap">
|
||||
select distinct c.id, c.company_code, c.company_name, c.status, c.created_at, c.updated_at
|
||||
from sys_company c
|
||||
inner join sys_user u on u.company_id = c.id
|
||||
where u.phone = #{phone}
|
||||
and u.status = 'ENABLED'
|
||||
and c.status = 'ENABLED'
|
||||
order by c.id
|
||||
</select>
|
||||
|
||||
<select id="listAll" resultMap="SysCompanyResultMap">
|
||||
select <include refid="CompanyColumns"/>
|
||||
from sys_company
|
||||
order by id
|
||||
</select>
|
||||
|
||||
<update id="updateStatus">
|
||||
update sys_company
|
||||
set status = #{status}, updated_at = current_timestamp
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteAll">
|
||||
delete from sys_company
|
||||
</delete>
|
||||
</mapper>
|
||||
29
src/main/resources/mapper/SysMenuMapper.xml
Normal file
29
src/main/resources/mapper/SysMenuMapper.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.labelsys.backend.mapper.SysMenuMapper">
|
||||
<resultMap id="SysMenuResultMap" type="com.labelsys.backend.entity.SysMenu">
|
||||
<id column="id" property="id"/>
|
||||
<result column="company_id" property="companyId"/>
|
||||
<result column="permission_code" property="permissionCode"/>
|
||||
<result column="menu_code" property="menuCode"/>
|
||||
<result column="menu_name" property="menuName"/>
|
||||
<result column="path" property="path"/>
|
||||
<result column="sort_order" property="sortOrder"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="listCurrentMenus" resultMap="SysMenuResultMap">
|
||||
select distinct m.id, m.company_id, m.permission_code, m.menu_code, m.menu_name, m.path, m.sort_order, m.created_at, m.updated_at
|
||||
from sys_menu m
|
||||
inner join sys_position_permission pp
|
||||
on pp.company_id = m.company_id
|
||||
and pp.permission_code = m.permission_code
|
||||
where m.company_id = #{companyId}
|
||||
and pp.position_code in
|
||||
<foreach collection="positionCodes" item="positionCode" open="(" separator="," close=")">
|
||||
#{positionCode}
|
||||
</foreach>
|
||||
order by m.sort_order, m.id
|
||||
</select>
|
||||
</mapper>
|
||||
94
src/main/resources/mapper/SysUserMapper.xml
Normal file
94
src/main/resources/mapper/SysUserMapper.xml
Normal file
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.labelsys.backend.mapper.SysUserMapper">
|
||||
<resultMap id="SysUserResultMap" type="com.labelsys.backend.entity.SysUser">
|
||||
<id column="id" property="id"/>
|
||||
<result column="company_id" property="companyId"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="role" property="role"/>
|
||||
<result column="position" property="position"/>
|
||||
<result column="real_name" property="realName"/>
|
||||
<result column="password_hash" property="passwordHash"/>
|
||||
<result column="must_change_password" property="mustChangePassword"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="session_version" property="sessionVersion"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="UserColumns">
|
||||
id, company_id, phone, username, role, position, real_name, password_hash, must_change_password,
|
||||
status, session_version, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="com.labelsys.backend.entity.SysUser">
|
||||
insert into sys_user (
|
||||
id, company_id, phone, username, role, position, real_name, password_hash, must_change_password,
|
||||
status, session_version, created_at, updated_at
|
||||
)
|
||||
values (
|
||||
#{id}, #{companyId}, #{phone}, #{username}, #{role}, #{position}, #{realName}, #{passwordHash}, #{mustChangePassword},
|
||||
#{status}, #{sessionVersion}, current_timestamp, current_timestamp
|
||||
)
|
||||
</insert>
|
||||
|
||||
<select id="findById" resultMap="SysUserResultMap">
|
||||
select <include refid="UserColumns"/> from sys_user where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndCompanyId" resultMap="SysUserResultMap">
|
||||
select <include refid="UserColumns"/> from sys_user where id = #{id} and company_id = #{companyId}
|
||||
</select>
|
||||
|
||||
<select id="findByCompanyIdAndPhone" resultMap="SysUserResultMap">
|
||||
select <include refid="UserColumns"/> from sys_user where company_id = #{companyId} and phone = #{phone}
|
||||
</select>
|
||||
|
||||
<select id="listByCompanyId" resultMap="SysUserResultMap">
|
||||
select <include refid="UserColumns"/> from sys_user where company_id = #{companyId} order by id
|
||||
</select>
|
||||
|
||||
<select id="listCompanyAdmins" resultMap="SysUserResultMap">
|
||||
select <include refid="UserColumns"/>
|
||||
from sys_user
|
||||
where company_id = #{companyId} and position = 'ADMIN'
|
||||
order by id
|
||||
</select>
|
||||
|
||||
<update id="updatePassword">
|
||||
update sys_user
|
||||
set password_hash = #{passwordHash},
|
||||
must_change_password = #{mustChangePassword},
|
||||
updated_at = current_timestamp
|
||||
where id = #{id} and company_id = #{companyId}
|
||||
</update>
|
||||
|
||||
<update id="updateAssignment">
|
||||
update sys_user
|
||||
set role = #{role},
|
||||
position = #{position},
|
||||
session_version = session_version + 1,
|
||||
updated_at = current_timestamp
|
||||
where id = #{id} and company_id = #{companyId}
|
||||
</update>
|
||||
|
||||
<update id="updateStatus">
|
||||
update sys_user
|
||||
set status = #{status},
|
||||
session_version = session_version + 1,
|
||||
updated_at = current_timestamp
|
||||
where id = #{id} and company_id = #{companyId}
|
||||
</update>
|
||||
|
||||
<update id="bumpSessionVersion">
|
||||
update sys_user
|
||||
set session_version = session_version + 1,
|
||||
updated_at = current_timestamp
|
||||
where id = #{id} and company_id = #{companyId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteAll">
|
||||
delete from sys_user
|
||||
</delete>
|
||||
</mapper>
|
||||
23
src/main/resources/sql/data.sql
Normal file
23
src/main/resources/sql/data.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
insert into sys_company (id, company_code, company_name, status) values
|
||||
(1, 'PLATFORM', '平台公司', 'ENABLED'),
|
||||
(2, 'ALPHA', '甲公司', 'ENABLED')
|
||||
on conflict do nothing;
|
||||
|
||||
insert into sys_user (id, company_id, phone, username, role, position, real_name, password_hash, must_change_password, status, session_version) values
|
||||
(1, 1, '13900000000', 'platform-admin', 'ENGINEER', 'ADMIN', '平台管理员', '$2a$10$TGPk5rNNhKNJQvTWImw5J.LVzw9HDFWR6hyNJCkLDcp0GU8/vp0aS', false, 'ENABLED', 1),
|
||||
(2, 2, '13800138000', 'alpha-admin', 'EMPLOYEE', 'ADMIN', '甲公司管理员', '$2a$10$/hSD8ch7A9lFWi/DOb8yJOHdlrhV57p95CBv9Uv93Yky7t6c4Rs/S', true, 'ENABLED', 1),
|
||||
(3, 2, '13700000000', 'alpha-annotator', 'EMPLOYEE', 'ANNOTATOR', '甲公司标注员', '$2a$10$bRMZPcIaiB1BUx6HPw6FSODPSuph8kUi8/JZOM6lACwjjhkbBL5mq', false, 'ENABLED', 1),
|
||||
(4, 2, '13600000000', 'alpha-manager', 'MANAGER', 'REVIEWER', '甲公司经理', '$2a$10$bRMZPcIaiB1BUx6HPw6FSODPSuph8kUi8/JZOM6lACwjjhkbBL5mq', false, 'ENABLED', 1),
|
||||
(5, 2, '13500000000', 'alpha-engineer', 'ENGINEER', 'ADMIN', '甲公司工程师', '$2a$10$bRMZPcIaiB1BUx6HPw6FSODPSuph8kUi8/JZOM6lACwjjhkbBL5mq', false, 'ENABLED', 1)
|
||||
on conflict do nothing;
|
||||
|
||||
insert into sys_menu (id, company_id, permission_code, menu_code, menu_name, path, sort_order) values
|
||||
(201, 2, 'USER_MANAGE', 'USER_MANAGE', '员工管理', '/users', 1),
|
||||
(202, 2, 'DATA_RECORD_VIEW', 'DATA_RECORDS', '数据记录', '/data-records', 2)
|
||||
on conflict do nothing;
|
||||
|
||||
insert into biz_data_record (id, company_id, creator_id, creator_role, record_name) values
|
||||
(401, 2, 3, 'EMPLOYEE', '员工创建的数据'),
|
||||
(402, 2, 4, 'MANAGER', '经理创建的数据'),
|
||||
(403, 2, 5, 'ENGINEER', '工程师创建的数据')
|
||||
on conflict do nothing;
|
||||
47
src/main/resources/sql/schema.sql
Normal file
47
src/main/resources/sql/schema.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
create table if not exists sys_company (
|
||||
id bigint primary key,
|
||||
company_code varchar(64) not null unique,
|
||||
company_name varchar(128) not null,
|
||||
status varchar(32) not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
updated_at timestamp default current_timestamp
|
||||
);
|
||||
|
||||
create table if not exists sys_user (
|
||||
id bigint primary key,
|
||||
company_id bigint not null,
|
||||
phone varchar(32) not null,
|
||||
username varchar(64),
|
||||
role varchar(32) not null,
|
||||
position varchar(32) not null,
|
||||
real_name varchar(64) not null,
|
||||
password_hash varchar(255) not null,
|
||||
must_change_password boolean not null default true,
|
||||
status varchar(32) not null,
|
||||
session_version integer not null default 1,
|
||||
created_at timestamp default current_timestamp,
|
||||
updated_at timestamp default current_timestamp,
|
||||
constraint uq_sys_user_company_phone unique (company_id, phone)
|
||||
);
|
||||
|
||||
create table if not exists sys_menu (
|
||||
id bigint primary key,
|
||||
company_id bigint not null,
|
||||
permission_code varchar(64) not null,
|
||||
menu_code varchar(64) not null,
|
||||
menu_name varchar(128) not null,
|
||||
path varchar(255) not null,
|
||||
sort_order integer not null default 0,
|
||||
created_at timestamp default current_timestamp,
|
||||
updated_at timestamp default current_timestamp
|
||||
);
|
||||
|
||||
create table if not exists biz_data_record (
|
||||
id bigint primary key,
|
||||
company_id bigint not null,
|
||||
creator_id bigint not null,
|
||||
creator_role varchar(32) not null,
|
||||
record_name varchar(255) not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
updated_at timestamp default current_timestamp
|
||||
);
|
||||
Reference in New Issue
Block a user