1
0

7 Commits

Author SHA1 Message Date
28d70e5f9a feat(web): 修复逻辑删除,增加可选查询 2024-12-05 17:58:38 +08:00
6a68085870 feat(authentication): 为 Authentication 实体添加软删除功能
- 在 Authentication 类中添加 @SQLDelete 和 @Where 注解,实现软删除
- 移除 target 和 evidences 关联中的 @Where 注解,避免重复应用软删除逻辑
2024-12-05 17:57:27 +08:00
15b6f98598 refactor(web): 移除用户和数据文件创建时的冗余信息
- 移除了 DataFileService 中设置创建和修改用户的代码- 更新了 UserService 中的当前登录用户获取方式,增加了 Optional 类型的方法
- 移除了 EntityHelper 中填充创建者和修改者的代码
2024-12-05 17:56:59 +08:00
9d6e977d93 feat(web): 添加实体审计功能并配置审计用户
- 在 SimpleEntity 中添加 @CreatedBy 和 @LastModifiedBy 注解
- 在 WebApplication 中添加 AuditorAware Bean
- 使用 UserService 的 currentLoginUserOptional 方法获取当前登录用户
2024-12-05 17:54:58 +08:00
a6c128da64 feat(web): 增加REST统一查询参数 2024-12-03 13:00:16 +08:00
1ec345e18d feat(web): 增加授权相关界面 2024-12-02 19:07:22 +08:00
e7918f9039 feat(web): 避免h2的数据库关键字 2024-12-02 16:27:01 +08:00
33 changed files with 706 additions and 130 deletions

View File

@@ -1,5 +1,5 @@
const information = { export const information = {
debug: true, debug: false,
// baseUrl: '', // baseUrl: '',
baseUrl: 'http://127.0.0.1:20080', baseUrl: 'http://127.0.0.1:20080',
title: '可信供给中心', title: '可信供给中心',
@@ -17,6 +17,7 @@ export function useAmis(amisObject) {
struct, struct,
{ {
data: { data: {
debug: information.debug,
base: information.baseUrl, base: information.baseUrl,
}, },
}, },
@@ -98,6 +99,7 @@ export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB)
accept: accept, accept: accept,
maxSize: maxSize, maxSize: maxSize,
autoUpload: false, autoUpload: false,
drag: true,
startChunkApi: apiPost('${base}/upload/start'), startChunkApi: apiPost('${base}/upload/start'),
chunkApi: apiPost('${base}/upload/slice'), chunkApi: apiPost('${base}/upload/slice'),
finishChunkApi: apiPost('${base}/upload/finish'), finishChunkApi: apiPost('${base}/upload/finish'),
@@ -197,7 +199,7 @@ export function stringField(field, label, width = undefined, wrap = false) {
if (width) { if (width) {
data['width'] = width data['width'] = width
} }
if (wrap) { if (!wrap) {
data['className'] = 'nowrap' data['className'] = 'nowrap'
} }
return data return data
@@ -247,10 +249,11 @@ export const userStateMapping = [
mappingItem('禁用', 'DISABLED', 'bg-danger'), mappingItem('禁用', 'DISABLED', 'bg-danger'),
] ]
export const confirmationStateMapping = [ export const permissionStateMapping = [
mappingItem('未确权', 'NONE'), mappingItem('未确权', 'NONE'),
mappingItem('草稿', 'DRAFT', 'bg-primary'), mappingItem('草稿', 'DRAFT', 'bg-primary'),
mappingItem('审查中', 'CHECKING', 'bg-warning'), mappingItem('审查中', 'CHECKING', 'bg-warning'),
mappingItem('用户审查中', 'USER_CHECKING', 'bg-warning'),
mappingItem('通过', 'NORMAL', 'bg-success'), mappingItem('通过', 'NORMAL', 'bg-success'),
mappingItem('驳回', 'REJECT', 'bg-danger'), mappingItem('驳回', 'REJECT', 'bg-danger'),
] ]

View File

@@ -6,14 +6,19 @@ import {
formInputClearable, formInputClearable,
formInputMultiFileStatic, formInputMultiFileStatic,
horizontalFormOptions, horizontalFormOptions,
information,
inputFileFormItemCommonOptions, inputFileFormItemCommonOptions,
size100MB size100MB
} from "../constants.js"; } from "../constants.js";
import {resourceList} from "../../pages/index/tab-data.js"; import {resourceList} from "../../pages/index/tab-data.js";
import {resourceDetailDialog} from "../resource/dialog-resource.js"; import {resourceDetailDialog} from "../resource/dialog-resource.js";
function detailForm(showCreatedUserAndModifiedUser = false) { const CONFIRMATION_TYPE = 'confirmation'
const AUTHENTICATION_TYPE = 'authentication'
function detailForm(pickerApi = apiGet('${base}/data_resource/list'), showCreatedUserAndModifiedUser = false) {
return { return {
debug: information.debug,
id: 'permission_form', id: 'permission_form',
type: 'form', type: 'form',
...horizontalFormOptions(), ...horizontalFormOptions(),
@@ -34,7 +39,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
size: 'md', size: 'md',
valueField: 'id', valueField: 'id',
labelField: 'name', labelField: 'name',
source: apiGet('${base}/data_resource/list'), source: pickerApi,
pickerSchema: { pickerSchema: {
...resourceList(), ...resourceList(),
}, },
@@ -55,6 +60,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
}, },
{ {
type: 'textarea', type: 'textarea',
placeholder: '请输入确权说明',
label: '确权说明', label: '确权说明',
name: 'description', name: 'description',
...formInputClearable, ...formInputClearable,
@@ -70,12 +76,38 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
joinValues: false, joinValues: false,
...inputFileFormItemCommonOptions(undefined, size100MB), ...inputFileFormItemCommonOptions(undefined, size100MB),
}, },
{
visibleOn: `\${${AUTHENTICATION_TYPE}}`,
type: 'input-datetime-range',
name: 'activeTime',
extraName: 'expiredTime',
label: '授权时间',
required: true,
format: 'YYYY-MM-DD HH:mm:ss',
shortcuts: [
'7dayslater',
'14dayslater',
'30dayslater',
'180dayslater',
'365dayslater',
]
},
...(showCreatedUserAndModifiedUser ? formCreatedUserAndModifiedUser() : []) ...(showCreatedUserAndModifiedUser ? formCreatedUserAndModifiedUser() : [])
] ]
} }
} }
export function permissionAddDialog() { export function confirmationAddDialog() {
return permissionAddDialog(CONFIRMATION_TYPE)
}
export function authenticationAddDialog() {
return permissionAddDialog(AUTHENTICATION_TYPE)
}
function permissionAddDialog(type) {
let data = {add: true}
data[type] = true
return { return {
actionType: 'dialog', actionType: 'dialog',
dialog: { dialog: {
@@ -93,17 +125,25 @@ export function permissionAddDialog() {
} }
], ],
body: { body: {
...detailForm(), ...detailForm(generateApi(type)),
api: apiPost('${base}/confirmation/save'), api: apiPost(`\${base}/${type}/save`),
data: { data: data,
add: true,
},
} }
} }
} }
} }
export function permissionDetailDialog(field = 'id', actions = []) { export function confirmationDetailDialog(field = 'id', actions = []) {
return permissionDetailDialog(CONFIRMATION_TYPE, field, actions)
}
export function authenticationDetailDialog(field = 'id', actions = []) {
return permissionDetailDialog(AUTHENTICATION_TYPE, field, actions)
}
function permissionDetailDialog(type, field = 'id', actions = []) {
let data = {detail: true}
data[type] = true
return { return {
actionType: 'dialog', actionType: 'dialog',
dialog: { dialog: {
@@ -111,18 +151,26 @@ export function permissionDetailDialog(field = 'id', actions = []) {
size: 'md', size: 'md',
actions: actions, actions: actions,
body: { body: {
...detailForm(true), ...detailForm(generateApi(type), true),
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`), initApi: apiGet(`\${base}/${type}/detail/\${${field}}`),
static: true, static: true,
data: { data: data,
detail: true,
},
} }
} }
} }
} }
export function permissionEditeDialog(field = 'id') { export function confirmationEditeDialog(field = 'id') {
return permissionEditeDialog(CONFIRMATION_TYPE, field)
}
export function authenticationEditeDialog(field = 'id') {
return permissionEditeDialog(CONFIRMATION_TYPE, field)
}
function permissionEditeDialog(type, field = 'id') {
let data = {edit: true}
data[type] = true
return { return {
actionType: 'dialog', actionType: 'dialog',
dialog: { dialog: {
@@ -140,13 +188,20 @@ export function permissionEditeDialog(field = 'id') {
} }
], ],
body: { body: {
...detailForm(), ...detailForm(generateApi(type)),
api: apiPost('${base}/confirmation/save'), api: apiPost(`\${base}/${type}/save`),
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`), initApi: apiGet(`\${base}/${type}/detail/\${${field}}`),
data: { data: data,
edit: true,
}
}, },
} }
} }
} }
function generateApi(type) {
switch (type) {
case AUTHENTICATION_TYPE:
return apiGet('${base}/data_resource/list_no_authentication')
case CONFIRMATION_TYPE:
return apiGet('${base}/data_resource/list_no_confirmation')
}
}

