whycxzp
2023-10-18 4b84413b2662c00264e828a359ee86e86d93e321
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.whyc.listener;
 
import com.whyc.dto.ServiceModel;
import com.whyc.factory.FaceEngineFactory;
import com.whyc.mapper.CommonMapper;
import com.whyc.mapper.PageParamUserMapper;
import com.whyc.service.InterfaceService;
import com.whyc.service.ProcessSurveyService;
import com.whyc.util.ActionUtil;
import com.whyc.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
 
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.Map;
 
/**
 * 应用启动时初始化
 * 应用关闭时销毁
 */
@WebListener
public class ApplicationListener implements ServletContextListener {
    @Resource
    private PageParamUserMapper pageParamUserMapper;
    @Resource
    private CommonMapper commonMapper;
 
    @Resource
    private ProcessSurveyService processSurveyService;
 
    @Autowired
    private InterfaceService interfaceService;
    /*PowerACDCDataServer powerACDCDataServer = new PowerACDCDataServer();
    PowerAlarmServer powerAlarmServer = new PowerAlarmServer();
    PowerInsulateServer powerInsulateServer = new PowerInsulateServer();
    PowerChargerServer powerChargerServer = new PowerChargerServer();*/
 
    //Thread thread_calculateTimeInUse = new Thread(new CalculateTimeInUse(),"Thread_calculateTimeInUse");
 
 
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
 
        //应用启动时,检查是否存在表,不存在则新建
        //告警语音设置表
        String tableName = commonMapper.existTable("web_site", "tb_alarm_voice_set");
        if(tableName == null){
            commonMapper.createTable4AlarmVoiceSet();
        }
        /*//刷新 天气城市的数据--聚合平台,弃用
        new WeatherCityService().insertBatch();*/
        //视频token获取存入,从萤石云获取
        String resultJson = HttpUtil.doPost(HttpUtil.VIDEO_URL, HttpUtil.VIDEO_REQUEST_BODY);
        ServiceModel model = ActionUtil.getGson().fromJson(resultJson, ServiceModel.class);
        ServletContext application = servletContextEvent.getServletContext();
        application.setAttribute("videoToken",model);
 
        //版本迭代需要打补丁,PageParamUser追加字段type,扩展表的使用范围,原来表记录的type字段统一追加为1
        pageParamUserMapper.setOldRecord();
        //告警实时数据
        Map<String, Object> alarmMap = interfaceService.getAlarmMap(null);
        application.setAttribute("alarmMap",alarmMap);
        //更新平台版本号和启动时间
        processSurveyService.updateWebStartTimeAndVersion();
 
    }
 
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        int i = FaceEngineFactory.getInstance().unInit();
        System.out.println("faceEngine引擎卸载");
        //thread_calculateTimeInUse.interrupt();
        //System.out.println("计算时长线程终止");
        /*try {
            powerACDCDataServer.stop();
            powerAlarmServer.stop();
            powerInsulateServer.stop();
            powerChargerServer.stop();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }*/
 
    }
}