feat: 添加Omada初始化任务
This commit is contained in:
@@ -219,7 +219,8 @@ CREATE TABLE `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
|
||||
|
||||
@@ -129,7 +129,7 @@ CREATE TABLE `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
|
||||
|
||||
@@ -8,14 +8,13 @@ import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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.RequestMapping;
|
||||
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.OperationResponseHistoryRetentionOpenApiVo;
|
||||
import org.wfc.omada.api.maintenance.model.OperationResponseWithoutResult;
|
||||
import org.wfc.omada.config.FeignConfig;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@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",
|
||||
produces = "*/*",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<OperationResponseHistoryRetentionOpenApiVo> getDataRetention(@ApiParam(value = "Omada ID",required=true) @PathVariable("omadacId") String omadacId);
|
||||
ResponseEntity<OperationResponseHistoryRetentionOpenApiVo> getDataRetention();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,4 +54,7 @@ public interface RemoteUserService
|
||||
|
||||
@PostMapping("/device/deviceJob")
|
||||
public R<Boolean> deviceJob();
|
||||
|
||||
@PostMapping("/device/settingJob")
|
||||
public R<Boolean> settingJob();
|
||||
}
|
||||
|
||||
@@ -47,6 +47,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
||||
public R<Boolean> deviceJob() {
|
||||
return R.fail("记录设备信息失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> settingJob() {
|
||||
return R.fail("oamda setting job error:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +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.task.OmadaTask;
|
||||
import org.wfc.job.util.CronUtils;
|
||||
import org.wfc.job.util.ScheduleUtils;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SysJobController extends BaseController
|
||||
private ISysJobService jobService;
|
||||
|
||||
@Autowired
|
||||
private CdrInfoTask cdrInfoTask;
|
||||
private OmadaTask omadaTask;
|
||||
|
||||
/**
|
||||
* 查询定时任务列表
|
||||
@@ -175,8 +175,8 @@ public class SysJobController extends BaseController
|
||||
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 (sysJob != null && sysJob.getInvokeTarget().contains("omadaTask")) {
|
||||
R<Boolean> omadaResult = omadaTask.testOmadaApi();
|
||||
if (omadaResult.getCode() != 200) {
|
||||
return error(omadaResult.getMsg());
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import org.wfc.system.api.RemoteUserService;
|
||||
import org.wfc.user.api.RemoteUUserService;
|
||||
|
||||
/**
|
||||
* @description: 话单信息任务
|
||||
* @description: omada任务
|
||||
* @author: cyc
|
||||
* @since: 2024-12-10
|
||||
* @since: 2025-01-16
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("cdrInfoTask")
|
||||
public class CdrInfoTask {
|
||||
@Component("omadaTask")
|
||||
public class OmadaTask {
|
||||
|
||||
@Autowired
|
||||
private RemoteUUserService remoteUUserService;
|
||||
@@ -22,7 +22,7 @@ public class CdrInfoTask {
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
public void addCdrInfo() {
|
||||
public void syncJob() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
remoteUserService.deviceJob();
|
||||
remoteUUserService.addCdrInfoByOmadaApi();
|
||||
@@ -33,4 +33,8 @@ public class CdrInfoTask {
|
||||
public R<Boolean> testOmadaApi() {
|
||||
return remoteUserService.deviceJob();
|
||||
}
|
||||
|
||||
public R<Boolean> initJob() {
|
||||
return remoteUserService.settingJob();
|
||||
}
|
||||
}
|
||||
@@ -74,4 +74,8 @@ public class SysDeviceController extends BaseController {
|
||||
return toAjax(sysDeviceService.deviceJob());
|
||||
}
|
||||
|
||||
@PostMapping("/settingJob")
|
||||
public AjaxResult settingJob() {
|
||||
return toAjax(sysDeviceService.settingJob());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
public interface ISysDeviceService extends IService<SysDevice> {
|
||||
|
||||
boolean deviceJob();
|
||||
|
||||
boolean settingJob();
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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;
|
||||
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.model.OperationResponseGridVoSiteSummaryInfo;
|
||||
import org.wfc.omada.api.organization.model.SiteSummaryInfo;
|
||||
@@ -40,6 +43,9 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
|
||||
@Autowired
|
||||
private OmadaDeviceApi omadaDeviceApi;
|
||||
|
||||
@Autowired
|
||||
private OmadaHistoryDataRetentionApi omadaHistoryDataRetentionApi;
|
||||
|
||||
@Autowired
|
||||
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 int OMADA_ERROR_CODE = -44112;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
public boolean deviceJob() {
|
||||
ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteList = omadaSiteApi.getSiteList(1, 1000);
|
||||
if (siteList.getBody() == null) {
|
||||
@@ -58,6 +64,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
|
||||
redisService.deleteObject(REDIS_ACCESS_TOKEN);
|
||||
redisService.deleteObject(REDIS_REFRESH_TOKEN);
|
||||
}
|
||||
settingJob();
|
||||
List<SiteSummaryInfo> sites = siteList.getBody().getResult().getData();
|
||||
for (SiteSummaryInfo site : sites) {
|
||||
ResponseEntity<OperationResponseGridVoDeviceInfo> deviceList = omadaDeviceApi.getDeviceList(site.getSiteId(), 1, 1000);
|
||||
@@ -84,4 +91,27 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user