From 28d70e5f9a27e89fc9c1be111d1f63625e7542e4 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 5 Dec 2024 17:58:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E4=BF=AE=E5=A4=8D=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gringotts-frontend/components/constants.js | 5 +- .../permission/dialog-permission.js | 23 +++-- .../base/controller/DetailController.java | 2 - .../base/controller/ListController.java | 5 +- .../controller/SimpleControllerSupport.java | 31 +++--- .../base/controller/query/ListQuery.java | 53 ---------- .../query/{DetailQuery.java => Query.java} | 31 +++--- .../domain/base/service/SimpleService.java | 13 +-- .../base/service/SimpleServiceSupport.java | 96 +++++++++---------- .../controller/CheckOrderController.java | 7 +- .../confirmation/entity/Confirmation.java | 2 - .../controller/DataResourceController.java | 27 ++++++ .../domain/resource/entity/DataResource.java | 5 - .../repository/DataResourceRepository.java | 7 ++ .../resource/service/DataResourceService.java | 30 ++++++ .../src/main/resources/application.yml | 2 + .../eshore/gringotts/web/TestQueryParse.java | 9 +- 17 files changed, 183 insertions(+), 165 deletions(-) delete mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/ListQuery.java rename gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/{DetailQuery.java => Query.java} (76%) diff --git a/gringotts-frontend/components/constants.js b/gringotts-frontend/components/constants.js index 9e60d52..9f0f015 100644 --- a/gringotts-frontend/components/constants.js +++ b/gringotts-frontend/components/constants.js @@ -1,5 +1,5 @@ -const information = { - debug: true, +export const information = { + debug: false, // baseUrl: '', baseUrl: 'http://127.0.0.1:20080', title: '可信供给中心', @@ -17,6 +17,7 @@ export function useAmis(amisObject) { struct, { data: { + debug: information.debug, base: information.baseUrl, }, }, diff --git a/gringotts-frontend/components/permission/dialog-permission.js b/gringotts-frontend/components/permission/dialog-permission.js index 2dd762c..cbcc34c 100644 --- a/gringotts-frontend/components/permission/dialog-permission.js +++ b/gringotts-frontend/components/permission/dialog-permission.js @@ -6,6 +6,7 @@ import { formInputClearable, formInputMultiFileStatic, horizontalFormOptions, + information, inputFileFormItemCommonOptions, size100MB } from "../constants.js"; @@ -15,9 +16,9 @@ import {resourceDetailDialog} from "../resource/dialog-resource.js"; const CONFIRMATION_TYPE = 'confirmation' const AUTHENTICATION_TYPE = 'authentication' -function detailForm(showCreatedUserAndModifiedUser = false) { +function detailForm(pickerApi = apiGet('${base}/data_resource/list'), showCreatedUserAndModifiedUser = false) { return { - debug: true, + debug: information.debug, id: 'permission_form', type: 'form', ...horizontalFormOptions(), @@ -38,7 +39,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) { size: 'md', valueField: 'id', labelField: 'name', - source: apiGet('${base}/data_resource/list'), + source: pickerApi, pickerSchema: { ...resourceList(), }, @@ -59,6 +60,7 @@ function detailForm(showCreatedUserAndModifiedUser = false) { }, { type: 'textarea', + placeholder: '请输入确权说明', label: '确权说明', name: 'description', ...formInputClearable, @@ -123,7 +125,7 @@ function permissionAddDialog(type) { } ], body: { - ...detailForm(), + ...detailForm(generateApi(type)), api: apiPost(`\${base}/${type}/save`), data: data, } @@ -149,7 +151,7 @@ function permissionDetailDialog(type, field = 'id', actions = []) { size: 'md', actions: actions, body: { - ...detailForm(true), + ...detailForm(generateApi(type), true), initApi: apiGet(`\${base}/${type}/detail/\${${field}}`), static: true, data: data, @@ -186,7 +188,7 @@ function permissionEditeDialog(type, field = 'id') { } ], body: { - ...detailForm(), + ...detailForm(generateApi(type)), api: apiPost(`\${base}/${type}/save`), initApi: apiGet(`\${base}/${type}/detail/\${${field}}`), data: data, @@ -194,3 +196,12 @@ function permissionEditeDialog(type, field = 'id') { } } } + +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') + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/DetailController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/DetailController.java index 6aa3ef2..69c5899 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/DetailController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/DetailController.java @@ -1,7 +1,6 @@ package com.eshore.gringotts.web.domain.base.controller; import com.eshore.gringotts.web.configuration.amis.AmisResponse; -import com.eshore.gringotts.web.domain.base.controller.query.DetailQuery; /** * @author lanyuanxiaoyao @@ -9,5 +8,4 @@ import com.eshore.gringotts.web.domain.base.controller.query.DetailQuery; */ public interface DetailController { AmisResponse detail(Long id) throws Exception; - AmisResponse detail(DetailQuery query) throws Exception; } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/ListController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/ListController.java index 7ff1779..ebdffe0 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/ListController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/ListController.java @@ -1,7 +1,7 @@ package com.eshore.gringotts.web.domain.base.controller; import com.eshore.gringotts.web.configuration.amis.AmisResponse; -import com.eshore.gringotts.web.domain.base.controller.query.ListQuery; +import com.eshore.gringotts.web.domain.base.controller.query.Query; import org.eclipse.collections.api.list.ImmutableList; /** @@ -10,5 +10,6 @@ import org.eclipse.collections.api.list.ImmutableList; */ public interface ListController { AmisResponse> list() throws Exception; - AmisResponse> list(ListQuery query) throws Exception; + + AmisResponse> list(Query query) throws Exception; } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java index d24d58e..12abd94 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/SimpleControllerSupport.java @@ -1,10 +1,12 @@ 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.domain.base.controller.query.DetailQuery; -import com.eshore.gringotts.web.domain.base.controller.query.ListQuery; +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.service.SimpleServiceSupport; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.list.ImmutableList; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -15,11 +17,11 @@ import org.springframework.web.bind.annotation.RequestBody; * @author lanyuanxiaoyao * @date 2024-11-26 */ +@Slf4j public abstract class SimpleControllerSupport implements SimpleController { protected static final String SAVE = "/save"; protected static final String LIST = "/list"; - protected static final String DETAIL_ID = "/detail/{id}"; - protected static final String DETAIL = "/detail"; + protected static final String DETAIL = "/detail/{id}"; protected static final String REMOVE = "/remove/{id}"; private final SimpleServiceSupport service; @@ -48,22 +50,25 @@ public abstract class SimpleControllerSupport> list(@RequestBody ListQuery query) throws Exception { - return null; + public AmisResponse> 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_ID) + @GetMapping(DETAIL) @Override public AmisResponse detail(@PathVariable Long id) throws Exception { return AmisResponse.responseSuccess(toDetailItem(service.detail(id))); } - @PostMapping(DETAIL) - @Override - public AmisResponse detail(@RequestBody DetailQuery query) throws Exception { - return null; - } - @GetMapping(REMOVE) @Override public AmisResponse remove(@PathVariable Long id) { diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/ListQuery.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/ListQuery.java deleted file mode 100644 index dd23f15..0000000 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/ListQuery.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.eshore.gringotts.web.domain.base.controller.query; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.ToString; -import org.eclipse.collections.api.list.ImmutableList; - -/** - * @author lanyuanxiaoyao - * @date 2024-12-03 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@ToString(callSuper = true) -@EqualsAndHashCode(callSuper = true) -public class ListQuery extends DetailQuery { - private ImmutableList sort; - private Pageable page; - - public ListQuery(Queryable query) { - super(query); - } - - public ListQuery(Queryable query, ImmutableList sort, Pageable page) { - super(query); - this.sort = sort; - this.page = page; - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - public static class Sortable { - private String column; - private Direction direction; - - public enum Direction { - ASC, - DESC, - } - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - public static class Pageable { - private Integer page = 1; - private Integer size = 10; - } -} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/DetailQuery.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/Query.java similarity index 76% rename from gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/DetailQuery.java rename to gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/Query.java index ce40e26..729326a 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/DetailQuery.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/query/Query.java @@ -1,9 +1,6 @@ package com.eshore.gringotts.web.domain.base.controller.query; -import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; -import lombok.NoArgsConstructor; import org.eclipse.collections.api.list.ImmutableList; import org.eclipse.collections.api.map.ImmutableMap; @@ -14,15 +11,12 @@ import org.eclipse.collections.api.map.ImmutableMap; * @date 2024-12-03 */ @Data -@NoArgsConstructor -@AllArgsConstructor -public class DetailQuery { +public class Query { private Queryable query; + private ImmutableList sort; + private Pageable page; @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor public static class Queryable { private ImmutableList nullEqual; private ImmutableList notNullEqual; @@ -42,11 +36,26 @@ public class DetailQuery { private ImmutableMap notBetween; @Data - @NoArgsConstructor - @AllArgsConstructor 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; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java index a502019..924239d 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java @@ -1,7 +1,6 @@ package com.eshore.gringotts.web.domain.base.service; -import com.eshore.gringotts.web.domain.base.controller.query.DetailQuery; -import com.eshore.gringotts.web.domain.base.controller.query.ListQuery; +import com.eshore.gringotts.web.domain.base.controller.query.Query; import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; import java.util.Optional; import org.eclipse.collections.api.list.ImmutableList; @@ -18,23 +17,15 @@ public interface SimpleService { ImmutableList list(ImmutableSet ids) throws Exception; - ImmutableList list(ListQuery query) throws Exception; + ImmutableList list(Query query) throws Exception; Optional detailOptional(Long id) throws Exception; - Optional detailOptional(DetailQuery query) throws Exception; - ENTITY detail(Long id) throws Exception; - ENTITY detail(DetailQuery query) throws Exception; - ENTITY detailOrThrow(Long id) throws Exception; - ENTITY detailOrThrow(DetailQuery query) throws Exception; - ENTITY detailOrNull(Long id) throws Exception; - ENTITY detailOrNull(DetailQuery query) throws Exception; - void remove(Long id) throws Exception; } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleServiceSupport.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleServiceSupport.java index b1b00ce..6482da4 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleServiceSupport.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleServiceSupport.java @@ -2,10 +2,10 @@ 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.EnumUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import com.eshore.gringotts.web.domain.base.controller.query.DetailQuery; -import com.eshore.gringotts.web.domain.base.controller.query.ListQuery; +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.repository.SimpleRepository; import com.eshore.gringotts.web.domain.user.entity.User; @@ -13,6 +13,7 @@ import com.eshore.gringotts.web.domain.user.service.UserService; import java.util.Optional; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.transaction.Transactional; @@ -51,11 +52,6 @@ public abstract class SimpleServiceSupport implemen ); entity = targetEntity; } - User user = userService.currentLoginUser(); - if (ObjectUtil.isNull(entity.getCreatedUser())) { - entity.setCreatedUser(user); - } - entity.setModifiedUser(user); entity = repository.save(entity); return entity.getId(); } @@ -76,59 +72,83 @@ public abstract class SimpleServiceSupport implemen )); } + private Path column(Root root, String column) { + String[] columns = StrUtil.splitToArray(column, "/"); + Path path = root.get(columns[0]); + for (int i = 1; i < columns.length; i++) { + path = path.get(columns[i]); + } + return path; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private Object value(Path column, Object value) { + Class javaType = column.getJavaType(); + if (EnumUtil.isEnum(javaType)) { + return EnumUtil.fromString((Class) javaType, (String) value); + } + return value; + } + @SuppressWarnings("unchecked") - private ImmutableList queryPredicates(DetailQuery.Queryable queryable, Root root, CriteriaQuery query, CriteriaBuilder builder) { + private ImmutableList queryPredicates(Query.Queryable queryable, Root root, CriteriaQuery query, CriteriaBuilder builder) { MutableList predicates = Lists.mutable.empty(); if (ObjectUtil.isEmpty(queryable)) { return predicates.toImmutable(); } if (ObjectUtil.isNotEmpty(queryable.getNullEqual())) { - queryable.getNullEqual().forEach(column -> predicates.add(builder.isNull(root.get(column)))); + queryable.getNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column)))); } if (ObjectUtil.isNotEmpty(queryable.getNotNullEqual())) { - queryable.getNotNullEqual().forEach(column -> predicates.add(builder.isNull(root.get(column)))); + queryable.getNotNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column)))); } if (ObjectUtil.isNotEmpty(queryable.getEmpty())) { - queryable.getEmpty().forEach(column -> predicates.add(builder.isEmpty(root.get(column)))); + queryable.getEmpty().forEach(column -> predicates.add(builder.isEmpty(column(root, column)))); } if (ObjectUtil.isNotEmpty(queryable.getNotEmpty())) { - queryable.getNotEmpty().forEach(column -> predicates.add(builder.isNotEmpty(root.get(column)))); + queryable.getNotEmpty().forEach(column -> predicates.add(builder.isNotEmpty(column(root, column)))); } if (ObjectUtil.isNotEmpty(queryable.getEqual())) { - queryable.getEqual().forEachKeyValue((column, value) -> predicates.add(builder.equal(root.get(column), value))); + queryable.getEqual().forEachKeyValue((column, value) -> { + Path path = column(root, column); + predicates.add(builder.equal(path, value(path, value))); + }); } if (ObjectUtil.isNotEmpty(queryable.getNotEqual())) { - queryable.getEqual().forEachKeyValue((column, value) -> predicates.add(builder.notEqual(root.get(column), value))); + queryable.getEqual().forEachKeyValue((column, value) -> { + Path 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(root.get(column), value))); + 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(root.get(column), value))); + 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(root.get(column), (Comparable) value))); + queryable.getGreat().forEachKeyValue((column, value) -> predicates.add(builder.greaterThan(column(root, column), (Comparable) value))); } if (ObjectUtil.isNotEmpty(queryable.getLess())) { - queryable.getLess().forEachKeyValue((column, value) -> predicates.add(builder.lessThan(root.get(column), (Comparable) value))); + queryable.getLess().forEachKeyValue((column, value) -> predicates.add(builder.lessThan(column(root, column), (Comparable) value))); } if (ObjectUtil.isNotEmpty(queryable.getGreatEqual())) { - queryable.getGreatEqual().forEachKeyValue((column, value) -> predicates.add(builder.greaterThanOrEqualTo(root.get(column), (Comparable) value))); + queryable.getGreatEqual().forEachKeyValue((column, value) -> predicates.add(builder.greaterThanOrEqualTo(column(root, column), (Comparable) value))); } if (ObjectUtil.isNotEmpty(queryable.getLessEqual())) { - queryable.getLessEqual().forEachKeyValue((column, value) -> predicates.add(builder.lessThanOrEqualTo(root.get(column), (Comparable) value))); + queryable.getLessEqual().forEachKeyValue((column, value) -> predicates.add(builder.lessThanOrEqualTo(column(root, column), (Comparable) value))); } if (ObjectUtil.isNotEmpty(queryable.getIn())) { - queryable.getIn().forEachKeyValue((column, value) -> predicates.add(builder.in(root.get(column)).value(value))); + 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(root.get(column)).value(value).not())); + 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(root.get(column), value.getStart(), value.getEnd()))); + 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(root.get(column), value.getStart(), value.getEnd()))); + queryable.getNotBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd()))); } return predicates.toImmutable(); } @@ -143,7 +163,7 @@ public abstract class SimpleServiceSupport implemen } @Override - public ImmutableList list(ListQuery listQuery) throws Exception { + public ImmutableList list(Query listQuery) throws Exception { return Lists.immutable.ofAll(repository.findAll( (root, query, builder) -> { MutableList predicates = Lists.mutable.ofAll(listPredicates(root, query, builder)); @@ -168,47 +188,21 @@ public abstract class SimpleServiceSupport implemen ); } - @Override - public Optional detailOptional(DetailQuery detailQuery) throws Exception { - return repository.findOne( - (root, query, builder) -> { - MutableList predicates = Lists.mutable.ofAll(listPredicates(root, query, builder)); - predicates.addAllIterable(queryPredicates(detailQuery.getQuery(), root, query, builder)); - return builder.and(predicates.toArray(new Predicate[predicates.size()])); - } - ); - } - @Override public ENTITY detail(Long id) { return detailOrNull(id); } - @Override - public ENTITY detail(DetailQuery query) throws Exception { - return detailOrNull(query); - } - @Override public ENTITY detailOrThrow(Long id) { return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id)); } - @Override - public ENTITY detailOrThrow(DetailQuery query) throws Exception { - return detailOptional(query).orElseThrow(IdNotFoundException::new); - } - @Override public ENTITY detailOrNull(Long id) { return detailOptional(id).orElse(null); } - @Override - public ENTITY detailOrNull(DetailQuery query) throws Exception { - return detailOptional(query).orElse(null); - } - @Transactional(rollbackOn = Throwable.class) @Override public void remove(Long id) { diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java index b59ae66..a3b6454 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/check/controller/CheckOrderController.java @@ -2,7 +2,7 @@ package com.eshore.gringotts.web.domain.check.controller; 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.query.ListQuery; +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.service.CheckOrderService; import com.fasterxml.jackson.core.JsonProcessingException; @@ -17,6 +17,8 @@ import org.eclipse.collections.api.map.ImmutableMap; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 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; @@ -44,8 +46,9 @@ public class CheckOrderController implements ListController> list(ListQuery query) throws Exception { + public AmisResponse> list(@RequestBody Query query) throws Exception { return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem)); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/entity/Confirmation.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/entity/Confirmation.java index 709ec69..5eb643d 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/entity/Confirmation.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/confirmation/entity/Confirmation.java @@ -55,11 +55,9 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; public class Confirmation extends CheckingNeededEntity { @OneToOne(fetch = FetchType.EAGER) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private DataResource target; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @ToString.Exclude - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private Set evidences; } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java index 69e09dd..f0909cb 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java @@ -2,6 +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.configuration.amis.AmisResponse; 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; @@ -30,7 +31,9 @@ import java.util.Map; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; +import org.eclipse.collections.api.list.ImmutableList; 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.RestController; @@ -45,14 +48,38 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/data_resource") public class DataResourceController extends SimpleControllerSupport { private final ObjectMapper mapper; + private final DataResourceService dataResourceService; private final DataFileService dataFileService; public DataResourceController(DataResourceService dataResourceService, DataFileService dataFileService, Jackson2ObjectMapperBuilder builder) { super(dataResourceService); + this.dataResourceService = dataResourceService; this.dataFileService = dataFileService; this.mapper = builder.build(); } + @GetMapping(LIST + "_no_confirmation") + public AmisResponse> 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> listNoAuthentication() { + return AmisResponse.responseSuccess(dataResourceService.listNoAuthentication().collect(entity -> { + try { + return toListItem(entity); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + } + @Override protected DataResource fromSaveItem(SaveItem item) throws JsonProcessingException { ResourceType type = generateResourceType(item); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java index d17a84e..8575f97 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java @@ -59,24 +59,19 @@ public class DataResource extends LogicDeleteEntity { @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @ToString.Exclude - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private ResourceType type; @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @ToString.Exclude - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private ResourceFormat format; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @ToString.Exclude - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private DataFile example; @OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target") @ToString.Exclude - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private Confirmation confirmation; @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target") @ToString.Exclude - @Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE) private Set authentications; } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/repository/DataResourceRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/repository/DataResourceRepository.java index 25600ec..3b0d0f1 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/repository/DataResourceRepository.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/repository/DataResourceRepository.java @@ -12,10 +12,17 @@ import org.springframework.stereotype.Repository; @SuppressWarnings("NullableProblems") @Repository public interface DataResourceRepository extends SimpleRepository { + @Override + @EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH) + List findAll(Specification specification); + @Override @EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH) List findAll(Specification specification, Sort sort); + @EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH) + List findAllByConfirmationIsNull(); + @Override @EntityGraph(value = "data_resource.detail", type = EntityGraph.EntityGraphType.FETCH) Optional findOne(Specification specification); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java index 6c4e1bf..550f355 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/service/DataResourceService.java @@ -1,14 +1,23 @@ 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.confirmation.entity.Confirmation; 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; 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.ResourceTypeRepository; +import com.eshore.gringotts.web.domain.user.entity.User; 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 org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.ImmutableList; import org.springframework.stereotype.Service; /** @@ -19,13 +28,34 @@ import org.springframework.stereotype.Service; @Slf4j @Service public class DataResourceService extends SimpleServiceSupport { + private final DataResourceRepository dataResourceRepository; private final ResourceTypeRepository resourceTypeRepository; private final ResourceFormatRepository resourceFormatRepository; + private final UserService userService; public DataResourceService(DataResourceRepository repository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) { super(repository, userService); + this.dataResourceRepository = repository; this.resourceTypeRepository = resourceTypeRepository; this.resourceFormatRepository = resourceFormatRepository; + this.userService = userService; + } + + public ImmutableList listNoConfirmation() { + return Lists.immutable.ofAll(dataResourceRepository.findAllByConfirmationIsNull()); + } + + public ImmutableList listNoAuthentication() { + User user = userService.currentLoginUser(); + return Lists.immutable.ofAll(dataResourceRepository.findAll( + (root, query, builder) -> { + SetJoin authenticationJoin = root.joinSet("authentications", JoinType.LEFT); + authenticationJoin.on(builder.notEqual(authenticationJoin.get("createdUser"), user)); + Join confirmationJoin = root.join("confirmation", JoinType.LEFT); + confirmationJoin.on(builder.equal(confirmationJoin.get("state"), CheckingNeededEntity.State.NORMAL)); + return null; + } + )); } @Override diff --git a/gringotts-web/src/main/resources/application.yml b/gringotts-web/src/main/resources/application.yml index fb7b5ee..d57d449 100644 --- a/gringotts-web/src/main/resources/application.yml +++ b/gringotts-web/src/main/resources/application.yml @@ -17,6 +17,8 @@ spring: multipart: max-file-size: 10MB max-request-size: 20MB + jackson: + date-format: 'yyyy-MM-dd HH:mm:ss' fenix: print-banner: false print-sql: false diff --git a/gringotts-web/src/test/java/com/eshore/gringotts/web/TestQueryParse.java b/gringotts-web/src/test/java/com/eshore/gringotts/web/TestQueryParse.java index a0fc8a2..962203a 100644 --- a/gringotts-web/src/test/java/com/eshore/gringotts/web/TestQueryParse.java +++ b/gringotts-web/src/test/java/com/eshore/gringotts/web/TestQueryParse.java @@ -1,7 +1,6 @@ package com.eshore.gringotts.web; -import com.eshore.gringotts.web.domain.base.controller.query.DetailQuery; -import com.eshore.gringotts.web.domain.base.controller.query.ListQuery; +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; @@ -17,7 +16,7 @@ public class TestQueryParse { mapper.registerModule(new EclipseCollectionsModule()); mapper.registerModule(new JavaTimeModule()); // language=JSON - System.out.println(mapper.readValue("{}", DetailQuery.class)); + System.out.println(mapper.readValue("{}", Query.class)); // language=JSON System.out.println(mapper.readValue("{\n" + " \"query\": {\n" + @@ -25,7 +24,7 @@ public class TestQueryParse { " \"name\": \"lanyuanxiaoyao\"\n" + " }\n" + " }\n" + - "}", DetailQuery.class)); + "}", Query.class)); // language=JSON System.out.println(mapper.readValue("{\n" + " \"query\": {\n" + @@ -64,6 +63,6 @@ public class TestQueryParse { " \"size\": 10,\n" + " \"page\": 1\n" + " }\n" + - "}", ListQuery.class)); + "}", Query.class)); } }