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]
* @return com.epmet.entity.IcOrganizationCodeInfoEntity
*/
IcOrganizationCodeInfoEntity selectByCommunityIdAndCustomerId(@Param("customerId") String customerId,
@Param("communityId") String communityId);
IcOrganizationCodeInfoEntity selectByIdAndType(@Param("customerId") String customerId,
@Param("sysId") String sysId,
@Param("sysType") String sysType);
/**
* @describe: 根据客户id和社区id更新小区编号
@ -31,32 +32,32 @@ public interface IcOrganizationCodeInfoDao extends BaseDao<IcOrganizationCodeInf
* @params [communEntity]
* @return void
*/
void updateNeiByCuIdAndCoId(IcOrganizationCodeInfoEntity communEntity);
void updateMaxNumByIdAndType(IcOrganizationCodeInfoEntity communEntity);
/**
* @describe: 根据客户id和社区id更新楼栋编号
* @author wangtong
* @date 2022/6/29 14:51
* @params [buildingEntity]
* @return void
*/
void updateBuildingByCuIdAndCoId(IcOrganizationCodeInfoEntity buildingEntity);
/**
* @describe: 根据客户id和社区id更新单元编号
* @author wangtong
* @date 2022/6/29 15:01
* @params [unitEntity]
* @return void
*/
void updateUnitByCuIdAndCoId(IcOrganizationCodeInfoEntity unitEntity);
/**
* @describe: 根据客户id和社区id更新房屋编号
* @author wangtong
* @date 2022/6/29 15:25
* @params [houseEntity]
* @return void
*/
void updateHouseByCuIdAndCoId(IcOrganizationCodeInfoEntity houseEntity);
// /**
// * @describe: 根据客户id和社区id更新楼栋编号
// * @author wangtong
// * @date 2022/6/29 14:51
// * @params [buildingEntity]
// * @return void
// */
// void updateBuildingByCuIdAndCoId(IcOrganizationCodeInfoEntity buildingEntity);
//
// /**
// * @describe: 根据客户id和社区id更新单元编号
// * @author wangtong
// * @date 2022/6/29 15:01
// * @params [unitEntity]
// * @return void
// */
// void updateUnitByCuIdAndCoId(IcOrganizationCodeInfoEntity unitEntity);
//
// /**
// * @describe: 根据客户id和社区id更新房屋编号
// * @author wangtong
// * @date 2022/6/29 15:25
// * @params [houseEntity]
// * @return void
// */
// 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;
/**
* 社区id
* 社区/小区/楼栋/单元id
*/
private String communityId;
/**
* 该社区下最大的小区编码序列号
*/
private String neighborMaxNum;
/**
* 该社区下最大的楼栋编码序列号
*/
private String buildingMaxNum;
private String sysId;
/**
* 该社区下最大的单元编码序列号
* 类型
* 社区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.entity.*;
import com.epmet.enums.BuildingTypeEnums;
import com.epmet.enums.OrganizationTypeEnums;
import com.epmet.excel.IcBuildingExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.model.BuildingInfoModel;
@ -146,11 +147,9 @@ public class BuildingServiceImpl implements BuildingService {
* @return void
*/
private void updateBuildingMaxNum(String customerId,IcBulidingAddFormDTO formDTO){
//获取楼栋id、行政编码
OrganizationCommunityDTO communResult = icNeighborHoodDao.selectCommunityByNeiId(formDTO.getNeighborHoodId());
//如果是自增的,则最大数+1
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
Integer buildMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getBuildingMaxNum())?1:Integer.valueOf(communEntity.getBuildingMaxNum()) + 1;
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByIdAndType(customerId, formDTO.getNeighborHoodId(), OrganizationTypeEnums.NEI.getCode());
Integer buildMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getMaxNum())?1:Integer.valueOf(communEntity.getMaxNum()) + 1;
Integer submitMaxNum = null;
try {
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(), "编码转换失败", "编码转换失败");
}
if(buildMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setBuildingMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, buildMaxNum));
icOrganizationCodeInfoDao.updateBuildingByCuIdAndCoId(communEntity);
communEntity.setMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, buildMaxNum));
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.result.*;
import com.epmet.entity.*;
import com.epmet.enums.HouseChangeEnums;
import com.epmet.enums.HousePurposeEnums;
import com.epmet.enums.HouseRentFlagEnums;
import com.epmet.enums.HouseTypeEnums;
import com.epmet.enums.*;
import com.epmet.feign.EpmetAdminOpenFeignClient;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
@ -179,11 +176,9 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
* @return void
*/
private void updateHouseMaxNum(String customerId, IcHouseAddFormDTO formDTO){
//获取社区id、单元编码
OrganizationCommunityDTO communResult = icBuildingUnitDao.selectCommunityByUnitId(formDTO.getBuildingUnitId());
//如果是自增的,则最大数+1
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
Integer houseMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getHouseMaxNum())?1:Integer.valueOf(communEntity.getHouseMaxNum()) + 1;
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByIdAndType(customerId, formDTO.getBuildingUnitId(), OrganizationTypeEnums.UNIT.getCode());
Integer houseMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getMaxNum())?1:Integer.valueOf(communEntity.getMaxNum()) + 1;
Integer submitMaxNum = null;
try {
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(), "编码转换失败", "编码转换失败");
}
if(houseMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setHouseMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(4, houseMaxNum));
icOrganizationCodeInfoDao.updateHouseByCuIdAndCoId(communEntity);
communEntity.setMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(4, houseMaxNum));
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.OrganizationCommunityDTO;
import com.epmet.entity.*;
import com.epmet.enums.OrganizationTypeEnums;
import com.epmet.redis.IcOrganizationCodeInfoRedis;
import com.epmet.service.IcOrganizationCodeInfoService;
import org.apache.commons.lang3.StringUtils;
@ -108,7 +109,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
@Override
@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)) {
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(), "未查到相关社区信息", "未查到相关社区信息");
}
//查询该社区下是否存在数据
IcOrganizationCodeInfoEntity communEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
IcOrganizationCodeInfoEntity communEntity = baseDao.selectByIdAndType(customerId, communResult.getCommunityId(), OrganizationTypeEnums.COMM.getCode());
if (null == communEntity) {
Integer neighborMaxNum = 1;
String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
//开发测试需要检测,因为包含行政编码为空的社区,会出现小区编码重复的情况
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode,null);
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode, null);
while (null != isHaveCoding) {
neighborMaxNum++;
neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode,null);
isHaveCoding = icNeighborHoodDao.selectByCoding(neighborCode, null);
}
result.setCoding(neighborCode);
@ -136,28 +137,29 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//新增该社区辅助数据
IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity();
newEntity.setCustomerId(customerId);
newEntity.setCommunityId(communResult.getCommunityId());
if(updateFlag){
newEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum));
newEntity.setSysId(communResult.getCommunityId());
if (updateFlag) {
newEntity.setMaxNum(getNewMaxIndex(3, neighborMaxNum));
}
newEntity.setSysType(OrganizationTypeEnums.COMM.getCode());
baseDao.insert(newEntity);
} 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);
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode,null);
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode, null);
while (null != isHaveCoding) {
//先更新已有的最大值
communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateNeiByCuIdAndCoId(communEntity);
communEntity.setMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateMaxNumByIdAndType(communEntity);
neighborMaxNum++;
neiCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode,null);
isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode, null);
}
//更新该社区下最大的小区编号
if(updateFlag) {
communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateNeiByCuIdAndCoId(communEntity);
if (updateFlag) {
communEntity.setMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateMaxNumByIdAndType(communEntity);
}
String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
result.setCoding(neiCode);
@ -168,7 +170,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
@Override
@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)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
}
@ -181,7 +183,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
}
//如果小区编码为空,先生成小区编码并更新
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.setSysCoding(org.getSysCoding());
icNeighborHoodDao.updateById(neighborHood);
@ -189,43 +191,49 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//获取社区id、小区编码
OrganizationCommunityDTO communResult = icNeighborHoodDao.selectCommunityByNeiId(neighborhoodId);
//查询该社区下是否存在楼栋数据
IcOrganizationCodeInfoEntity buildingEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
if (StringUtils.isBlank(buildingEntity.getBuildingMaxNum())) {
result.setCoding(communResult.getCoding() + "001");
result.setSysCoding(communResult.getSysCoding() + "001");
//补充该社区的楼栋最大数
// buildingEntity.setBuildingMaxNum("001");
//查询该小区下是否存在楼栋数据
IcOrganizationCodeInfoEntity buildingEntity = baseDao.selectByIdAndType(customerId, neighborhoodId, OrganizationTypeEnums.NEI.getCode());
if (null == buildingEntity) {
Integer maxNum = 1;
result.setCoding(communResult.getCoding() + getNewMaxIndex(3, maxNum));
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, maxNum));
//新增该楼栋辅助数据
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 {
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);
IcBuildingEntity isHaveCoding = icBuildingDao.selectByCoding(buildingCode,null);
IcBuildingEntity isHaveCoding = icBuildingDao.selectByCoding(buildingCode, null);
while (null != isHaveCoding) {
//先更新已有的最大值
buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum));
baseDao.updateBuildingByCuIdAndCoId(buildingEntity);
buildingEntity.setMaxNum(getNewMaxIndex(3, buildingMaxNum));
baseDao.updateMaxNumByIdAndType(buildingEntity);
buildingMaxNum++;
buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum);
isHaveCoding = icBuildingDao.selectByCoding(buildingCode,null);
isHaveCoding = icBuildingDao.selectByCoding(buildingCode, null);
}
result.setCoding(buildingCode);
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, buildingMaxNum));
//更新该社区下最大的楼栋编号
if(updateFlag) {
buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum));
if (updateFlag) {
buildingEntity.setMaxNum(getNewMaxIndex(3, buildingMaxNum));
baseDao.updateMaxNumByIdAndType(buildingEntity);
}
}
if(updateFlag) {
baseDao.updateBuildingByCuIdAndCoId(buildingEntity);
}
return new Result<OrganizationCodeResultDTO>().ok(result);
}
@Override
@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)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
}
@ -238,8 +246,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
}
//如果楼栋编码为空,先生成楼栋编码并更新
if (StringUtils.isBlank(buildingEntity.getSysCoding())) {
ImportGeneralDTO neiInfo = icBuildingDao.selectBuildingById(buildingId);
OrganizationCodeResultDTO org = getBuildingCoding(customerId, neiInfo.getNeighborHoodId(),true).getData();
ImportGeneralDTO neiInfo = icBuildingDao.selectBuildingById(buildingId);
OrganizationCodeResultDTO org = getBuildingCoding(customerId, neiInfo.getNeighborHoodId(), true).getData();
buildingEntity.setCoding(org.getCoding());
buildingEntity.setSysCoding(org.getSysCoding());
icBuildingDao.updateById(buildingEntity);
@ -247,15 +255,23 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//获取社区id、楼栋编码
OrganizationCommunityDTO communResult = icBuildingDao.selectCommunityByBuildingId(buildingId);
//查询该社区下是否存在单元数据
IcOrganizationCodeInfoEntity unitEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
if (StringUtils.isBlank(unitEntity.getUnitMaxNum())) {
result.setCoding(communResult.getCoding() + "01");
result.setSysCoding(communResult.getSysCoding() + "01");
//补充该社区的单元最大数
unitEntity.setUnitMaxNum("01");
//查询该楼栋下是否存在单元数据
IcOrganizationCodeInfoEntity unitEntity = baseDao.selectByIdAndType(customerId, buildingId, OrganizationTypeEnums.BUI.getCode());
if (null == unitEntity) {
Integer maxNum = 1;
result.setCoding(communResult.getCoding() + getNewMaxIndex(2, maxNum));
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, maxNum));
//新增该单元辅助数据
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 {
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);
IcBuildingUnitEntity isHaveCoding = icBuildingUnitDao.selectByCoding(unitCode);
@ -268,17 +284,17 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, unitMaxNum));
//更新该社区下最大的单元编号
if(updateFlag) {
unitEntity.setUnitMaxNum(getNewMaxIndex(2, unitMaxNum));
if (updateFlag) {
unitEntity.setMaxNum(getNewMaxIndex(2, unitMaxNum));
baseDao.updateMaxNumByIdAndType(unitEntity);
}
}
baseDao.updateUnitByCuIdAndCoId(unitEntity);
return new Result<OrganizationCodeResultDTO>().ok(result);
}
@Override
@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)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空");
}
@ -291,8 +307,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
}
//如果单元编码为空,先生成单元编码并更新
if (StringUtils.isBlank(unitEntity.getSysCoding())) {
HouseInfoResultDTO buildingInfo = icBuildingUnitDao.getUnitDetail(unitId);
OrganizationCodeResultDTO org = getUnitCoding(customerId, buildingInfo.getBuildingId(),true).getData();
HouseInfoResultDTO buildingInfo = icBuildingUnitDao.getUnitDetail(unitId);
OrganizationCodeResultDTO org = getUnitCoding(customerId, buildingInfo.getBuildingId(), true).getData();
unitEntity.setCoding(org.getCoding());
unitEntity.setSysCoding(org.getSysCoding());
icBuildingUnitDao.updateById(unitEntity);
@ -300,21 +316,29 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//获取社区id、单元编码
OrganizationCommunityDTO communResult = icBuildingUnitDao.selectCommunityByUnitId(unitId);
//查询该社区下是否存在单元数据
IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
if (StringUtils.isBlank(houseEntity.getUnitMaxNum())) {
result.setCoding(communResult.getCoding() + "001");
//补充该社区的房屋最大数
// houseEntity.setHouseMaxNum("001");
//查询该单元下是否存在房屋数据
IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByIdAndType(customerId, unitId, OrganizationTypeEnums.UNIT.getCode());
if (null == houseEntity) {
Integer maxNum = 1;
result.setCoding(communResult.getCoding() + getNewMaxIndex(4, maxNum));
//新增该单元辅助数据
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 {
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);
IcHouseEntity isHaveCoding = icHouseDao.selectByCoding(houseCode);
while (null != isHaveCoding) {
//先更新已有的最大值
houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum));
baseDao.updateHouseByCuIdAndCoId(houseEntity);
houseEntity.setMaxNum(getNewMaxIndex(4, houseMaxNum));
baseDao.updateMaxNumByIdAndType(houseEntity);
houseMaxNum++;
houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum);
isHaveCoding = icHouseDao.selectByCoding(houseCode);
@ -323,8 +347,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
//更新该社区下最大的房屋编号
// houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum));
// baseDao.updateMaxNumByIdAndType(houseEntity);
}
// baseDao.updateHouseByCuIdAndCoId(houseEntity);
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.IcNeighborHoodPropertyEntity;
import com.epmet.entity.IcOrganizationCodeInfoEntity;
import com.epmet.enums.OrganizationTypeEnums;
import com.epmet.excel.IcNeighborHoodExcel;
import com.epmet.feign.EpmetUserOpenFeignClient;
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(), "未查到相关社区信息", "未查到相关社区信息");
}
//如果是自增的,则最大数+1
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
Integer neighborMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getNeighborMaxNum())?1:Integer.valueOf(communEntity.getNeighborMaxNum()) + 1;
IcOrganizationCodeInfoEntity communEntity = icOrganizationCodeInfoDao.selectByIdAndType(customerId, communResult.getCommunityId(), OrganizationTypeEnums.COMM.getCode());
Integer neighborMaxNum = org.apache.commons.lang3.StringUtils.isBlank(communEntity.getMaxNum())?1:Integer.valueOf(communEntity.getMaxNum()) + 1;
Integer submitMaxNum = null;
try {
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(), "编码转换失败", "编码转换失败");
}
if(neighborMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setNeighborMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, neighborMaxNum));
icOrganizationCodeInfoDao.updateNeiByCuIdAndCoId(communEntity);
communEntity.setMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, neighborMaxNum));
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">
<result property="customerId" column="CUSTOMER_ID"/>
<result property="communityId" column="COMMUNITY_ID"/>
<result property="neighborMaxNum" column="NEIGHBOR_MAX_NUM"/>
<result property="buildingMaxNum" column="BUILDING_MAX_NUM"/>
<result property="houseMaxNum" column="HOUSE_MAX_NUM"/>
<result property="sysId" column="SYS_ID"/>
<result property="sysType" column="SYS_TYPE"/>
<result property="maxNum" column="MAX_NUM"/>
</resultMap>
<select id="selectByCommunityIdAndCustomerId" resultType="com.epmet.entity.IcOrganizationCodeInfoEntity">
<select id="selectByIdAndType" resultType="com.epmet.entity.IcOrganizationCodeInfoEntity">
select *
from ic_organization_code_info
where CUSTOMER_ID=#{customerId}
and COMMUNITY_ID = #{communityId}
and SYS_ID = #{sysId}
AND SYS_TYPE = #{sysType}
</select>
<update id="updateNeiByCuIdAndCoId">
<update id="updateMaxNumByIdAndType">
update ic_organization_code_info
set NEIGHBOR_MAX_NUM=#{neighborMaxNum}
set MAX_NUM=#{maxNum}
where CUSTOMER_ID = #{customerId}
and COMMUNITY_ID = #{communityId}
</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}
and SYS_ID = #{sysId}
AND SYS_TYPE = #{sysType}
</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>

Loading…
Cancel
Save