严智鑫
2025-06-13 d14cdaf28222bfef468185e34de7c823f1436b19
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
package com.mes;
 
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.connect.IndustrialInterface.Api;
import com.mes.connect.Thread.MachineThread;
import com.mes.model.entity.Machine;
import com.mes.model.mapper.MachineMapper;
import com.mes.model.service.MachineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Component
@Order(1)
 
public class AppRunnerConfig implements ApplicationRunner {
 
    @Autowired
    Api api;
    @Autowired
    MachineService machineService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        // TODO Auto-generated method stub
        //1.根据数据库设备表加载数据  得到全部 设备信息
        List<Machine> listMachine = machineService.getMachineConfig();
        //2.根据设备配置进行加载多线程
        for (int i = 1; i < listMachine.size(); i++)
            try {
                Machine machine = listMachine.get(i);
                Thread thread = new Thread(new MachineThread(machine, api));
                thread.start();
                thread.setName(machine.getName());
            } catch (Exception e) {
                // TODO: handle exception
                System.out.println("多线程异常!!");
            }
    }
}