严智鑫
2025-11-13 945bc394f40d8af1072a53da9a94f24207124e6d
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
package com.northglass.service.system;
 
import java.sql.Driver;
 
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.test.data.DataFixtures;
import org.springside.modules.utils.PropertiesLoader;
 
import com.northglass.log.GLoggerFactory;
import com.northglass.service.loadmachine.LoadMachineService;
 
@Component
@Transactional
public class SystemService {
 
    private static final Logger LOGGER = GLoggerFactory.getLogger(SystemService.class);
    
//    @Autowired
//    private StockMachineService stockMachineService;
//    
    @Autowired
    private LoadMachineService loadMachineService;
    
    @SuppressWarnings("unchecked")
    public boolean initializeDatabase() {
        LOGGER.debug("> Start initializeDatabase");
        boolean result = false;
        
        try {
            PropertiesLoader propertiesLoader = new PropertiesLoader("classpath:/application.properties");
            
            SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
            dataSource.setDriverClass((Class<? extends Driver>) Class.forName(propertiesLoader.getProperty("jdbc.driver")));
            dataSource.setUrl(propertiesLoader.getProperty("jdbc.url"));
            dataSource.setUsername(propertiesLoader.getProperty("jdbc.username"));
            dataSource.setPassword(propertiesLoader.getProperty("jdbc.password"));
            
            DataFixtures.executeScript(dataSource, "classpath:/sql/mysql/schema.sql");
            
            // 导入设备数据后重设状态,并启动链接
            //machineService.resetState();
            
            // 设置仓储货架、吊装位、上片位、立式理片货架状态
            //deviceService.resetRankState();
            
            System.out.println("导入成功,请关闭服务并重新启动 ……");
            result = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            System.out.println("导入失败!");
        }
        
        LOGGER.debug("> End initializeDatabase");
        return result;
    }
    
    public void resetState() {
        LOGGER.debug("> Start resetState");
        
//        stockMachineService.resetState();
        loadMachineService.resetState();
//        measureMachineService.resetState();
        
        LOGGER.debug("> End systemService");
    }
    
    public void connect() {
        LOGGER.debug("> Start connect");
        
//        stockMachineService.connect();
        loadMachineService.connect();
//        edgeMachineService.connect();
//   //     flowMachineService.connect();
//        measureMachineService.connect();
//
//        
//        stockControlService.listen();
//        cuttingControlService.listen();
        
        LOGGER.debug("> End connect");
    }
}