Compare commits
4 Commits
66bf1b9242
...
58f2173fb0
| Author | SHA1 | Date | |
|---|---|---|---|
| 58f2173fb0 | |||
| 00e88078a2 | |||
| 3bda73badf | |||
| 499b7dc597 |
@@ -1,5 +1,5 @@
|
||||
const information = {
|
||||
debug: false,
|
||||
debug: true,
|
||||
// baseUrl: '',
|
||||
baseUrl: 'http://127.0.0.1:20080',
|
||||
title: '可信供给中心',
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
size100MB
|
||||
} from "../constants.js";
|
||||
import {resourceList} from "../../pages/index/tab-data.js";
|
||||
import {resourceDetailDialog} from "../resource/dialog-resource.js";
|
||||
|
||||
function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
return {
|
||||
@@ -36,6 +37,20 @@ function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
source: apiGet('${base}/data_resource/list'),
|
||||
pickerSchema: {
|
||||
...resourceList(),
|
||||
},
|
||||
staticSchema: {
|
||||
type: 'tpl',
|
||||
tpl: "<span class='text-primary' style='cursor: pointer'>${targetName}</span>",
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
...resourceDetailDialog('targetId'),
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -88,13 +103,13 @@ export function permissionAddDialog() {
|
||||
}
|
||||
}
|
||||
|
||||
export function permissionDetailDialog(field = 'id') {
|
||||
export function permissionDetailDialog(field = 'id', actions = []) {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '确权申请详情',
|
||||
size: 'md',
|
||||
actions: [],
|
||||
actions: actions,
|
||||
body: {
|
||||
...detailForm(true),
|
||||
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
|
||||
|
||||
@@ -327,7 +327,7 @@ export function resourceAddDialog() {
|
||||
}
|
||||
}
|
||||
|
||||
export function resourceDetailDialog() {
|
||||
export function resourceDetailDialog(field = 'id') {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
@@ -337,7 +337,7 @@ export function resourceDetailDialog() {
|
||||
body: {
|
||||
...detailForm(true),
|
||||
static: true,
|
||||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||||
initApi: apiGet(`\${base}/data_resource/detail/\${${field}}`),
|
||||
data: {
|
||||
detail: true,
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ useAmis(information => {
|
||||
tabs: [
|
||||
// tabOverview(),
|
||||
// tabMarket(),
|
||||
tabCheck(),
|
||||
tabData(),
|
||||
tabPermissions(),
|
||||
tabCheck(),
|
||||
tabUser(),
|
||||
tabSettings(),
|
||||
]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {checkerOnly} from "../../components/constants.js";
|
||||
import {apiGet, apiPost, checkerOnly, crudCommonOptions} from "../../components/constants.js";
|
||||
import {permissionDetailDialog} from "../../components/permission/dialog-permission.js";
|
||||
|
||||
export function tabCheck() {
|
||||
return {
|
||||
@@ -6,7 +7,53 @@ export function tabCheck() {
|
||||
title: '审核审查',
|
||||
icon: 'fa fa-shield-halved',
|
||||
body: [
|
||||
'hello world'
|
||||
{
|
||||
type: 'crud',
|
||||
api: apiGet('${base}/check/list'),
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
name: 'name',
|
||||
label: '描述',
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
width: 100,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...permissionDetailDialog(
|
||||
'parameters.confirmationId',
|
||||
[
|
||||
{
|
||||
type: 'each',
|
||||
name: 'operations',
|
||||
items: {
|
||||
type: 'action',
|
||||
label: '${item.name}',
|
||||
level: '${item.level}',
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
...apiPost('${base}/check/operation/${item.operation}'),
|
||||
data: '${parameters}'
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
),
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface DetailController<DETAIL_ITEM> {
|
||||
AmisResponse<DETAIL_ITEM> detail(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface ListController<LIST_ITEM> {
|
||||
AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface RemoveController {
|
||||
AmisResponse<Object> remove(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface SaveController<SAVE_ITEM> {
|
||||
AmisResponse<Long> save(SAVE_ITEM item) throws Exception;
|
||||
}
|
||||
@@ -1,60 +1,8 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public abstract class SimpleController<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
||||
protected static final String SAVE = "/save";
|
||||
protected static final String LIST = "/list";
|
||||
protected static final String DETAIL = "/detail/{id}";
|
||||
protected static final String REMOVE = "/remove/{id}";
|
||||
|
||||
private final SimpleService<ENTITY> service;
|
||||
|
||||
public SimpleController(SimpleService<ENTITY> service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@PostMapping(SAVE)
|
||||
public AmisResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||
return AmisResponse.responseSuccess(service.save(fromSaveItem(item)));
|
||||
}
|
||||
|
||||
@GetMapping(LIST)
|
||||
public AmisResponse<ImmutableSet<LIST_ITEM>> list() {
|
||||
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
||||
try {
|
||||
return toListItem(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@GetMapping(DETAIL)
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||
return AmisResponse.responseSuccess(toDetailItem(service.detail(id)));
|
||||
}
|
||||
|
||||
@GetMapping(REMOVE)
|
||||
public AmisResponse<Object> remove(@PathVariable Long id) {
|
||||
service.remove(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
protected abstract ENTITY fromSaveItem(SAVE_ITEM item) throws Exception;
|
||||
|
||||
protected abstract LIST_ITEM toListItem(ENTITY entity) throws Exception;
|
||||
|
||||
protected abstract DETAIL_ITEM toDetailItem(ENTITY entity) throws Exception;
|
||||
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, ListController<LIST_ITEM>, DetailController<DETAIL_ITEM>, RemoveController {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
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 LIST = "/list";
|
||||
protected static final String DETAIL = "/detail/{id}";
|
||||
protected static final String REMOVE = "/remove/{id}";
|
||||
|
||||
private final SimpleServiceSupport<ENTITY> service;
|
||||
|
||||
public SimpleControllerSupport(SimpleServiceSupport<ENTITY> service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@PostMapping(SAVE)
|
||||
@Override
|
||||
public AmisResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||
return AmisResponse.responseSuccess(service.save(fromSaveItem(item)));
|
||||
}
|
||||
|
||||
@GetMapping(LIST)
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<LIST_ITEM>> list() {
|
||||
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
||||
try {
|
||||
return toListItem(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@GetMapping(DETAIL)
|
||||
@Override
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||
return AmisResponse.responseSuccess(toDetailItem(service.detail(id)));
|
||||
}
|
||||
|
||||
@GetMapping(REMOVE)
|
||||
@Override
|
||||
public AmisResponse<Object> remove(@PathVariable Long id) {
|
||||
service.remove(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
protected abstract ENTITY fromSaveItem(SAVE_ITEM item) throws Exception;
|
||||
|
||||
protected abstract LIST_ITEM toListItem(ENTITY entity) throws Exception;
|
||||
|
||||
protected abstract DETAIL_ITEM toDetailItem(ENTITY entity) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* 需要审查
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface CheckingService {
|
||||
ImmutableList<CheckOrder> checkingList();
|
||||
|
||||
void onChecked(String operation, ImmutableMap<String, Object> parameters);
|
||||
|
||||
@Value
|
||||
class CheckOrder {
|
||||
String name;
|
||||
ImmutableList<CheckOperation> operations;
|
||||
ImmutableMap<String, Object> parameters;
|
||||
}
|
||||
|
||||
@Data
|
||||
class CheckOperation {
|
||||
/**
|
||||
* 全局唯一
|
||||
*/
|
||||
private final String operation;
|
||||
private final String name;
|
||||
private final String level;
|
||||
|
||||
public CheckOperation(String operation, String name) {
|
||||
this(operation, name, "default");
|
||||
}
|
||||
|
||||
public CheckOperation(String operation, String name, String level) {
|
||||
this.operation = operation;
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,125 +1,28 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
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.service.UserService;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class SimpleService<ENTITY extends SimpleEntity> {
|
||||
private final SimpleRepository<ENTITY, Long> repository;
|
||||
private final UserService userService;
|
||||
public interface SimpleService<ENTITY extends SimpleEntity> {
|
||||
Long save(ENTITY entity) throws Exception;
|
||||
|
||||
public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) {
|
||||
this.repository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
ImmutableList<ENTITY> list() throws Exception;
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public Long save(ENTITY entity) {
|
||||
if (ObjectUtil.isNotNull(entity.getId())) {
|
||||
Long id = entity.getId();
|
||||
ENTITY targetEntity = repository.findById(entity.getId()).orElseThrow(() -> new IdNotFoundException(id));
|
||||
BeanUtil.copyProperties(
|
||||
entity,
|
||||
targetEntity,
|
||||
CopyOptions.create()
|
||||
.setIgnoreProperties("id", "createdUser", "createdTime", "modifiedUser", "modifiedTime")
|
||||
);
|
||||
entity = targetEntity;
|
||||
}
|
||||
User user = userService.currentLoginUser();
|
||||
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
||||
entity.setCreatedUser(user);
|
||||
}
|
||||
entity.setModifiedUser(user);
|
||||
entity = repository.save(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception;
|
||||
|
||||
public ImmutableSet<ENTITY> list() {
|
||||
return Sets.immutable.ofAll(repository.findAll(
|
||||
(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));
|
||||
}
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by("createdTime").descending()
|
||||
));
|
||||
}
|
||||
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
||||
|
||||
public ImmutableSet<ENTITY> list(ImmutableSet<Long> ids) {
|
||||
return Sets.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull))
|
||||
);
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by("createdTime").descending()
|
||||
));
|
||||
}
|
||||
ENTITY detail(Long id) throws Exception;
|
||||
|
||||
public Optional<ENTITY> detailOptional(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return repository.findOne(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||
builder.equal(root.get("id"), id)
|
||||
);
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
}
|
||||
);
|
||||
}
|
||||
ENTITY detailOrThrow(Long id) throws Exception;
|
||||
|
||||
public ENTITY detail(Long id) {
|
||||
return detailOptional(id).orElse(null);
|
||||
}
|
||||
ENTITY detailOrNull(Long id) throws Exception;
|
||||
|
||||
public ENTITY detailOrThrow(Long id) {
|
||||
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void remove(Long id) {
|
||||
if (ObjectUtil.isNotNull(id)) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class IdNotFoundException extends RuntimeException {
|
||||
public IdNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的资源不存在", id));
|
||||
}
|
||||
}
|
||||
void remove(Long id) throws Exception;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
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.service.UserService;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.transaction.Transactional;
|
||||
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.MutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implements SimpleService<ENTITY> {
|
||||
private final SimpleRepository<ENTITY, Long> repository;
|
||||
private final UserService userService;
|
||||
|
||||
public SimpleServiceSupport(SimpleRepository<ENTITY, Long> repository, UserService userService) {
|
||||
this.repository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public Long save(ENTITY entity) {
|
||||
if (ObjectUtil.isNotNull(entity.getId())) {
|
||||
Long id = entity.getId();
|
||||
ENTITY targetEntity = repository.findById(entity.getId()).orElseThrow(() -> new IdNotFoundException(id));
|
||||
BeanUtil.copyProperties(
|
||||
entity,
|
||||
targetEntity,
|
||||
CopyOptions.create()
|
||||
.setIgnoreProperties("id", "createdUser", "createdTime", "modifiedUser", "modifiedTime")
|
||||
);
|
||||
entity = targetEntity;
|
||||
}
|
||||
User user = userService.currentLoginUser();
|
||||
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
||||
entity.setCreatedUser(user);
|
||||
}
|
||||
entity.setModifiedUser(user);
|
||||
entity = repository.save(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ENTITY> list() {
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(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));
|
||||
}
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by("createdTime").descending()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) {
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull))
|
||||
);
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by("createdTime").descending()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ENTITY> detailOptional(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return repository.findOne(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||
builder.equal(root.get("id"), id)
|
||||
);
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detail(Long id) {
|
||||
return detailOrNull(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detailOrThrow(Long id) {
|
||||
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detailOrNull(Long id) {
|
||||
return detailOptional(id).orElse(null);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void remove(Long id) {
|
||||
if (ObjectUtil.isNotNull(id)) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class IdNotFoundException extends RuntimeException {
|
||||
public IdNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的资源不存在", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.eshore.gringotts.web.domain.check.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.ListController;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* 监管
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("check")
|
||||
public class CheckController implements ListController<CheckingService.CheckOrder> {
|
||||
private final ImmutableList<CheckingService> checkingServices;
|
||||
private final MutableMap<String, CheckingService> serviceMap = Maps.mutable.<String, CheckingService>empty().asSynchronized();
|
||||
|
||||
public CheckController(ApplicationContext applicationContext) {
|
||||
this.checkingServices = Lists.immutable.ofAll(applicationContext.getBeansOfType(CheckingService.class).values());
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<CheckingService.CheckOrder>> list() throws Exception {
|
||||
return AmisResponse.responseSuccess(
|
||||
checkingServices.flatCollect(checkingService -> {
|
||||
ImmutableList<CheckingService.CheckOrder> orders = checkingService.checkingList();
|
||||
orders.flatCollect(CheckingService.CheckOrder::getOperations)
|
||||
.forEach(operation -> serviceMap.put(operation.getOperation(), checkingService));
|
||||
return orders;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/operation/{operation}")
|
||||
public AmisResponse<Object> operation(@PathVariable String operation, @RequestBody ImmutableMap<String, Object> data) {
|
||||
log.info("Check operation: {} data: {} target: {}", operation, data, serviceMap.get(operation).getClass().getSimpleName());
|
||||
CheckingService service = serviceMap.getOrDefault(operation, null);
|
||||
if (ObjectUtil.isNull(service)) {
|
||||
throw new RuntimeException("服务未找到");
|
||||
}
|
||||
service.onChecked(operation, data);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||
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;
|
||||
@@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("confirmation")
|
||||
public class ConfirmationController extends SimpleController<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||
public class ConfirmationController extends SimpleControllerSupport<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||
private final ConfirmationService confirmationService;
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
@@ -20,6 +20,10 @@ import org.springframework.stereotype.Repository;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface ConfirmationRepository extends SimpleRepository<Confirmation, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Confirmation> findAll(Specification<Confirmation> specification);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Confirmation> findAll(Specification<Confirmation> specification, Sort sort);
|
||||
@@ -32,6 +36,10 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Confirmation confirmation set confirmation.state = ?2, confirmation.modifiedUser = ?3, confirmation.modifiedTime = current_timestamp where confirmation.id = ?1")
|
||||
@Query("update Confirmation confirmation \n" +
|
||||
"set confirmation.state = ?2, \n" +
|
||||
" confirmation.modifiedUser = ?3, \n" +
|
||||
" confirmation.modifiedTime = current_timestamp \n" +
|
||||
"where confirmation.id = ?1")
|
||||
void updateStateById(Long id, Confirmation.State state, User modifiedUser);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.confirmation.repository.ConfirmationRepository;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -14,7 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ConfirmationService extends SimpleService<Confirmation> {
|
||||
public class ConfirmationService extends SimpleServiceSupport<Confirmation> implements CheckingService {
|
||||
private final ConfirmationRepository confirmationRepository;
|
||||
private final UserService userService;
|
||||
|
||||
@@ -40,6 +46,36 @@ public class ConfirmationService extends SimpleService<Confirmation> {
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<CheckOrder> checkingList() {
|
||||
return Lists.immutable.ofAll(
|
||||
confirmationRepository.findAll(
|
||||
(root, query, builder) -> builder.equal(root.get("state"), Confirmation.State.CHECKING)
|
||||
)
|
||||
)
|
||||
.collect(confirmation -> new CheckOrder(
|
||||
StrUtil.format("资源名为「{}」的确权申请", confirmation.getTarget().getName()),
|
||||
Lists.immutable.of(
|
||||
new CheckOperation("confirmation_check_apply", "通过"),
|
||||
new CheckOperation("confirmation_check_reject", "拒绝", "danger")
|
||||
),
|
||||
Maps.immutable.of("confirmationId", confirmation.getId())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChecked(String operation, ImmutableMap<String, Object> parameters) {
|
||||
Long id = (Long) parameters.get("confirmationId");
|
||||
switch (operation) {
|
||||
case "confirmation_check_apply":
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.NORMAL, userService.currentLoginUser());
|
||||
break;
|
||||
case "confirmation_check_reject":
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ConfirmationDuplicatedException extends RuntimeException {
|
||||
public ConfirmationDuplicatedException() {
|
||||
super("数据资源已绑定确权申请,无法再次申请");
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.order.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 工单
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-27
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@DynamicUpdate
|
||||
@Table(name = Constants.TABLE_PREFIX + "work_order")
|
||||
public class WorkOrder extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
private String description;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.eshore.gringotts.web.domain.resource.controller;
|
||||
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||
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;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/data_resource")
|
||||
public class DataResourceController extends SimpleController<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 DataFileService dataFileService;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.eshore.gringotts.web.domain.resource.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
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.type.ResourceType;
|
||||
@@ -18,7 +18,7 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataResourceService extends SimpleService<DataResource> {
|
||||
public class DataResourceService extends SimpleServiceSupport<DataResource> {
|
||||
private final ResourceTypeRepository resourceTypeRepository;
|
||||
private final ResourceFormatRepository resourceFormatRepository;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.eshore.gringotts.web.domain.upload.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.upload.repository.DataFileRepository;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
@@ -16,7 +16,7 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataFileService extends SimpleService<DataFile> {
|
||||
public class DataFileService extends SimpleServiceSupport<DataFile> {
|
||||
private final DataFileRepository dataFileRepository;
|
||||
private final UserService userService;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user