| | |
| | | |
| | | import com.whyc.dto.ServiceModel; |
| | | import com.whyc.factory.FaceEngineFactory; |
| | | import com.whyc.mapper.LicenseMapper; |
| | | import com.whyc.mapper.CommonMapper; |
| | | import com.whyc.mapper.PageParamUserMapper; |
| | | import com.whyc.service.LicenseService; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.service.BaoJiGroupBattGroupService; |
| | | import com.whyc.service.InterfaceService; |
| | | import com.whyc.service.ProcessSurveyService; |
| | | import com.whyc.service.UserService; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.HttpUtil; |
| | | import com.whyc.util.PropertiesUtil; |
| | | import com.whyc.util.RSAUtil; |
| | | 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.io.FileInputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Properties; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 应用启动时初始化 |
| | |
| | | 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"); |
| | | //Thread thread_calculateTimeInUse = new Thread(new CalculateTimeInUse(),"Thread_calculateTimeInUse"); |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private BaoJiGroupBattGroupService baoJiGroupBattGroupService; |
| | | |
| | | @Override |
| | | public void contextInitialized(ServletContextEvent servletContextEvent) { |
| | | //license凭证使用时长计时 |
| | | thread_calculateTimeInUse.start(); |
| | | ServletContext application = servletContextEvent.getServletContext(); |
| | | //记录系统的运行初始时间 |
| | | application.setAttribute("system_start_time", System.currentTimeMillis()); |
| | | //清除错误的包机组机房关系 |
| | | baoJiGroupBattGroupService.clearErrorRelationship(); |
| | | |
| | | //载入config.properties文件数据流 |
| | | PropertiesUtil.props = new Properties(); |
| | | try { |
| | | String path = (getClass().getClassLoader().getResource("").toURI()).getPath(); |
| | | //FileInputStream fis = new FileInputStream(path + "config.properties"); |
| | | FileInputStream fis = new FileInputStream(path + "config.properties"); |
| | | PropertiesUtil.props.load(new InputStreamReader(fis, StandardCharsets.UTF_8)); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | //应用启动时,检查是否存在表,不存在则新建 |
| | | //告警语音设置表 |
| | | String tableName = commonMapper.existTable("web_site", "tb_alarm_voice_set"); |
| | | if(tableName == null){ |
| | | commonMapper.createTable4AlarmVoiceSet(); |
| | | } |
| | | //应用启动时,检查是否存在表,不存在则新建--聚合平台,弃用 |
| | | /*boolean exist = DAOHelper.exist("web_site", "tb_weather_city"); |
| | | if(!exist){ |
| | | boolean createStatus = false; |
| | | while (!createStatus){ |
| | | createStatus = new WeatherCityDao().createTable(); |
| | | } |
| | | } |
| | | //刷新 天气城市的数据--聚合平台,弃用 |
| | | /*//刷新 天气城市的数据--聚合平台,弃用 |
| | | new WeatherCityService().insertBatch();*/ |
| | | //视频token获取存入 |
| | | //视频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(); |
| | | //密码结构更新到3 0 72 |
| | | UserInf sysAdmin = userService.getById(1); |
| | | String uSnId = sysAdmin.getUSnId(); |
| | | if(RSAUtil.decrypt(uSnId,RSAUtil.getPrivateKey()) == null){ //最新结构解码失败 |
| | | //为旧版密码,采用旧版解码并转为新版 |
| | | List<UserInf> all = userService.getAll(); |
| | | List<UserInf> userListWithNewPwd = new LinkedList<>(); |
| | | for (int i = 1; i < all.size(); i++) { //第一条记录非密码,跳过 |
| | | UserInf userInf = all.get(i); |
| | | String pwdOldEncrypt = userInf.getUSnId(); |
| | | String pwd = RSAUtil.decrypt(pwdOldEncrypt, RSAUtil.getPrivateKeyOld()); |
| | | if(pwd != null) { |
| | | String pwdNewEncrypt = RSAUtil.encrypt(pwd, RSAUtil.getPublicKey()); |
| | | userInf.setUSnId(pwdNewEncrypt); |
| | | userListWithNewPwd.add(userInf); |
| | | } |
| | | } |
| | | if(userListWithNewPwd.size()>0) { |
| | | userService.updatePasswordsTo3072(userListWithNewPwd); |
| | | System.out.println("password system renewed"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | public void contextDestroyed(ServletContextEvent servletContextEvent) { |
| | | int i = FaceEngineFactory.getInstance().unInit(); |
| | | System.out.println("faceEngine引擎卸载"); |
| | | thread_calculateTimeInUse.interrupt(); |
| | | System.out.println("计算时长线程终止"); |
| | | //thread_calculateTimeInUse.interrupt(); |
| | | //System.out.println("计算时长线程终止"); |
| | | /*try { |
| | | powerACDCDataServer.stop(); |
| | | powerAlarmServer.stop(); |
| | |
| | | e.printStackTrace(); |
| | | }*/ |
| | | |
| | | } |
| | | |
| | | class CalculateTimeInUse implements Runnable{ |
| | | @Resource |
| | | private LicenseMapper licenseMapper; |
| | | @Resource |
| | | private LicenseService licenseService; |
| | | @Override |
| | | public void run() { |
| | | boolean exist = licenseMapper.selectExist()>0; |
| | | if(!exist){ |
| | | licenseMapper.createTable(); |
| | | }else{ |
| | | boolean existColumn = licenseMapper.existColumn()>0; |
| | | if(!existColumn){ |
| | | //这里 |
| | | licenseMapper.reCreateTable(); |
| | | } |
| | | } |
| | | while (true){ |
| | | //更新单位为60s |
| | | boolean flag = licenseService.updateTimeInUse(); |
| | | /*if (!flag){ |
| | | throw new LicenseTimeInUseUpdateException(); |
| | | }*/ |
| | | try { |
| | | Thread.sleep(60000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |