diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrganizationCodeResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrganizationCodeResultDTO.java new file mode 100644 index 0000000000..c370f5bbe3 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrganizationCodeResultDTO.java @@ -0,0 +1,26 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @program: epmet-cloud + * @description:小区-楼栋-房屋编码 + * @author: wangtong + * @create: 2022-06-29 09:51 + **/ +@Data +public class OrganizationCodeResultDTO implements Serializable { + + /** + * 可编辑的楼栋编码 + */ + private String coding; + + + /** + * 不可编辑的楼栋编码 + */ + private String sysCoding; +} diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrganizationCommunityDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrganizationCommunityDTO.java new file mode 100644 index 0000000000..1933aeaa66 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrganizationCommunityDTO.java @@ -0,0 +1,24 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @program: epmet-cloud + * @description: + * @author: wangtong + * @create: 2022-06-29 10:13 + **/ +@Data +public class OrganizationCommunityDTO implements Serializable { + + private String communityId; + + private String areaCode; + + private String coding; + + private String sysCoding; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseInformationController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseInformationController.java index 13bf9edbe5..ea9b6504a0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseInformationController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseInformationController.java @@ -24,10 +24,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.HouseInformationFormDTO; import com.epmet.dto.result.*; import com.epmet.entity.IcNeighborHoodEntity; -import com.epmet.service.HouseInformationService; -import com.epmet.service.IcBuildingService; -import com.epmet.service.IcBuildingUnitService; -import com.epmet.service.IcNeighborHoodService; +import com.epmet.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -56,6 +53,9 @@ public class HouseInformationController { @Resource private HouseInformationService houseInformationService; + @Autowired + private IcOrganizationCodeInfoService icOrganizationCodeInfoService; + /** * @describe: 【双实录入】小区详情 * @author wangtong @@ -242,4 +242,40 @@ public class HouseInformationController { formDTO.setStaffId(tokenDTO.getUserId()); return new Result>().ok(houseInformationService.getHouseList(formDTO)); } + + /** + * @describe: 【双实录入】获取小区编码 + * @author wangtong + * @date 2022/6/29 9:59 + * @params [tokenDTO, gridId] + * @return com.epmet.commons.tools.utils.Result + */ + @PostMapping("getNeighborHoodCoding/{gridId}") + public Result getNeighborHoodCoding(@LoginUser TokenDto tokenDTO, @PathVariable("gridId") String gridId) { + return icOrganizationCodeInfoService.getNeighborHoodCoding(tokenDTO.getCustomerId(),gridId); + } + + /** + * @describe: 【双实录入】获取楼栋编码 + * @author wangtong + * @date 2022/6/29 9:59 + * @params [tokenDTO, neighborhoodId] + * @return com.epmet.commons.tools.utils.Result + */ + @PostMapping("getBuildingCoding/{neighborhoodId}") + public Result getBuildingCoding(@LoginUser TokenDto tokenDTO, @PathVariable("neighborhoodId") String neighborhoodId) { + return icOrganizationCodeInfoService.getBuildingCoding(tokenDTO.getCustomerId(),neighborhoodId); + } + + /** + * @describe: 【双实录入】获取房屋编码 + * @author wangtong + * @date 2022/6/29 9:59 + * @params [tokenDTO, unitId] + * @return com.epmet.commons.tools.utils.Result + */ + @PostMapping("getHouseCoding/{unitId}") + public Result getHouseCoding(@LoginUser TokenDto tokenDTO, @PathVariable("unitId") String unitId) { + return icOrganizationCodeInfoService.getHouseCoding(tokenDTO.getCustomerId(),unitId); + } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java index 737e579fa5..1fb999e0f0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java @@ -384,4 +384,13 @@ public interface CustomerGridDao extends BaseDao { int updateTotalUser(@Param("gridId") String gridId, @Param("incrCount") long incrCount); List getDelGridIdList(@Param("agencyId") String agencyId); + + /** + * @describe: 通过网格id获取社区行政编码 + * @author wangtong + * @date 2022/6/29 10:16 + * @params [gridId] + * @return com.epmet.dto.result.OrganizationCommunityDTO + */ + OrganizationCommunityDTO selectCommunityByGridId(@Param("gridId") String gridId); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java index a996255750..e38cfbbdda 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java @@ -204,4 +204,23 @@ public interface IcBuildingDao extends BaseDao { * @return com.epmet.dto.result.IcBulidingDetailDTO */ IcBulidingDetailDTO getBuildingDetail(@Param("buildingId") String buildingId); + + /** + * @describe: 查询社区id及楼栋编码 + * @author wangtong + * @date 2022/6/29 14:39 + * @params [buildingId] + * @return com.epmet.dto.result.OrganizationCommunityDTO + */ + OrganizationCommunityDTO selectCommunityByBuildingId(@Param("buildingId") String buildingId); + + /** + * @describe: 通过可编辑编码查询 + * @author wangtong + * @date 2022/6/29 14:57 + * @params [coding] + * @return com.epmet.entity.IcBuildingEntity + */ + IcBuildingEntity selectByCoding(@Param("coding") String coding); + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingUnitDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingUnitDao.java index ad5e8358a7..09c40920ed 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingUnitDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingUnitDao.java @@ -19,6 +19,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.result.HouseInfoResultDTO; +import com.epmet.dto.result.OrganizationCommunityDTO; import com.epmet.entity.IcBuildingUnitEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -59,4 +60,22 @@ public interface IcBuildingUnitDao extends BaseDao { * @return com.epmet.dto.result.HouseInfoResultDTO */ HouseInfoResultDTO getUnitDetail(@Param("unitId") String unitId); + + /** + * @describe: 通过可编辑编码查询 + * @author wangtong + * @date 2022/6/29 14:59 + * @params [coding] + * @return com.epmet.entity.IcBuildingUnitEntity + */ + IcBuildingUnitEntity selectByCoding(@Param("coding") String coding); + + /** + * @describe: 查询社区id及单元编码 + * @author wangtong + * @date 2022/6/29 15:15 + * @params [buildingId] + * @return com.epmet.dto.result.OrganizationCommunityDTO + */ + OrganizationCommunityDTO selectCommunityByUnitId(@Param("unitId") String unitId); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcHouseDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcHouseDao.java index 8efb45cf92..9779126809 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcHouseDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcHouseDao.java @@ -172,4 +172,13 @@ public interface IcHouseDao extends BaseDao { * @return java.util.List */ List searchHouseZipList(IcHouseListFormDTO formDTO); + + /** + * @describe: 通过可编辑的编码查询 + * @author wangtong + * @date 2022/6/29 15:24 + * @params [coding] + * @return com.epmet.entity.IcHouseEntity + */ + IcHouseEntity selectByCoding(@Param("coding") String coding); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java index ca929081cc..0bdd1d770f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java @@ -23,6 +23,7 @@ import com.epmet.dto.ImportGeneralDTO; import com.epmet.dto.NeighborHoodAndManagementDTO; import com.epmet.dto.form.IcNeighborHoodListFormDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO; +import com.epmet.dto.result.OrganizationCommunityDTO; import com.epmet.entity.IcHouseEntity; import com.epmet.entity.IcNeighborHoodEntity; import com.epmet.excel.IcNeighborHoodExcel; @@ -91,4 +92,22 @@ public interface IcNeighborHoodDao extends BaseDao { void updateOneNeighborHood(ImportGeneralDTO info); String getAreaCode(@Param("neighborHoodId")String neighborHoodId); + + /** + * @describe: 查询社区id及小区编码 + * @author wangtong + * @date 2022/6/29 13:35 + * @params [neighborhoodId] + * @return com.epmet.dto.result.OrganizationCommunityDTO + */ + OrganizationCommunityDTO selectCommunityByNeiId(@Param("neighborhoodId") String neighborhoodId); + + /** + * @describe: 通过可编辑的编码查询 + * @author wangtong + * @date 2022/6/29 14:08 + * @params [coding] + * @return com.epmet.entity.IcNeighborHoodEntity + */ + IcNeighborHoodEntity selectByCoding(@Param("coding") String coding); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcOrganizationCodeInfoDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcOrganizationCodeInfoDao.java index c3b0a92d80..f2429582e2 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcOrganizationCodeInfoDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcOrganizationCodeInfoDao.java @@ -3,6 +3,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.IcOrganizationCodeInfoEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 小区/楼栋/房屋编码辅助表 @@ -12,5 +13,50 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface IcOrganizationCodeInfoDao extends BaseDao { - -} \ No newline at end of file + + /** + * @describe: 通过客户id和社区id查询 + * @author wangtong + * @date 2022/6/29 10:24 + * @params [customerId, communityId] + * @return com.epmet.entity.IcOrganizationCodeInfoEntity + */ + IcOrganizationCodeInfoEntity selectByCommunityIdAndCustomerId(@Param("customerId") String customerId, + @Param("communityId") String communityId); + + /** + * @describe: 根据客户id和社区id更新小区编号 + * @author wangtong + * @date 2022/6/29 10:53 + * @params [communEntity] + * @return void + */ + void updateNeiByCuIdAndCoId(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); +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcBuildingUnitEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcBuildingUnitEntity.java index bce611c47f..02124c90cc 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcBuildingUnitEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcBuildingUnitEntity.java @@ -55,4 +55,14 @@ public class IcBuildingUnitEntity extends BaseEpmetEntity { */ private String unitName; + /** + * 楼栋编码 + */ + private String coding; + + /** + * 楼栋系统编码 + */ + private String sysCoding; + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcOrganizationCodeInfoEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcOrganizationCodeInfoEntity.java index f4e9671a73..e8c4a6d939 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcOrganizationCodeInfoEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcOrganizationCodeInfoEntity.java @@ -37,6 +37,10 @@ public class IcOrganizationCodeInfoEntity{ */ private String buildingMaxNum; + /** + * 该社区下最大的单元编码序列号 + */ + private String unitMaxNum; /** * 该社区下最大的房屋编码序列号 */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcOrganizationCodeInfoService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcOrganizationCodeInfoService.java index e98db783b5..c0e3bb5545 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcOrganizationCodeInfoService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcOrganizationCodeInfoService.java @@ -2,7 +2,9 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; import com.epmet.dto.IcOrganizationCodeInfoDTO; +import com.epmet.dto.result.OrganizationCodeResultDTO; import com.epmet.entity.IcOrganizationCodeInfoEntity; import java.util.List; @@ -75,4 +77,40 @@ public interface IcOrganizationCodeInfoService extends BaseService + */ + Result getNeighborHoodCoding(String customerId, String gridId); + + /** + * @describe: 【双实录入】获取楼栋编码 + * @author wangtong + * @date 2022/6/29 9:59 + * @params [tokenDTO, neighborhoodId] + * @return com.epmet.commons.tools.utils.Result + */ + Result getBuildingCoding(String customerId, String neighborhoodId); + + /** + * @describe: 【双实录入】获取单元编码 + * @author wangtong + * @date 2022/6/29 9:59 + * @params [tokenDTO, neighborhoodId] + * @return com.epmet.commons.tools.utils.Result + */ + Result getUnitCoding(String customerId, String buildingId); + + /** + * @describe: 【双实录入】获取房屋编码 + * @author wangtong + * @date 2022/6/29 9:59 + * @params [tokenDTO, unitId] + * @return com.epmet.commons.tools.utils.Result + */ + Result getHouseCoding(String customerId, String unitId); +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java index d6eba569b3..8cbb9ebbe0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcOrganizationCodeInfoServiceImpl.java @@ -3,12 +3,19 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.constant.FieldConstant; -import com.epmet.dao.IcOrganizationCodeInfoDao; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dao.*; import com.epmet.dto.IcOrganizationCodeInfoDTO; -import com.epmet.entity.IcOrganizationCodeInfoEntity; +import com.epmet.dto.ImportGeneralDTO; +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.redis.IcOrganizationCodeInfoRedis; import com.epmet.service.IcOrganizationCodeInfoService; import org.apache.commons.lang3.StringUtils; @@ -32,6 +39,21 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl page(Map params) { IPage page = baseDao.selectPage( @@ -48,8 +70,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); @@ -84,4 +106,232 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl getNeighborHoodCoding(String customerId, String gridId) { + if (StringUtils.isBlank(customerId) || StringUtils.isBlank(gridId)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); + } + OrganizationCodeResultDTO result = new OrganizationCodeResultDTO(); + //获取社区id、行政编码 + OrganizationCommunityDTO communResult = customerGridDao.selectCommunityByGridId(gridId); + if (null == communResult || StringUtils.isBlank(communResult.getCommunityId())) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关社区信息", "未查到相关社区信息"); + } + //查询该社区下是否存在数据 + IcOrganizationCodeInfoEntity communEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); + if (null == communEntity) { + String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + "001"; + + result.setCoding(neighborCode); + result.setSysCoding(neighborCode); + //新增该社区辅助数据 + IcOrganizationCodeInfoEntity newEntity = new IcOrganizationCodeInfoEntity(); + newEntity.setCustomerId(customerId); + newEntity.setCommunityId(communResult.getCommunityId()); + newEntity.setNeighborMaxNum("001"); + baseDao.insert(newEntity); + } else { + Integer neighborMaxNum = Integer.valueOf(communEntity.getNeighborMaxNum()) + 1; + //验证可编辑的编码是否有重复 + String neiCode = communResult.getCoding() + getNewMaxIndex(3, neighborMaxNum); + IcNeighborHoodEntity isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode); + while (null != isHaveCoding) { + neighborMaxNum++; + neiCode = communResult.getCoding() + getNewMaxIndex(3, neighborMaxNum); + isHaveCoding = icNeighborHoodDao.selectByCoding(neiCode); + } + //更新该社区下最大的小区编号 + communEntity.setNeighborMaxNum(getNewMaxIndex(3, neighborMaxNum)); + baseDao.updateNeiByCuIdAndCoId(communEntity); + + String neighborCode = getCompleteAreaCode(communResult.getAreaCode()) + getNewMaxIndex(3, neighborMaxNum); + result.setCoding(neiCode); + result.setSysCoding(neighborCode); + } + return new Result().ok(result); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result getBuildingCoding(String customerId, String neighborhoodId) { + if (StringUtils.isBlank(customerId) || StringUtils.isBlank(neighborhoodId)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); + } + //组装返回结果 + OrganizationCodeResultDTO result = new OrganizationCodeResultDTO(); + + IcNeighborHoodEntity neighborHood = icNeighborHoodDao.selectById(neighborhoodId); + if (null == neighborHood) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关小区信息", "未查到相关小区信息"); + } + //如果小区编码为空,先生成小区编码并更新 + if (StringUtils.isBlank(neighborHood.getSysCoding())) { + OrganizationCodeResultDTO org = getNeighborHoodCoding(customerId, neighborHood.getGridId()).getData(); + neighborHood.setCoding(org.getCoding()); + neighborHood.setSysCoding(org.getSysCoding()); + icNeighborHoodDao.updateById(neighborHood); + } + + //获取社区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"); + } else { + Integer buildingMaxNum = Integer.valueOf(buildingEntity.getBuildingMaxNum()) + 1; + //验证可编辑的编码是否有重复 + String buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum); + IcBuildingEntity isHaveCoding = icBuildingDao.selectByCoding(buildingCode); + while (null != isHaveCoding) { + buildingMaxNum++; + buildingCode = communResult.getCoding() + getNewMaxIndex(3, buildingMaxNum); + isHaveCoding = icBuildingDao.selectByCoding(buildingCode); + } + result.setCoding(buildingCode); + result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(3, buildingMaxNum)); + + //更新该社区下最大的楼栋编号 + buildingEntity.setBuildingMaxNum(getNewMaxIndex(3, buildingMaxNum)); + } + baseDao.updateBuildingByCuIdAndCoId(buildingEntity); + return new Result().ok(result); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result getUnitCoding(String customerId, String buildingId) { + if (StringUtils.isBlank(customerId) || StringUtils.isBlank(buildingId)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); + } + //组装返回结果 + OrganizationCodeResultDTO result = new OrganizationCodeResultDTO(); + + IcBuildingEntity buildingEntity = icBuildingDao.selectById(buildingId); + if (null == buildingEntity) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关楼栋信息", "未查到相关楼栋信息"); + } + //如果楼栋编码为空,先生成楼栋编码并更新 + if (StringUtils.isBlank(buildingEntity.getSysCoding())) { + ImportGeneralDTO neiInfo = icBuildingDao.selectBuildingById(buildingId); + OrganizationCodeResultDTO org = getBuildingCoding(customerId, neiInfo.getNeighborHoodId()).getData(); + buildingEntity.setCoding(org.getCoding()); + buildingEntity.setSysCoding(org.getSysCoding()); + icBuildingDao.updateById(buildingEntity); + } + + //获取社区id、楼栋编码 + OrganizationCommunityDTO communResult = icBuildingDao.selectCommunityByBuildingId(buildingId); + //查询该社区下是否存在单元数据 + IcOrganizationCodeInfoEntity unitEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); + if (StringUtils.isBlank(unitEntity.getUnitMaxNum())) { + result.setCoding(communResult.getCoding() + "001"); + result.setSysCoding(communResult.getSysCoding() + "001"); + //补充该社区的单元最大数 + unitEntity.setUnitMaxNum("001"); + } else { + Integer unitMaxNum = Integer.valueOf(unitEntity.getUnitMaxNum()) + 1; + //验证可编辑的编码是否有重复 + String unitCode = communResult.getCoding() + getNewMaxIndex(2, unitMaxNum); + IcBuildingUnitEntity isHaveCoding = icBuildingUnitDao.selectByCoding(unitCode); + while (null != isHaveCoding) { + unitMaxNum++; + unitCode = communResult.getCoding() + getNewMaxIndex(2, unitMaxNum); + isHaveCoding = icBuildingUnitDao.selectByCoding(unitCode); + } + result.setCoding(unitCode); + result.setSysCoding(communResult.getSysCoding() + getNewMaxIndex(2, unitMaxNum)); + + //更新该社区下最大的单元编号 + unitEntity.setUnitMaxNum(getNewMaxIndex(2, unitMaxNum)); + } + baseDao.updateUnitByCuIdAndCoId(unitEntity); + return new Result().ok(result); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result getHouseCoding(String customerId, String unitId) { + if (StringUtils.isBlank(customerId) || StringUtils.isBlank(unitId)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所有字段不可为空", "所有字段不可为空"); + } + //组装返回结果 + OrganizationCodeResultDTO result = new OrganizationCodeResultDTO(); + + IcBuildingUnitEntity unitEntity = icBuildingUnitDao.selectById(unitId); + if (null == unitEntity) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关单元信息", "未查到相关单元信息"); + } + //如果单元编码为空,先生成单元编码并更新 + if (StringUtils.isBlank(unitEntity.getSysCoding())) { + HouseInfoResultDTO buildingInfo = icBuildingUnitDao.getUnitDetail(unitId); + OrganizationCodeResultDTO org = getUnitCoding(customerId, buildingInfo.getBuildingId()).getData(); + unitEntity.setCoding(org.getCoding()); + unitEntity.setSysCoding(org.getSysCoding()); + icBuildingUnitDao.updateById(unitEntity); + } + + //获取社区id、单元编码 + OrganizationCommunityDTO communResult = icBuildingUnitDao.selectCommunityByUnitId(unitId); + //查询该社区下是否存在单元数据 + IcOrganizationCodeInfoEntity houseEntity = baseDao.selectByCommunityIdAndCustomerId(customerId, communResult.getCommunityId()); + if (StringUtils.isBlank(houseEntity.getUnitMaxNum())) { + result.setCoding(communResult.getCoding() + "001"); + //补充该社区的单元最大数 + houseEntity.setUnitMaxNum("001"); + } else { + Integer houseMaxNum = Integer.valueOf(houseEntity.getUnitMaxNum()) + 1; + //验证可编辑的编码是否有重复 + String houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum); + IcHouseEntity isHaveCoding = icHouseDao.selectByCoding(houseCode); + while (null != isHaveCoding) { + houseMaxNum++; + houseCode = communResult.getCoding() + getNewMaxIndex(4, houseMaxNum); + isHaveCoding = icHouseDao.selectByCoding(houseCode); + } + result.setCoding(houseCode); + + //更新该社区下最大的房屋编号 + houseEntity.setUnitMaxNum(getNewMaxIndex(4, houseMaxNum)); + } + baseDao.updateHouseByCuIdAndCoId(houseEntity); + return new Result().ok(result); + } + + /** + * @return java.lang.String + * @describe: 把数字转换成maxLength位的字符串,不够的前面补0 + * @author wangtong + * @date 2022/6/29 10:30 + * @params [maxLength, maxIndex] + */ + private String getNewMaxIndex(Integer maxLength, Integer maxIndex) { + String result = maxIndex.toString(); + while (result.length() < maxLength) { + result = "0" + result; + } + return result; + } + + /** + * @return java.lang.String + * @describe: 补全行政编码,12位 + * @author wangtong + * @date 2022/6/29 10:34 + * @params [areaCode] + */ + private String getCompleteAreaCode(String areaCode) { + if (StringUtils.isBlank(areaCode)) { + areaCode = "0"; + } + while (areaCode.length() < 12) { + areaCode = areaCode + "0"; + } + return areaCode; + } + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.32__alter_ic_organization_code_info.sql b/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.32__alter_ic_organization_code_info.sql new file mode 100644 index 0000000000..aa87d01a3a --- /dev/null +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.32__alter_ic_organization_code_info.sql @@ -0,0 +1,4 @@ +alter table ic_organization_code_info add COLUMN`UNIT_MAX_NUM` varchar(10) NOT NULL COMMENT '该社区下最大的单元编码序列号'; + +alter table ic_building_unit add COLUMN `CODING` varchar(64) DEFAULT NULL COMMENT '单元编码'; +alter table ic_building_unit add COLUMN `SYS_CODING` varchar(64) DEFAULT NULL COMMENT '单元系统编码'; diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml index e428bc42c6..c98c898f26 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml @@ -861,5 +861,13 @@ UPDATE customer_grid SET total_user = total_user+#{incrCount} where id = #{gridId} and del_flag = '0' + diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml index c87edfccd5..a7ffad3cd8 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml @@ -428,5 +428,22 @@ WHERE b.DEL_FLAG = '0' AND b.ID = #{buildingId} + + diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingUnitDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingUnitDao.xml index 31b2e4873e..fe5a0ef73b 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingUnitDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingUnitDao.xml @@ -40,6 +40,24 @@ WHERE bu.DEL_FLAG = '0' AND bu.ID = #{unitId} + + diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml index c55f985fc5..326bbc864f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml @@ -521,5 +521,11 @@ #{id} ) + diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml index 8d6e24b5f7..544451a17c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml @@ -312,4 +312,20 @@ a.del_flag = '0' AND a.ID = #{neighborHoodId} + + diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcOrganizationCodeInfoDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcOrganizationCodeInfoDao.xml index b544ba7019..c5fea23a4f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcOrganizationCodeInfoDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcOrganizationCodeInfoDao.xml @@ -10,6 +10,36 @@ + + + update ic_organization_code_info + set NEIGHBOR_MAX_NUM=#{neighborMaxNum} + where CUSTOMER_ID = #{customerId} + and COMMUNITY_ID = #{communityId} + + + update ic_organization_code_info + set BUILDING_MAX_NUM=#{buildingMaxNum} + where CUSTOMER_ID = #{customerId} + and COMMUNITY_ID = #{communityId} + + + update ic_organization_code_info + set UNIT_MAX_NUM=#{unitMaxNum} + where CUSTOMER_ID = #{customerId} + and COMMUNITY_ID = #{communityId} + + + update ic_organization_code_info + set HOUSE_MAX_NUM=#{houseMaxNum} + where CUSTOMER_ID = #{customerId} + and COMMUNITY_ID = #{communityId} + - \ No newline at end of file +