Browse Source

新增组织V2接口提交

dev_shibei_match
yinzuomei 4 years ago
parent
commit
9df85e7e4a
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  2. 27
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/AddAreaCodeFormDTO.java
  3. 10
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
  4. 12
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java
  5. 4
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/constant/AreaCodeConstant.java
  6. 14
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/AreaCodeController.java
  7. 4
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/AreaCodeDao.java
  8. 10
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/AreaCodeService.java
  9. 70
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java
  10. 16
      epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/AreaCodeDao.xml
  11. 86
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyV2FormDTO.java
  12. 14
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AddAgencyResultDTO.java
  13. 6
      epmet-module/gov-org/gov-org-server/pom.xml
  14. 22
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java
  15. 2
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java
  16. 9
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java
  17. 2
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java
  18. 63
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java
  19. 12
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java
  20. 4
      epmet-module/gov-org/gov-org-server/src/main/resources/logback-spring.xml
  21. 10
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java

@ -70,6 +70,8 @@ public enum EpmetErrorCode {
NOT_DEL_AGENCY_PER(8205, "该机关存在工作人员,不允许删除"),
NOT_DEL_DEPARTMENT(8206, "该部门存在工作人员,不允许删除"),
NOT_DEL_AGENCY_GRID(8207, "该机关存在网格,不允许删除"),
AREA_CODE_ALREADY_EXISTS(8208,"组织区划已被占用,请重新选择"),
AGENCY_NAME_ALREADY_EXISTS(8209,"您当前的组织名称已存在,请重新修改"),
REQUIRE_PERMISSION(8301, "您没有足够的操作权限"),
THIRD_PLAT_REQUEST_ERROR(8302, "请求第三方平台错误"),

27
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/AddAreaCodeFormDTO.java

@ -0,0 +1,27 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 描述一下
*
* @author yinzuomei@elink-cn.com
* @date 2021/4/13 14:36
*/
@Data
public class AddAreaCodeFormDTO implements Serializable {
@NotBlank(message = "currentAreaLevel不能为空")
private String currentAreaLevel;
@NotBlank(message = "parentAreaCode不能为空")
private String parentAreaCode;
/**
* 新增的街道或者社区名称
*/
@NotBlank(message = "name不能为空")
private String name;
}

10
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java

@ -113,4 +113,14 @@ public interface EpmetCommonServiceOpenFeignClient {
**/
@PostMapping(value = "commonservice/areacode/addstreetcommareacode", consumes = MediaType.APPLICATION_JSON_VALUE)
Result<String> addStreetCommAreaCode(@RequestBody AddAreaCodeDictFormDTO formDTO);
/**
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.lang.String>
* @author yinzuomei
* @description 自定义行政地区编码
* @Date 2021/4/13 14:31
**/
@PostMapping(value = "commonservice/areacode/addareacode", consumes = MediaType.APPLICATION_JSON_VALUE)
Result<String> addAreaCode(AddAreaCodeFormDTO formDTO);
}

12
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java

@ -89,4 +89,16 @@ public class EpmetCommonServiceOpenFeignClientFallback implements EpmetCommonSer
public Result<String> addStreetCommAreaCode(AddAreaCodeDictFormDTO formDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "addStreetCommAreaCode", formDTO);
}
/**
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.lang.String>
* @author yinzuomei
* @description 自定义行政地区编码
* @Date 2021/4/13 14:31
**/
@Override
public Result<String> addAreaCode(AddAreaCodeFormDTO formDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "addAreaCode", formDTO);
}
}

4
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/constant/AreaCodeConstant.java

@ -26,4 +26,8 @@ public interface AreaCodeConstant {
String LEVEL_ERROR = "RootAreaLevel填写错误【%s】";
String FIRST_THREE_UD="001_UD";
String FIRST_TOW_UD="01_UD";
String UD="_UD";
}

14
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/AreaCodeController.java

@ -26,6 +26,7 @@ import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.dto.form.AddAreaCodeDictFormDTO;
import com.epmet.dto.form.AddAreaCodeFormDTO;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.service.AreaCodeService;
@ -107,4 +108,17 @@ public class AreaCodeController {
ValidatorUtils.validateEntity(formDTO);
return new Result<String>().ok(areaCodeService.addStreetCommAreaCode(formDTO));
}
/**
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.lang.String>
* @author yinzuomei
* @description 自定义行政地区编码-产品自身使用
* @Date 2021/4/13 14:40
**/
@PostMapping(value = "addareacode")
Result<String> addAreaCode(@RequestBody AddAreaCodeFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<String>().ok(areaCodeService.addAreaCode(formDTO));
}
}

