package org.ts.ddcs.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
import org.ts.ddcs.business.lkszy.service.LkszyService;
import org.ts.ddcs.business.rtu.service.RtuService;
import org.ts.ddcs.log.LogHelper;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.*;

/**
 * @author dylan
 */
@Component
public class DataProcess {

    private ExecutorService treadPool = Executors.newFixedThreadPool(1);

    @Resource
    public RedisTemplate redisTemplate;

    @Resource
    public LkszyService lkszyService;

    @Resource
    public RtuService rtuService;

    @PostConstruct
    public void init() {
        DataProcessHolder.newInstance().dataProcess = this;
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
    }

    public void submitJtPhotoTast() {
        try {
            JtTakePhotoTask task = new JtTakePhotoTask();
            FutureTask<Integer> futureTask = new FutureTask<>(task);
            this.treadPool.submit(futureTask);
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }

    public void submitLkszyDataShareTast() {
        try {
            LkszyDataShareTask task = new LkszyDataShareTask();
            FutureTask<Integer> futureTask = new FutureTask<>(task);
            this.treadPool.submit(futureTask);
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
