Browse Source

双实信息录入-编码辅助表结构调整

feature/teamB_zz_wgh
Jackwang 3 years ago
parent
commit
88a8e2235f
  1. 32
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/enums/OrganizationTypeEnums.java
  2. 59
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcOrganizationCodeInfoDao.java
  3. 28
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcOrganizationCodeInfoEntity.java
  4. 11
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java
  5. 15
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java
  6. 146
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java
  7. 9
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/NeighborHoodServiceImpl.java
  8. 8
      epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.34__alter_ic_organization_code_info.sql
  9. 55
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcOrganizationCodeInfoDao.xml

32
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/enums/OrganizationTypeEnums.java

@ -0,0 +1,32 @@
package com.epmet.enums;
public enum OrganizationTypeEnums {
COMM("community","社区"),
NEI("neighbor","小区"),
BUI("building","楼栋"),
UNIT("unit","单元");
private String code;
private String name;
OrganizationTypeEnums(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

59
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcOrganizationCodeInfoDao.java

@ -21,8 +21,9 @@ public interface IcOrganizationCodeInfoDao extends BaseDao<IcOrganizationCodeInf
* @params [customerId, communityId] * @params [customerId, communityId]
* @return com.epmet.entity.IcOrganizationCodeInfoEntity * @return com.epmet.entity.IcOrganizationCodeInfoEntity
*/ */
IcOrganizationCodeInfoEntity selectByCommunityIdAndCustomerId(@Param("customerId") String customerId, IcOrganizationCodeInfoEntity selectByIdAndType(@Param("customerId") String customerId,
@Param("communityId") String communityId); @Param("sysId") String sysId,
@Param("sysType") String sysType);
/** /**
* @describe: 根据客户id和社区id更新小区编号 * @describe: 根据客户id和社区id更新小区编号
@ -31,32 +32,32 @@ public interface IcOrganizationCodeInfoDao extends BaseDao<IcOrganizationCodeInf
* @params [communEntity] * @params [communEntity]
* @return void * @return void
*/ */
void updateNeiByCuIdAndCoId(IcOrganizationCodeInfoEntity communEntity); void updateMaxNumByIdAndType(IcOrganizationCodeInfoEntity communEntity);
/** // /**
* @describe: 根据客户id和社区id更新楼栋编号 // * @describe: 根据客户id和社区id更新楼栋编号
* @author wangtong // * @author wangtong
* @date 2022/6/29 14:51 // * @date 2022/6/29 14:51
* @params [buildingEntity] // * @params [buildingEntity]
* @return void // * @return void
*/ // */
void updateBuildingByCuIdAndCoId(IcOrganizationCodeInfoEntity buildingEntity); // void updateBuildingByCuIdAndCoId(IcOrganizationCodeInfoEntity buildingEntity);
//
/** // /**
* @describe: 根据客户id和社区id更新单元编号 // * @describe: 根据客户id和社区id更新单元编号
* @author wangtong // * @author wangtong
* @date 2022/6/29 15:01 // * @date 2022/6/29 15:01
* @params [unitEntity] // * @params [unitEntity]
* @return void // * @return void
*/ // */
void updateUnitByCuIdAndCoId(IcOrganizationCodeInfoEntity unitEntity); // void updateUnitByCuIdAndCoId(IcOrganizationCodeInfoEntity unitEntity);
//
/** // /**
* @describe: 根据客户id和社区id更新房屋编号 // * @describe: 根据客户id和社区id更新房屋编号
* @author wangtong // * @author wangtong
* @date 2022/6/29 15:25 // * @date 2022/6/29 15:25
* @params [houseEntity] // * @params [houseEntity]
* @return void // * @return void
*/ // */
void updateHouseByCuIdAndCoId(IcOrganizationCodeInfoEntity houseEntity); // void updateHouseByCuIdAndCoId(IcOrganizationCodeInfoEntity houseEntity);
} }

28
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcOrganizationCodeInfoEntity.java

