From 452e317ea65c928643280bf05619ef3209744c7b Mon Sep 17 00:00:00 2001 From: YUJT Date: Fri, 22 Apr 2022 14:08:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9E=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PowerAxisStructServiceImpl.java | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/axis/service/impl/PowerAxisStructServiceImpl.java b/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/axis/service/impl/PowerAxisStructServiceImpl.java index a898ae5..67f0ebe 100644 --- a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/axis/service/impl/PowerAxisStructServiceImpl.java +++ b/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/axis/service/impl/PowerAxisStructServiceImpl.java @@ -6,12 +6,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.TreeUtils; +import com.epmet.dto.CustomerAgencyDTO; +import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.plugin.power.dto.axis.PowerAxisStructDTO; import com.epmet.plugin.power.dto.axis.form.*; import com.epmet.plugin.power.dto.axis.result.*; @@ -40,6 +44,9 @@ import java.util.Map; @Service public class PowerAxisStructServiceImpl extends BaseServiceImpl implements PowerAxisStructService { + @Autowired + private GovOrgOpenFeignClient govOrgOpenFeignClient; + @Autowired private PowerAxisTagService powerAxisTagService; @@ -123,18 +130,72 @@ public class PowerAxisStructServiceImpl extends BaseServiceImpl NumConstant.ZERO) { + if (baseDao.queryCategory(form) > NumConstant.ZERO) { throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), StringUtils.EMPTY, "同一组织下只允许存在一个顶级节点"); } } - int x = baseDao.queryName(form); - if (x > NumConstant.ZERO) { + if (baseDao.queryName(form) > NumConstant.ZERO) { throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), StringUtils.EMPTY, "同一组织下不允许存在重名的节点"); } + + this.assembleStruct(form, loginUserUtil.getLoginUserCustomerId()); + baseDao.insert(form); } + /** + * 组装节点对象 + * + * @param struct 提交的表单 + * @param customerId 客户ID + * @return void + * @author work@yujt.net.cn + * @date 2022/4/22/0022 14:04 + */ + private void assembleStruct(PowerAxisStructEntity struct, String customerId) { + + struct.setCustomerId(customerId); + + // 上级节点 + String pid = struct.getPid(); + // 类别编码 + String categoryCode = struct.getCategoryCode(); + if (StringUtils.isBlank(pid)) { + // 查询类别编码对应的节点级别 + int structLevel = powerAxisTagService.selectStructLevelByCode(customerId, PowerTagCategoryEnum.STRUCT.category(), categoryCode); + if (PowerTagLevelEnum.ROOT.level() == structLevel) { + pid = NumConstant.ZERO_STR; + } else { + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), StringUtils.EMPTY, "请选择上级节点"); + } + } + String agencyId = struct.getAgencyId(); + if (NumConstant.ZERO_STR.equals(pid) && StringUtils.isBlank(agencyId)) { + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), StringUtils.EMPTY, "请选择绑定组织"); + } + if (NumConstant.ZERO_STR.equals(pid)) { + // 新增顶级节点 + Result agencyInfoResult = govOrgOpenFeignClient.getAgencyById(agencyId); + if (!agencyInfoResult.success()) { + throw new EpmetException(agencyInfoResult.getCode(), agencyInfoResult.getInternalMsg(), agencyInfoResult.getMsg()); + } + CustomerAgencyDTO agencyInfo = agencyInfoResult.getData(); + struct.setAgencyId(agencyInfo.getId()); + struct.setAgencyName(agencyInfo.getOrganizationName()); + struct.setAgencyType(agencyInfo.getLevel()); + } else { + // 新增一级节点或二级节点 + PowerAxisStructEntity parentStruct = baseDao.selectById(pid); + struct.setAgencyId(parentStruct.getAgencyId()); + struct.setAgencyName(parentStruct.getAgencyName()); + struct.setAgencyType(parentStruct.getAgencyType()); + // 新增二级节点,pids 为 一级节点的id;新增三级节点,pids为 一级节点的ID拼接二级节点的ID + String[] pids = NumConstant.ZERO_STR.equals(parentStruct.getPid()) + ? new String[]{parentStruct.getId()} : new String[]{parentStruct.getId(), parentStruct.getPid()}; + struct.setPids(StringUtils.join(pids, StrConstant.COLON)); + } + } + @Override public int modifyRog(PowerAxisStructEntity form) { if (form.getId().equals(form.getPid())) { @@ -152,6 +213,9 @@ public class PowerAxisStructServiceImpl extends BaseServiceImpl