4
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/AreaCodeDao.java

@ -36,4 +36,8 @@ public interface AreaCodeDao extends BaseDao<AreaCodeEntity> {
List<AreaCodeDTO> selectAllArea();
AreaCodeDTO selectByCountyCode(String countyCode);
AreaCodeDTO selectByCityCode(String cityCode);
AreaCodeDTO selectMaxCounty(String cityCode);
}

10
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/AreaCodeService.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.dto.form.AddAreaCodeDictFormDTO;
import com.epmet.dto.form.AddAreaCodeFormDTO;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.entity.AreaCodeEntity;
@ -113,4 +114,13 @@ public interface AreaCodeService extends BaseService<AreaCodeEntity> {
* @Date 2021/2/5 17:39
**/
String addStreetCommAreaCode(AddAreaCodeDictFormDTO formDTO);
/**
* @return java.lang.String
* @param formDTO
* @author yinzuomei
* @description 自定义行政地区编码
* @Date 2021/4/13 14:40
**/
String addAreaCode(AddAreaCodeFormDTO formDTO);
}

70
epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java

@ -34,6 +34,7 @@ import com.epmet.dao.AreaCodeDao;
import com.epmet.dto.AreaCodeChildDTO;
import com.epmet.dto.AreaCodeDTO;
import com.epmet.dto.form.AddAreaCodeDictFormDTO;
import com.epmet.dto.form.AddAreaCodeFormDTO;
import com.epmet.dto.form.AreaCodeDictFormDTO;
import com.epmet.dto.result.AreaCodeDictResultDTO;
import com.epmet.entity.AreaCodeEntity;
@ -588,7 +589,7 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
**/
@Override
public String addStreetCommAreaCode(AddAreaCodeDictFormDTO formDTO) {
String originalParentCode = formDTO.getParentAreaCode().replaceAll("_UD", "");
String originalParentCode = formDTO.getParentAreaCode().replaceAll(AreaCodeConstant.UD, "");
if (originalParentCode.length() < NumConstant.SIX) {
throw new RenException("目前只允许添加街道或社区");
}
@ -624,13 +625,13 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
//如果是增加街道
areaCodeChildDTO.setLevel(NumConstant.FOUR);
} else {
areaCodeChildDTO.setLevel(null != parent && null != parent.getLevel() ? parent.getLevel() + 1 : null);
areaCodeChildDTO.setLevel(null != parent && null != parent.getLevel() ? parent.getLevel() + NumConstant.ONE : null);
}
//获取子级中最大的编码
AreaCodeChildDTO maxChildDto = childDao.selectMaxChild(formDTO.getParentAreaCode().trim());
if (null == maxChildDto) {
//默认添加001
areaCodeChildDTO.setCode(formDTO.getParentAreaCode().concat("001_UD"));
areaCodeChildDTO.setCode(formDTO.getParentAreaCode().concat(AreaCodeConstant.FIRST_THREE_UD));
} else {
//去掉_UD +1赋值;370124001225_UD 锦源社区
/*String[] codeArr = maxChildDto.getCode().split(StrConstant.UNDER_LINE);
@ -641,14 +642,14 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
long num = Long.parseLong(codeArr[NumConstant.ZERO]) + NumConstant.ONE;
String numStr = String.valueOf(num);
String temp = "";
if (numStr.length() == 2) {
temp = "0".concat(numStr);
} else if (numStr.length() == 1) {
if (numStr.length() == NumConstant.TWO) {
temp = NumConstant.ZERO_STR.concat(numStr);
} else if (numStr.length() == NumConstant.ONE) {
temp = "00".concat(numStr);
} else {
temp = numStr;
}
areaCodeChildDTO.setCode(formDTO.getParentAreaCode().concat(temp).concat("_UD"));
areaCodeChildDTO.setCode(formDTO.getParentAreaCode().concat(temp).concat(AreaCodeConstant.UD));
/*log.info("最大="+maxChildDto.getCode()+";去初父级("+formDTO.getParentAreaCode()+"):"+subStr);
log.info("数字位+1="+num);
log.info("temp="+temp);*/
@ -657,4 +658,59 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
areaCodeChildService.save(areaCodeChildDTO);
return areaCodeChildDTO.getCode();
}
/**
* @param formDTO
* @return java.lang.String
* @author yinzuomei
* @description 自定义行政地区编码
* @Date 2021/4/13 14:40
**/
@Transactional(rollbackFor = Exception.class)
@Override
public String addAreaCode(AddAreaCodeFormDTO formDTO) {
String areaCode = "";
switch (formDTO.getCurrentAreaLevel()) {
case AreaCodeConstant.DISTRICT:
areaCode = addDistrictAreaCode(formDTO.getParentAreaCode(),formDTO.getName());
break;
case AreaCodeConstant.STREET:
areaCode = addStreetCommAreaCode(ConvertUtils.sourceToTarget(formDTO,AddAreaCodeDictFormDTO.class));
break;
case AreaCodeConstant.COMMUNITY:
areaCode = addStreetCommAreaCode(ConvertUtils.sourceToTarget(formDTO,AddAreaCodeDictFormDTO.class));
break;
default:
log.info("currentAreaLevel值为"+formDTO.getCurrentAreaLevel());
}
return areaCode;
}
private String addDistrictAreaCode(String cityCode, String countyName) {
AreaCodeDTO city = baseDao.selectByCityCode(cityCode);
AreaCodeEntity insert = ConvertUtils.sourceToTarget(city, AreaCodeEntity.class);
insert.setCityName(countyName);
AreaCodeDTO maxCountyDTO = baseDao.selectMaxCounty(cityCode);
if (null == maxCountyDTO) {
insert.setCountyCode(cityCode.concat(AreaCodeConstant.FIRST_TOW_UD));
} else {
//山东省37
//济南市3701
//济南高新技术产业开发区370171
//370172_UD
if (NumConstant.SIX == maxCountyDTO.getCountyCode().length()) {
long maxCountyCode = Long.parseLong(maxCountyDTO.getCountyCode());
long newCountyCode = maxCountyCode + NumConstant.ONE;
insert.setCountyCode(String.valueOf(newCountyCode));
} else {
String countyCode = maxCountyDTO.getCountyCode().replace(AreaCodeConstant.FIRST_TOW_UD, StrConstant.EPMETY_STR);
long maxCountyCode = Long.parseLong(countyCode);
long newCountyCode = maxCountyCode + NumConstant.ONE;
insert.setCountyCode(String.valueOf(newCountyCode));
}
}
baseDao.insert(insert);
return insert.getCountyCode();
}
}

