|
@ -19,6 +19,7 @@ package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
@ -42,6 +43,7 @@ import com.epmet.dto.GovStaffRoleDTO; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.entity.CustomerAgencyEntity; |
|
|
import com.epmet.entity.CustomerAgencyEntity; |
|
|
|
|
|
import com.epmet.entity.CustomerDepartmentEntity; |
|
|
import com.epmet.entity.CustomerGridEntity; |
|
|
import com.epmet.entity.CustomerGridEntity; |
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
@ -62,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -155,57 +158,26 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
originalEntity.setCode(formDTO.getCode()); |
|
|
originalEntity.setCode(formDTO.getCode()); |
|
|
originalEntity.setContacts(formDTO.getContacts()); |
|
|
originalEntity.setContacts(formDTO.getContacts()); |
|
|
originalEntity.setMobile(formDTO.getMobile()); |
|
|
originalEntity.setMobile(formDTO.getMobile()); |
|
|
if (StringUtils.isNotBlank(originalEntity.getAreaCode()) |
|
|
|
|
|
&& originalEntity.getAreaCode().contains("UD") |
|
|
|
|
|
&& StringUtils.isNotBlank(formDTO.getAreaCode()) |
|
|
|
|
|
&& "other".equals(formDTO.getAreaCode())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "自定义编码不允许修改", "自定义组织区划代码不允许修改"); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isNotBlank(formDTO.getAreaCode()) && !formDTO.getAreaCode().equals(originalEntity.getAreaCode())) { |
|
|
|
|
|
CustomerAgencyEntity parent = customerAgencyDao.selectById(originalEntity.getPid()); |
|
|
|
|
|
//如果修改了areaCode。
|
|
|
|
|
|
if(StringUtils.isNotBlank(originalEntity.getAreaCode())){ |
|
|
|
|
|
//如果原来这个组织有area_code再去更新,没有其实应该按照pids去更新。
|
|
|
|
|
|
// customerAgencyDao.updateSubAgencyAreaCode(originalEntity.getCustomerId(), originalEntity.getAreaCode(), formDTO.getUserId());
|
|
|
|
|
|
customerAgencyDao.updateSubAgencyAreaCodeById(originalEntity.getCustomerId(), originalEntity.getId(), formDTO.getUserId()); |
|
|
|
|
|
//网格的
|
|
|
|
|
|
customerGridDao.updateSubGridAreaCode(originalEntity.getCustomerId(), originalEntity.getId(), formDTO.getUserId()); |
|
|
|
|
|
//部门的
|
|
|
|
|
|
customerDepartmentDao.updateSubDeptAreaCode(originalEntity.getCustomerId(), originalEntity.getAreaCode(), formDTO.getUserId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断areaCodeSwitch:open: 选择地区编码必填;closed: 无需选择地区编码
|
|
|
//当前客户开启了area_code_switch参数:open: 选择地区编码必填;closed: 无需选择地区编码
|
|
|
if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { |
|
|
if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { |
|
|
//校验areaCode是否被使用过
|
|
|
//开关开启后,areaCode必填
|
|
|
if (!"other".equals(formDTO.getAreaCode())) { |
|
|
String originalAreaCode =originalEntity.getAreaCode(); |
|
|
List<String> agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(formDTO.getAreaCode(),formDTO.getAgencyId()); |
|
|
checkEditAgencyFormDTO(formDTO,originalAreaCode); |
|
|
if (CollectionUtils.isNotEmpty(agencyIds)) { |
|
|
// 1、之前当前组织没有编码,本次修改设置了编码
|
|
|
//已经被占用,提示
|
|
|
// 2、之前已经有编码,本次修改为了其他编码
|
|
|
throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg()); |
|
|
if (StringUtils.isNotBlank(formDTO.getAreaCode()) && !formDTO.getAreaCode().equals(originalAreaCode)) { |
|
|
} |
|
|
CustomerAgencyEntity parent = customerAgencyDao.selectById(originalEntity.getPid()); |
|
|
originalEntity.setAreaCode(formDTO.getAreaCode()); |
|
|
String newAreaCode=getAgencyNewAreaCode(formDTO,parent); |
|
|
originalEntity.setParentAreaCode(parent.getAreaCode()); |
|
|
originalEntity.setAreaCode(newAreaCode); |
|
|
}else{ |
|
|
|
|
|
//如果选择的是other,需要自定义一个编码
|
|
|
|
|
|
AddAreaCodeFormDTO addAreaCodeFormDTO = new AddAreaCodeFormDTO(); |
|
|
|
|
|
addAreaCodeFormDTO.setCurrentAreaLevel(formDTO.getLevel()); |
|
|
|
|
|
addAreaCodeFormDTO.setParentAreaCode(parent.getAreaCode()); |
|
|
|
|
|
addAreaCodeFormDTO.setName(formDTO.getAgencyName()); |
|
|
|
|
|
Result<String> addAreaCodeResult = epmetCommonServiceOpenFeignClient.addAreaCode(addAreaCodeFormDTO); |
|
|
|
|
|
if (!addAreaCodeResult.success() || StringUtils.isBlank(addAreaCodeResult.getData())) { |
|
|
|
|
|
if (addAreaCodeResult.getCode() > 8000) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "自定义area_code异常" + addAreaCodeResult.getMsg()); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
originalEntity.setAreaCode(addAreaCodeResult.getData()); |
|
|
|
|
|
originalEntity.setParentAreaCode(parent.getAreaCode()); |
|
|
originalEntity.setParentAreaCode(parent.getAreaCode()); |
|
|
|
|
|
formDTO.setAreaCode(newAreaCode); |
|
|
} |
|
|
} |
|
|
|
|
|
//什么时候要全部置为空呢?原来没有现在有 || 原来与现在不一致
|
|
|
|
|
|
if ((StringUtils.isBlank(originalAreaCode) && StringUtils.isNotBlank(formDTO.getAreaCode())) |
|
|
|
|
|
|| (!formDTO.getAreaCode().equals(originalAreaCode))) { |
|
|
|
|
|
updateSubOrg(originalEntity.getCustomerId(),formDTO,originalAreaCode); |
|
|
} |
|
|
} |
|
|
//更新直属部门和直属网格的areaCode
|
|
|
|
|
|
customerGridDao.updateGridAreaCode(originalEntity.getId(),formDTO.getAreaCode(),formDTO.getUserId()); |
|
|
|
|
|
customerDepartmentDao.updateDeptAreaCode(originalEntity.getId(),formDTO.getAreaCode(),formDTO.getUserId()); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//1:更新当前组织信息
|
|
|
//1:更新当前组织信息
|
|
@ -252,6 +224,104 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 所有下家组织、网格、部门的area_code,parent_area_code置为空 |
|
|
|
|
|
* 直属组织parent_area_code、直属网格+直属部门的area_code更新为最新值 |
|
|
|
|
|
* @param customerId |
|
|
|
|
|
* @param formDTO |
|
|
|
|
|
* @param originalAreaCode |
|
|
|
|
|
*/ |
|
|
|
|
|
private void updateSubOrg(String customerId, EditAgencyFormDTO formDTO,String originalAreaCode) { |
|
|
|
|
|
//如果原来这个组织有area_code再去更新,没有其实应该按照pids去更新。
|
|
|
|
|
|
customerAgencyDao.updateSubAgencyAreaCodeById(customerId, formDTO.getAgencyId(), formDTO.getUserId()); |
|
|
|
|
|
//网格的
|
|
|
|
|
|
customerGridDao.updateSubGridAreaCode(customerId, formDTO.getAgencyId(), formDTO.getUserId()); |
|
|
|
|
|
//部门的
|
|
|
|
|
|
customerDepartmentDao.updateSubDeptAreaCode(customerId, originalAreaCode, formDTO.getUserId()); |
|
|
|
|
|
|
|
|
|
|
|
//1、更新直属网格的areaCode
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerGridEntity> updateGridWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateGridWrapper.eq(CustomerGridEntity::getPid,formDTO.getAgencyId()) |
|
|
|
|
|
.set(CustomerGridEntity::getAreaCode, formDTO.getAreaCode()) |
|
|
|
|
|
.set(CustomerGridEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerGridEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
int subGridRows=customerGridDao.update(null,updateGridWrapper); |
|
|
|
|
|
log.info(String.format("更新了%s个直属网格的area_code",subGridRows)); |
|
|
|
|
|
|
|
|
|
|
|
// 2、更新直属部门的area_code
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerDepartmentEntity> updateDeptWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateDeptWrapper.eq(CustomerDepartmentEntity::getAgencyId,formDTO.getAgencyId()) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getAreaCode, formDTO.getAreaCode()) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
int gridRows=customerDepartmentDao.update(null,updateDeptWrapper); |
|
|
|
|
|
log.info(String.format("更新了%s个直属部门的area_code",gridRows)); |
|
|
|
|
|
|
|
|
|
|
|
// 3、更新下级组织的parent_area_code
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerAgencyEntity> updateAgencyWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateAgencyWrapper.eq(CustomerAgencyEntity::getPid,formDTO.getAgencyId()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getParentAreaCode, formDTO.getAreaCode()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
Integer rows = customerAgencyDao.update(null, updateAgencyWrapper); |
|
|
|
|
|
log.info(String.format("更新了%s个下级组织的parent_area_code",rows)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param formDTO 编辑组织入参 |
|
|
|
|
|
* @param parent 当前编辑组织的上级组织 |
|
|
|
|
|
* @return 返回组织区划编码 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getAgencyNewAreaCode(EditAgencyFormDTO formDTO, CustomerAgencyEntity parent) { |
|
|
|
|
|
String newAreaCode=""; |
|
|
|
|
|
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()); |
|
|
|
|
|
} |
|
|
|
|
|
newAreaCode=formDTO.getAreaCode(); |
|
|
|
|
|
} else { |
|
|
|
|
|
//如果选择的是other,需要自定义一个编码
|
|
|
|
|
|
AddAreaCodeFormDTO addAreaCodeFormDTO = new AddAreaCodeFormDTO(); |
|
|
|
|
|
addAreaCodeFormDTO.setCurrentAreaLevel(formDTO.getLevel()); |
|
|
|
|
|
addAreaCodeFormDTO.setParentAreaCode(parent.getAreaCode()); |
|
|
|
|
|
addAreaCodeFormDTO.setName(formDTO.getAgencyName()); |
|
|
|
|
|
Result<String> addAreaCodeResult = epmetCommonServiceOpenFeignClient.addAreaCode(addAreaCodeFormDTO); |
|
|
|
|
|
if (!addAreaCodeResult.success() || StringUtils.isBlank(addAreaCodeResult.getData())) { |
|
|
|
|
|
if (addAreaCodeResult.getCode() > 8000) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "自定义area_code异常" + addAreaCodeResult.getInternalMsg(), addAreaCodeResult.getMsg()); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
newAreaCode=addAreaCodeResult.getData(); |
|
|
|
|
|
} |
|
|
|
|
|
return newAreaCode; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 如果当前客户开启了areaCode,校验参数逼单 |
|
|
|
|
|
* @param formDTO |
|
|
|
|
|
*/ |
|
|
|
|
|
private void checkEditAgencyFormDTO(EditAgencyFormDTO formDTO,String originalAreaCode) { |
|
|
|
|
|
if (StringUtils.isBlank(formDTO.getAreaCode())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "area_code_switch is open areaCode不能为空", "组织区划不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.isBlank(formDTO.getParentAreaCode())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "area_code_switch is open parentAreaCode不能为空", "请先设置上级组织的组织区划"); |
|
|
|
|
|
} |
|
|
|
|
|
//如果当前组织已经使用了自定义编码,不允许在选择其他。
|
|
|
|
|
|
if (StringUtils.isNotBlank(originalAreaCode) |
|
|
|
|
|
&& originalAreaCode.contains("UD") |
|
|
|
|
|
&& StringUtils.isNotBlank(formDTO.getAreaCode()) |
|
|
|
|
|
&& "other".equals(formDTO.getAreaCode())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "自定义编码不允许修改", "自定义组织区划代码不允许修改"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param formDTO |
|
|
* @param formDTO |
|
|
* @return |
|
|
* @return |
|
@ -546,8 +616,12 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
addAreaCodeFormDTO.setName(formDTO.getAgencyName()); |
|
|
addAreaCodeFormDTO.setName(formDTO.getAgencyName()); |
|
|
Result<String> addAreaCodeResult = epmetCommonServiceOpenFeignClient.addAreaCode(addAreaCodeFormDTO); |
|
|
Result<String> addAreaCodeResult = epmetCommonServiceOpenFeignClient.addAreaCode(addAreaCodeFormDTO); |
|
|
if (!addAreaCodeResult.success() || StringUtils.isBlank(addAreaCodeResult.getData())) { |
|
|
if (!addAreaCodeResult.success() || StringUtils.isBlank(addAreaCodeResult.getData())) { |
|
|
|
|
|
if (addAreaCodeResult.getCode() > 8000) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "自定义area_code异常" + addAreaCodeResult.getInternalMsg(), addAreaCodeResult.getMsg()); |
|
|
|
|
|
} else { |
|
|
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); |
|
|
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
insertEntity.setAreaCode(addAreaCodeResult.getData()); |
|
|
insertEntity.setAreaCode(addAreaCodeResult.getData()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|