| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | |
| | | if (StringUtils.isEmpty(ser.getCompanyId())) { |
| | | ser.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | if (StringUtils.isEmpty(ser.getDeptId())) { |
| | | ser.setDeptId(ContextUtil.subDeptId(null)); |
| | | |
| | | //判断接口路径 |
| | | if (StringUtils.isEmpty(ser.getPlateNumUrl())) { |
| | | ser.setPlateNumUrl("/open/api/get-plateNum"); |
| | | } |
| | | if (StringUtils.isBlank(ser.getUpdateBy())) { |
| | | if (StringUtils.isEmpty(ser.getPlayUrl())) { |
| | | ser.setPlayUrl("/open/api/get-media"); |
| | | } |
| | | if (StringUtils.isEmpty(ser.getSnapUrl())) { |
| | | ser.setSnapUrl("/open/api/snap-img"); |
| | | } |
| | | if (StringUtils.isEmpty(ser.getPtzUrl())) { |
| | | ser.setPtzUrl("/open/api/ptz-media"); |
| | | } |
| | | |
| | | ser.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | ser.setUpdateTime(new Date()); |
| | | if (StringUtils.isBlank(ser.getCreateBy())) { |
| | | ser.setCreateBy(ContextUtil.getLoginUserName()); |
| | | ser.setCreateTime(new Date()); |
| | | ser.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | ser.setUpdateTime(new Date()); |
| | | gatewaySerMapper.insert(ser); |
| | | } else { |
| | | ser.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | ser.setUpdateTime(new Date()); |
| | | gatewaySerMapper.updateById(ser); |
| | | } |
| | | |
| | | refreshCache(ser.getCompanyId()); |
| | | } |
| | | |
| | | /** |
| | | * 异步更新网关状态 |
| | | * @param ser 信息 |
| | | * @param status 状态 |
| | | * @param isUpdateTime 是否更新心跳时间 |
| | | */ |
| | | @Async |
| | | public void updateStatus(GatewaySer ser, String status, boolean isUpdateTime) { |
| | | |
| | | if(isUpdateTime){ |
| | | //心跳时间 |
| | | ser.setHeartbeatTime(new Date()); |
| | | } |
| | | |
| | | ser.setUpdateTime(new Date()); |
| | | ser.setStatus(status); |
| | | gatewaySerMapper.updateById(ser); |
| | | |
| | | setCacheSer(ser); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 根据分机ID获取分机信息 |
| | | * |
| | | * @param companyId |
| | | * @param deptId |
| | | * @return |
| | | */ |
| | | public List<GatewaySer> getCacheSerByDeptId(String companyId, String deptId) { |
| | | if (StringUtils.isEmpty(deptId)) { |
| | | return null; |
| | | } |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEVICE_SER_LIST, deptId) + "*"; |
| | | Collection<String> keys = redisCache.keys(patten); |
| | | if (null == keys) { |
| | | return null; |
| | | } |
| | | |
| | | List<GatewaySer> list = new ArrayList<>(); |
| | | for (String key : keys) { |
| | | list.add((GatewaySer) redisCache.getCacheObject(key)); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 根据分机ID获取分机信息 |
| | | * |
| | | * @param companyId |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEVICE_SER_LIST) + "*"; |
| | | String patten = RedisConst.buildKey(companyId, RedisConst.KEY_GATEWAY_SER_LIST) + "*"; |
| | | Collection<String> keys = redisCache.keys(patten); |
| | | if (null == keys) { |
| | | return null; |
| | | } |
| | | |
| | | List<GatewaySer> list = new ArrayList<>(); |
| | | GatewaySer ser = null; |
| | | for (String key : keys) { |
| | | ser = (GatewaySer) redisCache.getCacheObject(key); |