16
epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/AreaCodeDao.xml

@ -11,4 +11,20 @@
<select id="selectByCountyCode" resultType="com.epmet.dto.AreaCodeDTO">
select * from area_code m where m.COUNTY_CODE=#{countyCode}
</select>
<select id="selectByCityCode" resultType="com.epmet.dto.AreaCodeDTO" parameterType="java.lang.String">
select distinct ac.PROVINCE_CODE,ac.PROVINCE_NAME,ac.CITY_CODE,ac.CITY_NAME
from area_code ac
where ac.DEL_FLAG='0'
and ac.CITY_CODE=#{cityCode}
</select>
<select id="selectMaxCounty" resultType="com.epmet.dto.AreaCodeDTO" parameterType="java.lang.String">
select *
from area_code ac
where ac.DEL_FLAG='0'
and ac.CITY_CODE=#{cityCode}
order by ac.COUNTY_CODE desc
limit 1
</select>
</mapper>

86
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyV2FormDTO.java

@ -0,0 +1,86 @@
package com.epmet.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 添加组织V2
*
* @author yinzuomei@elink-cn.com
* @date 2021/4/13 11:08
*/
@Data
public class AddAgencyV2FormDTO implements Serializable {
private static final long serialVersionUID = -8951334902226679043L;
public interface AddUserInternalGroup {
}
public interface DefaultUserShowGroup extends CustomerClientShowGroup {
}
public interface AreaCodeGroup extends CustomerClientShowGroup {
}
@NotBlank(message = "上级组织ID不能为空", groups = AddUserInternalGroup.class)
private String parentAgencyId;
/**
* 机构组织名称
*/
@NotBlank(message = "组织名称不能为空", groups = DefaultUserShowGroup.class)
@Length(max = 50, message = "组织名称不能超过50个字", groups = DefaultUserShowGroup.class)
private String agencyName;
/**
* 机关级别社区级community
* 街道:street,
* 区县级: district,
* 市级: city
* 省级:province
*/
@NotBlank(message = "组织级别不能为空;社区级:community,乡(镇、街道)级:street,区县级: district,市级: city省级:province", groups = AddUserInternalGroup.class)
private String level;
/**
* open: 选择地区编码必填closed: 无需选择地区编码;0409新增返参
*/
@NotBlank(message = "areaCodeSwitch不能为空", groups = AddUserInternalGroup.class)
private String areaCodeSwitch;
/**
* 地区编码
*/
@NotBlank(message = "请选择组织区划", groups = AreaCodeGroup.class)
private String areaCode;
/**
* 省份
*/
private String province;
/**
* 城市
*/
private String city;
/**
* 区县
*/
private String district;
/**
* 区域编码字典中的街道名称来源于/data/aggregator/org/nextlevelareacodelist接口里的areaName
*/
private String street;
/**
* 区域编码字典中的社区名称来源于/data/aggregator/org/nextlevelareacodelist接口里的areaName
*/
private String community;
}

