Commit d2c810f0 by 杨林龙

添加不在店统计数据定时任务

1 parent 4e72dbcd
package cn.com.glsx.schedulerjob.task.modules.service;
import cn.com.glsx.stdinterface.api.StatisticsInStoreClient;
import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author liuyf
* @date 2021年01月26日 下午2:37:40
*/
@Slf4j
@Service
public class StatisticsInStoreSchedulerJobService {
@Autowired
private StatisticsInStoreClient statisticsInStoreClient;
public void calculateStatisticsInStoreDateEveryDay() {
log.info("开始统计并插入不在店统计数据===");
R<Integer> statisticsR = statisticsInStoreClient.statisticsAndInsertInStoreDataEveryDay();
log.info("统计的返回结果===" + JSON.toJSONString(statisticsR));
}
}
package cn.com.glsx.schedulerjob.task.taskscheduler;
import cn.com.glsx.schedulerjob.task.modules.service.StatisticsInStoreSchedulerJobService;
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;
/**
* 统计并插入不在店统计任务
*/
@Slf4j
@Component
@ElasticSimpleJob(jobName = "StatisticsInStoreSchedulerJob", cron = "0 30 4 * * ?")
public class StatisticsInStoreSchedulerJob implements SimpleJob {
@Autowired
private StatisticsInStoreSchedulerJobService statisticsInStoreSchedulerJobService;
@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);
statisticsInStoreSchedulerJobService.calculateStatisticsInStoreDateEveryDay();
log.info("---------------{}-结束--------------", normalDate);
}
}
...@@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringRunner; ...@@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@Slf4j @Slf4j
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class InStoreSchedulerJobServiceTest { public class InStoreSchedulerJobServiceTest {
@Autowired @Autowired
InStoreSchedulerJobService inStoreSchedulerJobService; InStoreSchedulerJobService inStoreSchedulerJobService;
......
...@@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner; ...@@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@Slf4j @Slf4j
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class MySimpleJobServiceTest { public class MySimpleJobServiceTest {
@Autowired @Autowired
private MySimpleJobService mySimpleJobService; private MySimpleJobService mySimpleJobService;
......
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)
class StatisticsInStoreSchedulerJobServiceTest {
@Autowired
StatisticsInStoreSchedulerJobService statisticsInStoreSchedulerJobService;
@Test
public void calculateInStoreDateEveryDay() {
System.out.println("statisticsInStoreSchedulerJobService start===");
statisticsInStoreSchedulerJobService.calculateStatisticsInStoreDateEveryDay();
System.out.println("statisticsInStoreSchedulerJobService 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!