From 58f2173fb02179c75cb8d993ace67df426a679c4 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 28 Nov 2024 17:39:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E5=A2=9E=E5=8A=A0=E7=A1=AE?= =?UTF-8?q?=E6=9D=83=E7=8A=B6=E6=80=81=E5=AE=A1=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gringotts-frontend/components/constants.js | 2 +- .../permission/dialog-permission.js | 19 +++++- .../components/resource/dialog-resource.js | 4 +- gringotts-frontend/pages/index/main.js | 2 +- gringotts-frontend/pages/index/tab-check.js | 51 +++++++++++++++- .../domain/base/service/CheckingService.java | 45 ++++++++++++++ .../check/controller/CheckController.java | 61 +++++++++++++++++++ .../repository/ConfirmationRepository.java | 4 ++ .../service/ConfirmationService.java | 38 +++++++++++- .../web/domain/order/entity/WorkOrder.java | 32 ---------- 10 files changed, 217 insertions(+), 41 deletions(-) create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckController.java delete mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/order/entity/WorkOrder.java diff --git a/gringotts-frontend/components/constants.js b/gringotts-frontend/components/constants.js index 47be294..784aad4 100644 --- a/gringotts-frontend/components/constants.js +++ b/gringotts-frontend/components/constants.js @@ -1,5 +1,5 @@ const information = { - debug: false, + debug: true, // baseUrl: '', baseUrl: 'http://127.0.0.1:20080', title: '可信供给中心', diff --git a/gringotts-frontend/components/permission/dialog-permission.js b/gringotts-frontend/components/permission/dialog-permission.js index 7d973af..53352e5 100644 --- a/gringotts-frontend/components/permission/dialog-permission.js +++ b/gringotts-frontend/components/permission/dialog-permission.js @@ -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: "${targetName}", + 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}}`), diff --git a/gringotts-frontend/components/resource/dialog-resource.js b/gringotts-frontend/components/resource/dialog-resource.js index 33fd40f..7ccfdc6 100644 --- a/gringotts-frontend/components/resource/dialog-resource.js +++ b/gringotts-frontend/components/resource/dialog-resource.js @@ -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, } diff --git a/gringotts-frontend/pages/index/main.js b/gringotts-frontend/pages/index/main.js index 84f0bbd..54c098f 100644 --- a/gringotts-frontend/pages/index/main.js +++ b/gringotts-frontend/pages/index/main.js @@ -59,9 +59,9 @@ useAmis(information => { tabs: [ // tabOverview(), // tabMarket(), + tabCheck(), tabData(), tabPermissions(), - tabCheck(), tabUser(), tabSettings(), ] diff --git a/gringotts-frontend/pages/index/tab-check.js b/gringotts-frontend/pages/index/tab-check.js index 7584aa5..159a66a 100644 --- a/gringotts-frontend/pages/index/tab-check.js +++ b/gringotts-frontend/pages/index/tab-check.js @@ -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}' + } + } + }, + ] + ), + }, + ] + } + ] + } ] } } \ No newline at end of file diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java new file mode 100644 index 0000000..41fc773 --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java @@ -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 checkingList(); + + void onChecked(String operation, ImmutableMap parameters); + + @Value + class CheckOrder { + String name; + ImmutableList operations; + ImmutableMap 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; + } + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckController.java new file mode 100644 index 0000000..6f73c7b --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckController.java @@ -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 { + private final ImmutableList checkingServices; + private final MutableMap serviceMap = Maps.mutable.empty().asSynchronized(); + + public CheckController(ApplicationContext applicationContext) { + this.checkingServices = Lists.immutable.ofAll(applicationContext.getBeansOfType(CheckingService.class).values()); + } + + @GetMapping("/list") + @Override + public AmisResponse> list() throws Exception { + return AmisResponse.responseSuccess( + checkingServices.flatCollect(checkingService -> { + ImmutableList orders = checkingService.checkingList(); + orders.flatCollect(CheckingService.CheckOrder::getOperations) + .forEach(operation -> serviceMap.put(operation.getOperation(), checkingService)); + return orders; + }) + ); + } + + @PostMapping("/operation/{operation}") + public AmisResponse operation(@PathVariable String operation, @RequestBody ImmutableMap 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(); + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java index 37c81d9..5d1e533 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/repository/ConfirmationRepository.java @@ -20,6 +20,10 @@ import org.springframework.stereotype.Repository; @SuppressWarnings("NullableProblems") @Repository public interface ConfirmationRepository extends SimpleRepository { + @Override + @EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH) + List findAll(Specification specification); + @Override @EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH) List findAll(Specification specification, Sort sort); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java index 22f8d60..b5a1f6f 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/service/ConfirmationService.java @@ -1,11 +1,17 @@ package com.eshore.gringotts.web.domain.confirmation.service; import cn.hutool.core.util.ObjectUtil; +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 SimpleServiceSupport { +public class ConfirmationService extends SimpleServiceSupport implements CheckingService { private final ConfirmationRepository confirmationRepository; private final UserService userService; @@ -40,6 +46,36 @@ public class ConfirmationService extends SimpleServiceSupport { confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser()); } + @Override + public ImmutableList 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 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("数据资源已绑定确权申请,无法再次申请"); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/order/entity/WorkOrder.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/order/entity/WorkOrder.java deleted file mode 100644 index c864a6e..0000000 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/order/entity/WorkOrder.java +++ /dev/null @@ -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; -}