Browse Source

双实信息录入-新增编码重复利用机制

master
Jackwang 3 years ago
parent
commit
34e3f8c1a4
  1. 6
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseInformationController.java
  2. 8
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcOrganizationCodeInfoService.java
  3. 36
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java
  4. 33
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java
  5. 46
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java
  6. 43
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/NeighborHoodServiceImpl.java

6
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseInformationController.java

@ -262,7 +262,7 @@ public class HouseInformationController {
*/ */
@PostMapping("getNeighborHoodCoding/{gridId}") @PostMapping("getNeighborHoodCoding/{gridId}")
public Result<OrganizationCodeResultDTO> getNeighborHoodCoding(@LoginUser TokenDto tokenDTO, @PathVariable("gridId") String gridId) { public Result<OrganizationCodeResultDTO> getNeighborHoodCoding(@LoginUser TokenDto tokenDTO, @PathVariable("gridId") String gridId) {
return icOrganizationCodeInfoService.getNeighborHoodCoding(tokenDTO.getCustomerId(),gridId); return icOrganizationCodeInfoService.getNeighborHoodCoding(tokenDTO.getCustomerId(),gridId,false);
} }
/** /**
@ -274,7 +274,7 @@ public class HouseInformationController {
*/ */
@PostMapping("getBuildingCoding/{neighborhoodId}") @PostMapping("getBuildingCoding/{neighborhoodId}")
public Result<OrganizationCodeResultDTO> getBuildingCoding(@LoginUser TokenDto tokenDTO, @PathVariable("neighborhoodId") String neighborhoodId) { public Result<OrganizationCodeResultDTO> getBuildingCoding(@LoginUser TokenDto tokenDTO, @PathVariable("neighborhoodId") String neighborhoodId) {
return icOrganizationCodeInfoService.getBuildingCoding(tokenDTO.getCustomerId(),neighborhoodId); return icOrganizationCodeInfoService.getBuildingCoding(tokenDTO.getCustomerId(),neighborhoodId,false);
} }
/** /**
@ -286,6 +286,6 @@ public class HouseInformationController {
*/ */
@PostMapping("getHouseCoding/{unitId}") @PostMapping("getHouseCoding/{unitId}")
public Result<OrganizationCodeResultDTO> getHouseCoding(@LoginUser TokenDto tokenDTO, @PathVariable("unitId") String unitId) { public Result<OrganizationCodeResultDTO> getHouseCoding(@LoginUser TokenDto tokenDTO, @PathVariable("unitId") String unitId) {
return icOrganizationCodeInfoService.getHouseCoding(tokenDTO.getCustomerId(),unitId); return icOrganizationCodeInfoService.getHouseCoding(tokenDTO.getCustomerId(),unitId,false);
} }
} }

8
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcOrganizationCodeInfoService.java

@ -85,7 +85,7 @@ public interface IcOrganizationCodeInfoService extends BaseService<IcOrganizatio
* @params [tokenDTO, gridId] * @params [tokenDTO, gridId]
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO> * @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO>
*/ */
Result<OrganizationCodeResultDTO> getNeighborHoodCoding(String customerId, String gridId); Result<OrganizationCodeResultDTO> getNeighborHoodCoding(String customerId, String gridId,Boolean updateFlag);
/** /**
* @describe: 双实录入获取楼栋编码 * @describe: 双实录入获取楼栋编码
@ -94,7 +94,7 @@ public interface IcOrganizationCodeInfoService extends BaseService<IcOrganizatio
* @params [tokenDTO, neighborhoodId] * @params [tokenDTO, neighborhoodId]
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO> * @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO>
*/ */
Result<OrganizationCodeResultDTO> getBuildingCoding(String customerId, String neighborhoodId); Result<OrganizationCodeResultDTO> getBuildingCoding(String customerId, String neighborhoodId,Boolean updateFlag);
/** /**
* @describe: 双实录入获取单元编码 * @describe: 双实录入获取单元编码
@ -103,7 +103,7 @@ public interface IcOrganizationCodeInfoService extends BaseService<IcOrganizatio
* @params [tokenDTO, neighborhoodId] * @params [tokenDTO, neighborhoodId]
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO> * @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO>
*/ */
Result<OrganizationCodeResultDTO> getUnitCoding(String customerId, String buildingId); Result<OrganizationCodeResultDTO> getUnitCoding(String customerId, String buildingId,Boolean updateFlag);
/** /**
* @describe: 双实录入获取房屋编码 * @describe: 双实录入获取房屋编码
@ -112,5 +112,5 @@ public interface IcOrganizationCodeInfoService extends BaseService<IcOrganizatio
* @params [tokenDTO, unitId] * @params [tokenDTO, unitId]
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO> * @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.OrganizationCodeResultDTO>
*/ */
Result<OrganizationCodeResultDTO> getHouseCoding(String customerId, String unitId); Result<OrganizationCodeResultDTO> getHouseCoding(String customerId, String unitId,Boolean updateFlag);
} }

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

