|
|
@ -19,10 +19,12 @@ package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
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.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
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.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
@ -33,6 +35,7 @@ import com.epmet.constant.CustomerAgencyConstant; |
|
|
|
import com.epmet.constant.OrgInfoConstant; |
|
|
|
import com.epmet.constant.RoleKeyConstants; |
|
|
|
import com.epmet.dao.CustomerAgencyDao; |
|
|
|
import com.epmet.dao.CustomerDepartmentDao; |
|
|
|
import com.epmet.dao.CustomerGridDao; |
|
|
|
import com.epmet.dao.IcBuildingDao; |
|
|
|
import com.epmet.dto.CustomerAgencyDTO; |
|
|
@ -40,6 +43,7 @@ import com.epmet.dto.GovStaffRoleDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.CustomerAgencyEntity; |
|
|
|
import com.epmet.entity.CustomerDepartmentEntity; |
|
|
|
import com.epmet.entity.CustomerGridEntity; |
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
|
@ -60,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -93,7 +98,8 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private IcBuildingDao icBuildingDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerDepartmentDao customerDepartmentDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
@ -152,31 +158,26 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
originalEntity.setCode(formDTO.getCode()); |
|
|
|
originalEntity.setContacts(formDTO.getContacts()); |
|
|
|
originalEntity.setMobile(formDTO.getMobile()); |
|
|
|
if (StringUtils.isNotBlank(formDTO.getAreaCode()) && !formDTO.getAreaCode().equals(originalEntity.getAreaCode())) { |
|
|
|
//如果修改了areaCode。
|
|
|
|
customerAgencyDao.updateSubAgencyAreaCode(originalEntity.getCustomerId(), originalEntity.getAreaCode(), formDTO.getUserId()); |
|
|
|
|
|
|
|
//判断areaCodeSwitch:open: 选择地区编码必填;closed: 无需选择地区编码
|
|
|
|
if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { |
|
|
|
//校验areaCode是否被使用过
|
|
|
|
if (!"other".equals(formDTO.getAreaCode())) { |
|
|
|
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(formDTO.getLevel()); |
|
|
|
addAreaCodeFormDTO.setParentAreaCode(formDTO.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()); |
|
|
|
|
|
|
|
//当前客户开启了area_code_switch参数:open: 选择地区编码必填;closed: 无需选择地区编码
|
|
|
|
if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { |
|
|
|
CustomerAgencyEntity parent = customerAgencyDao.selectById(originalEntity.getPid()); |
|
|
|
if (null != parent) { |
|
|
|
//开关开启后,areaCode必填
|
|
|
|
String originalAreaCode = originalEntity.getAreaCode(); |
|
|
|
checkEditAgencyFormDTO(formDTO, originalEntity); |
|
|
|
// 1、之前当前组织没有编码,本次修改设置了编码
|
|
|
|
// 2、之前已经有编码,本次修改为了其他编码
|
|
|
|
if (StringUtils.isNotBlank(formDTO.getAreaCode()) && !formDTO.getAreaCode().equals(originalAreaCode)) { |
|
|
|
String newAreaCode = getAgencyNewAreaCode(formDTO, parent); |
|
|
|
originalEntity.setAreaCode(newAreaCode); |
|
|
|
originalEntity.setParentAreaCode(parent.getAreaCode()); |
|
|
|
formDTO.setAreaCode(newAreaCode); |
|
|
|
} |
|
|
|
//什么时候要全部置为空呢?原来没有现在有 || 原来与现在不一致
|
|
|
|
if ((StringUtils.isBlank(originalAreaCode) && StringUtils.isNotBlank(formDTO.getAreaCode())) |
|
|
|
|| (!formDTO.getAreaCode().equals(originalAreaCode))) { |
|
|
|
updateSubOrg(originalEntity.getCustomerId(), formDTO, originalAreaCode); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -225,6 +226,107 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
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,CustomerAgencyEntity originalEntity) { |
|
|
|
//根组织不允许修改
|
|
|
|
if (StringUtils.isNotBlank(originalEntity.getPid()) && !NumConstant.ZERO_STR.equals(originalEntity.getPid())) { |
|
|
|
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(originalEntity.getAreaCode()) |
|
|
|
&& originalEntity.getAreaCode().contains("UD") |
|
|
|
&& StringUtils.isNotBlank(formDTO.getAreaCode()) |
|
|
|
&& "other".equals(formDTO.getAreaCode())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "自定义编码不允许修改", "自定义组织区划代码不允许修改"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
@ -287,27 +389,6 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
agencysResultDTO.setCode(entity.getCode()); |
|
|
|
agencysResultDTO.setContacts(entity.getContacts()); |
|
|
|
agencysResultDTO.setMobile(entity.getMobile()); |
|
|
|
//2021.5.26 sun 添加当前组织对应客户的根组织级别返参 start
|
|
|
|
if (null != entity) { |
|
|
|
if (null == entity.getPids() || "".equals(entity.getPids())) { |
|
|
|
agencysResultDTO.setRootlevel(entity.getLevel()); |
|
|
|
} else { |
|
|
|
String id = Arrays.asList(entity.getPids().split(":")).get(0); |
|
|
|
CustomerAgencyEntity rootEntity = customerAgencyDao.selectById(id); |
|
|
|
if (null != rootEntity) { |
|
|
|
agencysResultDTO.setRootlevel(rootEntity.getLevel()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//2021.5.26 sun 添加当前组织对应客户的根组织级别返参 end
|
|
|
|
//2:查询本机关的所有上级机关,按自上而下层级顺序
|
|
|
|
if (null == entity.getPids()) { |
|
|
|
agencysResultDTO.setParentList(parentList); |
|
|
|
return new Result<AgencysResultDTO>().ok(agencysResultDTO); |
|
|
|
} |
|
|
|
List<String> listStr = Arrays.asList(entity.getPids().split(":")); |
|
|
|
parentList = customerAgencyDao.selectPAgencyById(listStr); |
|
|
|
agencysResultDTO.setParentList(parentList); |
|
|
|
agencysResultDTO.setAreaCodeSwitch(customerOrgParameterService.getAreaCodeSwitch(entity.getCustomerId())); |
|
|
|
agencysResultDTO.setAreaName(StrConstant.EPMETY_STR); |
|
|
|
agencysResultDTO.setAreaCode(StringUtils.isNotBlank(entity.getAreaCode())?entity.getAreaCode():StrConstant.EPMETY_STR); |
|
|
@ -333,13 +414,30 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
agencysResultDTO.setAreaName(StrConstant.EPMETY_STR); |
|
|
|
} |
|
|
|
} |
|
|
|
//2021.5.26 sun 添加当前组织对应客户的根组织级别返参 start
|
|
|
|
if (null != entity) { |
|
|
|
if (null == entity.getPids() || "".equals(entity.getPids())) { |
|
|
|
agencysResultDTO.setRootlevel(entity.getLevel()); |
|
|
|
} else { |
|
|
|
String id = Arrays.asList(entity.getPids().split(":")).get(0); |
|
|
|
CustomerAgencyEntity rootEntity = customerAgencyDao.selectById(id); |
|
|
|
if (null != rootEntity) { |
|
|
|
agencysResultDTO.setRootlevel(rootEntity.getLevel()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//2021.5.26 sun 添加当前组织对应客户的根组织级别返参 end
|
|
|
|
//2:查询本机关的所有上级机关,按自上而下层级顺序
|
|
|
|
if (StringUtils.isBlank(entity.getPids())) { |
|
|
|
agencysResultDTO.setParentList(parentList); |
|
|
|
return new Result<AgencysResultDTO>().ok(agencysResultDTO); |
|
|
|
} |
|
|
|
List<String> listStr = Arrays.asList(entity.getPids().split(":")); |
|
|
|
parentList = customerAgencyDao.selectPAgencyById(listStr); |
|
|
|
agencysResultDTO.setParentList(parentList); |
|
|
|
return new Result<AgencysResultDTO>().ok(agencysResultDTO); |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
String m="1234"; |
|
|
|
System.out.println(m.equals("1234") ? "yes" : "no"); |
|
|
|
} |
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
@ -519,7 +617,11 @@ public class AgencyServiceImpl implements AgencyService { |
|
|
|
addAreaCodeFormDTO.setName(formDTO.getAgencyName()); |
|
|
|
Result<String> addAreaCodeResult = epmetCommonServiceOpenFeignClient.addAreaCode(addAreaCodeFormDTO); |
|
|
|
if (!addAreaCodeResult.success() || StringUtils.isBlank(addAreaCodeResult.getData())) { |
|
|
|
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); |
|
|
|
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()); |
|
|
|
} |
|
|
|
} |
|
|
|
insertEntity.setAreaCode(addAreaCodeResult.getData()); |
|
|
|
} |
|
|
|