Commit ed56c8ce by 杨林龙

开发设备激活补充定时激活位置点数据定时任务

1 parent d2c810f0
package cn.com.glsx.schedulerjob.task.modules.service;
import cn.com.glsx.stdinterface.api.DeviceActiveClient;
import cn.com.glsx.stdinterface.dto.DeviceActiveDto;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 定时任务更新设备激活定位数据
*
* @author yangll
*/
@Slf4j
@Service
public class DeviceActiveSchedulerJobService {
@Autowired
private DeviceActiveClient deviceActiveClient;
/**
* 定时任务更新设备激活定位数据
*/
public void updateDeviceActiveInfoEveryDay() {
log.info("开始更新设备激活数据===");
R<List<String>> unActiveSnListR = deviceActiveClient.getUnActiveInfoSnList();
List<String> unActiveSnList = unActiveSnListR.getDataList(new TypeToken<List<String>>() {
}.getType());
log.info("设备号集合:" + JSONUtil.toJsonStr(unActiveSnList));
if (CollectionUtil.isEmpty(unActiveSnList)) {
log.info("unActiveSnList is null");
return;
}
DeviceActiveDto deviceActiveDto = new DeviceActiveDto();
deviceActiveDto.setSnList(unActiveSnList);
R statisticsR = deviceActiveClient.saveActiveInfo(deviceActiveDto);
log.info("更新设备激活数据的返回结果===" + JSON.toJSONString(statisticsR));
}
}
package cn.com.glsx.schedulerjob.task.taskscheduler;
import cn.com.glsx.schedulerjob.task.modules.service.DeviceActiveSchedulerJobService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
import com.glsx.plat.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 更新设备激活定位数据
*
* @author yangll
*/
@Slf4j
@Component
@ElasticSimpleJob(jobName = "DeviceActiveSchedulerJob", cron = "0 30 5 * * ?")
public class DeviceActiveSchedulerJob implements SimpleJob {
@Autowired
private DeviceActiveSchedulerJobService deviceActiveSchedulerJobService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("Thread ID: {}, 作业分片总数: {}, " +
"当前分片项: {}.当前参数: {}," +
"作业名称: {}.作业自定义参数: {}",
Thread.currentThread().getId(),
shardingContext.getShardingTotalCount(),
shardingContext.getShardingItem(),
shardingContext.getShardingParameter(),
shardingContext.getJobName(),
shardingContext.getJobParameter()
);
String normalDate = DateUtils.formatNormal(new Date());
log.info("---------------{}-开始----------------", normalDate);
deviceActiveSchedulerJobService.updateDeviceActiveInfoEveryDay();
log.info("---------------{}-结束--------------", normalDate);
}
}
package cn.com.glsx.schedulerjob.task.modules.service;
import cn.com.glsx.Application;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DeviceActiveSchedulerJobServiceTest {
@Autowired
private DeviceActiveSchedulerJobService deviceActiveSchedulerJobService;
@Test
public void updateDeviceActiveInfoEveryDay() {
System.out.println("start===");
deviceActiveSchedulerJobService.updateDeviceActiveInfoEveryDay();
System.out.println("end===");
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!