14
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AddAgencyResultDTO.java

@ -33,8 +33,18 @@ public class AddAgencyResultDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 机关组织Id
* 新添加的组织Id
*/
private String agencyId = "";
private String agencyId;
/**
* 新添加的组织地区编码
*/
private String areaCode;
/**
* open: 选择地区编码必填closed: 无需选择地区编码;0409新增返参
*/
private String areaCodeSwitch;
}

6
epmet-module/gov-org/gov-org-server/pom.xml

@ -101,6 +101,12 @@
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>common-service-client</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

22
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java

@ -33,6 +33,7 @@ import com.epmet.dto.result.AgencysResultDTO;
import com.epmet.dto.result.SubAgencyResultDTO;
import com.epmet.entity.CustomerAgencyEntity;
import com.epmet.service.AgencyService;
import com.epmet.service.CustomerAgencyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -54,6 +55,8 @@ public class AgencyController {
@Autowired
private AgencyService agencyService;
@Autowired
private CustomerAgencyService customerAgencyService;
/**
* @param formDTO
@ -81,6 +84,25 @@ public class AgencyController {
return agencyService.addAgency(formDTO);
}
/**
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.AddAgencyResultDTO>
* @author yinzuomei
* @description 添加组织V2
* @Date 2021/4/13 11:09
**/
@PostMapping("addagency-v2")
@RequirePermission(requirePermission = RequirePermissionEnum.ORG_SUBAGENCY_CREATE)
public Result<AddAgencyResultDTO> addAgencyV2(@RequestBody AddAgencyV2FormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, AddAgencyV2FormDTO.DefaultUserShowGroup.class, AddAgencyV2FormDTO.AddUserInternalGroup.class);
if (formDTO.getAreaCodeSwitch().equals(CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN)) {
ValidatorUtils.validateEntity(formDTO, AddAgencyV2FormDTO.AreaCodeGroup.class);
}
//组织名称是否存在
customerAgencyService.checkAgencyName(formDTO.getAgencyName());
return new Result<AddAgencyResultDTO>().ok(agencyService.addAgencyV2(formDTO));
}
/**
* 添加根级组织
* @param form

2
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java

@ -224,4 +224,6 @@ public interface CustomerAgencyDao extends BaseDao<CustomerAgencyEntity> {
* @Date 2020/12/15 10:04
**/
int delByAgencyId(@Param("agencyId") String agencyId, @Param("operateUserId") String operateUserId);
List<String> selectAgencyIdsByAreaCode(String areaCode);
}

9
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java

@ -108,4 +108,13 @@ public interface AgencyService {
* @Date 2020/7/16 17:13
**/
void saveRootAgency(AddAgencyAndStaffFormDTO agencyAndStaff);
/**
* 添加组织V2
*
* @param formDTO rule id
* @return com.epmet.dto.result.AddAgencyResultDTO
*/
AddAgencyResultDTO addAgencyV2(AddAgencyV2FormDTO formDTO);
}

2
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CustomerAgencyService.java

@ -234,4 +234,6 @@ public interface CustomerAgencyService extends BaseService<CustomerAgencyEntity>
* @author sun
**/
OrganizeTreeResultDTO organizeTree(String agencyId);
void checkAgencyName(String agencyName);
}

63
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java

