Browse Source

修改新增节点的逻辑

dev_power_axis
YUJT 4 years ago
parent
commit
452e317ea6
  1. 72
      epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/axis/service/impl/PowerAxisStructServiceImpl.java

72
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<PowerAxisStructDao, PowerAxisStructEntity> implements PowerAxisStructService {
@Autowired
private GovOrgOpenFeignClient govOrgOpenFeignClient;
@Autowired
private PowerAxisTagService powerAxisTagService;
@ -123,18 +130,72 @@ public class PowerAxisStructServiceImpl extends BaseServiceImpl<PowerAxisStructD
public void addOrg(PowerAxisStructEntity form) {
int structLevel = powerAxisTagService.selectStructLevelByCode(loginUserUtil.getLoginUserCustomerId(), PowerTagCategoryEnum.STRUCT.category(), form.getCategoryCode());
if (PowerTagLevelEnum.ROOT.level() == structLevel) {
int y = baseDao.queryCategory(form);
if (y > 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<CustomerAgencyDTO> 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<PowerAxisStructD
if (x != 0) {
return -3;
}
this.assembleStruct(form, loginUserUtil.getLoginUserCustomerId());
int i = baseDao.updateById(form);
return i;
}

Loading…
Cancel
Save