2
0

feat: 添加Omada初始化任务

This commit is contained in:
caiyuchao
2025-01-16 10:26:15 +08:00
parent e173c62c0c
commit d1ff37370c
10 changed files with 64 additions and 16 deletions

View File

@@ -219,7 +219,8 @@ CREATE TABLE `sys_job` (
-- ---------------------------- -- ----------------------------
-- Records of sys_job -- Records of sys_job
-- ---------------------------- -- ----------------------------
INSERT INTO `sys_job` VALUES (4, 'Omada定时任务', 'DEFAULT', 'cdrInfoTask.addCdrInfo', '0/30 * * * * ?', '3', '1', '0', 'admin', '2024-05-08 21:50:55', '', NULL, ''); INSERT INTO `sys_job` VALUES (4, 'Omada同步任务', 'DEFAULT', 'omadaTask.syncJob', '0/30 * * * * ?', '3', '1', '0', 'admin', '2024-05-08 21:50:55', '', NULL, '');
INSERT INTO `sys_job` VALUES (5, 'Omada初始化任务', 'DEFAULT', 'omadaTask.initJob', '0 0 0/1 * * ? ', '3', '1', '0', 'admin', '2024-05-08 21:50:55', '', NULL, '');
-- ---------------------------- -- ----------------------------
-- Table structure for sys_job_log -- Table structure for sys_job_log

View File

@@ -129,7 +129,7 @@ CREATE TABLE `u_bill_rule` (
-- ---------------------------- -- ----------------------------
-- Records of u_bill_rule -- Records of u_bill_rule
-- ---------------------------- -- ----------------------------
INSERT INTO `u_bill_rule` VALUES (1, 1.0000, 1, 1, 0, 0, NULL, NULL, 2, '2025-01-07 17:11:30'); INSERT INTO `u_bill_rule` VALUES (1, 1.0000, 1, 1, 1, 0, NULL, NULL, 2, '2025-01-07 17:11:30');
-- ---------------------------- -- ----------------------------
-- Table structure for u_cdr -- Table structure for u_cdr

View File

@@ -8,14 +8,13 @@ import io.swagger.annotations.ApiResponses;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.wfc.omada.config.FeignConfig;
import org.wfc.omada.api.maintenance.model.ModifyHistoryRetentionOpenApiVo; import org.wfc.omada.api.maintenance.model.ModifyHistoryRetentionOpenApiVo;
import org.wfc.omada.api.maintenance.model.OperationResponseHistoryRetentionOpenApiVo; import org.wfc.omada.api.maintenance.model.OperationResponseHistoryRetentionOpenApiVo;
import org.wfc.omada.api.maintenance.model.OperationResponseWithoutResult; import org.wfc.omada.api.maintenance.model.OperationResponseWithoutResult;
import org.wfc.omada.config.FeignConfig;
import javax.validation.Valid; import javax.validation.Valid;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-12-04T11:40:03.102+08:00[Asia/Shanghai]") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-12-04T11:40:03.102+08:00[Asia/Shanghai]")
@@ -38,7 +37,7 @@ public interface OmadaHistoryDataRetentionApi {
@RequestMapping(value = "/openapi/v1/${omada.omadac-id}/retention", @RequestMapping(value = "/openapi/v1/${omada.omadac-id}/retention",
produces = "*/*", produces = "*/*",
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<OperationResponseHistoryRetentionOpenApiVo> getDataRetention(@ApiParam(value = "Omada ID",required=true) @PathVariable("omadacId") String omadacId); ResponseEntity<OperationResponseHistoryRetentionOpenApiVo> getDataRetention();
/** /**

View File

@@ -54,4 +54,7 @@ public interface RemoteUserService
@PostMapping("/device/deviceJob") @PostMapping("/device/deviceJob")
public R<Boolean> deviceJob(); public R<Boolean> deviceJob();
@PostMapping("/device/settingJob")
public R<Boolean> settingJob();
} }

View File

@@ -47,6 +47,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
public R<Boolean> deviceJob() { public R<Boolean> deviceJob() {
return R.fail("记录设备信息失败:" + throwable.getMessage()); return R.fail("记录设备信息失败:" + throwable.getMessage());
} }
@Override
public R<Boolean> settingJob() {
return R.fail("oamda setting job error:" + throwable.getMessage());
}
}; };
} }
} }

View File

@@ -24,7 +24,7 @@ import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.utils.SecurityUtils; import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.job.domain.SysJob; import org.wfc.job.domain.SysJob;
import org.wfc.job.service.ISysJobService; import org.wfc.job.service.ISysJobService;
import org.wfc.job.task.CdrInfoTask; import org.wfc.job.task.OmadaTask;
import org.wfc.job.util.CronUtils; import org.wfc.job.util.CronUtils;
import org.wfc.job.util.ScheduleUtils; import org.wfc.job.util.ScheduleUtils;
@@ -44,7 +44,7 @@ public class SysJobController extends BaseController
private ISysJobService jobService; private ISysJobService jobService;
@Autowired @Autowired
private CdrInfoTask cdrInfoTask; private OmadaTask omadaTask;
/** /**
* 查询定时任务列表 * 查询定时任务列表
@@ -175,8 +175,8 @@ public class SysJobController extends BaseController
public AjaxResult run(@RequestBody SysJob job) throws SchedulerException public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
{ {
SysJob sysJob = jobService.selectJobById(job.getJobId()); SysJob sysJob = jobService.selectJobById(job.getJobId());
if (sysJob != null && sysJob.getInvokeTarget().contains("cdrInfoTask")) { if (sysJob != null && sysJob.getInvokeTarget().contains("omadaTask")) {
R<Boolean> omadaResult = cdrInfoTask.testOmadaApi(); R<Boolean> omadaResult = omadaTask.testOmadaApi();
if (omadaResult.getCode() != 200) { if (omadaResult.getCode() != 200) {
return error(omadaResult.getMsg()); return error(omadaResult.getMsg());
} }

View File

@@ -8,13 +8,13 @@ import org.wfc.system.api.RemoteUserService;
import org.wfc.user.api.RemoteUUserService; import org.wfc.user.api.RemoteUUserService;
/** /**
* @description: 话单信息任务 * @description: omada任务
* @author: cyc * @author: cyc
* @since: 2024-12-10 * @since: 2025-01-16
*/ */
@Slf4j @Slf4j
@Component("cdrInfoTask") @Component("omadaTask")
public class CdrInfoTask { public class OmadaTask {
@Autowired @Autowired
private RemoteUUserService remoteUUserService; private RemoteUUserService remoteUUserService;
@@ -22,7 +22,7 @@ public class CdrInfoTask {
@Autowired @Autowired
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
public void addCdrInfo() { public void syncJob() {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
remoteUserService.deviceJob(); remoteUserService.deviceJob();
remoteUUserService.addCdrInfoByOmadaApi(); remoteUUserService.addCdrInfoByOmadaApi();
@@ -33,4 +33,8 @@ public class CdrInfoTask {
public R<Boolean> testOmadaApi() { public R<Boolean> testOmadaApi() {
return remoteUserService.deviceJob(); return remoteUserService.deviceJob();
} }
public R<Boolean> initJob() {
return remoteUserService.settingJob();
}
} }

View File

@@ -74,4 +74,8 @@ public class SysDeviceController extends BaseController {
return toAjax(sysDeviceService.deviceJob()); return toAjax(sysDeviceService.deviceJob());
} }
@PostMapping("/settingJob")
public AjaxResult settingJob() {
return toAjax(sysDeviceService.settingJob());
}
} }

View File

@@ -14,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface ISysDeviceService extends IService<SysDevice> { public interface ISysDeviceService extends IService<SysDevice> {
boolean deviceJob(); boolean deviceJob();
boolean settingJob();
} }

View File

@@ -6,11 +6,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wfc.common.redis.service.RedisService; import org.wfc.common.redis.service.RedisService;
import org.wfc.omada.api.device.OmadaDeviceApi; import org.wfc.omada.api.device.OmadaDeviceApi;
import org.wfc.omada.api.device.model.DeviceInfo; import org.wfc.omada.api.device.model.DeviceInfo;
import org.wfc.omada.api.device.model.OperationResponseGridVoDeviceInfo; import org.wfc.omada.api.device.model.OperationResponseGridVoDeviceInfo;
import org.wfc.omada.api.maintenance.OmadaHistoryDataRetentionApi;
import org.wfc.omada.api.maintenance.model.HistoryRetentionOpenApiVo;
import org.wfc.omada.api.maintenance.model.ModifyHistoryRetentionOpenApiVo;
import org.wfc.omada.api.maintenance.model.OperationResponseHistoryRetentionOpenApiVo;
import org.wfc.omada.api.organization.OmadaSiteApi; import org.wfc.omada.api.organization.OmadaSiteApi;
import org.wfc.omada.api.organization.model.OperationResponseGridVoSiteSummaryInfo; import org.wfc.omada.api.organization.model.OperationResponseGridVoSiteSummaryInfo;
import org.wfc.omada.api.organization.model.SiteSummaryInfo; import org.wfc.omada.api.organization.model.SiteSummaryInfo;
@@ -40,6 +43,9 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
@Autowired @Autowired
private OmadaDeviceApi omadaDeviceApi; private OmadaDeviceApi omadaDeviceApi;
@Autowired
private OmadaHistoryDataRetentionApi omadaHistoryDataRetentionApi;
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
@@ -47,7 +53,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
private static final String REDIS_REFRESH_TOKEN = "wfc-api-omada:refresh-token"; private static final String REDIS_REFRESH_TOKEN = "wfc-api-omada:refresh-token";
private static final int OMADA_ERROR_CODE = -44112; private static final int OMADA_ERROR_CODE = -44112;
@Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
public boolean deviceJob() { public boolean deviceJob() {
ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteList = omadaSiteApi.getSiteList(1, 1000); ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteList = omadaSiteApi.getSiteList(1, 1000);
if (siteList.getBody() == null) { if (siteList.getBody() == null) {
@@ -58,6 +64,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
redisService.deleteObject(REDIS_ACCESS_TOKEN); redisService.deleteObject(REDIS_ACCESS_TOKEN);
redisService.deleteObject(REDIS_REFRESH_TOKEN); redisService.deleteObject(REDIS_REFRESH_TOKEN);
} }
settingJob();
List<SiteSummaryInfo> sites = siteList.getBody().getResult().getData(); List<SiteSummaryInfo> sites = siteList.getBody().getResult().getData();
for (SiteSummaryInfo site : sites) { for (SiteSummaryInfo site : sites) {
ResponseEntity<OperationResponseGridVoDeviceInfo> deviceList = omadaDeviceApi.getDeviceList(site.getSiteId(), 1, 1000); ResponseEntity<OperationResponseGridVoDeviceInfo> deviceList = omadaDeviceApi.getDeviceList(site.getSiteId(), 1, 1000);
@@ -84,4 +91,27 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
return true; return true;
} }
public boolean settingJob() {
// 启用Omada历史记录保留
ResponseEntity<OperationResponseHistoryRetentionOpenApiVo> dataRetentionRes = omadaHistoryDataRetentionApi.getDataRetention();
if (dataRetentionRes.getBody() == null) {
return false;
}
HistoryRetentionOpenApiVo historyRetention = dataRetentionRes.getBody().getResult();
if (!historyRetention.getClientsDataEnable()) {
ModifyHistoryRetentionOpenApiVo modify = new ModifyHistoryRetentionOpenApiVo();
modify.setClientsDataEnable(true);
modify.setClientHistory(31);
modify.setKnownClient(31);
modify.setDaily(90);
modify.setWeekly(180);
modify.setPortalAuth(31);
modify.setLog(31);
modify.setRogueAp(31);
omadaHistoryDataRetentionApi.modifyRetention(modify);
}
return true;
}
} }