@ -34,11 +34,13 @@ import com.epmet.dto.GovStaffRoleDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.entity.CustomerAgencyEntity;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.redis.CustomerAgencyRedis;
import com.epmet.service.AgencyService;
import com.epmet.service.CustomerAgencyService;
import com.epmet.service.CustomerOrgParameterService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -77,6 +79,9 @@ public class AgencyServiceImpl implements AgencyService {
private LoginUserUtil loginUserUtil;
@Autowired
private CustomerOrgParameterService customerOrgParameterService;
@Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
/**
* @param formDTO
@ -411,4 +416,62 @@ public class AgencyServiceImpl implements AgencyService {
}
/**
* 添加组织V2
*
* @param formDTO rule id
* @return com.epmet.dto.result.AddAgencyResultDTO
*/
@Transactional(rollbackFor = Exception.class)
@Override
public AddAgencyResultDTO addAgencyV2(AddAgencyV2FormDTO formDTO) {
CustomerAgencyDTO parent = customerAgencyService.get(formDTO.getParentAgencyId());
if (null == parent) {
throw new RenException(String.format("添加组织失败:没有找到跟组织信息,parentAgencyId=%s", formDTO.getParentAgencyId()));
}
AddAgencyResultDTO resultDTO = new AddAgencyResultDTO();
resultDTO.setAreaCodeSwitch(formDTO.getAreaCodeSwitch());
//判断areaCodeSwitch:open: 选择地区编码必填;closed: 无需选择地区编码
CustomerAgencyEntity insertEntity = ConvertUtils.sourceToTarget(formDTO, CustomerAgencyEntity.class);
insertEntity.setOrganizationName(formDTO.getAgencyName());
insertEntity.setTotalUser(NumConstant.ZERO);
insertEntity.setPid(parent.getId());
insertEntity.setCustomerId(parent.getCustomerId());
insertEntity.setParentAreaCode(parent.getAreaCode());
if (StringUtils.isBlank(parent.getPid()) || NumConstant.ZERO_STR.equals(parent.getPid())) {
//如果上级是根级组织
insertEntity.setPids(parent.getId());
insertEntity.setAllParentName(parent.getOrganizationName());
} else {
insertEntity.setPids(parent.getPids().concat(StrConstant.COLON).concat(parent.getId()));
insertEntity.setAllParentName(parent.getAllParentName().concat(StrConstant.HYPHEN).concat(parent.getOrganizationName()));
}
if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) {
//校验areaCode是否被使用过
if (!"other".equals(formDTO.getAreaCode())) {
List<String> agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(insertEntity.getAreaCode());
if (CollectionUtils.isNotEmpty(agencyIds)) {
//已经被占用,提示
throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg());
}
}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())) {
throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg());
}
insertEntity.setAreaCode(addAreaCodeResult.getData());
}
}
customerAgencyDao.insert(insertEntity);
//3:返回新组织Id
resultDTO.setAgencyId(insertEntity.getId());
resultDTO.setAreaCode(StrConstant.EPMETY_STR);
return resultDTO;
}
}

12
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerAgencyServiceImpl.java

@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
@ -40,6 +41,7 @@ import com.epmet.feign.OperCrmFeignClient;
import com.epmet.redis.CustomerAgencyRedis;
import com.epmet.service.CustomerAgencyService;
import com.epmet.util.ModuleConstant;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -1057,4 +1059,14 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao
return baseDao.selectorganizeTree(agencyId);
}
@Override
public void checkAgencyName(String agencyName) {
QueryWrapper<CustomerAgencyEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(agencyName), "ORGANIZATION_NAME", agencyName);
List<CustomerAgencyEntity> entityList = baseDao.selectList(wrapper);
if (CollectionUtils.isNotEmpty(entityList)) {
throw new RenException(EpmetErrorCode.AGENCY_NAME_ALREADY_EXISTS.getCode(), EpmetErrorCode.AGENCY_NAME_ALREADY_EXISTS.getMsg());
}
}
}

4
epmet-module/gov-org/gov-org-server/src/main/resources/logback-spring.xml

@ -128,14 +128,14 @@
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文档只记录ERROR级别的 发送钉钉短信 -->
<filter class="com.epmet.commons.tools.filter.LogMsgSendFilter">
<!--<filter class="com.epmet.commons.tools.filter.LogMsgSendFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
<webHook>${webHook}</webHook>
<secret>${secret}</secret>
<appName>${appname}</appName>
</filter>
</filter>-->
</appender>
<!-- 开发、测试环境 -->

10
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml

@ -399,4 +399,14 @@
UPDATED_TIME=NOW()
where id=#{agencyId}
</update>
<select id="selectAgencyIdsByAreaCode" resultType="java.lang.String" parameterType="java.lang.String">
SELECT
ca.id
FROM
customer_agency ca
WHERE
ca.DEL_FLAG = '0'
AND ca.AREA_CODE = #{areaCode}
</select>
</mapper>
Loading…
Cancel
Save