@ -23,27 +23,23 @@ public class IcOrganizationCodeInfoEntity{
private String customerId; private String customerId;
/** /**
* 社区id * 社区/小区/楼栋/单元id
*/ */
private String communityId; private String sysId;
/**
* 该社区下最大的小区编码序列号
*/
private String neighborMaxNum;
/**
* 该社区下最大的楼栋编码序列号
*/
private String buildingMaxNum;
/** /**
* 该社区下最大的单元编码序列号 * 类型
* 社区community
* 小区neighbor
* 楼栋building
* 单元unit
*/ */
private String unitMaxNum; private String sysType;
/** /**
* 该社区下最大的房屋编码序列号 * 最大数
*/ */
private String houseMaxNum; private String maxNum;
} }

11
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java

@ -33,6 +33,7 @@ import com.epmet.dto.form.*;
import com.epmet.dto.result.*; import com.epmet.dto.result.*;
import com.epmet.entity.*; import com.epmet.entity.*;
import com.epmet.enums.BuildingTypeEnums; import com.epmet.enums.BuildingTypeEnums;
import com.epmet.enums.OrganizationTypeEnums;
import com.epmet.excel.IcBuildingExcel; import com.epmet.excel.IcBuildingExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.model.BuildingInfoModel; import com.epmet.model.BuildingInfoModel;
@ -146,11 +147,9 @@ public class BuildingServiceImpl implements BuildingService {
* @return void * @return void
*/ */
private void updateBuildingMaxNum(String customerId,IcBulidingAddFormDTO formDTO){ private void updateBuildingMaxNum(String customerId,IcBulidingAddFormDTO formDTO){
//获取楼栋id、行政编码
OrganizationCommunityDTO communResult = icNeighborHoodDao.selectCommunityByNeiId(formDTO.getNeighborHoodId());
//如果是自增的,则最大数+1 //如果是自增的,则最大数+1
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByIdAndType(customerId, formDTO.getNeighborHoodId(), OrganizationTypeEnums.NEI.getCode());
Integer buildMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getBuildingMaxNum())?1:Integer.valueOf(communEntity.getBuildingMaxNum()) + 1; Integer buildMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getMaxNum())?1:Integer.valueOf(communEntity.getMaxNum()) + 1;
Integer submitMaxNum = null; Integer submitMaxNum = null;
try { try {
submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-3)); submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-3));
@ -159,8 +158,8 @@ public class BuildingServiceImpl implements BuildingService {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败");
} }
if(buildMaxNum.intValue() == submitMaxNum.intValue()){ if(buildMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setBuildingMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, buildMaxNum)); communEntity.setMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, buildMaxNum));
icOrganizationCodeInfoDao.updateBuildingByCuIdAndCoId(communEntity); icOrganizationCodeInfoDao.updateMaxNumByIdAndType(communEntity);
} }
} }

15
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java

@ -34,10 +34,7 @@ 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.*; import com.epmet.entity.*;
import com.epmet.enums.HouseChangeEnums; import com.epmet.enums.*;
import com.epmet.enums.HousePurposeEnums;
import com.epmet.enums.HouseRentFlagEnums;
import com.epmet.enums.HouseTypeEnums;
import com.epmet.feign.EpmetAdminOpenFeignClient; import com.epmet.feign.EpmetAdminOpenFeignClient;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.feign.EpmetUserOpenFeignClient;
@ -179,11 +176,9 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
* @return void * @return void
*/ */
private void updateHouseMaxNum(String customerId, IcHouseAddFormDTO formDTO){ private void updateHouseMaxNum(String customerId, IcHouseAddFormDTO formDTO){
//获取社区id、单元编码
OrganizationCommunityDTO communResult = icBuildingUnitDao.selectCommunityByUnitId(formDTO.getBuildingUnitId());
//如果是自增的,则最大数+1 //如果是自增的,则最大数+1
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByIdAndType(customerId, formDTO.getBuildingUnitId(), OrganizationTypeEnums.UNIT.getCode());
Integer houseMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getHouseMaxNum())?1:Integer.valueOf(communEntity.getHouseMaxNum()) + 1; Integer houseMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getMaxNum())?1:Integer.valueOf(communEntity.getMaxNum()) + 1;
Integer submitMaxNum = null; Integer submitMaxNum = null;
try { try {
submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-4)); submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-4));
@ -192,8 +187,8 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败");
} }
if(houseMaxNum.intValue() == submitMaxNum.intValue()){ if(houseMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setHouseMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(4, houseMaxNum)); communEntity.setMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(4, houseMaxNum));
icOrganizationCodeInfoDao.updateHouseByCuIdAndCoId(communEntity); icOrganizationCodeInfoDao.updateMaxNumByIdAndType(communEntity);
} }
} }