View File

@@ -59,9 +59,9 @@ useAmis(information => {
tabs: [ tabs: [
// tabOverview(), // tabOverview(),
// tabMarket(), // tabMarket(),
tabPermissions(),
tabCheck(), tabCheck(),
tabData(), tabData(),
tabPermissions(),
tabUser(), tabUser(),
tabSettings(), tabSettings(),
] ]

View File

@@ -9,7 +9,7 @@ import {
stringField, stringField,
timeField, timeField,
} from "../../components/constants.js"; } from "../../components/constants.js";
import {permissionDetailDialog} from "../../components/permission/dialog-permission.js"; import {confirmationDetailDialog} from "../../components/permission/dialog-permission.js";
export function tabCheck() { export function tabCheck() {
return { return {
@@ -40,7 +40,7 @@ export function tabCheck() {
type: 'action', type: 'action',
label: '处理', label: '处理',
level: 'link', level: 'link',
...permissionDetailDialog( ...confirmationDetailDialog(
'parameters.confirmationId', 'parameters.confirmationId',
[ [
{ {
@@ -67,7 +67,7 @@ export function tabCheck() {
type: 'action', type: 'action',
label: '查看', label: '查看',
level: 'link', level: 'link',
...permissionDetailDialog('parameters.confirmationId'), ...confirmationDetailDialog('parameters.confirmationId'),
}, },
]), ]),
], ],

View File

@@ -8,10 +8,10 @@ import {
arrayInCheck, arrayInCheck,
arrayOutCheck, arrayOutCheck,
confirmationState, confirmationState,
confirmationStateMapping,
crudCommonOptions, crudCommonOptions,
mappingField, mappingField,
operationField, operationField,
permissionStateMapping,
timeField, timeField,
userOnly userOnly
} from "../../components/constants.js"; } from "../../components/constants.js";
@@ -40,7 +40,7 @@ export function resourceList() {
label: '描述', label: '描述',
name: 'description', name: 'description',
}, },
mappingField('confirmationState', '确权状态', confirmationStateMapping), mappingField('confirmationState', '确权状态', permissionStateMapping),
timeField('createdTime', '创建时间'), timeField('createdTime', '创建时间'),
operationField('操作', undefined, [ operationField('操作', undefined, [
{ {

View File

@@ -1,9 +1,10 @@
import { import {
apiGet, apiGet,
confirmationStateMapping,
crudCommonOptions, crudCommonOptions,
customerOnly,
mappingField, mappingField,
operationField, operationField,
permissionStateMapping,
providerOnly, providerOnly,
stringField, stringField,
stringWrapField, stringWrapField,
@@ -11,9 +12,12 @@ import {
userOnly, userOnly,
} from "../../components/constants.js"; } from "../../components/constants.js";
import { import {
permissionAddDialog, authenticationAddDialog,
permissionDetailDialog, authenticationDetailDialog,
permissionEditeDialog, authenticationEditeDialog,
confirmationAddDialog,
confirmationDetailDialog,
confirmationEditeDialog,
} from "../../components/permission/dialog-permission.js"; } from "../../components/permission/dialog-permission.js";
export function tabPermissions() { export function tabPermissions() {
@@ -25,6 +29,85 @@ export function tabPermissions() {
body: { body: {
type: 'tabs', type: 'tabs',
tabs: [ tabs: [
{
visibleOn: customerOnly,
title: '授权管理',
body: {
type: 'crud',
api: {
...apiGet('${base}/authentication/list')
},
...crudCommonOptions(),
headerToolbar: [
'reload',
{
type: 'action',
label: '',
icon: 'fa fa-plus',
...authenticationAddDialog()
},
],
columns: [
stringField('name', '名称', 200),
stringWrapField('description', '描述'),
mappingField('state', '状态', permissionStateMapping),
timeField('createdTime', '创建时间'),
operationField('操作', undefined, [
{
type: 'action',
label: '查看',
level: 'link',
...authenticationDetailDialog(),
},
{
visibleOn: "${state === 'CHECKING'}",
type: 'action',
label: '撤销',
level: 'link',
confirmTitle: '确认撤销',
confirmText: '确认撤销名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/authentication/retract/${id}'),
},
{
visibleOn: "${state === 'DRAFT' || state === 'REJECT'}",
type: 'action',
label: '提交',
level: 'link',
confirmTitle: '确认提交',
confirmText: '确认提交名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/authentication/submit/${id}'),
},
{
type: 'dropdown-button',
level: 'link',
icon: 'fa fa-ellipsis-h',
hideCaret: true,
trigger: 'hover',
buttons: [
{
disabledOn: "${state !== 'DRAFT'}",
type: 'action',
label: '编辑',
level: 'link',
...authenticationEditeDialog(),
},
{
disabledOn: "${state === 'CHECKING'}",
type: 'action',
label: "删除",
confirmTitle: '确认删除',
confirmText: '确认删除名称为「${name}」的确权申请吗?删除后对应的数据资源处于未确权状态。',
actionType: 'ajax',
api: apiGet('${base}/authentication/remove/${id}'),
},
]
},
]),
]
}
},
{ {
visibleOn: providerOnly, visibleOn: providerOnly,
title: '确权管理', title: '确权管理',
@@ -40,20 +123,20 @@ export function tabPermissions() {
type: 'action', type: 'action',
label: '', label: '',
icon: 'fa fa-plus', icon: 'fa fa-plus',
...permissionAddDialog() ...confirmationAddDialog()
}, },
], ],
columns: [ columns: [
stringField('name', '名称', 200), stringField('name', '名称', 200),
stringWrapField('description', '描述'), stringWrapField('description', '描述'),
mappingField('state', '状态', confirmationStateMapping), mappingField('state', '状态', permissionStateMapping),
timeField('createdTime', '创建时间'), timeField('createdTime', '创建时间'),
operationField('操作', undefined, [ operationField('操作', undefined, [
{ {
type: 'action', type: 'action',
label: '查看', label: '查看',
level: 'link', level: 'link',
...permissionDetailDialog(), ...confirmationDetailDialog(),
}, },
{ {
visibleOn: "${state === 'CHECKING'}", visibleOn: "${state === 'CHECKING'}",
@@ -87,7 +170,7 @@ export function tabPermissions() {
type: 'action', type: 'action',
label: '编辑', label: '编辑',
level: 'link', level: 'link',
...permissionEditeDialog(), ...confirmationEditeDialog(),
}, },
{ {
disabledOn: "${state === 'CHECKING'}", disabledOn: "${state === 'CHECKING'}",
@@ -104,10 +187,6 @@ export function tabPermissions() {
] ]
} }
}, },
{
title: '授权管理',
body: []
}
] ]
} }
} }

View File

@@ -1,6 +1,7 @@
package com.eshore.gringotts.web; package com.eshore.gringotts.web;
import com.blinkfox.fenix.EnableFenix; import com.blinkfox.fenix.EnableFenix;
import com.eshore.gringotts.web.domain.user.entity.User;
import com.eshore.gringotts.web.domain.user.service.UserService; import com.eshore.gringotts.web.domain.user.service.UserService;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
@@ -9,6 +10,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
@@ -41,4 +44,9 @@ public class WebApplication implements ApplicationRunner {
// 初始化系统管理员 // 初始化系统管理员
userService.initial(); userService.initial();
} }
@Bean
public AuditorAware<User> auditorAware(UserService userService) {
return userService::currentLoginUserOptional;
}
} }

View File

@@ -0,0 +1,87 @@
package com.eshore.gringotts.web.domain.authentication.controller;
import com.eshore.gringotts.web.domain.authentication.entity.Authentication;
import com.eshore.gringotts.web.domain.authentication.service.AuthenticationService;
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
import com.eshore.gringotts.web.domain.resource.service.DataResourceService;
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.set.ImmutableSet;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lanyuanxiaoyao
* @date 2024-12-02
*/
@Slf4j
@RestController
@RequestMapping("authentication")
public class AuthenticationController extends SimpleControllerSupport<Authentication, AuthenticationController.SaveItem, AuthenticationController.ListItem, AuthenticationController.DetailItem> {
private final AuthenticationService authenticationService;
private final DataResourceService dataResourceService;
private final DataFileService dataFileService;
public AuthenticationController(AuthenticationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
super(service);
this.authenticationService = service;
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService;
}
@Override
protected Authentication fromSaveItem(SaveItem item) throws Exception {
Authentication authentication = new Authentication();
authentication.setId(item.getId());
authentication.setDescription(item.getDescription());
authentication.setTarget(dataResourceService.detailOrThrow(item.getTargetId()));
authentication.setEvidences(dataFileService.list(item.getEvidenceFiles().collect(FileInfo::getValue)).toSet());
authentication.setActiveTime(item.getActiveTime());
authentication.setExpiredTime(item.getExpiredTime());
return null;
}
@Override
protected ListItem toListItem(Authentication entity) {
ListItem item = new ListItem();
item.setId(entity.getId());
item.setName(entity.getTarget().getName());
item.setDescription(entity.getDescription());
item.setState(entity.getState().name());
item.setCreatedUsername(entity.getCreatedUser().getUsername());
item.setCreatedTime(entity.getCreatedTime());
return item;
}
@Override
protected DetailItem toDetailItem(Authentication entity) {
return null;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class SaveItem extends SimpleSaveItem<Authentication> {
private Long targetId;
private String description;
private ImmutableSet<FileInfo> evidenceFiles;
private LocalDateTime activeTime;
private LocalDateTime expiredTime;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class ListItem extends SimpleListItem<Authentication> {
private String name;
private String description;
private String state;
}
@Data
public static final class DetailItem {}
}

View File

@@ -5,8 +5,10 @@ import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity; import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
import com.eshore.gringotts.web.domain.resource.entity.DataResource; import com.eshore.gringotts.web.domain.resource.entity.DataResource;
import com.eshore.gringotts.web.domain.upload.entity.DataFile; import com.eshore.gringotts.web.domain.upload.entity.DataFile;
import java.time.LocalDateTime;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode; import javax.persistence.ConstraintMode;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners; import javax.persistence.EntityListeners;
@@ -23,6 +25,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@@ -49,14 +52,24 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@NamedAttributeNode(value = "createdUser"), @NamedAttributeNode(value = "createdUser"),
@NamedAttributeNode(value = "modifiedUser"), @NamedAttributeNode(value = "modifiedUser"),
}) })
@SQLDelete(sql = "update " + Constants.TABLE_PREFIX + "authentication" + " set deleted = true where id = ?")
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
public class Authentication extends CheckingNeededEntity { public class Authentication extends CheckingNeededEntity {
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private DataResource target; private DataResource target;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private Set<DataFile> evidences; private Set<DataFile> evidences;
/**
* 生效时间
*/
@Column(nullable = false)
private LocalDateTime activeTime = LocalDateTime.now();
/**
* 过期时间
*/
@Column(nullable = false)
private LocalDateTime expiredTime = LocalDateTime.now().plusDays(1);
} }

View File

@@ -0,0 +1,13 @@
package com.eshore.gringotts.web.domain.authentication.repository;
import com.eshore.gringotts.web.domain.authentication.entity.Authentication;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import org.springframework.stereotype.Repository;
/**
* @author lanyuanxiaoyao
* @date 2024-12-02
*/
@Repository
public interface AuthenticationRepository extends SimpleRepository<Authentication, Long> {
}

View File

@@ -0,0 +1,31 @@
package com.eshore.gringotts.web.domain.authentication.service;
import com.eshore.gringotts.web.domain.authentication.entity.Authentication;
import com.eshore.gringotts.web.domain.authentication.repository.AuthenticationRepository;
import com.eshore.gringotts.web.domain.base.service.CheckingService;
import com.eshore.gringotts.web.domain.base.service.LogicDeleteService;
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
import com.eshore.gringotts.web.domain.user.service.UserService;
import javax.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.stereotype.Service;
/**
* @author lanyuanxiaoyao
* @date 2024-12-02
*/
@Slf4j
@Service
public class AuthenticationService extends LogicDeleteService<Authentication> implements CheckingService {
private final AuthenticationRepository authenticationRepository;
public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager) {
super(repository, userService, manager);
this.authenticationRepository = repository;
}
@Override
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
}
}

View File

@@ -1,6 +1,7 @@
package com.eshore.gringotts.web.domain.base.controller; package com.eshore.gringotts.web.domain.base.controller;
import com.eshore.gringotts.web.configuration.amis.AmisResponse; import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.base.controller.query.Query;
import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.ImmutableList;
/** /**
@@ -9,4 +10,6 @@ import org.eclipse.collections.api.list.ImmutableList;
*/ */
public interface ListController<LIST_ITEM> { public interface ListController<LIST_ITEM> {
AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception; AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception;
AmisResponse<ImmutableList<LIST_ITEM>> list(Query query) throws Exception;
} }

View File

@@ -1,8 +1,12 @@
package com.eshore.gringotts.web.domain.base.controller; package com.eshore.gringotts.web.domain.base.controller;
import cn.hutool.core.util.ObjectUtil;
import com.eshore.gringotts.web.configuration.amis.AmisResponse; import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport; import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.ImmutableList;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@@ -13,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody;
* @author lanyuanxiaoyao * @author lanyuanxiaoyao
* @date 2024-11-26 * @date 2024-11-26
*/ */
@Slf4j
public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> implements SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> { public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> implements SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
protected static final String SAVE = "/save"; protected static final String SAVE = "/save";
protected static final String LIST = "/list"; protected static final String LIST = "/list";
@@ -33,7 +38,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
@GetMapping(LIST) @GetMapping(LIST)
@Override @Override
public AmisResponse<ImmutableList<LIST_ITEM>> list() { public AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception {
return AmisResponse.responseSuccess(service.list().collect(entity -> { return AmisResponse.responseSuccess(service.list().collect(entity -> {
try { try {
return toListItem(entity); return toListItem(entity);
@@ -43,6 +48,21 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
})); }));
} }
@PostMapping(LIST)
@Override
public AmisResponse<ImmutableList<LIST_ITEM>> list(@RequestBody Query query) throws Exception {
if (ObjectUtil.isNull(query)) {
return AmisResponse.responseSuccess(Lists.immutable.empty());
}
return AmisResponse.responseSuccess(service.list(query).collect(entity -> {
try {
return toListItem(entity);
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
}
@GetMapping(DETAIL) @GetMapping(DETAIL)
@Override @Override
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception { public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {

View File

@@ -0,0 +1,61 @@
package com.eshore.gringotts.web.domain.base.controller.query;
import lombok.Data;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
/**
* 统一查询
*
* @author lanyuanxiaoyao
* @date 2024-12-03
*/
@Data
public class Query {
private Queryable query;
private ImmutableList<Sortable> sort;
private Pageable page;
@Data
public static class Queryable {
private ImmutableList<String> nullEqual;
private ImmutableList<String> notNullEqual;
private ImmutableList<String> empty;
private ImmutableList<String> notEmpty;
private ImmutableMap<String, ?> equal;
private ImmutableMap<String, ?> notEqual;
private ImmutableMap<String, String> like;
private ImmutableMap<String, String> notLike;
private ImmutableMap<String, ?> great;
private ImmutableMap<String, ?> less;
private ImmutableMap<String, ?> greatEqual;
private ImmutableMap<String, ?> lessEqual;
private ImmutableMap<String, ImmutableList<?>> in;
private ImmutableMap<String, ImmutableList<?>> notIn;
private ImmutableMap<String, Between> between;
private ImmutableMap<String, Between> notBetween;
@Data
public static class Between {
private String start;
private String end;
}
}
@Data
public static class Sortable {
private String column;
private Direction direction;
public enum Direction {
ASC,
DESC,
}
}
@Data
public static class Pageable {
private Integer page;
private Integer size;
}
}

View File

@@ -35,6 +35,10 @@ public class CheckingNeededEntity extends LogicDeleteEntity {
* 审查中 * 审查中
*/ */
CHECKING, CHECKING,
/**
* 用户审核
*/
USER_CHECKING,
/** /**
* 正常 * 正常
*/ */

View File

@@ -12,7 +12,9 @@ import javax.persistence.OneToOne;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@@ -33,11 +35,13 @@ public class SimpleEntity extends IdOnlyEntity {
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@CreatedBy
private User createdUser; private User createdUser;
@LastModifiedDate @LastModifiedDate
private LocalDateTime modifiedTime; private LocalDateTime modifiedTime;
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@LastModifiedBy
private User modifiedUser; private User modifiedUser;
} }

View File

@@ -30,12 +30,7 @@ public abstract class LogicDeleteService<ENTITY extends LogicDeleteEntity> exten
} }
@Override @Override
protected ImmutableList<Predicate> extraListPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) { protected ImmutableList<Predicate> listPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
return Lists.immutable.of(builder.equal(root.get("deleted"), false));
}
@Override
protected ImmutableList<Predicate> extraDetailPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
return Lists.immutable.of(builder.equal(root.get("deleted"), false)); return Lists.immutable.of(builder.equal(root.get("deleted"), false));
} }

View File

@@ -1,5 +1,6 @@
package com.eshore.gringotts.web.domain.base.service; package com.eshore.gringotts.web.domain.base.service;
import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import java.util.Optional; import java.util.Optional;
import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.ImmutableList;
@@ -16,6 +17,8 @@ public interface SimpleService<ENTITY extends SimpleEntity> {
ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception; ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception;
ImmutableList<ENTITY> list(Query query) throws Exception;
Optional<ENTITY> detailOptional(Long id) throws Exception; Optional<ENTITY> detailOptional(Long id) throws Exception;
ENTITY detail(Long id) throws Exception; ENTITY detail(Long id) throws Exception;

View File

@@ -2,8 +2,10 @@ package com.eshore.gringotts.web.domain.base.service;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository; import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.user.entity.User; import com.eshore.gringotts.web.domain.user.entity.User;
@@ -11,6 +13,7 @@ import com.eshore.gringotts.web.domain.user.service.UserService;
import java.util.Optional; import java.util.Optional;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@@ -49,53 +52,128 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
); );
entity = targetEntity; entity = targetEntity;
} }
User user = userService.currentLoginUser();
if (ObjectUtil.isNull(entity.getCreatedUser())) {
entity.setCreatedUser(user);
}
entity.setModifiedUser(user);
entity = repository.save(entity); entity = repository.save(entity);
return entity.getId(); return entity.getId();
} }
@Override @Override
public ImmutableList<ENTITY> list() { public ImmutableList<ENTITY> list() throws Exception {
return Lists.immutable.ofAll(repository.findAll( return Lists.immutable.ofAll(repository.findAll((root, query, builder) -> builder.and(listPredicates(root, query, builder).toArray(new Predicate[]{}))));
(root, query, builder) -> {
MutableList<Predicate> predicates = Lists.mutable.empty();
User user = userService.currentLoginUser();
if (User.isNotAdministrator(user)) {
predicates.add(builder.equal(root.get("createdUser"), user));
}
predicates.addAllIterable(extraListPredicates(root, query, builder));
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
},
Sort.by("createdTime").descending()
));
} }
@Override @Override
public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) { public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception {
return Lists.immutable.ofAll(repository.findAll( return Lists.immutable.ofAll(repository.findAll(
(root, query, builder) -> { (root, query, builder) -> {
MutableList<Predicate> predicates = Lists.mutable.of( MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicates(root, query, builder));
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull)) predicates.add(builder.in(root.get("id")).value(ids));
); return builder.and(predicates.toArray(new Predicate[predicates.size()]));
User user = userService.currentLoginUser(); }
if (User.isNotAdministrator(user)) { ));
predicates.add(builder.equal(root.get("createdUser"), user)); }
}
predicates.addAllIterable(extraListPredicates(root, query, builder)); private <Y> Path<Y> column(Root<ENTITY> root, String column) {
String[] columns = StrUtil.splitToArray(column, "/");
Path<Y> path = root.get(columns[0]);
for (int i = 1; i < columns.length; i++) {
path = path.get(columns[i]);
}
return path;
}
@SuppressWarnings({"unchecked", "rawtypes"})
private <Y> Object value(Path<Y> column, Object value) {
Class<?> javaType = column.getJavaType();
if (EnumUtil.isEnum(javaType)) {
return EnumUtil.fromString((Class<Enum>) javaType, (String) value);
}
return value;
}
@SuppressWarnings("unchecked")
private ImmutableList<Predicate> queryPredicates(Query.Queryable queryable, Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
MutableList<Predicate> predicates = Lists.mutable.empty();
if (ObjectUtil.isEmpty(queryable)) {
return predicates.toImmutable();
}
if (ObjectUtil.isNotEmpty(queryable.getNullEqual())) {
queryable.getNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
}
if (ObjectUtil.isNotEmpty(queryable.getNotNullEqual())) {
queryable.getNotNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
}
if (ObjectUtil.isNotEmpty(queryable.getEmpty())) {
queryable.getEmpty().forEach(column -> predicates.add(builder.isEmpty(column(root, column))));
}
if (ObjectUtil.isNotEmpty(queryable.getNotEmpty())) {
queryable.getNotEmpty().forEach(column -> predicates.add(builder.isNotEmpty(column(root, column))));
}
if (ObjectUtil.isNotEmpty(queryable.getEqual())) {
queryable.getEqual().forEachKeyValue((column, value) -> {
Path<Object> path = column(root, column);
predicates.add(builder.equal(path, value(path, value)));
});
}
if (ObjectUtil.isNotEmpty(queryable.getNotEqual())) {
queryable.getEqual().forEachKeyValue((column, value) -> {
Path<Object> path = column(root, column);
predicates.add(builder.notEqual(path, value(path, value)));
});
}
if (ObjectUtil.isNotEmpty(queryable.getLike())) {
queryable.getLike().forEachKeyValue((column, value) -> predicates.add(builder.like(column(root, column), value)));
}
if (ObjectUtil.isNotEmpty(queryable.getNotLike())) {
queryable.getNotLike().forEachKeyValue((column, value) -> predicates.add(builder.notLike(column(root, column), value)));
}
if (ObjectUtil.isNotEmpty(queryable.getGreat())) {
queryable.getGreat().forEachKeyValue((column, value) -> predicates.add(builder.greaterThan(column(root, column), (Comparable<Object>) value)));
}
if (ObjectUtil.isNotEmpty(queryable.getLess())) {
queryable.getLess().forEachKeyValue((column, value) -> predicates.add(builder.lessThan(column(root, column), (Comparable<Object>) value)));
}
if (ObjectUtil.isNotEmpty(queryable.getGreatEqual())) {
queryable.getGreatEqual().forEachKeyValue((column, value) -> predicates.add(builder.greaterThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
}
if (ObjectUtil.isNotEmpty(queryable.getLessEqual())) {
queryable.getLessEqual().forEachKeyValue((column, value) -> predicates.add(builder.lessThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
}
if (ObjectUtil.isNotEmpty(queryable.getIn())) {
queryable.getIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value)));
}
if (ObjectUtil.isNotEmpty(queryable.getNotIn())) {
queryable.getNotIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value).not()));
}
if (ObjectUtil.isNotEmpty(queryable.getBetween())) {
queryable.getBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
}
if (ObjectUtil.isNotEmpty(queryable.getNotBetween())) {
queryable.getNotBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
}
return predicates.toImmutable();
}
protected ImmutableList<Predicate> listPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
MutableList<Predicate> predicates = Lists.mutable.empty();
User user = userService.currentLoginUser();
if (User.isNotAdministrator(user)) {
predicates.add(builder.equal(root.get("createdUser"), user));
}
return predicates.toImmutable();
}
@Override
public ImmutableList<ENTITY> list(Query listQuery) throws Exception {
return Lists.immutable.ofAll(repository.findAll(
(root, query, builder) -> {
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicates(root, query, builder));
predicates.addAllIterable(queryPredicates(listQuery.getQuery(), root, query, builder));
return builder.and(predicates.toArray(new Predicate[predicates.size()])); return builder.and(predicates.toArray(new Predicate[predicates.size()]));
}, },
Sort.by("createdTime").descending() Sort.by("createdTime").descending()
)); ));
} }
protected ImmutableList<Predicate> extraListPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
return Lists.immutable.empty();
}
@Override @Override
public Optional<ENTITY> detailOptional(Long id) { public Optional<ENTITY> detailOptional(Long id) {
if (ObjectUtil.isNull(id)) { if (ObjectUtil.isNull(id)) {
@@ -103,23 +181,13 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
} }
return repository.findOne( return repository.findOne(
(root, query, builder) -> { (root, query, builder) -> {
MutableList<Predicate> predicates = Lists.mutable.of( MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicates(root, query, builder));
builder.equal(root.get("id"), id) predicates.add(builder.equal(root.get("id"), id));
);
User user = userService.currentLoginUser();
if (User.isNotAdministrator(user)) {
predicates.add(builder.equal(root.get("createdUser"), user));
}
predicates.addAllIterable(extraDetailPredicates(root, query, builder));
return builder.and(predicates.toArray(new Predicate[predicates.size()])); return builder.and(predicates.toArray(new Predicate[predicates.size()]));
} }
); );
} }
protected ImmutableList<Predicate> extraDetailPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
return Lists.immutable.empty();
}
@Override @Override
public ENTITY detail(Long id) { public ENTITY detail(Long id) {
return detailOrNull(id); return detailOrNull(id);
@@ -144,6 +212,10 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
} }
public static final class IdNotFoundException extends RuntimeException { public static final class IdNotFoundException extends RuntimeException {
public IdNotFoundException() {
super("资源不存在");
}
public IdNotFoundException(Long id) { public IdNotFoundException(Long id) {
super(StrUtil.format("ID为{}的资源不存在", id)); super(StrUtil.format("ID为{}的资源不存在", id));
} }

View File

@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.check.controller;
import com.eshore.gringotts.web.configuration.amis.AmisResponse; import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.base.controller.ListController; import com.eshore.gringotts.web.domain.base.controller.ListController;
import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.eshore.gringotts.web.domain.check.entity.CheckOrder; import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
import com.eshore.gringotts.web.domain.check.service.CheckOrderService; import com.eshore.gringotts.web.domain.check.service.CheckOrderService;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@@ -16,6 +17,8 @@ import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -43,6 +46,12 @@ public class CheckOrderController implements ListController<CheckOrderController
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem)); return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
} }
@PostMapping("/list")
@Override
public AmisResponse<ImmutableList<ListItem>> list(@RequestBody Query query) throws Exception {
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
}
@SneakyThrows @SneakyThrows
private ListItem toListItem(CheckOrder order) { private ListItem toListItem(CheckOrder order) {
ListItem item = new ListItem(); ListItem item = new ListItem();

View File

@@ -45,7 +45,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@NoArgsConstructor @NoArgsConstructor
public class CheckOrder extends SimpleEntity { public class CheckOrder extends SimpleEntity {
@Column(nullable = false) @Column(nullable = false)
private String key; private String keyword;
@Column(nullable = false) @Column(nullable = false)
private String description; private String description;
@Column(nullable = false) @Column(nullable = false)
@@ -73,14 +73,14 @@ public class CheckOrder extends SimpleEntity {
private Boolean over = false; private Boolean over = false;
public CheckOrder( public CheckOrder(
String key, String keyword,
String description, String description,
Type type, Type type,
String parameters, String parameters,
String targetClass, String targetClass,
User targetUser User targetUser
) { ) {
this.key = key; this.keyword = keyword;
this.description = description; this.description = description;
this.type = type; this.type = type;
this.parameters = parameters; this.parameters = parameters;
@@ -90,14 +90,14 @@ public class CheckOrder extends SimpleEntity {
} }
public CheckOrder( public CheckOrder(
String key, String keyword,
String description, String description,
Type type, Type type,
String parameters, String parameters,
String targetClass, String targetClass,
User.Role targetRole User.Role targetRole
) { ) {
this.key = key; this.keyword = keyword;
this.description = description; this.description = description;
this.type = type; this.type = type;
this.parameters = parameters; this.parameters = parameters;

View File

@@ -53,7 +53,7 @@ public class ConfirmationController extends SimpleControllerSupport<Confirmation
} }
@Override @Override
protected Confirmation fromSaveItem(SaveItem item) { protected Confirmation fromSaveItem(SaveItem item) throws Exception {
Confirmation confirmation = new Confirmation(); Confirmation confirmation = new Confirmation();
confirmation.setId(item.getId()); confirmation.setId(item.getId());
confirmation.setDescription(item.getDescription()); confirmation.setDescription(item.getDescription());

View File

@@ -55,11 +55,9 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
public class Confirmation extends CheckingNeededEntity { public class Confirmation extends CheckingNeededEntity {
@OneToOne(fetch = FetchType.EAGER) @OneToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private DataResource target; private DataResource target;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private Set<DataFile> evidences; private Set<DataFile> evidences;
} }

View File

@@ -69,7 +69,7 @@ public class ConfirmationService extends SimpleServiceSupport<Confirmation> impl
@Override @Override
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) { public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
if (StrUtil.equals(order.getKey(), "confirmation_check")) { if (StrUtil.equals(order.getKeyword(), "confirmation_check")) {
Long id = (Long) parameters.get("confirmationId"); Long id = (Long) parameters.get("confirmationId");
switch (operation) { switch (operation) {
case APPLY: case APPLY:

View File

@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.resource.controller;
import cn.hutool.core.util.EnumUtil; import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport; import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
import com.eshore.gringotts.web.domain.base.entity.FileInfo; import com.eshore.gringotts.web.domain.base.entity.FileInfo;
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem; import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
@@ -30,7 +31,9 @@ import java.util.Map;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.list.ImmutableList;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -45,14 +48,38 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/data_resource") @RequestMapping("/data_resource")
public class DataResourceController extends SimpleControllerSupport<DataResource, DataResourceController.SaveItem, DataResourceController.ListItem, DataResourceController.DetailItem> { public class DataResourceController extends SimpleControllerSupport<DataResource, DataResourceController.SaveItem, DataResourceController.ListItem, DataResourceController.DetailItem> {
private final ObjectMapper mapper; private final ObjectMapper mapper;
private final DataResourceService dataResourceService;
private final DataFileService dataFileService; private final DataFileService dataFileService;
public DataResourceController(DataResourceService dataResourceService, DataFileService dataFileService, Jackson2ObjectMapperBuilder builder) { public DataResourceController(DataResourceService dataResourceService, DataFileService dataFileService, Jackson2ObjectMapperBuilder builder) {
super(dataResourceService); super(dataResourceService);
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService; this.dataFileService = dataFileService;
this.mapper = builder.build(); this.mapper = builder.build();
} }
@GetMapping(LIST + "_no_confirmation")
public AmisResponse<ImmutableList<ListItem>> listNoConfirmation() {
return AmisResponse.responseSuccess(dataResourceService.listNoConfirmation().collect(entity -> {
try {
return toListItem(entity);
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
}
@GetMapping(LIST + "_no_authentication")
public AmisResponse<ImmutableList<ListItem>> listNoAuthentication() {
return AmisResponse.responseSuccess(dataResourceService.listNoAuthentication().collect(entity -> {
try {
return toListItem(entity);
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
}
@Override @Override
protected DataResource fromSaveItem(SaveItem item) throws JsonProcessingException { protected DataResource fromSaveItem(SaveItem item) throws JsonProcessingException {
ResourceType type = generateResourceType(item); ResourceType type = generateResourceType(item);

View File

@@ -59,24 +59,19 @@ public class DataResource extends LogicDeleteEntity {
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private ResourceType type; private ResourceType type;
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private ResourceFormat format; private ResourceFormat format;
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private DataFile example; private DataFile example;
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target") @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private Confirmation confirmation; private Confirmation confirmation;
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target") @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
@ToString.Exclude @ToString.Exclude
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
private Set<Authentication> authentications; private Set<Authentication> authentications;
} }

View File

@@ -12,10 +12,17 @@ import org.springframework.stereotype.Repository;
@SuppressWarnings("NullableProblems") @SuppressWarnings("NullableProblems")
@Repository @Repository
public interface DataResourceRepository extends SimpleRepository<DataResource, Long> { public interface DataResourceRepository extends SimpleRepository<DataResource, Long> {
@Override
@EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH)
List<DataResource> findAll(Specification<DataResource> specification);
@Override @Override
@EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH) @EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH)
List<DataResource> findAll(Specification<DataResource> specification, Sort sort); List<DataResource> findAll(Specification<DataResource> specification, Sort sort);
@EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH)
List<DataResource> findAllByConfirmationIsNull();
@Override @Override
@EntityGraph(value = "data_resource.detail", type = EntityGraph.EntityGraphType.FETCH) @EntityGraph(value = "data_resource.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<DataResource> findOne(Specification<DataResource> specification); Optional<DataResource> findOne(Specification<DataResource> specification);

View File

@@ -1,14 +1,23 @@
package com.eshore.gringotts.web.domain.resource.service; package com.eshore.gringotts.web.domain.resource.service;
import com.eshore.gringotts.web.domain.authentication.entity.Authentication;
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport; import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
import com.eshore.gringotts.web.domain.resource.entity.DataResource; import com.eshore.gringotts.web.domain.resource.entity.DataResource;
import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat; import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat;
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType; import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
import com.eshore.gringotts.web.domain.resource.repository.DataResourceRepository; import com.eshore.gringotts.web.domain.resource.repository.DataResourceRepository;
import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository; import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository;
import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository; import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository;
import com.eshore.gringotts.web.domain.user.entity.User;
import com.eshore.gringotts.web.domain.user.service.UserService; import com.eshore.gringotts.web.domain.user.service.UserService;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.SetJoin;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@@ -19,13 +28,34 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class DataResourceService extends SimpleServiceSupport<DataResource> { public class DataResourceService extends SimpleServiceSupport<DataResource> {
private final DataResourceRepository dataResourceRepository;
private final ResourceTypeRepository resourceTypeRepository; private final ResourceTypeRepository resourceTypeRepository;
private final ResourceFormatRepository resourceFormatRepository; private final ResourceFormatRepository resourceFormatRepository;
private final UserService userService;
public DataResourceService(DataResourceRepository repository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) { public DataResourceService(DataResourceRepository repository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
super(repository, userService); super(repository, userService);
this.dataResourceRepository = repository;
this.resourceTypeRepository = resourceTypeRepository; this.resourceTypeRepository = resourceTypeRepository;
this.resourceFormatRepository = resourceFormatRepository; this.resourceFormatRepository = resourceFormatRepository;
this.userService = userService;
}
public ImmutableList<DataResource> listNoConfirmation() {
return Lists.immutable.ofAll(dataResourceRepository.findAllByConfirmationIsNull());
}
public ImmutableList<DataResource> listNoAuthentication() {
User user = userService.currentLoginUser();
return Lists.immutable.ofAll(dataResourceRepository.findAll(
(root, query, builder) -> {
SetJoin<DataResource, Authentication> authenticationJoin = root.joinSet("authentications", JoinType.LEFT);
authenticationJoin.on(builder.notEqual(authenticationJoin.get("createdUser"), user));
Join<DataResource, Confirmation> confirmationJoin = root.join("confirmation", JoinType.LEFT);
confirmationJoin.on(builder.equal(confirmationJoin.get("state"), CheckingNeededEntity.State.NORMAL));
return null;
}
));
} }
@Override @Override

View File

@@ -36,9 +36,6 @@ public class DataFileService extends SimpleServiceSupport<DataFile> {
public Long initialDataFile(String filename) { public Long initialDataFile(String filename) {
DataFile dataFile = new DataFile(); DataFile dataFile = new DataFile();
dataFile.setFilename(filename); dataFile.setFilename(filename);
User loginUser = userService.currentLoginUser();
dataFile.setCreatedUser(loginUser);
dataFile.setModifiedUser(loginUser);
return dataFileRepository.save(dataFile).getId(); return dataFileRepository.save(dataFile).getId();
} }

View File

@@ -3,13 +3,12 @@ package com.eshore.gringotts.web.domain.user.service;
import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.SaTokenInfo; import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.eshore.gringotts.web.domain.user.entity.User; import com.eshore.gringotts.web.domain.user.entity.User;
import com.eshore.gringotts.web.domain.user.repository.UserRepository; import com.eshore.gringotts.web.domain.user.repository.UserRepository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.Optional;
import lombok.Data; import lombok.Data;
import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.list.ImmutableList;
@@ -73,7 +72,15 @@ public class UserService {
} }
public User currentLoginUser() { public User currentLoginUser() {
return userRepository.findById(StpUtil.getLoginIdAsLong()).orElseThrow(LoginNotFoundException::new); return currentLoginUserOptional().orElseThrow(LoginNotFoundException::new);
}
public Optional<User> currentLoginUserOptional() {
try {
return userRepository.findById(StpUtil.getLoginIdAsLong());
} catch (Throwable throwable) {
return Optional.empty();
}
} }
private User findUserByUsername(String username) { private User findUserByUsername(String username) {
@@ -129,7 +136,6 @@ public class UserService {
*/ */
public void registerFromAdministrator(String username, String password, User.Role role) { public void registerFromAdministrator(String username, String password, User.Role role) {
User loginUser = currentLoginUser(); User loginUser = currentLoginUser();
User user = new User(); User user = new User();
user.setUsername(username); user.setUsername(username);
user.setPassword(encryptPassword(password)); user.setPassword(encryptPassword(password));
@@ -137,8 +143,6 @@ public class UserService {
user.setState(User.State.NORMAL); user.setState(User.State.NORMAL);
user.setCheckedUser(loginUser); user.setCheckedUser(loginUser);
user.setCheckedTime(LocalDateTime.now()); user.setCheckedTime(LocalDateTime.now());
user.setCreatedUser(loginUser);
user.setModifiedUser(loginUser);
userRepository.save(user); userRepository.save(user);
} }

View File

@@ -1,9 +1,6 @@
package com.eshore.gringotts.web.helper; package com.eshore.gringotts.web.helper;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import com.eshore.gringotts.web.domain.user.entity.User;
import com.eshore.gringotts.web.domain.user.service.UserService;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@@ -20,13 +17,4 @@ public class EntityHelper {
repository.delete(old); repository.delete(old);
} }
} }
public static <E extends SimpleEntity> E fillCreatorAndModifier(E entity, UserService service) {
User user = service.currentLoginUser();
if (ObjectUtil.isNull(entity.getCreatedUser())) {
entity.setCreatedUser(user);
}
entity.setModifiedUser(user);
return entity;
}
} }

View File

@@ -17,6 +17,8 @@ spring:
multipart: multipart:
max-file-size: 10MB max-file-size: 10MB
max-request-size: 20MB max-request-size: 20MB
jackson:
date-format: 'yyyy-MM-dd HH:mm:ss'
fenix: fenix:
print-banner: false print-banner: false
print-sql: false print-sql: false

View File

@@ -0,0 +1,68 @@
package com.eshore.gringotts.web;
import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
/**
* @author lanyuanxiaoyao
* @date 2024-12-03
*/
public class TestQueryParse {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new EclipseCollectionsModule());
mapper.registerModule(new JavaTimeModule());
// language=JSON
System.out.println(mapper.readValue("{}", Query.class));
// language=JSON
System.out.println(mapper.readValue("{\n" +
" \"query\": {\n" +
" \"equal\": {\n" +
" \"name\": \"lanyuanxiaoyao\"\n" +
" }\n" +
" }\n" +
"}", Query.class));
// language=JSON
System.out.println(mapper.readValue("{\n" +
" \"query\": {\n" +
" \"equal\": {\n" +
" \"name\": \"lanyuanxiaoyao\"\n" +
" },\n" +
" \"notEqual\": {\n" +
" \"username\": \"lanyuanxiaoyao@qq.com\",\n" +
" \"password\": \"mingland87\"\n" +
" },\n" +
" \"great\": {\n" +
" \"age\": 12,\n" +
" \"createTime\": \"2020-10-12 00:00:00\"\n" +
" },\n" +
" \"in\": {\n" +
" \"age\": [\n" +
" 15,\n" +
" 18,\n" +
" 20\n" +
" ]\n" +
" },\n" +
" \"between\": {\n" +
" \"createTime\": {\n" +
" \"start\": \"2024-12-03 00:00:00\",\n" +
" \"end\": \"2024-12-03 00:00:00\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"sort\": [\n" +
" {\n" +
" \"column\": \"createTime\",\n" +
" \"direction\": \"ASC\"\n" +
" }\n" +
" ],\n" +
" \"page\": {\n" +
" \"size\": 10,\n" +
" \"page\": 1\n" +
" }\n" +
"}", Query.class));
}
}