|
@ -18,11 +18,14 @@ |
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
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.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
@ -36,13 +39,17 @@ import com.epmet.dto.*; |
|
|
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.entity.CustomerOrgParameterEntity; |
|
|
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.OperCrmFeignClient; |
|
|
import com.epmet.feign.OperCrmFeignClient; |
|
|
import com.epmet.redis.CustomerAgencyRedis; |
|
|
import com.epmet.redis.CustomerAgencyRedis; |
|
|
import com.epmet.service.CustomerAgencyService; |
|
|
import com.epmet.service.CustomerAgencyService; |
|
|
import com.epmet.util.ModuleConstant; |
|
|
import com.epmet.util.ModuleConstant; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
@ -62,6 +69,7 @@ import java.util.stream.Collectors; |
|
|
* @author generator generator@elink-cn.com |
|
|
* @author generator generator@elink-cn.com |
|
|
* @since v1.0.0 2020-04-20 |
|
|
* @since v1.0.0 2020-04-20 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao, CustomerAgencyEntity> implements CustomerAgencyService { |
|
|
public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao, CustomerAgencyEntity> implements CustomerAgencyService { |
|
|
|
|
|
|
|
@ -86,6 +94,11 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao |
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private RedisUtils redisUtils; |
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private CustomerOrgParameterDao customerOrgParameterDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageData<CustomerAgencyDTO> page(Map<String, Object> params) { |
|
|
public PageData<CustomerAgencyDTO> page(Map<String, Object> params) { |
|
@ -1220,4 +1233,140 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao |
|
|
return baseDao.getAgencyMobile(gridId); |
|
|
return baseDao.getAgencyMobile(gridId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 运营端-客户管理,修改客户信息,调用gov-org服务,修改组织区划开关,修改根组织areaCode入参。 |
|
|
|
|
|
* |
|
|
|
|
|
* @param formDTO |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
@Override |
|
|
|
|
|
public void configCustomerAreaCode(CustomerAreaCodeFormDTO formDTO) { |
|
|
|
|
|
//1、设置开关
|
|
|
|
|
|
CustomerOrgParameterEntity switchEntity = customerOrgParameterDao.selectByCustomerId(formDTO.getCustomerId(), CustomerAgencyConstant.AREA_CODE_SWITCH); |
|
|
|
|
|
if (null != switchEntity) { |
|
|
|
|
|
switchEntity.setParameterValue(formDTO.getAreaCodeSwitch()); |
|
|
|
|
|
customerOrgParameterDao.updateById(switchEntity); |
|
|
|
|
|
} else { |
|
|
|
|
|
CustomerOrgParameterEntity insert=new CustomerOrgParameterEntity(); |
|
|
|
|
|
insert.setCustomerId(formDTO.getCustomerId()); |
|
|
|
|
|
insert.setParameterKey(CustomerAgencyConstant.AREA_CODE_SWITCH); |
|
|
|
|
|
insert.setParameterValue(formDTO.getAreaCodeSwitch()); |
|
|
|
|
|
insert.setParameterName("是否开启区域编码"); |
|
|
|
|
|
insert.setDescription("open:当前客户新增组织需要选择areaCode;closed: 无需选择区域编码"); |
|
|
|
|
|
customerOrgParameterDao.insert(insert); |
|
|
|
|
|
} |
|
|
|
|
|
if(CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())){ |
|
|
|
|
|
//开关开启,并且修改了组织区划才会调用
|
|
|
|
|
|
CustomerAgencyEntity root=baseDao.selectById(formDTO.getRootAgencyId()); |
|
|
|
|
|
String originalAreaCode=root.getAreaCode(); |
|
|
|
|
|
//areaCode做了修改
|
|
|
|
|
|
if(!formDTO.getRootAgencyAreaCode().equals(originalAreaCode)){ |
|
|
|
|
|
log.warn("组织区划开关打开, 并且当前传入的areaCode与之前的不一致,所以要进行update操作"); |
|
|
|
|
|
String newAreaCode=getAgencyNewAreaCode(root.getId(),root.getOrganizationName(),root.getLevel(),formDTO.getRootAgencyAreaCode(),formDTO.getRootAgencyParentCode()); |
|
|
|
|
|
|
|
|
|
|
|
//1、更新根组织的area_code、
|
|
|
|
|
|
root.setAreaCode(newAreaCode); |
|
|
|
|
|
root.setParentAreaCode(formDTO.getRootAgencyParentCode()); |
|
|
|
|
|
baseDao.updateById(root); |
|
|
|
|
|
|
|
|
|
|
|
//2、直属下级的parent_areaCode赋值、areaCode(置空)
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerAgencyEntity> updateAgencyWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateAgencyWrapper.eq(CustomerAgencyEntity::getPid,root.getId()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getParentAreaCode,newAreaCode) |
|
|
|
|
|
.set(CustomerAgencyEntity::getAreaCode, StrConstant.EPMETY_STR) |
|
|
|
|
|
.set(CustomerAgencyEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
Integer rows = baseDao.update(null, updateAgencyWrapper); |
|
|
|
|
|
log.info(String.format("更新了%s个下级组织的parent_area_code",rows)); |
|
|
|
|
|
|
|
|
|
|
|
// 3、直属网格
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerGridEntity> updateGridWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateGridWrapper.eq(CustomerGridEntity::getPid,root.getId()) |
|
|
|
|
|
.set(CustomerGridEntity::getAreaCode, newAreaCode) |
|
|
|
|
|
.set(CustomerGridEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerGridEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
int subGridRows=customerGridDao.update(null,updateGridWrapper); |
|
|
|
|
|
log.info(String.format("更新了%s个直属网格的area_code",subGridRows)); |
|
|
|
|
|
|
|
|
|
|
|
// 4、直属部门
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerDepartmentEntity> updateDeptWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateDeptWrapper.eq(CustomerDepartmentEntity::getAgencyId,root.getId()) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getAreaCode, newAreaCode) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
int gridRows=customerDepartmentDao.update(null,updateDeptWrapper); |
|
|
|
|
|
log.info(String.format("更新了%s个直属部门的area_code",gridRows)); |
|
|
|
|
|
|
|
|
|
|
|
//5、非直属下级组织,统一置为空
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerAgencyEntity> agencyWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
agencyWrapper.ne(CustomerAgencyEntity::getPid,root.getId()) |
|
|
|
|
|
.like(CustomerAgencyEntity::getPids,root.getId()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getParentAreaCode,StrConstant.EPMETY_STR) |
|
|
|
|
|
.set(CustomerAgencyEntity::getAreaCode, StrConstant.EPMETY_STR) |
|
|
|
|
|
.set(CustomerAgencyEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerAgencyEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
baseDao.update(null, agencyWrapper); |
|
|
|
|
|
|
|
|
|
|
|
//6、非直属网格
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerGridEntity> gridWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
gridWrapper.ne(CustomerGridEntity::getPid,root.getId()) |
|
|
|
|
|
.like(CustomerGridEntity::getPids,root.getId()) |
|
|
|
|
|
.set(CustomerGridEntity::getAreaCode, StrConstant.EPMETY_STR) |
|
|
|
|
|
.set(CustomerGridEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerGridEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
customerGridDao.update(null,gridWrapper); |
|
|
|
|
|
|
|
|
|
|
|
//7、非直属部门的
|
|
|
|
|
|
LambdaUpdateWrapper<CustomerDepartmentEntity> deptWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
deptWrapper.ne(CustomerDepartmentEntity::getAgencyId,root.getId()) |
|
|
|
|
|
.like(CustomerDepartmentEntity::getAreaCode,originalAreaCode) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getAreaCode, StrConstant.EPMETY_STR) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getUpdatedBy,formDTO.getUserId()) |
|
|
|
|
|
.set(CustomerDepartmentEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
customerDepartmentDao.update(null,deptWrapper); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param agencyId |
|
|
|
|
|
* @param agencyName |
|
|
|
|
|
* @param level 社区级:community,乡(镇、街道)级:street,区县级: district,市级: city省级:province |
|
|
|
|
|
* @param areaCode |
|
|
|
|
|
* @param parentArenCode |
|
|
|
|
|
* @return 返回组织区划编码 |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
private String getAgencyNewAreaCode(String agencyId, String agencyName, String level,String areaCode, String parentArenCode) { |
|
|
|
|
|
String newAreaCode=""; |
|
|
|
|
|
if (!"other".equals(areaCode)) { |
|
|
|
|
|
//校验除了当前组织外,areaCode是否被使用过
|
|
|
|
|
|
List<String> agencyIds = baseDao.selectAgencyIdsByAreaCode(areaCode, agencyId); |
|
|
|
|
|
if (CollectionUtils.isNotEmpty(agencyIds)) { |
|
|
|
|
|
//已经被占用,提示
|
|
|
|
|
|
throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
newAreaCode=areaCode; |
|
|
|
|
|
} else { |
|
|
|
|
|
//如果选择的是other,需要自定义一个编码
|
|
|
|
|
|
AddAreaCodeFormDTO addAreaCodeFormDTO = new AddAreaCodeFormDTO(); |
|
|
|
|
|
addAreaCodeFormDTO.setCurrentAreaLevel(level); |
|
|
|
|
|
addAreaCodeFormDTO.setParentAreaCode(parentArenCode); |
|
|
|
|
|
addAreaCodeFormDTO.setName(agencyName); |
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|