146
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java

@ -16,6 +16,7 @@ import com.epmet.dto.result.HouseInfoResultDTO;
import com.epmet.dto.result.OrganizationCodeResultDTO; import com.epmet.dto.result.OrganizationCodeResultDTO;
import com.epmet.dto.result.OrganizationCommunityDTO; import com.epmet.dto.result.OrganizationCommunityDTO;
import com.epmet.entity.*; import com.epmet.entity.*;
import com.epmet.enums.OrganizationTypeEnums;
import com.epmet.redis.IcOrganizationCodeInfoRedis; import com.epmet.redis.IcOrganizationCodeInfoRedis;
import com.epmet.service.IcOrganizationCodeInfoService; import com.epmet.service.IcOrganizationCodeInfoService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -108,7 +109,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<OrganizationCodeResultDTO> getNeighborHoodCoding(String customerId, String gridId,Boolean updateFlag) { public Result<OrganizationCodeResultDTO> getNeighborHoodCoding(String customerId, String gridId, Boolean updateFlag) {
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(gridId)) { if (StringUtils.isBlank(customerId) || StringUtils.isBlank(gridId)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
} }
@ -119,16 +120,16 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关社区信息", "未查到相关社区信息"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关社区信息", "未查到相关社区信息");
} }
//查询该社区下是否存在数据 //查询该社区下是否存在数据
IcOrganizationCodeInfoEntity communEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity communEntity = baseDao.selectByIdAndType(customerId, communResult.getCommunityId(), OrganizationTypeEnums.COMM.getCode());
if (null == communEntity) { if (null == communEntity) {
Integer neighborMaxNum = 1; Integer neighborMaxNum = 1;
String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
//开发测试需要检测,因为包含行政编码为空的社区,会出现小区编码重复的情况 //开发测试需要检测,因为包含行政编码为空的社区,会出现小区编码重复的情况
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode,null); IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode, null);
while (null != isHaveCoding) { while (null != isHaveCoding) {
neighborMaxNum++; neighborMaxNum++;
neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode,null); isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode, null);
} }
result.setCoding(neighborCode); result.setCoding(neighborCode);
@ -136,28 +137,29 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//新增该社区辅助数据 //新增该社区辅助数据
IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity(); IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity();
newEntity.setCustomerId(customerId); newEntity.setCustomerId(customerId);
newEntity.setCommunityId(communResult.getCommunityId()); newEntity.setSysId(communResult.getCommunityId());
if(updateFlag){ if (updateFlag) {
newEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum)); newEntity.setMaxNum(getNewMaxIndex(3, neighborMaxNum));
} }
newEntity.setSysType(OrganizationTypeEnums.COMM.getCode());
baseDao.insert(newEntity); baseDao.insert(newEntity);
} else { } else {
Integer neighborMaxNum = Integer.valueOf(communEntity.getNeighborMaxNum()) + 1; Integer neighborMaxNum = StringUtils.isBlank(communEntity.getMaxNum()) ? 1 : Integer.valueOf(communEntity.getMaxNum()) + 1;
//验证可编辑的编码是否有重复 //验证可编辑的编码是否有重复
String neiCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); String neiCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode,null); IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode, null);
while (null != isHaveCoding) { while (null != isHaveCoding) {
//先更新已有的最大值 //先更新已有的最大值
communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum)); communEntity.setMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateNeiByCuIdAndCoId(communEntity); baseDao.updateMaxNumByIdAndType(communEntity);
neighborMaxNum++; neighborMaxNum++;
neiCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); neiCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode,null); isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode, null);
} }
//更新该社区下最大的小区编号 //更新该社区下最大的小区编号
if(updateFlag) { if (updateFlag) {
communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum)); communEntity.setMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateNeiByCuIdAndCoId(communEntity); baseDao.updateMaxNumByIdAndType(communEntity);
} }
String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
result.setCoding(neiCode); result.setCoding(neiCode);
@ -168,7 +170,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<OrganizationCodeResultDTO> getBuildingCoding(String customerId, String neighborhoodId,Boolean updateFlag) { public Result<OrganizationCodeResultDTO> getBuildingCoding(String customerId, String neighborhoodId, Boolean updateFlag) {
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(neighborhoodId)) { if (StringUtils.isBlank(customerId) || StringUtils.isBlank(neighborhoodId)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
} }
@ -181,7 +183,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
} }
//如果小区编码为空,先生成小区编码并更新 //如果小区编码为空,先生成小区编码并更新
if (StringUtils.isBlank(neighborHood.getSysCoding())) { if (StringUtils.isBlank(neighborHood.getSysCoding())) {
OrganizationCodeResultDTO org = getNeighborHoodCoding(customerId, neighborHood.getGridId(),true).getData(); OrganizationCodeResultDTO org = getNeighborHoodCoding(customerId, neighborHood.getGridId(), true).getData();
neighborHood.setCoding(org.getCoding()); neighborHood.setCoding(org.getCoding());
neighborHood.setSysCoding(org.getSysCoding()); neighborHood.setSysCoding(org.getSysCoding());
icNeighborHoodDao.updateById(neighborHood); icNeighborHoodDao.updateById(neighborHood);
@ -189,43 +191,49 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//获取社区id、小区编码 //获取社区id、小区编码
OrganizationCommunityDTO communResult = icNeighborHoodDao.selectCommunityByNeiId(neighborhoodId); OrganizationCommunityDTO communResult = icNeighborHoodDao.selectCommunityByNeiId(neighborhoodId);
//查询该社区下是否存在楼栋数据 //查询该小区下是否存在楼栋数据
IcOrganizationCodeInfoEntity buildingEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity buildingEntity = baseDao.selectByIdAndType(customerId, neighborhoodId, OrganizationTypeEnums.NEI.getCode());
if (StringUtils.isBlank(buildingEntity.getBuildingMaxNum())) { if (null == buildingEntity) {
result.setCoding(communResult.getCoding() + "001"); Integer maxNum = 1;
result.setSysCoding(communResult.getSysCoding() + "001"); result.setCoding(communResult.getCoding() + getNewMaxIndex(3, maxNum));
//补充该社区的楼栋最大数 result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, maxNum));
// buildingEntity.setBuildingMaxNum("001"); //新增该楼栋辅助数据
IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity();
newEntity.setCustomerId(customerId);
newEntity.setSysId(neighborhoodId);
if (updateFlag) {
newEntity.setMaxNum(getNewMaxIndex(3, maxNum));
}
newEntity.setSysType(OrganizationTypeEnums.NEI.getCode());
baseDao.insert(newEntity);
} else { } else {
Integer buildingMaxNum = Integer.valueOf(buildingEntity.getBuildingMaxNum()) + 1; Integer buildingMaxNum = StringUtils.isBlank(buildingEntity.getMaxNum()) ? 1 : Integer.valueOf(buildingEntity.getMaxNum()) + 1;
//验证可编辑的编码是否有重复 //验证可编辑的编码是否有重复
String buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum); String buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum);
IcBuildingEntity isHaveCoding = icBuildingDao.selectByCoding(buildingCode,null); IcBuildingEntity isHaveCoding = icBuildingDao.selectByCoding(buildingCode, null);
while (null != isHaveCoding) { while (null != isHaveCoding) {
//先更新已有的最大值 //先更新已有的最大值
buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum)); buildingEntity.setMaxNum(getNewMaxIndex(3, buildingMaxNum));
baseDao.updateBuildingByCuIdAndCoId(buildingEntity); baseDao.updateMaxNumByIdAndType(buildingEntity);
buildingMaxNum++; buildingMaxNum++;
buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum); buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum);
isHaveCoding = icBuildingDao.selectByCoding(buildingCode,null); isHaveCoding = icBuildingDao.selectByCoding(buildingCode, null);
} }
result.setCoding(buildingCode); result.setCoding(buildingCode);
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, buildingMaxNum)); result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, buildingMaxNum));
//更新该社区下最大的楼栋编号 //更新该社区下最大的楼栋编号
if(updateFlag) { if (updateFlag) {
buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum)); buildingEntity.setMaxNum(getNewMaxIndex(3, buildingMaxNum));
baseDao.updateMaxNumByIdAndType(buildingEntity);
} }
} }
if(updateFlag) {
baseDao.updateBuildingByCuIdAndCoId(buildingEntity);
}
return new Result<OrganizationCodeResultDTO>().ok(result); return new Result<OrganizationCodeResultDTO>().ok(result);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<OrganizationCodeResultDTO> getUnitCoding(String customerId, String buildingId,Boolean updateFlag) { public Result<OrganizationCodeResultDTO> getUnitCoding(String customerId, String buildingId, Boolean updateFlag) {
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(buildingId)) { if (StringUtils.isBlank(customerId) || StringUtils.isBlank(buildingId)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
} }
@ -238,8 +246,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
} }
//如果楼栋编码为空,先生成楼栋编码并更新 //如果楼栋编码为空,先生成楼栋编码并更新
if (StringUtils.isBlank(buildingEntity.getSysCoding())) { if (StringUtils.isBlank(buildingEntity.getSysCoding())) {
ImportGeneralDTO neiInfo = icBuildingDao.selectBuildingById(buildingId); ImportGeneralDTO neiInfo = icBuildingDao.selectBuildingById(buildingId);
OrganizationCodeResultDTO org = getBuildingCoding(customerId, neiInfo.getNeighborHoodId(),true).getData(); OrganizationCodeResultDTO org = getBuildingCoding(customerId, neiInfo.getNeighborHoodId(), true).getData();
buildingEntity.setCoding(org.getCoding()); buildingEntity.setCoding(org.getCoding());
buildingEntity.setSysCoding(org.getSysCoding()); buildingEntity.setSysCoding(org.getSysCoding());
icBuildingDao.updateById(buildingEntity); icBuildingDao.updateById(buildingEntity);
@ -247,15 +255,23 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//获取社区id、楼栋编码 //获取社区id、楼栋编码
OrganizationCommunityDTO communResult = icBuildingDao.selectCommunityByBuildingId(buildingId); OrganizationCommunityDTO communResult = icBuildingDao.selectCommunityByBuildingId(buildingId);
//查询该社区下是否存在单元数据 //查询该楼栋下是否存在单元数据
IcOrganizationCodeInfoEntity unitEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity unitEntity = baseDao.selectByIdAndType(customerId, buildingId, OrganizationTypeEnums.BUI.getCode());
if (StringUtils.isBlank(unitEntity.getUnitMaxNum())) { if (null == unitEntity) {
result.setCoding(communResult.getCoding() + "01"); Integer maxNum = 1;
result.setSysCoding(communResult.getSysCoding() + "01"); result.setCoding(communResult.getCoding() + getNewMaxIndex(2, maxNum));
//补充该社区的单元最大数 result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, maxNum));
unitEntity.setUnitMaxNum("01"); //新增该单元辅助数据
IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity();
newEntity.setCustomerId(customerId);
newEntity.setSysId(buildingId);
if (updateFlag) {
newEntity.setMaxNum(getNewMaxIndex(2, maxNum));
}
newEntity.setSysType(OrganizationTypeEnums.BUI.getCode());
baseDao.insert(newEntity);
} else { } else {
Integer unitMaxNum = Integer.valueOf(unitEntity.getUnitMaxNum()) + 1; Integer unitMaxNum = StringUtils.isBlank(unitEntity.getMaxNum()) ? 1 : Integer.valueOf(unitEntity.getMaxNum()) + 1;
//验证可编辑的编码是否有重复 //验证可编辑的编码是否有重复
String unitCode = communResult.getCoding() + getNewMaxIndex(2, unitMaxNum); String unitCode = communResult.getCoding() + getNewMaxIndex(2, unitMaxNum);
IcBuildingUnitEntity isHaveCoding = icBuildingUnitDao.selectByCoding(unitCode); IcBuildingUnitEntity isHaveCoding = icBuildingUnitDao.selectByCoding(unitCode);
@ -268,17 +284,17 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, unitMaxNum)); result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, unitMaxNum));
//更新该社区下最大的单元编号 //更新该社区下最大的单元编号
if(updateFlag) { if (updateFlag) {
unitEntity.setUnitMaxNum(getNewMaxIndex(2, unitMaxNum)); unitEntity.setMaxNum(getNewMaxIndex(2, unitMaxNum));
baseDao.updateMaxNumByIdAndType(unitEntity);
} }
} }
baseDao.updateUnitByCuIdAndCoId(unitEntity);
return new Result<OrganizationCodeResultDTO>().ok(result); return new Result<OrganizationCodeResultDTO>().ok(result);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<OrganizationCodeResultDTO> getHouseCoding(String customerId, String unitId,Boolean updateFlag) { public Result<OrganizationCodeResultDTO> getHouseCoding(String customerId, String unitId, Boolean updateFlag) {
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(unitId)) { if (StringUtils.isBlank(customerId) || StringUtils.isBlank(unitId)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
} }
@ -291,8 +307,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
} }
//如果单元编码为空,先生成单元编码并更新 //如果单元编码为空,先生成单元编码并更新
if (StringUtils.isBlank(unitEntity.getSysCoding())) { if (StringUtils.isBlank(unitEntity.getSysCoding())) {
HouseInfoResultDTO buildingInfo = icBuildingUnitDao.getUnitDetail(unitId); HouseInfoResultDTO buildingInfo = icBuildingUnitDao.getUnitDetail(unitId);
OrganizationCodeResultDTO org = getUnitCoding(customerId, buildingInfo.getBuildingId(),true).getData(); OrganizationCodeResultDTO org = getUnitCoding(customerId, buildingInfo.getBuildingId(), true).getData();
unitEntity.setCoding(org.getCoding()); unitEntity.setCoding(org.getCoding());
unitEntity.setSysCoding(org.getSysCoding()); unitEntity.setSysCoding(org.getSysCoding());
icBuildingUnitDao.updateById(unitEntity); icBuildingUnitDao.updateById(unitEntity);
@ -300,21 +316,29 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//获取社区id、单元编码 //获取社区id、单元编码
OrganizationCommunityDTO communResult = icBuildingUnitDao.selectCommunityByUnitId(unitId); OrganizationCommunityDTO communResult = icBuildingUnitDao.selectCommunityByUnitId(unitId);
//查询该社区下是否存在单元数据 //查询该单元下是否存在房屋数据
IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByIdAndType(customerId, unitId, OrganizationTypeEnums.UNIT.getCode());
if (StringUtils.isBlank(houseEntity.getUnitMaxNum())) { if (null == houseEntity) {
result.setCoding(communResult.getCoding() + "001"); Integer maxNum = 1;
//补充该社区的房屋最大数 result.setCoding(communResult.getCoding() + getNewMaxIndex(4, maxNum));
// houseEntity.setHouseMaxNum("001"); //新增该单元辅助数据
IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity();
newEntity.setCustomerId(customerId);
newEntity.setSysId(unitId);
if (updateFlag) {
newEntity.setMaxNum(getNewMaxIndex(4, maxNum));
}
newEntity.setSysType(OrganizationTypeEnums.UNIT.getCode());
baseDao.insert(newEntity);
} else { } else {
Integer houseMaxNum = Integer.valueOf(houseEntity.getUnitMaxNum()) + 1; Integer houseMaxNum = StringUtils.isBlank(houseEntity.getMaxNum()) ? 1 : Integer.valueOf(houseEntity.getMaxNum()) + 1;
//验证可编辑的编码是否有重复 //验证可编辑的编码是否有重复
String houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum); String houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum);
IcHouseEntity isHaveCoding = icHouseDao.selectByCoding(houseCode); IcHouseEntity isHaveCoding = icHouseDao.selectByCoding(houseCode);
while (null != isHaveCoding) { while (null != isHaveCoding) {
//先更新已有的最大值 //先更新已有的最大值
houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum)); houseEntity.setMaxNum(getNewMaxIndex(4, houseMaxNum));
baseDao.updateHouseByCuIdAndCoId(houseEntity); baseDao.updateMaxNumByIdAndType(houseEntity);
houseMaxNum++; houseMaxNum++;
houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum); houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum);
isHaveCoding = icHouseDao.selectByCoding(houseCode); isHaveCoding = icHouseDao.selectByCoding(houseCode);
@ -323,8 +347,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//更新该社区下最大的房屋编号 //更新该社区下最大的房屋编号
// houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum)); // houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum));
// baseDao.updateMaxNumByIdAndType(houseEntity);
} }
// baseDao.updateHouseByCuIdAndCoId(houseEntity);
return new Result<OrganizationCodeResultDTO>().ok(result); return new Result<OrganizationCodeResultDTO>().ok(result);
} }

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

