|  |  | @ -27,6 +27,8 @@ import com.elink.esua.epdc.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.constant.StrConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.exception.RenException; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.redis.RedisKeys; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.redis.RedisUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.utils.IdentityNoUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.elink.esua.epdc.commons.tools.utils.Result; | 
			
		
	
	
		
			
				
					|  |  | @ -113,6 +115,9 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private QrCodeProperties qrCodeProperties; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private RedisUtils redisUtils; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<EpidemicBuildingUnitDTO> page(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         IPage<EpidemicBuildingUnitDTO> page = getPage(params); | 
			
		
	
	
		
			
				
					|  |  | @ -179,6 +184,13 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException("房屋已存在"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         checkData(dto); | 
			
		
	
		
			
				
					|  |  |  |         if (dto.getBuildingId() != null && dto.getUnit() != null) { | 
			
		
	
		
			
				
					|  |  |  |             int unitCode = getUnitNewCode(dto.getBuildingId(), dto.getUnit().trim().toUpperCase()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setUnitMaCode(unitCode); | 
			
		
	
		
			
				
					|  |  |  |             int roomCode = getRoomMaxCode(dto.getBuildingId(), dto.getUnit().trim().toUpperCase()); | 
			
		
	
		
			
				
					|  |  |  |             roomCode = roomCode + 1; | 
			
		
	
		
			
				
					|  |  |  |             dto.setRoomMaCode(roomCode); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         EpidemicBuildingUnitEntity entity = ConvertUtils.sourceToTarget(dto, EpidemicBuildingUnitEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         insert(entity); | 
			
		
	
		
			
				
					|  |  |  |         saveOrUpdateOwners(dto.getOwners(), entity.getId()); | 
			
		
	
	
		
			
				
					|  |  | @ -326,14 +338,28 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public int getMaxCode() { | 
			
		
	
		
			
				
					|  |  |  |         Integer maxCode = baseDao.getMaxCode(); | 
			
		
	
		
			
				
					|  |  |  |     public int getRoomMaxCode(Long buildingId, String unit) { | 
			
		
	
		
			
				
					|  |  |  |         Integer maxCode = baseDao.getRoomMaxCode(buildingId, unit); | 
			
		
	
		
			
				
					|  |  |  |         if (maxCode == null) { | 
			
		
	
		
			
				
					|  |  |  |             maxCode = 0; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return maxCode; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public int getUnitNewCode(Long buildingId, String unit) { | 
			
		
	
		
			
				
					|  |  |  |         Integer code = baseDao.getUnitCode(buildingId, unit); | 
			
		
	
		
			
				
					|  |  |  |         if (code != null && code != NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             return code; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         Integer maxCode = baseDao.getUnitMaxCode(buildingId); | 
			
		
	
		
			
				
					|  |  |  |         if (maxCode == null || maxCode == NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             maxCode = 0; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         maxCode = maxCode + 1; | 
			
		
	
		
			
				
					|  |  |  |         return maxCode; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void updateErrorRoom() { | 
			
		
	
		
			
				
					|  |  |  |         List<EpidemicBuildingUnitEntity> list = baseDao.getErrorRoom(); | 
			
		
	
	
		
			
				
					|  |  | @ -363,13 +389,59 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |         params.put("roomMaCode", "0"); | 
			
		
	
		
			
				
					|  |  |  |         List<EpidemicBuildingUnitEntity> list = baseDao.selectList(getWrapper(params)); | 
			
		
	
		
			
				
					|  |  |  |         if (!list.isEmpty()) { | 
			
		
	
		
			
				
					|  |  |  |             for (int i = 0; i < list.size(); i++) { | 
			
		
	
		
			
				
					|  |  |  |                 list.get(i).setRoomMaCode(i + 1); | 
			
		
	
		
			
				
					|  |  |  |             for (EpidemicBuildingUnitEntity epidemicBuildingUnitEntity : list) { | 
			
		
	
		
			
				
					|  |  |  |                 if (epidemicBuildingUnitEntity.getBuildingId() != null && StringUtils.isNotBlank(epidemicBuildingUnitEntity.getUnit())) { | 
			
		
	
		
			
				
					|  |  |  |                     updateUnitMaCode(epidemicBuildingUnitEntity); | 
			
		
	
		
			
				
					|  |  |  |                     if (StringUtils.isNotBlank(epidemicBuildingUnitEntity.getRoomNo())) { | 
			
		
	
		
			
				
					|  |  |  |                         updateRoomMaCode(epidemicBuildingUnitEntity); | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             updateBatchById(list); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     private void updateUnitMaCode(EpidemicBuildingUnitEntity entity) { | 
			
		
	
		
			
				
					|  |  |  |         String key = RedisKeys.getMaUnitCodeKey(entity.getBuildingId().toString(), entity.getUnit()); | 
			
		
	
		
			
				
					|  |  |  |         String nextKey = RedisKeys.getMaUnitNextCodeKey(entity.getBuildingId().toString()); | 
			
		
	
		
			
				
					|  |  |  |         Object obj = redisUtils.get(key); | 
			
		
	
		
			
				
					|  |  |  |         Object nextObj = redisUtils.get(nextKey); | 
			
		
	
		
			
				
					|  |  |  |         if (null != obj) { | 
			
		
	
		
			
				
					|  |  |  |             int maCodeCache = (int) obj; | 
			
		
	
		
			
				
					|  |  |  |             entity.setUnitMaCode(maCodeCache); | 
			
		
	
		
			
				
					|  |  |  |             redisUtils.set(key, maCodeCache, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         if (null != nextObj) { | 
			
		
	
		
			
				
					|  |  |  |             int maCodeCache = (int) nextObj; | 
			
		
	
		
			
				
					|  |  |  |             entity.setUnitMaCode(maCodeCache); | 
			
		
	
		
			
				
					|  |  |  |             redisUtils.set(key, maCodeCache, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |             redisUtils.set(nextKey, maCodeCache + 1, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         int maCode = getUnitNewCode(entity.getBuildingId(), entity.getUnit()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setUnitMaCode(maCode); | 
			
		
	
		
			
				
					|  |  |  |         redisUtils.set(key, maCode, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |         redisUtils.set(nextKey, maCode + 1, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     private void updateRoomMaCode(EpidemicBuildingUnitEntity entity) { | 
			
		
	
		
			
				
					|  |  |  |         String key = RedisKeys.getMaRoomCodeKey(entity.getBuildingId().toString(), entity.getUnit()); | 
			
		
	
		
			
				
					|  |  |  |         Object obj = redisUtils.get(key); | 
			
		
	
		
			
				
					|  |  |  |         if (null != obj) { | 
			
		
	
		
			
				
					|  |  |  |             int maCodeCache = (int) obj; | 
			
		
	
		
			
				
					|  |  |  |             maCodeCache = maCodeCache + 1; | 
			
		
	
		
			
				
					|  |  |  |             entity.setRoomMaCode(maCodeCache); | 
			
		
	
		
			
				
					|  |  |  |             redisUtils.set(key, maCodeCache, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         int maCode = getRoomMaxCode(entity.getBuildingId(), entity.getUnit()); | 
			
		
	
		
			
				
					|  |  |  |         maCode = maCode + 1; | 
			
		
	
		
			
				
					|  |  |  |         entity.setRoomMaCode(maCode); | 
			
		
	
		
			
				
					|  |  |  |         redisUtils.set(key, maCode, RedisUtils.HOUR_ONE_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public Result createBatchHouseCodeAndUrl() { | 
			
		
	
		
			
				
					|  |  |  |         epidemicPlotBuildingService.updateMaCode(); | 
			
		
	
	
		
			
				
					|  |  | @ -609,7 +681,7 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |             epidemicUserInfoService.updateBatchById(updateList); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         // 补充人房关系
 | 
			
		
	
		
			
				
					|  |  |  |         int roomCode = getMaxCode(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         List<EpidemicUnitInfoResultDTO> unitList = listAllUnitInfo(parentAndAllDeptDTO.getGrid()); | 
			
		
	
		
			
				
					|  |  |  |         List<EpidemicUnitOwnerEntity> addOwner = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         for (EpidemicUserInfoEntity item : addList) { | 
			
		
	
	
		
			
				
					|  |  | @ -633,6 +705,9 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |                     unitEntity.setOwnerName(item.getUserName()); | 
			
		
	
		
			
				
					|  |  |  |                     unitEntity.setMobile(item.getMobile()); | 
			
		
	
		
			
				
					|  |  |  |                     unitEntity.setRoomType(NumConstant.ONE_STR); | 
			
		
	
		
			
				
					|  |  |  |                     int unitCode = getUnitNewCode(buildingOptional.get().getId(), item.getUnit().trim().toUpperCase()); | 
			
		
	
		
			
				
					|  |  |  |                     unitEntity.setUnitMaCode(unitCode); | 
			
		
	
		
			
				
					|  |  |  |                     int roomCode = getRoomMaxCode(buildingOptional.get().getId(), item.getUnit().trim().toUpperCase()); | 
			
		
	
		
			
				
					|  |  |  |                     roomCode = roomCode + 1; | 
			
		
	
		
			
				
					|  |  |  |                     unitEntity.setRoomMaCode(roomCode); | 
			
		
	
		
			
				
					|  |  |  |                     unitEntity.setRoomCode(getRoomCode(buildingOptional.get().getBuildingMaCode(), roomCode)); | 
			
		
	
	
		
			
				
					|  |  | @ -690,6 +765,9 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui | 
			
		
	
		
			
				
					|  |  |  |                         unitEntity.setOwnerName(item.getUserName()); | 
			
		
	
		
			
				
					|  |  |  |                         unitEntity.setMobile(item.getMobile()); | 
			
		
	
		
			
				
					|  |  |  |                         unitEntity.setRoomType(NumConstant.ONE_STR); | 
			
		
	
		
			
				
					|  |  |  |                         int unitCode = getUnitNewCode(buildingOptional.get().getId(), item.getUnit().trim().toUpperCase()); | 
			
		
	
		
			
				
					|  |  |  |                         unitEntity.setUnitMaCode(unitCode); | 
			
		
	
		
			
				
					|  |  |  |                         int roomCode = getRoomMaxCode(buildingOptional.get().getId(), item.getUnit().trim().toUpperCase()); | 
			
		
	
		
			
				
					|  |  |  |                         roomCode = roomCode + 1; | 
			
		
	
		
			
				
					|  |  |  |                         unitEntity.setRoomMaCode(roomCode); | 
			
		
	
		
			
				
					|  |  |  |                         unitEntity.setRoomCode(getRoomCode(buildingOptional.get().getBuildingMaCode(), roomCode)); | 
			
		
	
	
		
			
				
					|  |  | 
 |