jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
123
124
125
126
127
128
129
130
131
132
133
134
package com.ld.igds.init;
 
import com.bstek.bdf2.core.model.DefaultCompany;
import com.bstek.dorado.annotation.Expose;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.sys.service.DicTriggerService;
import com.ld.igds.sys.service.SysCompanyService;
import com.ld.igds.sys.service.SysDeptService;
import com.ld.igds.sys.service.SystemService;
import com.ld.igds.view.service.BuildingService;
import com.ld.igds.view.service.HDepotService;
import com.ld.igds.view.service.DeviceService;
import com.ld.igds.view.service.SysConfService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * 配置系统级别的项目启动初始化信息
 *
 * @author Andy
 */
@Service
@Slf4j
@Order(value = 1)
public class SystemRunner implements CommandLineRunner {
 
    @Autowired
    private DicTriggerService dicService;
    @Autowired
    private CoreSerService coreSerService;
    @Autowired
    private HDepotService depotService;
    @Autowired
    private BuildingService buildingService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private SysConfService sysConfService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private SysCompanyService companyService;
    @Autowired
    private SystemService systemService;
    @Autowired
    private CoreCommonService coreCommonService;
 
    @Override
    public void run(String... args) throws Exception {
 
        List<DefaultCompany> list = companyService.getAll();
        //放入缓存
        coreCommonService.setCacheCompany(list);
 
        for (DefaultCompany company : list) {
            flushCache(company.getId(), company.getName());
        }
 
        //初始化用户部门内存
        sysDeptService.initUserDeptMap();
 
        // 刷新菜单
        systemService.refreshUrlCache();
    }
 
    public void flushCache(String companyId, String name) throws Exception {
 
        // 设置分机全部掉线
        coreSerService.allOffLine(companyId);
 
        // 初始化缓存
        dicService.refreshCache(companyId);
 
        //分机
        coreSerService.refreshCache(companyId);
 
        //初始化仓库
        depotService.flushCache(companyId);
 
        //系统配置
        sysConfService.flushCacheSysConf(companyId);
 
        // 需要先刷新仓库缓存后刷新配置
        Thread.sleep(500);
 
        //参数配置
        depotService.flushConfCache(companyId);
 
        //建筑物
        buildingService.refreshCache(companyId);
 
        //设备配置
        deviceService.refreshCache(companyId);
 
        //子部门配置
        sysDeptService.flushDeptCache(companyId);
 
        //初始化控制柜仓库的虚拟用户
        depotService.initUserDeptMap(companyId);
 
        log.info("* ");
        log.info("* ========================");
        log.info("* ");
        log.info("* 组织={},初始化缓存完成…………", companyId);
        log.info("* ");
        log.info("* ========================");
        log.info("* ");
    }
 
 
    /**
     * 刷新所有缓存,包括菜单
     *
     * @param companyId
     * @throws Exception
     */
    @Expose
    public void flushAllCache(String companyId) throws Exception {
 
        flushCache(companyId, "手动调用");
        //公司信息放入缓存
        List<DefaultCompany> list = companyService.getAll();
        coreCommonService.setCacheCompany(list);
 
        // 刷新菜单
        systemService.refreshUrlCache();
    }
}