@ -28,6 +28,7 @@ import com.epmet.entity.IcHouseEntity;
import com.epmet.entity.IcNeighborHoodEntity; import com.epmet.entity.IcNeighborHoodEntity;
import com.epmet.entity.IcNeighborHoodPropertyEntity; import com.epmet.entity.IcNeighborHoodPropertyEntity;
import com.epmet.entity.IcOrganizationCodeInfoEntity; import com.epmet.entity.IcOrganizationCodeInfoEntity;
import com.epmet.enums.OrganizationTypeEnums;
import com.epmet.excel.IcNeighborHoodExcel; import com.epmet.excel.IcNeighborHoodExcel;
import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.feign.GovOrgOpenFeignClient;
@ -128,8 +129,8 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关社区信息", "未查到相关社区信息"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关社区信息", "未查到相关社区信息");
} }
//如果是自增的,则最大数+1 //如果是自增的,则最大数+1
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByIdAndType(customerId, communResult.getCommunityId(), OrganizationTypeEnums.COMM.getCode());
Integer neighborMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getNeighborMaxNum())?1:Integer.valueOf(communEntity.getNeighborMaxNum()) + 1; Integer neighborMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getMaxNum())?1:Integer.valueOf(communEntity.getMaxNum()) + 1;
Integer submitMaxNum = null; Integer submitMaxNum = null;
try { try {
submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-3)); submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-3));
@ -138,8 +139,8 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败");
} }
if(neighborMaxNum.intValue() == submitMaxNum.intValue()){ if(neighborMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setNeighborMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, neighborMaxNum)); communEntity.setMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, neighborMaxNum));
icOrganizationCodeInfoDao.updateNeiByCuIdAndCoId(communEntity); icOrganizationCodeInfoDao.updateMaxNumByIdAndType(communEntity);
} }
} }

