admin
2024-04-11 a2e67e004a5b908cb2b5eeda53101befb0d9578f
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
package com.ruoyi;
 
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.task.CameraAssembleUtil;
import com.ruoyi.utils.FtpUtils;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class DataTransmissionThread extends Thread {
 
    private static RedisCache redisCache;//缓存
 
    static  {
        redisCache= SpringUtils.getBean(RedisCache.class);
    }
 
    public  static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
 
    public DataTransmissionThread(String name) {
        // 设置当前线程的名字
        this.setName(name);
    }
 
    @Override
    public void run() {
        while (true){
            Date date=new Date();
            String nowTime=format.format(date);
            //System.out.println("当前运行的线程名为: " + Thread.currentThread().getName()+nowTime);
            try{
                long listOrder=redisCache.lGetListSize(Thread.currentThread().getName());
 
                //缓存当前线程最新一次处理的情况   -  用于运维监控
                JSONObject runObj=new JSONObject();
                runObj.put("date",nowTime);
                runObj.put("pendingCount",listOrder);
                runObj.put("time",date.getTime());
                redisCache.setCacheObject(Thread.currentThread().getName()+"::Run",runObj);
                if(listOrder>0){
                    //获取队列中的第一个(防止发送频繁,一次只处理一个)
                    JSONObject obj= (JSONObject) redisCache.lGetLpopIndex(Thread.currentThread().getName());
 
                    if(Thread.currentThread().getName().equals("CameraAssemble")){
                        CameraAssembleUtil.DataTransmission(obj);
                    }
                }else{
                    Thread.sleep(1000);
                }
            }catch (Exception e){
                System.err.println(e);
            }
        }
 
    }
}