|
|
@@ -230,6 +230,38 @@ public class KwsEnterpriseService {
|
|
|
return kwsEntCertificate;
|
|
|
}
|
|
|
|
|
|
+ private void validateRegisterParentEnterprise(Long targetParentId, Long currentEntId) {
|
|
|
+ if (Objects.isNull(targetParentId) || targetParentId <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Objects.equals(targetParentId, currentEntId)) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, "上级企业不能为当前企业");
|
|
|
+ }
|
|
|
+
|
|
|
+ long childCount = kwsEnterpriseDao.selectCount(Wrappers.<KwsEnterprise>lambdaQuery()
|
|
|
+ .eq(BaseModel::getDelFlag, Global.NO)
|
|
|
+ .eq(KwsEnterprise::getPid, currentEntId));
|
|
|
+ if (childCount > 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, "当前企业存在下级企业,不能设置为其他企业的子级");
|
|
|
+ }
|
|
|
+
|
|
|
+ KwsEnterprise targetParent = kwsEnterpriseDao.selectByKey(targetParentId);
|
|
|
+ if (Objects.isNull(targetParent) || Objects.equals(targetParent.getDelFlag(), Global.YES)) {
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ENT_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ int parentLevel = getEnterpriseLevel(targetParent);
|
|
|
+ if (parentLevel + 1 > 2) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, "企业层级不能超过两级");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getEnterpriseLevel(KwsEnterprise enterprise) {
|
|
|
+ if (Objects.isNull(enterprise) || Objects.isNull(enterprise.getPid()) || enterprise.getPid() <= 0) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @param key 企业id
|
|
|
@@ -370,6 +402,7 @@ public class KwsEnterpriseService {
|
|
|
Long entId = kwsEnterprise.getId();
|
|
|
Date date = new Date();
|
|
|
Long userId = LoginUserHolder.getUserId();
|
|
|
+ validateRegisterParentEnterprise(reqVo.getEntPid(), entId);
|
|
|
kwsEnterprise.setCreditCode(reqVo.getOrgCode());//统一社会信用代码
|
|
|
kwsEnterprise.setCode(reqVo.getCode());
|
|
|
kwsEnterprise.setLegalName(reqVo.getLegalName());
|
|
|
@@ -377,7 +410,9 @@ public class KwsEnterpriseService {
|
|
|
kwsEnterprise.setHead(reqVo.getHead());
|
|
|
kwsEnterprise.setRegSource(LoginUserHolder.getClientType());
|
|
|
kwsEnterprise.setCityCode(reqVo.getCityCode());
|
|
|
- kwsEnterprise.setPid(reqVo.getEntPid());
|
|
|
+ if (Objects.nonNull(reqVo.getEntPid())) {
|
|
|
+ kwsEnterprise.setPid(reqVo.getEntPid());
|
|
|
+ }
|
|
|
SysArea sysArea = sysAreaDao.selectById(reqVo.getCityCode());
|
|
|
if (Objects.nonNull(sysArea)) {
|
|
|
kwsEnterprise.setCityName(sysArea.getMergerName());
|
|
|
@@ -1470,6 +1505,36 @@ public class KwsEnterpriseService {
|
|
|
return HttpResult.ok(enterprises);
|
|
|
}
|
|
|
|
|
|
+ public List<PlatformEnterpriseResVo> findPlatformEnterprise() {
|
|
|
+ List<KwsEnterprise> enterprises = kwsEnterpriseRepository.list(Wrappers.<KwsEnterprise>lambdaQuery()
|
|
|
+ .eq(BaseModel::getDelFlag, Global.UN_DELETED)
|
|
|
+ .eq(BaseModel::getStatus, Global.NO)
|
|
|
+ .orderByDesc(BaseModel::getCreateTime));
|
|
|
+ if (CollectionUtils.isEmpty(enterprises)) {
|
|
|
+ return List.of();
|
|
|
+ }
|
|
|
+
|
|
|
+// Set<Long> parentIds = enterprises.stream()
|
|
|
+// .map(KwsEnterprise::getPid)
|
|
|
+// .filter(Objects::nonNull)
|
|
|
+// .filter(pid -> pid > 0)
|
|
|
+// .collect(Collectors.toSet());
|
|
|
+// Map<Long, String> parentNameMap = CollectionUtils.isEmpty(parentIds) ? Collections.emptyMap()
|
|
|
+// : kwsEnterpriseRepository.list(Wrappers.<KwsEnterprise>lambdaQuery()
|
|
|
+// .in(KwsEnterprise::getId, parentIds)
|
|
|
+// .eq(BaseModel::getDelFlag, Global.UN_DELETED)
|
|
|
+// .eq(BaseModel::getStatus, Global.NO))
|
|
|
+// .stream()
|
|
|
+// .collect(Collectors.toMap(KwsEnterprise::getId, KwsEnterprise::getFirmName, (v1, v2) -> v1));
|
|
|
+
|
|
|
+ return enterprises.stream().map(item -> {
|
|
|
+ PlatformEnterpriseResVo vo = new PlatformEnterpriseResVo();
|
|
|
+ vo.setId(item.getId());
|
|
|
+ vo.setFirmName(item.getFirmName());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
public EntInfoResp queryEntInfo(EntInfoReq req) {
|
|
|
//如果是发起方是采购方,采购方只能是自己和下级,供应方可以选所有入住的供应企业
|
|
|
// 如果发起方是供应方,则供应方是能自己和下级,采购方可以是所有入住企业
|