8
epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.34__alter_ic_organization_code_info.sql

@ -0,0 +1,8 @@
Drop Table ic_organization_code_info;
CREATE TABLE `ic_organization_code_info` (
`CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id',
`SYS_ID` varchar(64) NOT NULL COMMENT '社区/小区/楼栋/单元id',
`SYS_TYPE` varchar(32) DEFAULT NULL COMMENT '类型:\r\n社区community \r\n小区neighbor \r\n楼栋building \r\n单元unit',
`MAX_NUM` varchar(32) DEFAULT NULL COMMENT '最大数'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='小区/楼栋/房屋编码辅助表';

55
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcOrganizationCodeInfoDao.xml

@ -5,41 +5,42 @@
<resultMap type="com.epmet.entity.IcOrganizationCodeInfoEntity" id="icOrganizationCodeInfoMap"> <resultMap type="com.epmet.entity.IcOrganizationCodeInfoEntity" id="icOrganizationCodeInfoMap">
<result property="customerId" column="CUSTOMER_ID"/> <result property="customerId" column="CUSTOMER_ID"/>
<result property="communityId" column="COMMUNITY_ID"/> <result property="sysId" column="SYS_ID"/>
<result property="neighborMaxNum" column="NEIGHBOR_MAX_NUM"/> <result property="sysType" column="SYS_TYPE"/>
<result property="buildingMaxNum" column="BUILDING_MAX_NUM"/> <result property="maxNum" column="MAX_NUM"/>
<result property="houseMaxNum" column="HOUSE_MAX_NUM"/>
</resultMap> </resultMap>
<select id="selectByCommunityIdAndCustomerId" resultType="com.epmet.entity.IcOrganizationCodeInfoEntity"> <select id="selectByIdAndType" resultType="com.epmet.entity.IcOrganizationCodeInfoEntity">
select * select *
from ic_organization_code_info from ic_organization_code_info
where CUSTOMER_ID=#{customerId} where CUSTOMER_ID=#{customerId}
and COMMUNITY_ID = #{communityId} and SYS_ID = #{sysId}
AND SYS_TYPE = #{sysType}
</select> </select>
<update id="updateNeiByCuIdAndCoId"> <update id="updateMaxNumByIdAndType">
update ic_organization_code_info update ic_organization_code_info
set NEIGHBOR_MAX_NUM=#{neighborMaxNum} set MAX_NUM=#{maxNum}
where CUSTOMER_ID = #{customerId} where CUSTOMER_ID = #{customerId}
and COMMUNITY_ID = #{communityId} and SYS_ID = #{sysId}
</update> AND SYS_TYPE = #{sysType}
<update id="updateBuildingByCuIdAndCoId">
update ic_organization_code_info
set BUILDING_MAX_NUM=#{buildingMaxNum}
where CUSTOMER_ID = #{customerId}
and COMMUNITY_ID = #{communityId}
</update>
<update id="updateUnitByCuIdAndCoId">
update ic_organization_code_info
set UNIT_MAX_NUM=#{unitMaxNum}
where CUSTOMER_ID = #{customerId}
and COMMUNITY_ID = #{communityId}
</update>
<update id="updateHouseByCuIdAndCoId">
update ic_organization_code_info
set HOUSE_MAX_NUM=#{houseMaxNum}
where CUSTOMER_ID = #{customerId}
and COMMUNITY_ID = #{communityId}
</update> </update>
<!-- <update id="updateBuildingByCuIdAndCoId">-->
<!-- update ic_organization_code_info-->
<!-- set BUILDING_MAX_NUM=#{buildingMaxNum}-->
<!-- where CUSTOMER_ID = #{customerId}-->
<!-- and COMMUNITY_ID = #{communityId}-->
<!-- </update>-->
<!-- <update id="updateUnitByCuIdAndCoId">-->
<!-- update ic_organization_code_info-->
<!-- set UNIT_MAX_NUM=#{unitMaxNum}-->
<!-- where CUSTOMER_ID = #{customerId}-->
<!-- and COMMUNITY_ID = #{communityId}-->
<!-- </update>-->
<!-- <update id="updateHouseByCuIdAndCoId">-->
<!-- update ic_organization_code_info-->
<!-- set HOUSE_MAX_NUM=#{houseMaxNum}-->
<!-- where CUSTOMER_ID = #{customerId}-->
<!-- and COMMUNITY_ID = #{communityId}-->
<!-- </update>-->
</mapper> </mapper>

Loading…
Cancel
Save