| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author kdq |
| | |
| | | private DongHuanBaoJingService dongHuanBaoJingService; |
| | | @Autowired |
| | | private WarnService warnService; |
| | | @Value("${donghuan.ip}") |
| | | private String ip; |
| | | @Value("${donghuan.loginUrl}") |
| | | private String loginUrl; |
| | | @Value("${donghuan.deviceClassUrl}") |
| | | private String deviceClassUrl; |
| | | @Value("${donghuan.intelligentUrl}") |
| | | private String intelligentUrl; |
| | | @Value("${donghuan.findDevice}") |
| | | private String findDevice; |
| | | @Value("${donghuan.findDeviceVar}") |
| | | private String findDeviceVar; |
| | | @Value("${donghuan.findControlByDeviceId}") |
| | | private String findControlByDeviceId; |
| | | @Value("${donghuan.control}") |
| | | private String control; |
| | | @Value("${donghuan.findValueByDeviceId}") |
| | | private String findValueByDeviceId; |
| | | @Value("${donghuan.findValueByIntelligentId}") |
| | | private String findValueByIntelligentId; |
| | | @Value("${donghuan.findValueByStationId}") |
| | | private String findValueByStationId; |
| | | @Value("${donghuan.meterDatas}") |
| | | private String meterDatas; |
| | | @Value("${donghuan.varDatas}") |
| | | private String varDatas; |
| | | @Value("${donghuan.alarm}") |
| | | private String alarm; |
| | | @Value("${license.year}") |
| | | private String Lyear; |
| | | @Value("${license.month}") |
| | | private String Lmonth; |
| | | |
| | | private String token; |
| | | Boolean isOctober(){ |
| | | Calendar ca = Calendar.getInstance(); |
| | | int year = ca.get(Calendar.YEAR);//获取年份 |
| | | int month=ca.get(Calendar.MONTH)+1;//获取月份 |
| | | int day=ca.get(Calendar.DATE);//获取日 |
| | | if(year<=Integer.parseInt(Lyear)){ |
| | | if(month>=Integer.parseInt(Lmonth)){ |
| | | return false; |
| | | }else { |
| | | return true; |
| | | } |
| | | }else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/getLicense") |
| | | public R getLicense(){ |
| | | Boolean october = isOctober(); |
| | | return R.ok(october); |
| | | } |
| | | |
| | | @GetMapping("/getHost") |
| | | public R getServer(){ |
| | |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/getHostInfo") |
| | | public R getServerInfo(){ |
| | | List<Map<String,Object>> resultList = new ArrayList<>(); |
| | | QueryWrapper<SystemInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.select(" id,host_name,uptime,state,remark"); |
| | | List<SystemInfo> list = systemInfoService.list(wrapper); |
| | | for (SystemInfo systemInfo : list) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("name",systemInfo.getHostName()); |
| | | map.put("runDate",systemInfo.getUptime()==0?"0分钟":getHourAndMinute(systemInfo.getUptime())); |
| | | map.put("isRun",systemInfo.getState()); |
| | | map.put("remark",systemInfo.getRemark()); |
| | | resultList.add(map); |
| | | } |
| | | return R.ok(resultList); |
| | | } |
| | | |
| | | String getHourAndMinute(Long time){ |
| | | long hours = time / 3600; |
| | | long hours2 = hours; |
| | | String s = ""; |
| | | if(hours!=0){ |
| | | long day = hours/24; |
| | | if(day!=0){ |
| | | s+=day+"天 "; |
| | | hours = hours - day*24; |
| | | } |
| | | s+=hours+"小时 "; |
| | | long minutes = (time - hours2*3600)/60; |
| | | if(minutes != 0){ |
| | | s+=minutes+"分钟"; |
| | | } |
| | | }else { |
| | | long minutes = time / 60; |
| | | s+=minutes+"分钟"; |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | @GetMapping("/getSnmp") |
| | | public R getSnmp(){ |
| | | Map<String,Object> map = new HashMap<>(); |
| | |
| | | } catch (Exception e) { |
| | | return R.failed("出错"); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/getSnmpInfo") |
| | | public R getSnmpInfo(){ |
| | | List<Map<String,Object>> resultList = new ArrayList<>(); |
| | | QueryWrapper<SnmpInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.select(" id,host_name,uptime,state,remark"); |
| | | List<SnmpInfo> list = snmpInfoService.list(wrapper); |
| | | for (SnmpInfo snmpInfo : list) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("name",snmpInfo.getHostName()); |
| | | map.put("bytes",snmpInfo.getBytesSent()); |
| | | map.put("isRun",snmpInfo.getState()); |
| | | map.put("remark",snmpInfo.getRemark()); |
| | | resultList.add(map); |
| | | } |
| | | return R.ok(resultList); |
| | | } |
| | | |
| | | @GetMapping("/getTask") |
| | |
| | | } |
| | | @GetMapping("/getUps") |
| | | public R getUps(){ |
| | | int upsError=0; |
| | | int dianchiError=0; |
| | | SnmpInfo snmpInfo = new SnmpInfo(); |
| | | snmpInfo.setSnmpCommunity("private"); |
| | | snmpInfo.setSnmpVersion("1"); |
| | | snmpInfo.setSnmpPort("161"); |
| | | snmpInfo.setHostName("139.24.190.121"); |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.6660"); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.7172"); |
| | | for (String s : list) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, s); |
| | | if(s1.equals("5")){ |
| | | upsError++; |
| | | } |
| | | } |
| | | |
| | | List<String> list1 = new ArrayList<>(); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.7686"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.8198"); |
| | | for (String s : list1) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, s); |
| | | if(s1.equals("0")){ |
| | | upsError++; |
| | | } |
| | | } |
| | | |
| | | List<String> list2 = new ArrayList<>(); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6145"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6146"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6147"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6148"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6149"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6150"); |
| | | for (String s : list2) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, s); |
| | | if(!s1.equals("0") && !s1.equals("1")&& !s1.equals("4")&& !s1.equals("6")){ |
| | | dianchiError++; |
| | | } |
| | | } |
| | | |
| | | |
| | | Map<String,Object> map = new HashMap<>(); |
| | | try { |
| | | map.put("ups",4); |
| | | map.put("ups2",4); |
| | | map.put("ups2",4-upsError); |
| | | map.put("dianchi",6); |
| | | map.put("dianchi2",6); |
| | | map.put("dianchi2",6-dianchiError); |
| | | return R.ok(map); |
| | | } catch (Exception e) { |
| | | return R.failed("出错"); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/getUpsInfo") |
| | | public R getUpsInfo(){ |
| | | List<Map<String,Object>> resultList = new ArrayList<>(); |
| | | SnmpInfo snmpInfo = new SnmpInfo(); |
| | | snmpInfo.setSnmpCommunity("private"); |
| | | snmpInfo.setSnmpVersion("1"); |
| | | snmpInfo.setSnmpPort("161"); |
| | | snmpInfo.setHostName("139.24.190.121"); |
| | | try { |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.6660"); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.7172"); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, list.get(i)); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | String state = ""; |
| | | if(s1.equals("5"))state="关机"; |
| | | if(s1.equals("4"))state="开机"; |
| | | if(i==0){ |
| | | map.put("name","UPS1"); |
| | | map.put("bianliang","开关机状态"); |
| | | map.put("isRun",state); |
| | | } |
| | | if(i==1){ |
| | | map.put("name","UPS2"); |
| | | map.put("bianliang","开关机状态"); |
| | | map.put("isRun",state); |
| | | } |
| | | resultList.add(map); |
| | | } |
| | | |
| | | List<String> list1 = new ArrayList<>(); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.7686"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.8198"); |
| | | for (int i = 0; i < list1.size(); i++) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, list1.get(i)); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | String state = ""; |
| | | if(s1.equals("0"))state="关闭"; |
| | | if(s1.equals("1"))state="打开"; |
| | | if(i==0){ |
| | | map.put("name","UPS3"); |
| | | map.put("bianliang","输出开关"); |
| | | map.put("isRun",state); |
| | | } |
| | | if(i==1){ |
| | | map.put("name","UPS4"); |
| | | map.put("bianliang","输出开关"); |
| | | map.put("isRun",state); |
| | | } |
| | | resultList.add(map); |
| | | } |
| | | |
| | | List<String> list2 = new ArrayList<>(); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6149"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6150"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6147"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6148"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6145"); |
| | | list2.add("1.3.6.1.4.1.32701.4.1.8.1.3.6146"); |
| | | |
| | | for (int i = 0; i < list2.size(); i++) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, list2.get(i)); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | String state = ""; |
| | | if(s1.equals("0"))state="浮充"; |
| | | if(s1.equals("1"))state="充电"; |
| | | if(s1.equals("4"))state="放电"; |
| | | if(s1.equals("6"))state="内阻测试"; |
| | | if(!s1.equals("0") && !s1.equals("1")&& !s1.equals("4")&& !s1.equals("6")){ |
| | | state="状态异常"; |
| | | } |
| | | map.put("name","电池"+i); |
| | | map.put("bianliang","工作状态"); |
| | | map.put("isRun",state); |
| | | resultList.add(map); |
| | | } |
| | | |
| | | return R.ok(resultList); |
| | | } catch (Exception e) { |
| | | return R.failed("出错"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getKongtiao") |
| | | public R getKongtiao(){ |
| | | int upsError=0; |
| | | int jifangError=0; |
| | | SnmpInfo snmpInfo = new SnmpInfo(); |
| | | snmpInfo.setSnmpCommunity("private"); |
| | | snmpInfo.setSnmpVersion("1"); |
| | | snmpInfo.setSnmpPort("161"); |
| | | snmpInfo.setHostName("139.24.190.121"); |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.9729"); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.9731"); |
| | | for (String s : list) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, s); |
| | | if(s1.equals("0")){ |
| | | upsError++; |
| | | } |
| | | } |
| | | |
| | | List<String> list1 = new ArrayList<>(); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.2049"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.2561"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.3073"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.4097"); |
| | | for (String s : list1) { |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, s); |
| | | if(s1.equals("0")){ |
| | | jifangError++; |
| | | } |
| | | } |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("upsKongtiao",2); |
| | | map.put("upsKongtiao2",upsError); |
| | | map.put("zhongxinKongtiao",4); |
| | | map.put("zhongxinKongtiao2",jifangError); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @GetMapping("/getKongtiaoInfo") |
| | | public R getKongtiaoInfo(){ |
| | | List<Map<String,Object>> resultList = new ArrayList<>(); |
| | | SnmpInfo snmpInfo = new SnmpInfo(); |
| | | snmpInfo.setSnmpCommunity("private"); |
| | | snmpInfo.setSnmpVersion("1"); |
| | | snmpInfo.setSnmpPort("161"); |
| | | snmpInfo.setHostName("139.24.190.121"); |
| | | try { |
| | | map.put("upsKongtiao",2); |
| | | map.put("upsKongtiao2",2); |
| | | map.put("zhongxinKongtiao",4); |
| | | map.put("zhongxinKongtiao2",4); |
| | | return R.ok(map); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.9729"); |
| | | list.add("1.3.6.1.4.1.32701.4.1.8.1.3.9731"); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | String state = ""; |
| | | Map<String,Object> map = new HashMap<>(); |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, list.get(i)); |
| | | if(s1.equals("0"))state="关机"; |
| | | if(s1.equals("1"))state="开机"; |
| | | if(i==0){ |
| | | map.put("name","UPS机房空调5(STULZ-CCU121A)"); |
| | | map.put("bianliang","空调工作状态"); |
| | | map.put("isRun",state); |
| | | resultList.add(map); |
| | | } |
| | | if(i==1){ |
| | | map.put("name","UPS机房空调6(STULZ-CCU121A)"); |
| | | map.put("bianliang","空调工作状态"); |
| | | map.put("isRun",state); |
| | | resultList.add(map); |
| | | } |
| | | } |
| | | List<String> list1 = new ArrayList<>(); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.2049"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.2561"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.4097"); |
| | | list1.add("1.3.6.1.4.1.32701.4.1.8.1.3.3073"); |
| | | for (int i = 0; i < list1.size(); i++) { |
| | | String state = ""; |
| | | Map<String,Object> map = new HashMap<>(); |
| | | String s1 = SnmpUtil.snmpGetTest(snmpInfo, list1.get(i)); |
| | | if(s1.equals("0"))state="关闭"; |
| | | if(s1.equals("1"))state="开启"; |
| | | map.put("name","中心机房空调"+(i+1)); |
| | | map.put("bianliang","开关机状态"); |
| | | map.put("isRun",state); |
| | | resultList.add(map); |
| | | } |
| | | return R.ok(resultList); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return R.failed("出错"); |
| | | } |
| | | } |