|
|
@ -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<IcOrganiz |
|
|
|
@Autowired |
|
|
|
private IcOrganizationCodeInfoRedis icOrganizationCodeInfoRedis; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerGridDao customerGridDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcNeighborHoodDao icNeighborHoodDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcBuildingDao icBuildingDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcBuildingUnitDao icBuildingUnitDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcHouseDao icHouseDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<IcOrganizationCodeInfoDTO> page(Map<String, Object> params) { |
|
|
|
IPage<IcOrganizationCodeInfoEntity> page = baseDao.selectPage( |
|
|
@ -48,8 +70,8 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz |
|
|
|
return ConvertUtils.sourceToTarget(entityList, IcOrganizationCodeInfoDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<IcOrganizationCodeInfoEntity> getWrapper(Map<String, Object> params){ |
|
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
|
private QueryWrapper<IcOrganizationCodeInfoEntity> getWrapper(Map<String, Object> params) { |
|
|
|
String id = (String) params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
QueryWrapper<IcOrganizationCodeInfoEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
@ -84,4 +106,232 @@ public class IcOrganizationCodeInfoServiceImpl extends BaseServiceImpl<IcOrganiz |
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result<OrganizationCodeResultDTO> 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<OrganizationCodeResultDTO>().ok(result); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result<OrganizationCodeResultDTO> 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<OrganizationCodeResultDTO>().ok(result); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result<OrganizationCodeResultDTO> 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<OrganizationCodeResultDTO>().ok(result); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result<OrganizationCodeResultDTO> 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<OrganizationCodeResultDTO>().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; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|