@ -90,6 +90,10 @@ public class BuildingServiceImpl implements BuildingService {
private ExecutorService executorService; private ExecutorService executorService;
@Autowired @Autowired
private IcOrganizationCodeInfoService icOrganizationCodeInfoService; private IcOrganizationCodeInfoService icOrganizationCodeInfoService;
@Autowired
private IcOrganizationCodeInfoDao icOrganizationCodeInfoDao;
@Autowired
private IcOrganizationCodeInfoServiceImpl icOrganizationCodeInfoServiceImpl;
@Override @Override
@ -106,6 +110,7 @@ public class BuildingServiceImpl implements BuildingService {
if(null != isHaveCoding){ if(null != isHaveCoding){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该楼栋编码已存在,请勿重复!","该楼栋编码已存在,请勿重复!"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该楼栋编码已存在,请勿重复!","该楼栋编码已存在,请勿重复!");
} }
updateBuildingMaxNum(customerId,formDTO);
} }
IcBuildingDTO icBuildingDTO = ConvertUtils.sourceToTarget(formDTO, IcBuildingDTO.class); IcBuildingDTO icBuildingDTO = ConvertUtils.sourceToTarget(formDTO, IcBuildingDTO.class);
icBuildingDTO.setCustomerId(customerId); icBuildingDTO.setCustomerId(customerId);
@ -121,7 +126,7 @@ public class BuildingServiceImpl implements BuildingService {
icBuildingUnit.setBuildingId(entity.getId()); icBuildingUnit.setBuildingId(entity.getId());
icBuildingUnit.setUnitName((i + 1) + "单元"); icBuildingUnit.setUnitName((i + 1) + "单元");
icBuildingUnit.setUnitNum(String.valueOf(i + 1)); icBuildingUnit.setUnitNum(String.valueOf(i + 1));
Result<OrganizationCodeResultDTO> codeResult = icOrganizationCodeInfoService.getUnitCoding(customerId,entity.getId()); Result<OrganizationCodeResultDTO> codeResult = icOrganizationCodeInfoService.getUnitCoding(customerId,entity.getId(),true);
if(!codeResult.success() || null == codeResult.getData()){ if(!codeResult.success() || null == codeResult.getData()){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "生成单元编码异常,请联系管理员","生成单元编码异常,请联系管理员"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "生成单元编码异常,请联系管理员","生成单元编码异常,请联系管理员");
} }
@ -133,6 +138,32 @@ public class BuildingServiceImpl implements BuildingService {
} }
/**
* @describe: 如果编码未改动提交则最大数+1
* @author wangtong
* @date 2022/7/5 10:43
* @params [formDTO]
* @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;
Integer submitMaxNum = null;
try {
submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-3));
}catch (Exception e){
e.printStackTrace();
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败");
}
if(buildMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setBuildingMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, buildMaxNum));
icOrganizationCodeInfoDao.updateBuildingByCuIdAndCoId(communEntity);
}
}
@Override @Override
public List<BuildingTreeLevelDTO> treeList(String customerId, String staffId) { public List<BuildingTreeLevelDTO> treeList(String customerId, String staffId) {
CustomerStaffInfoCacheResult agency = CustomerStaffRedis.getStaffInfo(customerId, staffId); CustomerStaffInfoCacheResult agency = CustomerStaffRedis.getStaffInfo(customerId, staffId);
@ -460,6 +491,7 @@ public class BuildingServiceImpl implements BuildingService {
if(null != isHaveCoding){ if(null != isHaveCoding){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该楼栋编码已存在,请勿重复!","该楼栋编码已存在,请勿重复!"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该楼栋编码已存在,请勿重复!","该楼栋编码已存在,请勿重复!");
} }
updateBuildingMaxNum(customerId,formDTO);
} }
IcBuildingDTO icBuildingDTO = ConvertUtils.sourceToTarget(formDTO, IcBuildingDTO.class); IcBuildingDTO icBuildingDTO = ConvertUtils.sourceToTarget(formDTO, IcBuildingDTO.class);
icBuildingDTO.setId(formDTO.getBuildingId()); icBuildingDTO.setId(formDTO.getBuildingId());
@ -502,7 +534,7 @@ public class BuildingServiceImpl implements BuildingService {
icBuildingUnit.setCustomerId(customerId); icBuildingUnit.setCustomerId(customerId);
icBuildingUnit.setUnitName(unitNum + "单元"); icBuildingUnit.setUnitName(unitNum + "单元");
icBuildingUnit.setUnitNum(unitNum); icBuildingUnit.setUnitNum(unitNum);
Result<OrganizationCodeResultDTO> codeResult = icOrganizationCodeInfoService.getUnitCoding(customerId,icBuilding.getId()); Result<OrganizationCodeResultDTO> codeResult = icOrganizationCodeInfoService.getUnitCoding(customerId,icBuilding.getId(),true);
if(!codeResult.success() || null == codeResult.getData()){ if(!codeResult.success() || null == codeResult.getData()){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "生成单元编码异常,请联系管理员","生成单元编码异常,请联系管理员"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "生成单元编码异常,请联系管理员","生成单元编码异常,请联系管理员");
} }

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

@ -127,6 +127,12 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
private OssFeignClient ossFeignClient; private OssFeignClient ossFeignClient;
@Autowired @Autowired
private EpmetAdminOpenFeignClient epmetAdminOpenFeignClient; private EpmetAdminOpenFeignClient epmetAdminOpenFeignClient;
@Autowired
private IcOrganizationCodeInfoDao icOrganizationCodeInfoDao;
@Autowired
private IcOrganizationCodeInfoServiceImpl icOrganizationCodeInfoServiceImpl;
@Autowired
private IcBuildingUnitDao icBuildingUnitDao;
@Override @Override
@ -143,6 +149,7 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
if(null != isHaveCoding){ if(null != isHaveCoding){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该房屋编码已存在,请勿重复!","该房屋编码已存在,请勿重复!"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该房屋编码已存在,请勿重复!","该房屋编码已存在,请勿重复!");
} }
updateHouseMaxNum(customerId,formDTO);
} }
IcHouseEntity icHouseDTO = ConvertUtils.sourceToTarget(formDTO, IcHouseEntity.class); IcHouseEntity icHouseDTO = ConvertUtils.sourceToTarget(formDTO, IcHouseEntity.class);
icHouseDTO.setCustomerId(customerId); icHouseDTO.setCustomerId(customerId);
@ -164,6 +171,32 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
icHouseDao.updateById(entity); icHouseDao.updateById(entity);
} }
/**
* @describe: 如果编码未改动提交则最大数+1
* @author wangtong
* @date 2022/7/5 10:53
* @params [customerId, formDTO]
* @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;
Integer submitMaxNum = null;
try {
submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-4));
}catch (Exception e){
e.printStackTrace();
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败");
}
if(houseMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setHouseMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(4, houseMaxNum));
icOrganizationCodeInfoDao.updateHouseByCuIdAndCoId(communEntity);
}
}
private String getHouseName(IcHouseAddFormDTO formDTO) { private String getHouseName(IcHouseAddFormDTO formDTO) {
//设置房间名 楼栋-单元号-门牌号 //设置房间名 楼栋-单元号-门牌号
IcBuildingDTO icBuilding = icBuildingService.get(formDTO.getBuildingId()); IcBuildingDTO icBuilding = icBuildingService.get(formDTO.getBuildingId());

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

@ -108,7 +108,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) { 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(), "所有字段不可为空", "所有字段不可为空");
} }
@ -137,7 +137,9 @@ 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.setCommunityId(communResult.getCommunityId());
if(updateFlag){
newEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum)); newEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum));
}
baseDao.insert(newEntity); baseDao.insert(newEntity);
} else { } else {
Integer neighborMaxNum = Integer.valueOf(communEntity.getNeighborMaxNum()) + 1; Integer neighborMaxNum = Integer.valueOf(communEntity.getNeighborMaxNum()) + 1;
@ -145,14 +147,18 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
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));
baseDao.updateNeiByCuIdAndCoId(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) {
communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum)); communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum));
baseDao.updateNeiByCuIdAndCoId(communEntity); baseDao.updateNeiByCuIdAndCoId(communEntity);
}
String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum);
result.setCoding(neiCode); result.setCoding(neiCode);
result.setSysCoding(neighborCode); result.setSysCoding(neighborCode);
@ -162,7 +168,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) { 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(), "所有字段不可为空", "所有字段不可为空");
} }
@ -175,7 +181,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
} }
//如果小区编码为空,先生成小区编码并更新 //如果小区编码为空,先生成小区编码并更新
if (StringUtils.isBlank(neighborHood.getSysCoding())) { if (StringUtils.isBlank(neighborHood.getSysCoding())) {
OrganizationCodeResultDTO org = getNeighborHoodCoding(customerId, neighborHood.getGridId()).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,13 +195,16 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
result.setCoding(communResult.getCoding() + "001"); result.setCoding(communResult.getCoding() + "001");
result.setSysCoding(communResult.getSysCoding() + "001"); result.setSysCoding(communResult.getSysCoding() + "001");
//补充该社区的楼栋最大数 //补充该社区的楼栋最大数
buildingEntity.setBuildingMaxNum("001"); // buildingEntity.setBuildingMaxNum("001");
} else { } else {
Integer buildingMaxNum = Integer.valueOf(buildingEntity.getBuildingMaxNum()) + 1; Integer buildingMaxNum = Integer.valueOf(buildingEntity.getBuildingMaxNum()) + 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));
baseDao.updateBuildingByCuIdAndCoId(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);
@ -204,15 +213,19 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, buildingMaxNum)); result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, buildingMaxNum));
//更新该社区下最大的楼栋编号 //更新该社区下最大的楼栋编号
if(updateFlag) {
buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum)); buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum));
} }
}
if(updateFlag) {
baseDao.updateBuildingByCuIdAndCoId(buildingEntity); 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) { 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(), "所有字段不可为空", "所有字段不可为空");
} }
@ -226,7 +239,7 @@ 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()).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);
@ -255,15 +268,17 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, unitMaxNum)); result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, unitMaxNum));
//更新该社区下最大的单元编号 //更新该社区下最大的单元编号
if(updateFlag) {
unitEntity.setUnitMaxNum(getNewMaxIndex(2, unitMaxNum)); unitEntity.setUnitMaxNum(getNewMaxIndex(2, unitMaxNum));
} }
}
baseDao.updateUnitByCuIdAndCoId(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) { 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(), "所有字段不可为空", "所有字段不可为空");
} }
@ -277,7 +292,7 @@ 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()).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);
@ -289,14 +304,17 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId());
if (StringUtils.isBlank(houseEntity.getUnitMaxNum())) { if (StringUtils.isBlank(houseEntity.getUnitMaxNum())) {
result.setCoding(communResult.getCoding() + "001"); result.setCoding(communResult.getCoding() + "001");
//补充该社区的单元最大数 //补充该社区的房屋最大数
houseEntity.setHouseMaxNum("001"); // houseEntity.setHouseMaxNum("001");
} else { } else {
Integer houseMaxNum = Integer.valueOf(houseEntity.getUnitMaxNum()) + 1; Integer houseMaxNum = Integer.valueOf(houseEntity.getUnitMaxNum()) + 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));
baseDao.updateHouseByCuIdAndCoId(houseEntity);
houseMaxNum++; houseMaxNum++;
houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum); houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum);
isHaveCoding = icHouseDao.selectByCoding(houseCode); isHaveCoding = icHouseDao.selectByCoding(houseCode);
@ -304,9 +322,9 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
result.setCoding(houseCode); result.setCoding(houseCode);
//更新该社区下最大的房屋编号 //更新该社区下最大的房屋编号
houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum)); // houseEntity.setHouseMaxNum(getNewMaxIndex(4, houseMaxNum));
} }
baseDao.updateHouseByCuIdAndCoId(houseEntity); // baseDao.updateHouseByCuIdAndCoId(houseEntity);
return new Result<OrganizationCodeResultDTO>().ok(result); return new Result<OrganizationCodeResultDTO>().ok(result);
} }
@ -317,7 +335,7 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz
* @date 2022/6/29 10:30 * @date 2022/6/29 10:30
* @params [maxLength, maxIndex] * @params [maxLength, maxIndex]
*/ */
private String getNewMaxIndex(Integer maxLength, Integer maxIndex) { public String getNewMaxIndex(Integer maxLength, Integer maxIndex) {
String result = maxIndex.toString(); String result = maxIndex.toString();
while (result.length() < maxLength) { while (result.length() < maxLength) {
result = "0" + result; result = "0" + result;

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

@ -11,8 +11,10 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.NeighborhoodConstant; import com.epmet.constant.NeighborhoodConstant;
import com.epmet.dao.CustomerGridDao;
import com.epmet.dao.IcNeighborHoodDao; import com.epmet.dao.IcNeighborHoodDao;
import com.epmet.dao.IcNeighborHoodPropertyDao; import com.epmet.dao.IcNeighborHoodPropertyDao;
import com.epmet.dao.IcOrganizationCodeInfoDao;
import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.IcNeighborHoodDTO; import com.epmet.dto.IcNeighborHoodDTO;
import com.epmet.dto.IcNeighborHoodPropertyDTO; import com.epmet.dto.IcNeighborHoodPropertyDTO;
@ -21,9 +23,11 @@ import com.epmet.dto.form.IcNeighborHoodAddFormDTO;
import com.epmet.dto.form.IcNeighborHoodListFormDTO; import com.epmet.dto.form.IcNeighborHoodListFormDTO;
import com.epmet.dto.form.IcUserBelongToChangedFormDTO; import com.epmet.dto.form.IcUserBelongToChangedFormDTO;
import com.epmet.dto.result.IcNeighborHoodResultDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO;
import com.epmet.dto.result.OrganizationCommunityDTO;
import com.epmet.entity.IcHouseEntity; 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.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;
@ -62,6 +66,12 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I
private IcNeighborHoodDao icNeighborHoodDao; private IcNeighborHoodDao icNeighborHoodDao;
@Autowired @Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@Autowired
private CustomerGridDao customerGridDao;
@Autowired
private IcOrganizationCodeInfoDao icOrganizationCodeInfoDao;
@Autowired
private IcOrganizationCodeInfoServiceImpl icOrganizationCodeInfoServiceImpl;
@Override @Override
@ -79,12 +89,13 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I
if (!customerAgencyResult.success()) { if (!customerAgencyResult.success()) {
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
} }
//小区编码不可重复 //小区编码不可重复,自增最大数+1
if(org.apache.commons.lang3.StringUtils.isNotBlank(formDTO.getCoding())){ if(org.apache.commons.lang3.StringUtils.isNotBlank(formDTO.getCoding())){
IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(formDTO.getCoding(),null); IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(formDTO.getCoding(),null);
if(null != isHaveCoding){ if(null != isHaveCoding){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该小区编码已存在,请勿重复!","该小区编码已存在,请勿重复!"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该小区编码已存在,请勿重复!","该小区编码已存在,请勿重复!");
} }
updateNeiMaxNum(customerId,formDTO);
} }
CustomerAgencyDTO customerAgencyDTO = Optional.ofNullable(customerAgencyResult.getData()).orElse(new CustomerAgencyDTO()); CustomerAgencyDTO customerAgencyDTO = Optional.ofNullable(customerAgencyResult.getData()).orElse(new CustomerAgencyDTO());
icNeighborHoodDTO.setParentAgencyId(customerAgencyDTO.getPid()); icNeighborHoodDTO.setParentAgencyId(customerAgencyDTO.getPid());
@ -103,6 +114,35 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I
} }
} }
/**
* @describe: 如果编码未改动提交则最大数+1
* @author wangtong
* @date 2022/7/5 10:47
* @params [customerId, formDTO]
* @return void
*/
private void updateNeiMaxNum(String customerId, IcNeighborHoodAddFormDTO formDTO){
//获取社区id、行政编码
OrganizationCommunityDTO communResult = customerGridDao.selectCommunityByGridId(formDTO.getGridId());
if (null == communResult || org.apache.commons.lang3.StringUtils.isBlank(communResult.getCommunityId())) {
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;
Integer submitMaxNum = null;
try {
submitMaxNum = Integer.valueOf(formDTO.getCoding().substring(formDTO.getCoding().length()-3));
}catch (Exception e){
e.printStackTrace();
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "编码转换失败", "编码转换失败");
}
if(neighborMaxNum.intValue() == submitMaxNum.intValue()){
communEntity.setNeighborMaxNum(icOrganizationCodeInfoServiceImpl.getNewMaxIndex(3, neighborMaxNum));
icOrganizationCodeInfoDao.updateNeiByCuIdAndCoId(communEntity);
}
}
/** /**
* 查询 * 查询
* @param formDTO * @param formDTO
@ -142,6 +182,7 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I
if(null != isHaveCoding){ if(null != isHaveCoding){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该小区编码已存在,请勿重复!","该小区编码已存在,请勿重复!"); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该小区编码已存在,请勿重复!","该小区编码已存在,请勿重复!");
} }
updateNeiMaxNum(customerId,formDTO);
} }
IcNeighborHoodDTO icNeighborHoodDTO = ConvertUtils.sourceToTarget(formDTO, IcNeighborHoodDTO.class); IcNeighborHoodDTO icNeighborHoodDTO = ConvertUtils.sourceToTarget(formDTO, IcNeighborHoodDTO.class);
icNeighborHoodDTO.setId(formDTO.getNeighborHoodId()); icNeighborHoodDTO.setId(formDTO.getNeighborHoodId());

Loading…
Cancel
Save