fix: 修复更换omada参数问题
This commit is contained in:
@@ -74,6 +74,15 @@ public class FeignConfig implements RequestInterceptor {
|
||||
authorization = PRE_ACCESS_TOKEN + cacheAccessToken;
|
||||
}
|
||||
if (StrUtil.isNotBlank(authorization)) {
|
||||
// 更新最新的omadaUrl和omadacId
|
||||
requestTemplate.target(omadaProperties.getOmadaUrl());
|
||||
String path = requestTemplate.path();
|
||||
String uri = path.substring(path.indexOf("/openapi/v1/") + 12);
|
||||
String lastUri = uri.substring(uri.indexOf("/"));
|
||||
if (!uri.startsWith("msp")) {
|
||||
requestTemplate.uri("/openapi/v1/" + omadaProperties.getOmadacId() + lastUri);
|
||||
}
|
||||
|
||||
// 添加授权请求头
|
||||
requestTemplate.header(AUTHORIZATION, authorization);
|
||||
}
|
||||
@@ -103,8 +112,7 @@ public class FeignConfig implements RequestInterceptor {
|
||||
ResponseEntity<OmadaResult<AuthorizeTokenVO>> responseEntity = restTemplate.exchange(uriString, HttpMethod.POST,
|
||||
request, new ParameterizedTypeReference<OmadaResult<AuthorizeTokenVO>>() {
|
||||
});
|
||||
OmadaResult<AuthorizeTokenVO> omadaResult = responseEntity.getBody();
|
||||
return omadaResult;
|
||||
return responseEntity.getBody();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.wfc.common.core.constant.Constants;
|
||||
import org.wfc.common.core.domain.R;
|
||||
import org.wfc.common.core.exception.job.TaskException;
|
||||
import org.wfc.common.core.utils.StringUtils;
|
||||
import org.wfc.common.core.utils.poi.ExcelUtil;
|
||||
@@ -23,6 +24,7 @@ import org.wfc.common.log.enums.BusinessType;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.job.domain.SysJob;
|
||||
import org.wfc.job.service.ISysJobService;
|
||||
import org.wfc.job.task.CdrInfoTask;
|
||||
import org.wfc.job.util.CronUtils;
|
||||
import org.wfc.job.util.ScheduleUtils;
|
||||
|
||||
@@ -41,6 +43,9 @@ public class SysJobController extends BaseController
|
||||
@Autowired
|
||||
private ISysJobService jobService;
|
||||
|
||||
@Autowired
|
||||
private CdrInfoTask cdrInfoTask;
|
||||
|
||||
/**
|
||||
* 查询定时任务列表
|
||||
*/
|
||||
@@ -169,6 +174,14 @@ public class SysJobController extends BaseController
|
||||
@PutMapping("/run")
|
||||
public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
|
||||
{
|
||||
SysJob sysJob = jobService.selectJobById(job.getJobId());
|
||||
if (sysJob != null && sysJob.getInvokeTarget().contains("cdrInfoTask")) {
|
||||
R<Boolean> omadaResult = cdrInfoTask.testOmadaApi();
|
||||
if (omadaResult.getCode() != 200) {
|
||||
return error(omadaResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = jobService.run(job);
|
||||
return result ? success() : error("任务不存在或已过期!");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.wfc.job.task;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.wfc.common.core.domain.R;
|
||||
import org.wfc.system.api.RemoteUserService;
|
||||
import org.wfc.user.api.RemoteUUserService;
|
||||
|
||||
@@ -23,9 +24,13 @@ public class CdrInfoTask {
|
||||
|
||||
public void addCdrInfo() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
remoteUUserService.addCdrInfoByOmadaApi();
|
||||
remoteUserService.deviceJob();
|
||||
remoteUUserService.addCdrInfoByOmadaApi();
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("wifi定时任务执行成功, 耗时:{} 毫秒", endTime - startTime);
|
||||
}
|
||||
|
||||
public R<Boolean> testOmadaApi() {
|
||||
return remoteUserService.deviceJob();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.wfc.common.redis.service.RedisService;
|
||||
import org.wfc.omada.api.device.OmadaDeviceApi;
|
||||
import org.wfc.omada.api.device.model.DeviceInfo;
|
||||
import org.wfc.omada.api.device.model.OperationResponseGridVoDeviceInfo;
|
||||
@@ -39,12 +40,24 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
|
||||
@Autowired
|
||||
private OmadaDeviceApi omadaDeviceApi;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
private static final String REDIS_ACCESS_TOKEN = "wfc-api-omada:access-token";
|
||||
private static final String REDIS_REFRESH_TOKEN = "wfc-api-omada:refresh-token";
|
||||
private static final int OMADA_ERROR_CODE = -44112;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deviceJob() {
|
||||
ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteList = omadaSiteApi.getSiteList(1, 1000);
|
||||
if (siteList.getBody() == null) {
|
||||
return false;
|
||||
}
|
||||
// 更换omada清空redis
|
||||
if (siteList.getBody().getErrorCode() == OMADA_ERROR_CODE) {
|
||||
redisService.deleteObject(REDIS_ACCESS_TOKEN);
|
||||
redisService.deleteObject(REDIS_REFRESH_TOKEN);
|
||||
}
|
||||
List<SiteSummaryInfo> sites = siteList.getBody().getResult().getData();
|
||||
for (SiteSummaryInfo site : sites) {
|
||||
ResponseEntity<OperationResponseGridVoDeviceInfo> deviceList = omadaDeviceApi.getDeviceList(site.getSiteId(), 1, 1000);
|
||||
|
||||
Reference in New Issue
Block a user