Skip to content

Commit

Permalink
format entity create updater user.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Nov 3, 2023
1 parent ced15a7 commit 6d0b47f
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Mono<UserDetails> changePassword(@RequestBody ChangePasswordRequest reque
}

@Data
public static class ChangePasswordRequest {
static class ChangePasswordRequest {

@NotBlank(message = "Password not empty!")
private String password;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.platform.boot.security;

import com.platform.boot.commons.base.AbstractDatabase;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.security.group.authority.GroupAuthority;
import com.platform.boot.security.group.member.GroupMemberResponse;
import com.platform.boot.security.tenant.member.TenantMemberResponse;
Expand Down Expand Up @@ -72,10 +73,10 @@ public Mono<UserDetails> findByUsername(String username) {
var userMono = this.usersService.loadByUsername(username)
.zipWhen(user -> this.authorities(user.getCode()));

var tuple2Mono = userMono
var userDetailsMono = userMono
.flatMap(tuple2 -> buildUserDetails(tuple2.getT1(), new HashSet<>(tuple2.getT2())));

return tuple2Mono.onErrorResume(throwable -> Mono.error(new AuthenticationServiceException(
return userDetailsMono.onErrorResume(throwable -> Mono.error(new AuthenticationServiceException(
throwable.getLocalizedMessage(), throwable)));
}

Expand All @@ -96,17 +97,20 @@ private Mono<UserDetails> buildUserDetails(User user, Set<GrantedAuthority> auth

private Mono<List<GroupMemberResponse>> loadGroups(String userCode) {
return this.queryWithCache("USER_GROUPS-" + userCode,
QUERY_GROUP_MEMBERS_SQL, Map.of("userCode", userCode), GroupMemberResponse.class).collectList();
QUERY_GROUP_MEMBERS_SQL, Map.of("userCode", userCode), GroupMemberResponse.class)
.flatMap(ContextUtils::userAuditorSerializable).collectList();
}

private Mono<List<TenantMemberResponse>> loadTenants(String userCode) {
return this.queryWithCache("USER_TENANTS-" + userCode,
QUERY_TENANT_MEMBERS_SQL, Map.of("userCode", userCode), TenantMemberResponse.class).collectList();
QUERY_TENANT_MEMBERS_SQL, Map.of("userCode", userCode), TenantMemberResponse.class)
.flatMap(ContextUtils::userAuditorSerializable).collectList();
}

private Mono<List<GrantedAuthority>> authorities(String userCode) {
return this.getAuthorities(userCode)
.concatWith(this.getGroupAuthorities(userCode)).distinct().collectList();
.concatWith(this.getGroupAuthorities(userCode))
.flatMap(ContextUtils::userAuditorSerializable).distinct().collectList();
}

private Flux<GrantedAuthority> getAuthorities(String userCode) {
Expand All @@ -122,10 +126,9 @@ private Flux<GrantedAuthority> getGroupAuthorities(String userCode) {
}

public Mono<Void> loginSuccess(String username) {
return this.entityTemplate.update(User.class)
.matching(Query.query(Criteria.where("username").is(username)))
.apply(Update.update("loginTime", LocalDateTime.now()))
.then();
Query query = Query.query(Criteria.where("username").is(username).ignoreCase(true));
Update update = Update.update("loginTime", LocalDateTime.now());
return this.entityTemplate.update(User.class).matching(query).apply(update).then();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class Group implements BaseEntity<Integer> {

private String code;

private String pcode;

@NotBlank(message = "Tenant [tenantCode] not be empty!")
private String tenantCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public GroupRequest securityCode(String securityCode) {
return this;
}

public GroupRequest id(Integer id) {
this.setId(id);
return this;
}

public Group toGroup() {
return BeanUtils.copyProperties(this, Group.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.platform.boot.security.group;


import com.platform.boot.commons.utils.ContextUtils;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class GroupsService extends AbstractDatabase {
public Flux<Group> search(GroupRequest request, Pageable pageable) {
var cacheKey = ContextUtils.cacheKey(request, pageable);
Query query = Query.query(request.toCriteria()).with(pageable);
return super.queryWithCache(cacheKey, query, Group.class).flatMap(ContextUtils::userAuditorSerializable);
return super.queryWithCache(cacheKey, query, Group.class)
.flatMap(ContextUtils::userAuditorSerializable);
}

public Mono<Page<Group>> page(GroupRequest request, Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class TenantsService extends AbstractDatabase {
public Flux<Tenant> search(TenantRequest request, Pageable pageable) {
var cacheKey = ContextUtils.cacheKey(request, pageable);
var query = Query.query(request.toCriteria()).with(pageable);
return super.queryWithCache(cacheKey, query, Tenant.class).flatMap(ContextUtils::userAuditorSerializable);
return super.queryWithCache(cacheKey, query, Tenant.class)
.flatMap(ContextUtils::userAuditorSerializable);
}

public Mono<Page<Tenant>> page(TenantRequest request, Pageable pageable) {
Expand Down
4 changes: 2 additions & 2 deletions boot/platform/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
logging:
register-shutdown-hook: true
level:
#web: debug
web: debug
com.platform.boot.*: debug
org.springframework.r2dbc: debug
#io.r2dbc.postgresql.QUERY: debug
Expand All @@ -23,7 +23,7 @@ spring:
max-acquire-time: 5s
validation-query: "select version()"
sql.init:
mode: never
mode: always
platform: postgres
encoding: utf-8
data.redis:
Expand Down
36 changes: 18 additions & 18 deletions boot/platform/src/main/resources/data-postgres.sql
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
insert into se_users(code, username, password, name, extend)
insert into se_users(code, username, password, name, creator, updater, extend)
values ('U1000', 'admin', '{pbkdf2}7d8a68bc5d507bd19bc153ff10bcdef66f5a5f3d0c1ab2438630e50b5c65894bccc2c7e4404c5afa',
'系统超级管理员', '{}');
insert into se_authorities(code, user_code, authority)
values ('A1000', 'U1000', 'ROLE_ADMINISTRATORS');
'系统超级管理员', 'U1000', 'U1000', '{}');
insert into se_authorities(code, user_code, authority, creator, updater)
values ('A1000', 'U1000', 'ROLE_ADMINISTRATORS', 'U1000', 'U1000');

insert into se_groups(code, name)
values ('G1000', '默认组');
insert into se_groups(code, name, creator, updater)
values ('G1000', '默认组', 'U1000', 'U1000');

insert into se_group_members(code, group_code, user_code)
values ('GM1000', 'G1000', 'U1000');
insert into se_group_members(code, group_code, user_code, creator, updater)
values ('GM1000', 'G1000', 'U1000', 'U1000', 'U1000');

insert into se_group_authorities(code, group_code, authority)
values ('GA1000', 'G1000', 'ROLE_GROUPS_ADMINISTRATORS');
insert into se_group_authorities(code, group_code, authority, creator, updater)
values ('GA1000', 'G1000', 'ROLE_GROUPS_ADMINISTRATORS', 'U1000', 'U1000');

insert into se_tenants(pcode, code, name)
values ('0', '610115', '默认租户');
insert into se_tenants(code, name, creator, updater)
values ('610115', '默认租户', 'U1000', 'U1000');

insert into se_tenant_members(code, tenant_code, user_code)
values ('TM1000', '610115', 'U1000');
insert into se_tenant_members(code, tenant_code, user_code, creator, updater)
values ('TM1000', '610115', 'U1000', 'U1000', 'U1000');

insert into se_menus(code, type, authority, name, path, extend)
values ('1000', 'FOLDER', 'ROLE_FOLDER_SYSTEM', 'System manager', '', '{
insert into se_menus(code, type, authority, name, path, creator, updater, extend)
values ('1000', 'FOLDER', 'ROLE_FOLDER_SYSTEM', 'System manager', '', 'U1000', 'U1000', '{
"icons": "settings"
}');

insert into se_menus(code, pcode, type, authority, name, path, extend)
values ('1001', '1000', 'MENU', 'ROLE_MENU_SYSTEM_MENUS', 'MENUS', '/system/menus', '{
insert into se_menus(code, pcode, type, authority, name, path, creator, updater, extend)
values ('1001', '1000', 'MENU', 'ROLE_MENU_SYSTEM_MENUS', 'MENUS', '/system/menus', 'U1000', 'U1000', '{
"icons": "menu-2"
}');
6 changes: 2 additions & 4 deletions boot/platform/src/main/resources/schema-postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ create table if not exists se_groups
(
id serial8 primary key,
code varchar(64) not null unique,
pcode varchar(64) not null default '0',
tenant_code varchar(64) not null default '0',
name varchar(512) not null,
extend jsonb,
Expand All @@ -51,7 +50,7 @@ create table if not exists se_groups
created_time timestamp default current_timestamp,
updated_time timestamp default current_timestamp
);
create index se_groups_pcode_tenant_code_name_idx on se_groups (pcode, tenant_code, name);
create index se_groups_tenant_code_name_idx on se_groups (tenant_code, name);
create index se_groups_extend_gin_idx on se_groups using gin (extend);
comment on table se_groups is '角色表';

Expand Down Expand Up @@ -90,7 +89,6 @@ create table if not exists se_tenants
(
id serial primary key,
code varchar(64) not null unique,
pcode varchar(64) not null,
name varchar(512) not null,
description text,
extend jsonb,
Expand All @@ -99,7 +97,7 @@ create table if not exists se_tenants
created_time timestamp default current_timestamp,
updated_time timestamp default current_timestamp
);
create index se_tenants_tenant_code_name_idx on se_tenants (pcode, name);
create index se_tenants_name_idx on se_tenants (name);
create index se_tenants_extend_gin_idx on se_tenants using gin (extend);
comment on table se_tenants is '租户表';

Expand Down

0 comments on commit 6d0b47f

Please sign in to comment.