whyclj
2020-10-23 291d27a34b52911dbcfd8232f0685d34b0fc96a8
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.dev.data;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Date;
import java.util.List;
 
import com.base.BaseData;
import com.base.Com;
import com.base.ComBase;
import com.sql.MysqlConnPool;
 
/**
 *     ´¦Àí×ÓÕ¾ºÍÆûÂÖ·¢µç»úÊý¾Ý
 * @author LiJun
 *
 */
public class ChildStoodParse_Thread implements Runnable{
    
    public static final int Config_DataType = 1;    //ÅäÖÃÐÅÏ¢
    public static final int State_DataType = 2;        //״ֵ̬ÐÅÏ¢
    
    public MysqlConnPool conn_pool;
    public List<Device_inf> devices;
    public List<ConfigData> configs;                //ÅäÖÃÎļþÊý¾Ý    
    public BaseData baseData;
    public int dev_id;                                //µ±Ç°½âÎöµÄÉ豸id
    public int dev_type;                            //Êý¾ÝÀàÐÍ
    
    public ChildStoodParse_Thread(MysqlConnPool conn_pool,List<Device_inf> devices,List<ConfigData> configs,BaseData baseData,int dev_type) {
        this.conn_pool = conn_pool;
        this.devices = devices;
        this.configs = configs;
        this.baseData = baseData;
        this.dev_type = dev_type;
    }
    
    @Override
    public void run() {
        //System.out.println(" ChildStoodParse_Thread start at "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        Device_inf device = null;
        if(dev_type == Dev_UDPServer_Thread.ZIZHAN_DATATYPE) {
            /************************½âÎö×ÓÕ¾Êý¾Ý°ü********************************************/
            device = assemDevData();        //½âÎöÊý¾Ý°ü
            if(null != device) {
                //¸üÐÂʵʱÊý¾Ý
                ChildStoodParse_Thread_SQL.upDeviceRtData(conn_pool,device);
                
                //²åÈëÀúʷʵʱÊý¾Ý
                ChildStoodParse_Thread_SQL.insertDeviceHistoryData(conn_pool, device);
                
                
            }            
        }else if(dev_type == Dev_UDPServer_Thread.QIFA_DATATYPE){
                        
            /************************½âÎöÆûÂÖ·¢µç»úÊý¾Ý°ü********************************************/
            for(int i = 0; i<devices.size();i++) {
                if(devices.get(i).dev_id/100 == 40) {
                    //¸üÐÂʵʱÊý¾Ý
                    ChildStoodParse_Thread_SQL.upDeviceRtData(conn_pool,device);
                    
                    //²åÈëÀúʷʵʱÊý¾Ý
                    ChildStoodParse_Thread_SQL.insertDeviceHistoryData(conn_pool, device);
                }                
            }
            
        }
        
        Dev_UDPServer_Thread.thread_count--;             //×ÜÏß³ÌÊý-1
    }
    
    //½âÎöÊý¾Ý
    public Device_inf assemDevData() {
        ByteBuffer bf = ByteBuffer.allocate(baseData.data.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(baseData.data);
        bf.flip();
        bf.position(0);
        int index;
        ConfigData data = null;
        for(int i=0;i<baseData.dataCount/2;i++) {
            index = ComBase.changeShortToInt(bf.getShort());
            data = configs.get(index-1);  
            data.setValue((float)ComBase.changeShortToDouble(bf.getShort()));
            //data.value = data.value + (float)Math.random()*100;
            if(i == 0) {
                dev_id = data.dev_id;
               }
        }
        return getNowDevice(dev_id);
    }
    
    /**
     *     »ñÈ¡µ±Ç°É豸
     * @param dev_id
     * @return
     */
    public Device_inf getNowDevice(int dev_id) {
        for(int i=0;i<devices.size();i++) {
            if(dev_id == devices.get(i).dev_id) {
                return devices.get(i);
            }
        }
        return null;
    }
    
    /**
     *     ¼ì²éÉ豸¸æ¾¯¼Ç¼
     * @param conn_pool
     * @param dev
     */
    public static void  checkDevAlarm(MysqlConnPool conn_pool,Device_inf dev) {
        String sql_str = "";
    }
    
    
    public static void main(String[] args) {
         int max=100,min=1;
         int ran2 = (int) (Math.random()*(max-min)+min); 
         System.out.println(ran2);
    }
}