|
|
@ -51,7 +51,6 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -133,9 +132,45 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result editAgency(EditAgencyFormDTO formDTO) { |
|
|
|
Result result = new Result(); |
|
|
|
CustomerAgencyEntity entity = getUpdateEntity(formDTO); |
|
|
|
CustomerAgencyEntity originalEntity = customerAgencyDao.selectById(formDTO.getAgencyId()); |
|
|
|
//当前客户下,同级组织中,组织名称不允许重复
|
|
|
|
customerAgencyService.checkAgencyName(formDTO.getAgencyName(),originalEntity.getCustomerId(),originalEntity.getLevel(),originalEntity.getId()); |
|
|
|
|
|
|
|
if (formDTO.getAreaCodeSwitch().equals(CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN)) { |
|
|
|
//开关开启,areaCode,areaName必填
|
|
|
|
if(!formDTO.getAreaCode().equals(originalEntity.getAreaCode())){ |
|
|
|
//重新选择了新的area_code
|
|
|
|
CustomerAgencyDTO parent = customerAgencyService.get(originalEntity.getPid()); |
|
|
|
if (null == parent ||StringUtils.isBlank(parent.getAreaCode())) { |
|
|
|
throw new RenException(EpmetErrorCode.SET_PARENT_AREA_CODE.getCode(),EpmetErrorCode.SET_PARENT_AREA_CODE.getMsg()); |
|
|
|
} |
|
|
|
originalEntity.setParentAreaCode(parent.getAreaCode()); |
|
|
|
if (!"other".equals(formDTO.getAreaCode())) { |
|
|
|
//校验areaCode是否被使用过
|
|
|
|
List<String> agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(formDTO.getAreaCode(),formDTO.getAgencyId()); |
|
|
|
if (CollectionUtils.isNotEmpty(agencyIds)) { |
|
|
|
//已经被占用,提示
|
|
|
|
throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg()); |
|
|
|
} |
|
|
|
originalEntity.setAreaCode(formDTO.getAreaCode()); |
|
|
|
}else{ |
|
|
|
//如果选择的是other,需要自定义一个编码
|
|
|
|
AddAreaCodeFormDTO addAreaCodeFormDTO = new AddAreaCodeFormDTO(); |
|
|
|
addAreaCodeFormDTO.setCurrentAreaLevel(originalEntity.getLevel()); |
|
|
|
addAreaCodeFormDTO.setParentAreaCode(parent.getAreaCode()); |
|
|
|
addAreaCodeFormDTO.setName(formDTO.getAgencyName()); |
|
|
|
Result<String> addAreaCodeResult = epmetCommonServiceOpenFeignClient.addAreaCode(addAreaCodeFormDTO); |
|
|
|
if (!addAreaCodeResult.success() || StringUtils.isBlank(addAreaCodeResult.getData())) { |
|
|
|
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); |
|
|
|
} |
|
|
|
originalEntity.setAreaCode(addAreaCodeResult.getData()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
originalEntity.setOrganizationName(formDTO.getAgencyName()); |
|
|
|
|
|
|
|
//1:更新当前组织信息
|
|
|
|
if (customerAgencyDao.updateById(entity) < NumConstant.ONE) { |
|
|
|
if (customerAgencyDao.updateById(originalEntity) < NumConstant.ONE) { |
|
|
|
log.error(CustomerAgencyConstant.UPDATE_EXCEPTION); |
|
|
|
throw new RenException(CustomerAgencyConstant.UPDATE_EXCEPTION); |
|
|
|
} |
|
|
@ -148,7 +183,6 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
} |
|
|
|
//3:循环组织列表,查询每一个组织的所有上级组织重新拼接所有上级名称(allParentName)字段值
|
|
|
|
List<CustomerAgencyEntity> editList = new ArrayList<>(); |
|
|
|
Date date = new Date(); |
|
|
|
agencyList.forEach(agency->{ |
|
|
|
//3-1:查询当前组织的所有上级组织
|
|
|
|
List<String> listStr = Arrays.asList(agency.getPids().split(":")); |
|
|
@ -178,12 +212,6 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private CustomerAgencyEntity getUpdateEntity(EditAgencyFormDTO formDTO) { |
|
|
|
CustomerAgencyEntity entity = customerAgencyDao.selectById(formDTO.getAgencyId()); |
|
|
|
entity.setOrganizationName(formDTO.getAgencyName()); |
|
|
|
return entity; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
@ -255,19 +283,19 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
if (null != entity && StringUtils.isNotBlank(entity.getAreaCode())) { |
|
|
|
switch (entity.getLevel()) { |
|
|
|
case CustomerAgencyConstant.PROVINCE_LEVEL: |
|
|
|
agencysResultDTO.setAreaName(entity.getProvince()); |
|
|
|
agencysResultDTO.setAreaName(null == entity.getProvince() ? StrConstant.EPMETY_STR : entity.getProvince()); |
|
|
|
break; |
|
|
|
case CustomerAgencyConstant.CITY_LEVEL: |
|
|
|
agencysResultDTO.setAreaName(entity.getCity()); |
|
|
|
agencysResultDTO.setAreaName(null == entity.getCity() ? StrConstant.EPMETY_STR : entity.getCity()); |
|
|
|
break; |
|
|
|
case CustomerAgencyConstant.DISTRICT: |
|
|
|
agencysResultDTO.setAreaName(entity.getDistrict()); |
|
|
|
agencysResultDTO.setAreaName(null == entity.getDistrict() ? StrConstant.EPMETY_STR : entity.getDistrict()); |
|
|
|
break; |
|
|
|
case CustomerAgencyConstant.STREET_LEVEL: |
|
|
|
agencysResultDTO.setAreaName(entity.getStreet()); |
|
|
|
agencysResultDTO.setAreaName(null == entity.getStreet() ? StrConstant.EPMETY_STR : entity.getStreet()); |
|
|
|
break; |
|
|
|
case CustomerAgencyConstant.COMMUNITY_LEVEL: |
|
|
|
agencysResultDTO.setAreaName(entity.getCommunity()); |
|
|
|
agencysResultDTO.setAreaName(null == entity.getCommunity() ? StrConstant.EPMETY_STR : entity.getCommunity()); |
|
|
|
break; |
|
|
|
default: |
|
|
|
agencysResultDTO.setAreaName(StrConstant.EPMETY_STR); |
|
|
@ -429,7 +457,7 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
public AddAgencyResultDTO addAgencyV2(AddAgencyV2FormDTO formDTO) { |
|
|
|
CustomerAgencyDTO parent = customerAgencyService.get(formDTO.getParentAgencyId()); |
|
|
|
if (null == parent) { |
|
|
|
throw new RenException(String.format("添加组织失败:没有找到跟组织信息,parentAgencyId=%s", formDTO.getParentAgencyId())); |
|
|
|
throw new RenException(String.format("添加组织失败:没有找到上级组织信息,agencyId=%s", formDTO.getParentAgencyId())); |
|
|
|
} |
|
|
|
AddAgencyResultDTO resultDTO = new AddAgencyResultDTO(); |
|
|
|
resultDTO.setAreaCodeSwitch(formDTO.getAreaCodeSwitch()); |
|
|
@ -438,7 +466,7 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { |
|
|
|
//校验areaCode是否被使用过
|
|
|
|
if (!"other".equals(formDTO.getAreaCode())) { |
|
|
|
List<String> agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(insertEntity.getAreaCode()); |
|
|
|
List<String> agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(insertEntity.getAreaCode(),null); |
|
|
|
if (CollectionUtils.isNotEmpty(agencyIds)) { |
|
|
|
//已经被占用,提示
|
|
|
|
throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg()); |
|
|
|