1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.qianwen.mdc.collect.runner;
 
import java.time.LocalDate;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
 
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
 
import com.google.common.collect.Sets;
import com.qianwen.mdc.collect.cache.TimeSliceCache;
import com.qianwen.mdc.collect.dto.CacheBuildDTO;
import com.qianwen.mdc.collect.mapper.iotdb.DeviceStateMapper;
import com.qianwen.mdc.collect.service.DeviceStateFixPointService;
import com.qianwen.mdc.collect.service.WorkstationAppMappingService;
 
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
 
@Component
public class InitRunner implements ApplicationRunner {
    private static final Logger log = LoggerFactory.getLogger(InitRunner.class);
 
    @Autowired
    private DeviceStateFixPointService stateFixPointService;
    @Autowired
    private TimeSliceCache timeSliceCache;
    @Autowired
    private DeviceStateMapper deviceStateMapper;
    //@Autowired
    //private WorkstationAppMappingService mappingService;;
    
    @Override
    public void run(ApplicationArguments args) throws Exception {
        
        //mappingService.saveToCache();
        
        //生成时间切片
        CacheBuildDTO cacheBuildDTO = CacheBuildDTO.builder().tenantIds(Sets.newHashSet(new String[]{"000000"})).targetDate(LocalDate.now()).build();
        timeSliceCache.build(cacheBuildDTO);
        
        checkNeedStateFixPoint();
    }
 
    //@RedisLock("posting:lock:initStateFixPoint")
    public void checkNeedStateFixPoint() {
        DateTime dateTime = DateTime.now();
        log.info("程序启动校验是否存在工位打过固定点....... ");
       
        Long count = deviceStateMapper.fixPointCountByDate(Integer.valueOf(DatePattern.PURE_DATE_FORMAT.format(dateTime)));
        /*
        Long result = this.workstationStateMapper.selectCount(Wrappers.<WorkstationState>lambdaQuery()
                .eq(WorkstationState::getFactoryDate, Integer.valueOf(DatePattern.PURE_DATE_FORMAT.format(dateTime)))
                .eq(WorkstationState::getIsFixPoint, Boolean.TRUE));
                */
        //Long result = 1L;
        if(count == null || count == 0) {
        //if (count <= 0) {
            log.info("设备未打过锚点,启动时打点....... ");
            //this.workStationStateFixPointService.workStationStateFixPoint(dateTime, null);
            stateFixPointService.deviceStateFixPoint(dateTime, null);
        }else {
            log.info("设备已存在锚点");
        }
    }
}