From 8fb11f192fb3ef73c4ea3b1771fb15eaadaa8b26 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Sat, 31 Aug 2024 17:07:16 +0800 Subject: [PATCH] =?UTF-8?q?modify:=201.=20=E5=8D=95=E4=BD=8D=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BF=AE=E6=94=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/helper/impl/RegionsCacheHelperImpl.java | 8 +-- .../hz/pm/api/projectlib/entity/QxPurchase.java | 3 - .../pm/api/projectlib/manage/QxProjectManage.java | 26 +++------ .../projectlib/model/req/QxPurchaseRecordReq.java | 4 -- .../pm/api/projectlib/model/vo/QxPurchaseVO.java | 3 - .../pm/api/user/controller/MhUnitController.java | 5 +- .../hz/pm/api/user/helper/MhUnitQueryHelper.java | 67 ++++++++++++++++++++++ .../com/hz/pm/api/user/manage/MhUnitManage.java | 30 ++++++++-- 8 files changed, 107 insertions(+), 39 deletions(-) create mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/user/helper/MhUnitQueryHelper.java diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/impl/RegionsCacheHelperImpl.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/impl/RegionsCacheHelperImpl.java index 789f84a..c704448 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/impl/RegionsCacheHelperImpl.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/helper/impl/RegionsCacheHelperImpl.java @@ -2,18 +2,18 @@ package com.hz.pm.api.common.helper.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.text.StrPool; -import com.hz.pm.api.sys.service.IRegionService; -import com.ningdatech.basic.exception.BizException; -import com.ningdatech.basic.util.CollUtils; -import com.hz.pm.api.common.model.constant.RegionConst; import com.hz.pm.api.common.helper.RegionCacheHelper; import com.hz.pm.api.common.helper.basic.AbstractRegionCacheHelper; import com.hz.pm.api.common.model.RegionMapKey; +import com.hz.pm.api.common.model.constant.RegionConst; import com.hz.pm.api.common.util.StrUtils; import com.hz.pm.api.sys.convert.RegionConverter; import com.hz.pm.api.sys.model.dto.RegionDTO; import com.hz.pm.api.sys.model.dto.RegionTreeDTO; import com.hz.pm.api.sys.model.vo.RegionTreeVO; +import com.hz.pm.api.sys.service.IRegionService; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.basic.util.CollUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxPurchase.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxPurchase.java index 3d86e34..e3da6ab 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxPurchase.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/QxPurchase.java @@ -34,9 +34,6 @@ public class QxPurchase { @ApiModelProperty("采购方式") private String purchaseMethod; - @ApiModelProperty("采购单位ID") - private Long purchaseUnitId; - @ApiModelProperty("采购单位名称") private String purchaseUnitName; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectManage.java index 46924ee..a77c6c4 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/QxProjectManage.java @@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.hz.pm.api.common.model.constant.MhUnitConst; +import com.hz.pm.api.common.util.BizUtils; import com.hz.pm.api.projectlib.entity.MhSystemReplaceInfo; import com.hz.pm.api.projectlib.entity.QxProject; import com.hz.pm.api.projectlib.entity.QxProjectSystemReplaceInfos; @@ -24,8 +24,8 @@ import com.hz.pm.api.projectlib.service.IMhSystemReplaceInfoService; import com.hz.pm.api.projectlib.service.IQxProjectService; import com.hz.pm.api.projectlib.service.IQxProjectSystemReplaceInfosService; import com.hz.pm.api.projectlib.service.IQxPurchaseService; -import com.hz.pm.api.user.helper.MhUnitCache; -import com.hz.pm.api.user.security.model.UserInfoDetails; +import com.hz.pm.api.user.helper.MhUnitQueryHelper; +import com.hz.pm.api.user.helper.MhUnitQueryHelper.UnitQueryState; import com.hz.pm.api.user.util.LoginUserUtil; import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.model.PageVo; @@ -51,7 +51,7 @@ import java.util.Map; @RequiredArgsConstructor public class QxProjectManage { - private final MhUnitCache mhUnitCache; + private final MhUnitQueryHelper unitQueryHelper; private final IQxProjectService qxProjectService; private final IMhSystemReplaceInfoService mhSystemReplaceInfoService; private final IQxProjectSystemReplaceInfosService qxProjectSystemReplaceInfosService; @@ -187,21 +187,11 @@ public class QxProjectManage { "select 1 from qx_project_system_replace_infos " + "where qx_project_system_replace_infos.project_id = qx_project.id " + "and replace_type = {0}", req.getReplaceType()); - UserInfoDetails userDetail = LoginUserUtil.loginUserDetail(); - if (req.getBuildOrgCode() != null) { - if (!userDetail.hasSuperAdmin()) { - List viewUnitIds = mhUnitCache.getViewChildIdsRecursion(userDetail.getMhUnitId()); - if (!viewUnitIds.contains(req.getBuildOrgCode())) { - return PageVo.empty(); - } - } - query.in(QxProject::getBuildOrgCode, mhUnitCache.getViewChildIdsRecursion(req.getBuildOrgCode())); - } else { - if (!LoginUserUtil.loginUserDetail().hasSuperAdmin() - && MhUnitConst.ROOT_UNIT_ID != userDetail.getMhUnitId()) { - query.in(QxProject::getBuildOrgCode, mhUnitCache.getViewChildIdsRecursion(userDetail.getMhUnitId())); - } + UnitQueryState unitQuery = unitQueryHelper.listCanViewUnitIds(req.getBuildOrgCode()); + if (!unitQuery.isState()) { + return PageVo.empty(); } + BizUtils.notEmpty(unitQuery.getUnitIds(), w -> query.in(QxProject::getBuildOrgCode, w)); Page page = qxProjectService.page(req.page(), query); return PageVo.of(BeanUtil.copyToList(page.getRecords(), QxProjectVO.class), page.getTotal()); } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/QxPurchaseRecordReq.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/QxPurchaseRecordReq.java index f1b0f79..a3929fe 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/QxPurchaseRecordReq.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/QxPurchaseRecordReq.java @@ -33,10 +33,6 @@ public class QxPurchaseRecordReq { @NotBlank(message = "采购方式不能为空") private String purchaseMethod; - @ApiModelProperty("采购单位ID") - @NotNull(message = "采购单位ID不能为空") - private Long purchaseUnitId; - @ApiModelProperty("采购单位名称") @NotBlank(message = "采购单位名称不能为空") private String purchaseUnitName; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/QxPurchaseVO.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/QxPurchaseVO.java index 4377c8a..b57e13b 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/QxPurchaseVO.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/QxPurchaseVO.java @@ -30,9 +30,6 @@ public class QxPurchaseVO { @ApiModelProperty("采购方式") private String purchaseMethod; - @ApiModelProperty("采购单位ID") - private Long purchaseUnitId; - @ApiModelProperty("采购单位名称") private String purchaseUnitName; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/user/controller/MhUnitController.java b/hz-pm-api/src/main/java/com/hz/pm/api/user/controller/MhUnitController.java index d6cf0ba..ddf577e 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/user/controller/MhUnitController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/user/controller/MhUnitController.java @@ -35,8 +35,9 @@ public class MhUnitController { @GetMapping("/tree") @ApiOperation("单位树") - public List getMhUnitTree(@RequestParam(required = false) String name) { - return mhUnitManage.getMhUnitTree(name); + public List getMhUnitTree(@RequestParam(required = false) String name, + @RequestParam(required = false) Long unitId) { + return mhUnitManage.getMhUnitTree(name, unitId); } @GetMapping("/wflowModelConfig/tree") diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/MhUnitQueryHelper.java b/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/MhUnitQueryHelper.java new file mode 100644 index 0000000..342be4e --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/user/helper/MhUnitQueryHelper.java @@ -0,0 +1,67 @@ +package com.hz.pm.api.user.helper; + +import com.hz.pm.api.common.model.constant.MhUnitConst; +import com.hz.pm.api.user.security.model.UserInfoDetails; +import com.hz.pm.api.user.util.LoginUserUtil; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + *

+ * MhUnitQueryHelper + *

+ * + * @author WendyYang + * @since 16:31 2024/8/31 + */ +@Component +@RequiredArgsConstructor +public class MhUnitQueryHelper { + + private final MhUnitCache unitCache; + + @Data + public static class UnitQueryState { + + private boolean state = true; + + private List unitIds; + + } + + /** + * 获取可查看的子部门ID列表 + * + * @param unitId 当前单位 + * @param user 用户信息 + * @return 可查看的子部门ID列表 + */ + public UnitQueryState listCanViewUnitIds(Long unitId, UserInfoDetails user) { + UnitQueryState state = new UnitQueryState(); + if (unitId == null) { + if (!user.hasSuperAdmin() && MhUnitConst.ROOT_UNIT_ID != user.getMhUnitId()) { + state.setUnitIds(unitCache.getViewChildIdsRecursion(user.getMhUnitId())); + } + } else { + if (!user.hasSuperAdmin() && !unitId.equals(user.getMhUnitId())) { + List unitIdPaths = unitCache.getUnitIdPaths(unitId); + if (!unitIdPaths.contains(user.getMhUnitId())) { + state.setState(false); + return state; + } + } + if (!unitId.equals(MhUnitConst.ROOT_UNIT_ID)) { + state.setUnitIds(unitCache.getViewChildIdsRecursion(unitId)); + } + } + return state; + } + + public UnitQueryState listCanViewUnitIds(Long unitId) { + return listCanViewUnitIds(unitId, LoginUserUtil.loginUserDetail()); + } + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/user/manage/MhUnitManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/user/manage/MhUnitManage.java index 5309e6c..c7c83f5 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/user/manage/MhUnitManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/user/manage/MhUnitManage.java @@ -2,7 +2,9 @@ package com.hz.pm.api.user.manage; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -55,13 +57,25 @@ public class MhUnitManage { private final MhUnitCache mhUnitCache; private final IUserInfoService userInfoService; - public List getMhUnitTree(String name) { + public List getMhUnitTree(String name, Long unitId) { List retUnits; List allUnits = mhUnitCache.all(); - if (StrUtils.isNotBlank(name)) { - allUnits.removeIf(w -> !w.getName().contains(name)); + if (StrUtil.isNotBlank(name) || unitId != null) { + if (StrUtil.isNotBlank(name)) { + allUnits.removeIf(w -> !w.getName().contains(name)); + } retUnits = allUnits.stream() - .map(w -> mhUnitCache.getUnitIdPaths(w.getId())) + .map(w -> { + List unitIdPaths = mhUnitCache.getUnitIdPaths(w.getId()); + if (unitId != null) { + if (!unitIdPaths.contains(unitId)) { + return null; + } + return unitIdPaths.subList(unitIdPaths.indexOf(unitId), unitIdPaths.size()); + } + return unitIdPaths; + }) + .filter(Objects::nonNull) .flatMap(Collection::stream) .distinct() .map(mhUnitCache::getById) @@ -78,7 +92,13 @@ public class MhUnitManage { node.setStrip(node.getType().getStrip()); return node; }).collect(Collectors.toList()); - return TreeUtil.convertToTree(nodes, unitRootParentId); + Long tmpRootParentId; + if (unitId != null) { + tmpRootParentId = mhUnitCache.getById(unitId).getParentId(); + } else { + tmpRootParentId = unitRootParentId; + } + return TreeUtil.convertToTree(nodes, tmpRootParentId); } public List getMhUnitStripTree() {