正在显示
26 个修改的文件
包含
786 行增加
和
43 行删除
| 1 | +package com.ruoyi.system.domain.sys; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.tool.BaseEntity; | ||
| 4 | +import io.swagger.annotations.ApiModel; | ||
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 6 | + | ||
| 7 | +@ApiModel("服务器状态监控") | ||
| 8 | +public class SysMonitorServer extends BaseEntity { | ||
| 9 | + @ApiModelProperty("主键ip") | ||
| 10 | + private String ip; | ||
| 11 | + @ApiModelProperty("CPU使用率(%%)") | ||
| 12 | + private Integer cpu_usage; | ||
| 13 | + @ApiModelProperty("内存使用率(%%)") | ||
| 14 | + private Integer memory_usage; | ||
| 15 | + @ApiModelProperty("磁盘使用率(%%)") | ||
| 16 | + private Integer disk_usage; | ||
| 17 | + @ApiModelProperty("系统连接数(%%)") | ||
| 18 | + private Integer connection_count; | ||
| 19 | + @ApiModelProperty("创建时间") | ||
| 20 | + private Long create_time; | ||
| 21 | + | ||
| 22 | + public String getIp() { | ||
| 23 | + return ip; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public void setIp(String ip) { | ||
| 27 | + this.ip = ip; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public Integer getCpu_usage() { | ||
| 31 | + return cpu_usage; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public void setCpu_usage(Integer cpu_usage) { | ||
| 35 | + this.cpu_usage = cpu_usage; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public Integer getMemory_usage() { | ||
| 39 | + return memory_usage; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setMemory_usage(Integer memory_usage) { | ||
| 43 | + this.memory_usage = memory_usage; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public Integer getDisk_usage() { | ||
| 47 | + return disk_usage; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public void setDisk_usage(Integer disk_usage) { | ||
| 51 | + this.disk_usage = disk_usage; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + public Integer getConnection_count() { | ||
| 55 | + return connection_count; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public void setConnection_count(Integer connection_count) { | ||
| 59 | + this.connection_count = connection_count; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public Long getCreate_time() { | ||
| 63 | + return create_time; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setCreate_time(Long create_time) { | ||
| 67 | + this.create_time = create_time; | ||
| 68 | + } | ||
| 69 | +} |
| 1 | +package com.ruoyi.system.domain.sys; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +@ApiModel("服务器状态监控") | ||
| 7 | +public class SysMonitorServerLog { | ||
| 8 | + @ApiModelProperty("主键") | ||
| 9 | + private Integer id; | ||
| 10 | + @ApiModelProperty("ip") | ||
| 11 | + private String ip; | ||
| 12 | + @ApiModelProperty("CPU使用率(%%)") | ||
| 13 | + private Integer cpu_usage; | ||
| 14 | + @ApiModelProperty("内存使用率(%%)") | ||
| 15 | + private Integer memory_usage; | ||
| 16 | + @ApiModelProperty("磁盘使用率(%%)") | ||
| 17 | + private Integer disk_usage; | ||
| 18 | + @ApiModelProperty("系统连接数") | ||
| 19 | + private Integer connection_count; | ||
| 20 | + @ApiModelProperty("创建时间") | ||
| 21 | + private Long create_time; | ||
| 22 | + | ||
| 23 | + public Integer getId() { | ||
| 24 | + return id; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setId(Integer id) { | ||
| 28 | + this.id = id; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getIp() { | ||
| 32 | + return ip; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setIp(String ip) { | ||
| 36 | + this.ip = ip; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public Integer getCpu_usage() { | ||
| 40 | + return cpu_usage; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setCpu_usage(Integer cpu_usage) { | ||
| 44 | + this.cpu_usage = cpu_usage; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public Integer getMemory_usage() { | ||
| 48 | + return memory_usage; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setMemory_usage(Integer memory_usage) { | ||
| 52 | + this.memory_usage = memory_usage; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public Integer getDisk_usage() { | ||
| 56 | + return disk_usage; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setDisk_usage(Integer disk_usage) { | ||
| 60 | + this.disk_usage = disk_usage; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public Integer getConnection_count() { | ||
| 64 | + return connection_count; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setConnection_count(Integer connection_count) { | ||
| 68 | + this.connection_count = connection_count; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public Long getCreate_time() { | ||
| 72 | + return create_time; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setCreate_time(Long create_time) { | ||
| 76 | + this.create_time = create_time; | ||
| 77 | + } | ||
| 78 | +} |
| @@ -103,7 +103,7 @@ public class PublicSQL { | @@ -103,7 +103,7 @@ public class PublicSQL { | ||
| 103 | values.append( ","); | 103 | values.append( ","); |
| 104 | } | 104 | } |
| 105 | stringBuffer.append( "`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"); | 105 | stringBuffer.append( "`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"); |
| 106 | - values.append( "'"+ escapeSql(value+"")+"'"); | 106 | + values.append("#{"+ field.getName()+"}"); |
| 107 | } | 107 | } |
| 108 | } catch (NoSuchMethodException e) { | 108 | } catch (NoSuchMethodException e) { |
| 109 | // TODO Auto-generated catch block | 109 | // TODO Auto-generated catch block |
| @@ -166,7 +166,7 @@ public class PublicSQL { | @@ -166,7 +166,7 @@ public class PublicSQL { | ||
| 166 | values += ","; | 166 | values += ","; |
| 167 | } | 167 | } |
| 168 | sql.append("`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"); | 168 | sql.append("`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"); |
| 169 | - values += "'"+escapeSql(value+"")+"'"; | 169 | + values += "#{"+field.getName()+"}"; |
| 170 | } | 170 | } |
| 171 | } catch (NoSuchMethodException e) { | 171 | } catch (NoSuchMethodException e) { |
| 172 | // TODO Auto-generated catch block | 172 | // TODO Auto-generated catch block |
| @@ -365,7 +365,7 @@ public class PublicSQL { | @@ -365,7 +365,7 @@ public class PublicSQL { | ||
| 365 | sql += tableName + " where 1=1 "; | 365 | sql += tableName + " where 1=1 "; |
| 366 | for(String key:map.keySet()) | 366 | for(String key:map.keySet()) |
| 367 | { | 367 | { |
| 368 | - sql += " and "+"`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(key)+"`"+"='"+escapeSql(map.get(key)+"")+"'"; | 368 | + sql += " and "+"`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(key)+"`"+"=#{map."+key+"}"; |
| 369 | } | 369 | } |
| 370 | return sql; | 370 | return sql; |
| 371 | } | 371 | } |
| @@ -391,7 +391,7 @@ public class PublicSQL { | @@ -391,7 +391,7 @@ public class PublicSQL { | ||
| 391 | } | 391 | } |
| 392 | String sql = "delete from "; | 392 | String sql = "delete from "; |
| 393 | sql += tableName + " where 1=1 "; | 393 | sql += tableName + " where 1=1 "; |
| 394 | - sql += " and "+"`id`"+"='"+escapeSql(id)+"'"; | 394 | + sql += " and "+"`id`"+"=#{id}"; |
| 395 | return sql; | 395 | return sql; |
| 396 | } | 396 | } |
| 397 | 397 | ||
| @@ -402,7 +402,7 @@ public class PublicSQL { | @@ -402,7 +402,7 @@ public class PublicSQL { | ||
| 402 | { | 402 | { |
| 403 | Object object = para.get("object"); | 403 | Object object = para.get("object"); |
| 404 | @SuppressWarnings("unchecked") | 404 | @SuppressWarnings("unchecked") |
| 405 | - Map<String,String> whereMap = (Map<String, String>) para.get("whereMap"); | 405 | + Map<String,Object> whereMap = (Map<String, Object>) para.get("whereMap"); |
| 406 | 406 | ||
| 407 | String tableName = changTableNameFromObject(object); | 407 | String tableName = changTableNameFromObject(object); |
| 408 | String sql = "select count(*) from "+tableName; | 408 | String sql = "select count(*) from "+tableName; |
| @@ -430,27 +430,35 @@ public class PublicSQL { | @@ -430,27 +430,35 @@ public class PublicSQL { | ||
| 430 | String s = "="; | 430 | String s = "="; |
| 431 | if(null != whereMap && null != whereMap.get(field.getName())) | 431 | if(null != whereMap && null != whereMap.get(field.getName())) |
| 432 | { | 432 | { |
| 433 | - s = whereMap.get(field.getName()); | 433 | + s = (String) whereMap.get(field.getName()); |
| 434 | if("like".equals(s)) | 434 | if("like".equals(s)) |
| 435 | { | 435 | { |
| 436 | value = "%"+value+"%"; | 436 | value = "%"+value+"%"; |
| 437 | - like += " or " + "`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" '"+escapeSql(value+"")+"'"+orther ; | ||
| 438 | - continue; | 437 | + Method setmethod = object.getClass().getMethod("set"+ com.ruoyi.common.utils.StringUtils.getName(field.getName()),String.class); |
| 438 | + if(null != setmethod) | ||
| 439 | + { | ||
| 440 | + setmethod.invoke(object,value); | ||
| 441 | + like += " or " + "`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` like #{object."+field.getName()+"}"+orther ; | ||
| 442 | + continue; | ||
| 443 | + } | ||
| 439 | } | 444 | } |
| 440 | if("time".equals(s)) | 445 | if("time".equals(s)) |
| 441 | { | 446 | { |
| 442 | s = ">"; | 447 | s = ">"; |
| 443 | - orther = " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`< '"+whereMap.get("end_"+field.getName())+"'"; | 448 | + orther = " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` < #{whereMap.end_"+field.getName()+"}"; |
| 449 | + } | ||
| 450 | + if("time=".equals(s)) | ||
| 451 | + { | ||
| 452 | + s = ">="; | ||
| 453 | + orther = " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` <= #{whereMap.end_"+field.getName()+"}" ; | ||
| 444 | } | 454 | } |
| 445 | if("in".equals(s)) | 455 | if("in".equals(s)) |
| 446 | { | 456 | { |
| 447 | - s = "in"; | ||
| 448 | - value = (value+"").replace(",","','"); | ||
| 449 | - where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" ("+"'"+value+"'"+")"+orther; | 457 | + where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` in (whereMap."+field.getName()+"s)"+orther; |
| 450 | continue; | 458 | continue; |
| 451 | } | 459 | } |
| 452 | } | 460 | } |
| 453 | - where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" '"+escapeSql(value+"")+"'"+orther; | 461 | + where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" #{object."+field.getName()+"}"+orther; |
| 454 | } | 462 | } |
| 455 | } catch (NoSuchMethodException e) { | 463 | } catch (NoSuchMethodException e) { |
| 456 | e.printStackTrace(); | 464 | e.printStackTrace(); |
| @@ -485,7 +493,7 @@ public class PublicSQL { | @@ -485,7 +493,7 @@ public class PublicSQL { | ||
| 485 | { | 493 | { |
| 486 | Object object = para.get("object"); | 494 | Object object = para.get("object"); |
| 487 | @SuppressWarnings("unchecked") | 495 | @SuppressWarnings("unchecked") |
| 488 | - Map<String,String> whereMap = (Map<String, String>) para.get("whereMap"); | 496 | + Map<String,Object> whereMap = (Map<String, Object>) para.get("whereMap"); |
| 489 | String selectStr = " * "; | 497 | String selectStr = " * "; |
| 490 | String order = ""; | 498 | String order = ""; |
| 491 | if(para.containsKey("order") && null != para.get("order")) | 499 | if(para.containsKey("order") && null != para.get("order")) |
| @@ -533,33 +541,41 @@ public class PublicSQL { | @@ -533,33 +541,41 @@ public class PublicSQL { | ||
| 533 | Method method; | 541 | Method method; |
| 534 | method = object.getClass().getMethod("get"+ com.ruoyi.common.utils.StringUtils.getName(field.getName())); | 542 | method = object.getClass().getMethod("get"+ com.ruoyi.common.utils.StringUtils.getName(field.getName())); |
| 535 | Object value = method.invoke(object); | 543 | Object value = method.invoke(object); |
| 536 | - if(!(null == value)) | 544 | + if(null != value) |
| 537 | { | 545 | { |
| 538 | String orther = ""; | 546 | String orther = ""; |
| 539 | String s = "="; | 547 | String s = "="; |
| 540 | - if(!(null == whereMap || null == whereMap.get(field.getName()))) | 548 | + if(null != whereMap && null != whereMap.get(field.getName())) |
| 541 | { | 549 | { |
| 542 | - s = whereMap.get(field.getName()); | 550 | + s = (String) whereMap.get(field.getName()); |
| 543 | if("like".equals(s)) | 551 | if("like".equals(s)) |
| 544 | { | 552 | { |
| 545 | value = "%"+value+"%"; | 553 | value = "%"+value+"%"; |
| 546 | - like += " or " + "`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" '"+escapeSql(value+"")+"'"+orther ; | ||
| 547 | - continue; | 554 | + Method setmethod = object.getClass().getMethod("set"+ com.ruoyi.common.utils.StringUtils.getName(field.getName()),String.class); |
| 555 | + if(null != setmethod) | ||
| 556 | + { | ||
| 557 | + setmethod.invoke(object,value); | ||
| 558 | + like += " or " + "`"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` like #{object."+field.getName()+"}"+orther ; | ||
| 559 | + continue; | ||
| 560 | + } | ||
| 548 | } | 561 | } |
| 549 | if("time".equals(s)) | 562 | if("time".equals(s)) |
| 550 | { | 563 | { |
| 551 | s = ">"; | 564 | s = ">"; |
| 552 | - orther = " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`< '"+whereMap.get("end_"+field.getName())+"'"; | 565 | + orther = " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` < #{whereMap.end_"+field.getName()+"}"; |
| 566 | + } | ||
| 567 | + if("time=".equals(s)) | ||
| 568 | + { | ||
| 569 | + s = ">="; | ||
| 570 | + orther = " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` <= #{whereMap.end_"+field.getName()+"}" ; | ||
| 553 | } | 571 | } |
| 554 | if("in".equals(s)) | 572 | if("in".equals(s)) |
| 555 | { | 573 | { |
| 556 | - s = "in"; | ||
| 557 | - value = (value+"").replace(",","','"); | ||
| 558 | - where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" ("+"'"+value+"'"+")"+orther; | 574 | + where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"` in (whereMap."+field.getName()+"s)"+orther; |
| 559 | continue; | 575 | continue; |
| 560 | } | 576 | } |
| 561 | } | 577 | } |
| 562 | - where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" '"+escapeSql(value+"")+"'"+orther; | 578 | + where += " and `"+com.ruoyi.common.utils.StringUtils.toUnderScoreCase(field.getName())+"`"+s+" #{object."+field.getName()+"}"+orther; |
| 563 | } | 579 | } |
| 564 | } catch (NoSuchMethodException e) { | 580 | } catch (NoSuchMethodException e) { |
| 565 | e.printStackTrace(); | 581 | e.printStackTrace(); |
| @@ -718,7 +734,7 @@ public class PublicSQL { | @@ -718,7 +734,7 @@ public class PublicSQL { | ||
| 718 | }else{ | 734 | }else{ |
| 719 | sb.append("("); | 735 | sb.append("("); |
| 720 | } | 736 | } |
| 721 | - sb.append("'"+ escapeSql(value+"")+"'"); | 737 | + sb.append("#{"+ field.getName()+"}"); |
| 722 | if(j==fields.length-1) | 738 | if(j==fields.length-1) |
| 723 | { | 739 | { |
| 724 | sb.append(")"); | 740 | sb.append(")"); |
| @@ -99,7 +99,7 @@ public interface PublicMapper { | @@ -99,7 +99,7 @@ public interface PublicMapper { | ||
| 99 | * @return | 99 | * @return |
| 100 | */ | 100 | */ |
| 101 | @SelectProvider(type = PublicSQL.class, method = "getObjectList") | 101 | @SelectProvider(type = PublicSQL.class, method = "getObjectList") |
| 102 | - List<Map<String,Object>> getObjectList(@Param("object") Object object, @Param("selectStr") String selectStr, @Param("whereMap") Map<String, String> whereMap, @Param("order") String order, @Param("pageSize") Integer pagetSize, @Param("pageNo") Integer pageNo); | 102 | + List<Map<String,Object>> getObjectList(@Param("object") Object object, @Param("selectStr") String selectStr, @Param("whereMap") Map<String, Object> whereMap, @Param("order") String order, @Param("pageSize") Integer pagetSize, @Param("pageNo") Integer pageNo); |
| 103 | 103 | ||
| 104 | /** | 104 | /** |
| 105 | * 查詢totle | 105 | * 查詢totle |
| @@ -79,7 +79,7 @@ public interface PublicService { | @@ -79,7 +79,7 @@ public interface PublicService { | ||
| 79 | * @param pageNo | 79 | * @param pageNo |
| 80 | * @return | 80 | * @return |
| 81 | */ | 81 | */ |
| 82 | - List<Map<String,Object>> getObjectList(Object object,String selectStr,Map<String, String> whereMap, String order, Integer pagetSize,Integer pageNo); | 82 | + List<Map<String,Object>> getObjectList(Object object,String selectStr,Map<String, Object> whereMap, String order, Integer pagetSize,Integer pageNo); |
| 83 | 83 | ||
| 84 | /** | 84 | /** |
| 85 | * 查詢totle | 85 | * 查詢totle |
| @@ -139,7 +139,7 @@ public class PublicServiceImpl implements PublicService { | @@ -139,7 +139,7 @@ public class PublicServiceImpl implements PublicService { | ||
| 139 | * @param pageNo | 139 | * @param pageNo |
| 140 | * @return | 140 | * @return |
| 141 | */ | 141 | */ |
| 142 | - public List<Map<String,Object>> getObjectList(Object object, String selectStr, Map<String, String> whereMap, String order, Integer pagetSize, Integer pageNo) | 142 | + public List<Map<String,Object>> getObjectList(Object object, String selectStr, Map<String, Object> whereMap, String order, Integer pagetSize, Integer pageNo) |
| 143 | { | 143 | { |
| 144 | return publicMapper.getObjectList(object,selectStr,whereMap,order,pagetSize,pageNo); | 144 | return publicMapper.getObjectList(object,selectStr,whereMap,order,pagetSize,pageNo); |
| 145 | } | 145 | } |
| 1 | +package com.ruoyi.common.tool; | ||
| 2 | + | ||
| 3 | +import org.springframework.data.annotation.Transient; | ||
| 4 | + | ||
| 5 | +import java.io.Serializable; | ||
| 6 | +import java.util.Map; | ||
| 7 | + | ||
| 8 | +public class MyBaseEntity implements Serializable { | ||
| 9 | + /** 搜索值 */ | ||
| 10 | + @Transient | ||
| 11 | + private String searchValue; | ||
| 12 | + /** 请求参数 */ | ||
| 13 | + private Map<String, Object> params; | ||
| 14 | + | ||
| 15 | + public String getSearchValue() { | ||
| 16 | + return searchValue; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setSearchValue(String searchValue) { | ||
| 20 | + this.searchValue = searchValue; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public Map<String, Object> getParams() { | ||
| 24 | + return params; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setParams(Map<String, Object> params) { | ||
| 28 | + this.params = params; | ||
| 29 | + } | ||
| 30 | +} |
| 1 | +package com.zhonglai.luhui.config.requestbodymiss; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | +import com.zhonglai.luhui.config.TokenConfig; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.stereotype.Component; | ||
| 9 | +import org.springframework.util.StreamUtils; | ||
| 10 | + | ||
| 11 | +import javax.servlet.*; | ||
| 12 | +import javax.servlet.annotation.WebFilter; | ||
| 13 | +import javax.servlet.http.HttpServletRequest; | ||
| 14 | +import java.io.IOException; | ||
| 15 | +import java.io.UnsupportedEncodingException; | ||
| 16 | +import java.util.Enumeration; | ||
| 17 | +import java.util.HashMap; | ||
| 18 | +import java.util.Map; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 实现 Filter | ||
| 22 | + * | ||
| 23 | + * 我们上面重写的 MyHttpServletRequestWrapper 什么时候生效呢? | ||
| 24 | + * | ||
| 25 | + * 我们可以自己实现一个 Filter,对原有的请求进行替换: | ||
| 26 | + */ | ||
| 27 | +@Component | ||
| 28 | +@WebFilter(filterName="httpServletRequestReplacedFilter",urlPatterns="/*") | ||
| 29 | +public class HttpServletRequestReplacedFilter implements Filter { | ||
| 30 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public void init(FilterConfig arg0) throws ServletException { | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public void doFilter(ServletRequest request, ServletResponse response, | ||
| 38 | + FilterChain chain) throws IOException, ServletException { | ||
| 39 | + | ||
| 40 | + RequestReaderHttpServletRequestWrapper requestWrapper = null; | ||
| 41 | + if (request instanceof HttpServletRequest) { | ||
| 42 | + requestWrapper = new RequestReaderHttpServletRequestWrapper((HttpServletRequest) request); | ||
| 43 | + printLog((HttpServletRequest)request,requestWrapper.getBody()); | ||
| 44 | + } | ||
| 45 | + //获取请求中的流如何,将取出来的字符串,再次转换成流,然后把它放入到新request对象中。 | ||
| 46 | + // 在chain.doFiler方法中传递新的request对象 | ||
| 47 | + if (requestWrapper == null) { | ||
| 48 | + chain.doFilter(request, response); | ||
| 49 | + } else { | ||
| 50 | + chain.doFilter(requestWrapper, response); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public void destroy() { | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + private void printLog(HttpServletRequest httpServletRequest,byte[] bodyBytes) throws UnsupportedEncodingException { | ||
| 60 | + logger.info("---------------------开始进入"+httpServletRequest.getRequestURL().toString()+"登录拦截----------------------------"); | ||
| 61 | + Map<String,Object> map = new HashMap<>(); | ||
| 62 | + map.put("parameterValue",httpServletRequest.getParameterMap()); | ||
| 63 | + | ||
| 64 | + // 打印请求头信息 | ||
| 65 | + Map<String,Object> headermap = new HashMap<>(); | ||
| 66 | + Enumeration<String> headerNames = httpServletRequest.getHeaderNames(); | ||
| 67 | + while (headerNames.hasMoreElements()) { | ||
| 68 | + String headerName = headerNames.nextElement(); | ||
| 69 | + String headerValue = httpServletRequest.getHeader(headerName); | ||
| 70 | + headermap.put(headerName, headerValue); | ||
| 71 | + } | ||
| 72 | + map.put("header",headermap); | ||
| 73 | + | ||
| 74 | + //获取请求body | ||
| 75 | + String body = new String(bodyBytes, httpServletRequest.getCharacterEncoding()); | ||
| 76 | + map.put("body",body); | ||
| 77 | + logger.info("---------------------参数:"+ GsonConstructor.get().toJson(map)+"----------------------------"); | ||
| 78 | + } | ||
| 79 | +} |
| 1 | +package com.zhonglai.luhui.config.requestbodymiss; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.ByteUtil; | ||
| 4 | +import com.zhonglai.luhui.config.TokenConfig; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.util.StreamUtils; | ||
| 9 | + | ||
| 10 | +import java.io.BufferedReader; | ||
| 11 | +import java.io.ByteArrayInputStream; | ||
| 12 | +import java.io.IOException; | ||
| 13 | +import java.io.InputStreamReader; | ||
| 14 | +import java.util.HashMap; | ||
| 15 | +import java.util.Map; | ||
| 16 | + | ||
| 17 | +import javax.servlet.ReadListener; | ||
| 18 | +import javax.servlet.ServletInputStream; | ||
| 19 | +import javax.servlet.ServletRequest; | ||
| 20 | +import javax.servlet.ServletResponse; | ||
| 21 | +import javax.servlet.http.HttpServletRequest; | ||
| 22 | +import javax.servlet.http.HttpServletRequestWrapper; | ||
| 23 | +import javax.servlet.http.HttpServletResponse; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * 首先重写 HttpServletRequestWrapper,把每次读取的流信息保存起来,便于重复读取。 | ||
| 27 | + */ | ||
| 28 | +public class RequestReaderHttpServletRequestWrapper extends HttpServletRequestWrapper { | ||
| 29 | + | ||
| 30 | + private final byte[] body; | ||
| 31 | + | ||
| 32 | + public RequestReaderHttpServletRequestWrapper(HttpServletRequest request) throws IOException { | ||
| 33 | + super(request); | ||
| 34 | + body = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public BufferedReader getReader() throws IOException { | ||
| 39 | + return new BufferedReader(new InputStreamReader(getInputStream())); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public ServletInputStream getInputStream() throws IOException { | ||
| 44 | + | ||
| 45 | + final ByteArrayInputStream bais = new ByteArrayInputStream(body); | ||
| 46 | + | ||
| 47 | + return new ServletInputStream() { | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public int read() throws IOException { | ||
| 51 | + return bais.read(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public boolean isFinished() { | ||
| 56 | + return false; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public boolean isReady() { | ||
| 61 | + return false; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public void setReadListener(ReadListener readListener) { | ||
| 66 | + | ||
| 67 | + } | ||
| 68 | + }; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public byte[] getBody() | ||
| 72 | + { | ||
| 73 | + return body; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | +} |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.annotation.PublicSQLConfig; | 3 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | import com.ruoyi.common.tool.BaseEntity; | 4 | import com.ruoyi.common.tool.BaseEntity; |
| 5 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 5 | import io.swagger.annotations.ApiModel; | 6 | import io.swagger.annotations.ApiModel; |
| 6 | import io.swagger.annotations.ApiModelProperty; | 7 | import io.swagger.annotations.ApiModelProperty; |
| 7 | 8 | ||
| @@ -14,7 +15,7 @@ import java.io.Serializable; | @@ -14,7 +15,7 @@ import java.io.Serializable; | ||
| 14 | * @date 2022-08-26 | 15 | * @date 2022-08-26 |
| 15 | */ | 16 | */ |
| 16 | @ApiModel("主机/网关") | 17 | @ApiModel("主机/网关") |
| 17 | -public class IotDevice extends BaseEntity implements Serializable | 18 | +public class IotDevice extends MyBaseEntity implements Serializable |
| 18 | { | 19 | { |
| 19 | @PublicSQLConfig(isSelect=false) | 20 | @PublicSQLConfig(isSelect=false) |
| 20 | private static final long serialVersionUID = 1L; | 21 | private static final long serialVersionUID = 1L; |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.annotation.PublicSQLConfig; | 3 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | import com.ruoyi.common.tool.BaseEntity; | 4 | import com.ruoyi.common.tool.BaseEntity; |
| 5 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 5 | import org.apache.commons.lang3.builder.ToStringBuilder; | 6 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 6 | import org.apache.commons.lang3.builder.ToStringStyle; | 7 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 7 | import io.swagger.annotations.ApiModel; | 8 | import io.swagger.annotations.ApiModel; |
| @@ -16,7 +17,7 @@ import java.io.Serializable; | @@ -16,7 +17,7 @@ import java.io.Serializable; | ||
| 16 | * @date 2022-08-26 | 17 | * @date 2022-08-26 |
| 17 | */ | 18 | */ |
| 18 | @ApiModel("产品") | 19 | @ApiModel("产品") |
| 19 | -public class IotProduct extends BaseEntity implements Serializable | 20 | +public class IotProduct extends MyBaseEntity implements Serializable |
| 20 | { | 21 | { |
| 21 | @PublicSQLConfig(isSelect=false) | 22 | @PublicSQLConfig(isSelect=false) |
| 22 | private static final long serialVersionUID = 1L; | 23 | private static final long serialVersionUID = 1L; |
lh-jar/lh-jar-device-service/src/main/java/com/zhonglai/luhui/device/domain/IotProductTranslate.java
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.tool.BaseEntity; | 3 | import com.ruoyi.common.tool.BaseEntity; |
| 4 | import com.ruoyi.common.annotation.PublicSQLConfig; | 4 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 5 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 5 | import io.swagger.annotations.ApiModel; | 6 | import io.swagger.annotations.ApiModel; |
| 6 | import io.swagger.annotations.ApiModelProperty; | 7 | import io.swagger.annotations.ApiModelProperty; |
| 7 | import org.apache.commons.lang3.builder.ToStringBuilder; | 8 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| @@ -14,7 +15,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; | @@ -14,7 +15,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; | ||
| 14 | * @date 2022-11-04 | 15 | * @date 2022-11-04 |
| 15 | */ | 16 | */ |
| 16 | @ApiModel("产品指标翻译") | 17 | @ApiModel("产品指标翻译") |
| 17 | -public class IotProductTranslate extends BaseEntity | 18 | +public class IotProductTranslate extends MyBaseEntity |
| 18 | { | 19 | { |
| 19 | @PublicSQLConfig(isSelect=false) | 20 | @PublicSQLConfig(isSelect=false) |
| 20 | private static final long serialVersionUID = 1L; | 21 | private static final long serialVersionUID = 1L; |
| 1 | package com.zhonglai.luhui.device.domain; | 1 | package com.zhonglai.luhui.device.domain; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.annotation.Excel; | 3 | import com.ruoyi.common.annotation.Excel; |
| 4 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 4 | import io.swagger.annotations.ApiModel; | 5 | import io.swagger.annotations.ApiModel; |
| 5 | import io.swagger.annotations.ApiModelProperty; | 6 | import io.swagger.annotations.ApiModelProperty; |
| 6 | import com.ruoyi.common.annotation.PublicSQLConfig; | 7 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| @@ -15,7 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; | @@ -15,7 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; | ||
| 15 | * @date 2024-06-13 | 16 | * @date 2024-06-13 |
| 16 | */ | 17 | */ |
| 17 | @ApiModel("产品解析插件包") | 18 | @ApiModel("产品解析插件包") |
| 18 | -public class IotProtocolClass extends BaseEntity | 19 | +public class IotProtocolClass extends MyBaseEntity |
| 19 | { | 20 | { |
| 20 | @PublicSQLConfig(isSelect=false) | 21 | @PublicSQLConfig(isSelect=false) |
| 21 | private static final long serialVersionUID = 1L; | 22 | private static final long serialVersionUID = 1L; |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.annotation.PublicSQLConfig; | 3 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | import com.ruoyi.common.tool.BaseEntity; | 4 | import com.ruoyi.common.tool.BaseEntity; |
| 5 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 5 | import org.apache.commons.lang3.builder.ToStringBuilder; | 6 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 6 | import org.apache.commons.lang3.builder.ToStringStyle; | 7 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 7 | import io.swagger.annotations.ApiModel; | 8 | import io.swagger.annotations.ApiModel; |
| @@ -16,7 +17,7 @@ import java.io.Serializable; | @@ -16,7 +17,7 @@ import java.io.Serializable; | ||
| 16 | * @date 2022-08-26 | 17 | * @date 2022-08-26 |
| 17 | */ | 18 | */ |
| 18 | @ApiModel("公司") | 19 | @ApiModel("公司") |
| 19 | -public class IotRole extends BaseEntity implements Serializable | 20 | +public class IotRole extends MyBaseEntity implements Serializable |
| 20 | { | 21 | { |
| 21 | @PublicSQLConfig(isSelect=false) | 22 | @PublicSQLConfig(isSelect=false) |
| 22 | private static final long serialVersionUID = 1L; | 23 | private static final long serialVersionUID = 1L; |
| 1 | package com.zhonglai.luhui.device.domain; | 1 | package com.zhonglai.luhui.device.domain; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.tool.BaseEntity; | 3 | import com.ruoyi.common.tool.BaseEntity; |
| 4 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 4 | import com.ruoyi.system.domain.user.UserTerminalGroupRelation; | 5 | import com.ruoyi.system.domain.user.UserTerminalGroupRelation; |
| 5 | import com.ruoyi.common.annotation.PublicSQLConfig; | 6 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 6 | import org.apache.commons.lang3.builder.ToStringBuilder; | 7 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| @@ -17,7 +18,7 @@ import java.io.Serializable; | @@ -17,7 +18,7 @@ import java.io.Serializable; | ||
| 17 | * @date 2022-08-26 | 18 | * @date 2022-08-26 |
| 18 | */ | 19 | */ |
| 19 | @ApiModel("终端") | 20 | @ApiModel("终端") |
| 20 | -public class IotTerminal extends BaseEntity implements Serializable | 21 | +public class IotTerminal extends MyBaseEntity implements Serializable |
| 21 | { | 22 | { |
| 22 | @PublicSQLConfig(isSelect=false) | 23 | @PublicSQLConfig(isSelect=false) |
| 23 | private static final long serialVersionUID = 1L; | 24 | private static final long serialVersionUID = 1L; |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.device.domain; | ||
| 2 | 2 | ||
| 3 | import com.ruoyi.common.annotation.PublicSQLConfig; | 3 | import com.ruoyi.common.annotation.PublicSQLConfig; |
| 4 | import com.ruoyi.common.tool.BaseEntity; | 4 | import com.ruoyi.common.tool.BaseEntity; |
| 5 | +import com.ruoyi.common.tool.MyBaseEntity; | ||
| 5 | import org.apache.commons.lang3.builder.ToStringBuilder; | 6 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 6 | import org.apache.commons.lang3.builder.ToStringStyle; | 7 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 7 | import io.swagger.annotations.ApiModel; | 8 | import io.swagger.annotations.ApiModel; |
| @@ -16,7 +17,7 @@ import java.io.Serializable; | @@ -16,7 +17,7 @@ import java.io.Serializable; | ||
| 16 | * @date 2022-08-26 | 17 | * @date 2022-08-26 |
| 17 | */ | 18 | */ |
| 18 | @ApiModel("物模型模板") | 19 | @ApiModel("物模型模板") |
| 19 | -public class IotThingsModel extends BaseEntity implements Serializable | 20 | +public class IotThingsModel extends MyBaseEntity implements Serializable |
| 20 | { | 21 | { |
| 21 | @PublicSQLConfig(isSelect=false) | 22 | @PublicSQLConfig(isSelect=false) |
| 22 | private static final long serialVersionUID = 1L; | 23 | private static final long serialVersionUID = 1L; |
| @@ -43,7 +43,7 @@ public class IotAlertNoticeChannelController extends BaseController { | @@ -43,7 +43,7 @@ public class IotAlertNoticeChannelController extends BaseController { | ||
| 43 | public TableDataInfo list(IotAlertNoticeChannel iotAlertNoticeChannel) | 43 | public TableDataInfo list(IotAlertNoticeChannel iotAlertNoticeChannel) |
| 44 | { | 44 | { |
| 45 | startPage(); | 45 | startPage(); |
| 46 | - Map<String, String> whereMap = new HashMap<>(); | 46 | + Map<String, Object> whereMap = new HashMap<>(); |
| 47 | whereMap.put("name","like"); | 47 | whereMap.put("name","like"); |
| 48 | List<Map<String,Object>> list = publicService.getObjectList(iotAlertNoticeChannel,"*",whereMap,"id desc",0,0); | 48 | List<Map<String,Object>> list = publicService.getObjectList(iotAlertNoticeChannel,"*",whereMap,"id desc",0,0); |
| 49 | return getDataTable(list); | 49 | return getDataTable(list); |
| 1 | package com.zhonglai.luhui.admin.controller.iot; | 1 | package com.zhonglai.luhui.admin.controller.iot; |
| 2 | 2 | ||
| 3 | +import java.util.HashMap; | ||
| 3 | import java.util.List; | 4 | import java.util.List; |
| 5 | +import java.util.Map; | ||
| 4 | import javax.servlet.http.HttpServletResponse; | 6 | import javax.servlet.http.HttpServletResponse; |
| 5 | 7 | ||
| 6 | import com.ruoyi.common.annotation.DataScope; | 8 | import com.ruoyi.common.annotation.DataScope; |
| 7 | import com.ruoyi.common.utils.DateUtils; | 9 | import com.ruoyi.common.utils.DateUtils; |
| 8 | import com.zhonglai.luhui.action.BaseController; | 10 | import com.zhonglai.luhui.action.BaseController; |
| 9 | import com.zhonglai.luhui.dao.service.PublicService; | 11 | import com.zhonglai.luhui.dao.service.PublicService; |
| 12 | +import com.zhonglai.luhui.device.domain.IotProduct; | ||
| 13 | +import com.zhonglai.luhui.device.domain.IotProtocolClass; | ||
| 10 | import com.zhonglai.luhui.security.utils.SecurityUtils; | 14 | import com.zhonglai.luhui.security.utils.SecurityUtils; |
| 11 | import com.zhonglai.luhui.sys.utils.ExcelUtil; | 15 | import com.zhonglai.luhui.sys.utils.ExcelUtil; |
| 12 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| @@ -138,4 +142,52 @@ public class IotDeviceController extends BaseController | @@ -138,4 +142,52 @@ public class IotDeviceController extends BaseController | ||
| 138 | int i = publicService.updateBySql("UPDATE `iot_device` SET label='"+label+"' WHERE client_id='"+client_id+"'"); | 142 | int i = publicService.updateBySql("UPDATE `iot_device` SET label='"+label+"' WHERE client_id='"+client_id+"'"); |
| 139 | return toAjax(i); | 143 | return toAjax(i); |
| 140 | } | 144 | } |
| 145 | + | ||
| 146 | + @ApiOperation("查看订阅信息") | ||
| 147 | + @PreAuthorize("@ss.hasPermi('iot:IotProduct:getProductSubTopic')") | ||
| 148 | + @GetMapping("/getProductSubTopic/{client_id}") | ||
| 149 | + public AjaxResult getProductSubTopic(@PathVariable String client_id) | ||
| 150 | + { | ||
| 151 | + Map<String,Object> map = new HashMap<>(); | ||
| 152 | + | ||
| 153 | + IotDevice iotDevice = publicService.getObject(IotDevice.class,"client_id",client_id+""); | ||
| 154 | + if(null == iotDevice ) | ||
| 155 | + { | ||
| 156 | + return AjaxResult.error("主机不存在"); | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + IotProduct iotProduct = publicService.getObject(IotProduct.class,"id",iotDevice.getProduct_id()+""); | ||
| 160 | + if(null == iotProduct ) | ||
| 161 | + { | ||
| 162 | + return AjaxResult.error("产品不存在"); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + IotProtocolClass iotProductClass = publicService.getObject(IotProtocolClass.class,"id",iotProduct.getAnalysis_clas()+""); | ||
| 166 | + if(null == iotProductClass) | ||
| 167 | + { | ||
| 168 | + return AjaxResult.error("解析插件不存在"); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + if(null == iotProductClass.getSub_topics()) | ||
| 172 | + { | ||
| 173 | + return AjaxResult.error("解析插件订阅主题为空"); | ||
| 174 | + } | ||
| 175 | + String[] sts = iotProductClass.getSub_topics().split(","); | ||
| 176 | + | ||
| 177 | + if(iotDevice.getCompletion_auth()==1) | ||
| 178 | + { | ||
| 179 | + for (int i=0;i<sts.length;i++) | ||
| 180 | + { | ||
| 181 | + sts[i] = "/"+iotProduct.getRole_id()+"/"+iotProduct.getMqtt_username()+"/"+iotDevice.getClient_id()+"/"+iotDevice.getPayload_type()+"/"+sts[i]; | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + map.put("address","mqtt2.proxy.yu2le.com"); | ||
| 186 | + map.put("port",1883); | ||
| 187 | + map.put("mqtt_username",iotProduct.getMqtt_username()); | ||
| 188 | + map.put("mqtt_password",iotProduct.getMqtt_password()); | ||
| 189 | + map.put("topics",sts); | ||
| 190 | + | ||
| 191 | + return AjaxResult.success(map); | ||
| 192 | + } | ||
| 141 | } | 193 | } |
| 1 | package com.zhonglai.luhui.admin.controller.iot; | 1 | package com.zhonglai.luhui.admin.controller.iot; |
| 2 | 2 | ||
| 3 | +import java.util.HashMap; | ||
| 3 | import java.util.List; | 4 | import java.util.List; |
| 5 | +import java.util.Map; | ||
| 4 | import javax.servlet.http.HttpServletResponse; | 6 | import javax.servlet.http.HttpServletResponse; |
| 5 | 7 | ||
| 8 | +import com.google.gson.JsonObject; | ||
| 6 | import com.zhonglai.luhui.action.BaseController; | 9 | import com.zhonglai.luhui.action.BaseController; |
| 10 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 7 | import com.zhonglai.luhui.security.utils.SecurityUtils; | 11 | import com.zhonglai.luhui.security.utils.SecurityUtils; |
| 8 | import com.zhonglai.luhui.sys.utils.ExcelUtil; | 12 | import com.zhonglai.luhui.sys.utils.ExcelUtil; |
| 9 | import io.swagger.annotations.Api; | 13 | import io.swagger.annotations.Api; |
| @@ -38,7 +42,6 @@ public class IotProductController extends BaseController | @@ -38,7 +42,6 @@ public class IotProductController extends BaseController | ||
| 38 | { | 42 | { |
| 39 | @Autowired | 43 | @Autowired |
| 40 | private IIotProductService IotProductService; | 44 | private IIotProductService IotProductService; |
| 41 | - | ||
| 42 | /** | 45 | /** |
| 43 | * 查询产品列表 | 46 | * 查询产品列表 |
| 44 | */ | 47 | */ |
| @@ -113,4 +116,5 @@ public class IotProductController extends BaseController | @@ -113,4 +116,5 @@ public class IotProductController extends BaseController | ||
| 113 | { | 116 | { |
| 114 | return toAjax(IotProductService.deleteIotProductByIds(ids)); | 117 | return toAjax(IotProductService.deleteIotProductByIds(ids)); |
| 115 | } | 118 | } |
| 119 | + | ||
| 116 | } | 120 | } |
| 1 | package com.zhonglai.luhui.admin.controller.monitor; | 1 | package com.zhonglai.luhui.admin.controller.monitor; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.core.domain.AjaxResult; | 3 | import com.ruoyi.common.core.domain.AjaxResult; |
| 4 | +import com.ruoyi.common.core.page.TableDataInfo; | ||
| 5 | +import com.ruoyi.common.utils.ServletUtils; | ||
| 6 | +import com.ruoyi.common.utils.ip.IpUtils; | ||
| 4 | import com.ruoyi.framework.web.domain.Server; | 7 | import com.ruoyi.framework.web.domain.Server; |
| 8 | +import com.ruoyi.system.domain.sys.SysMonitorServer; | ||
| 9 | +import com.ruoyi.system.domain.sys.SysMonitorServerLog; | ||
| 10 | +import com.zhonglai.luhui.action.BaseController; | ||
| 11 | +import com.zhonglai.luhui.admin.dto.MonitorServerUploadDto; | ||
| 12 | +import com.zhonglai.luhui.dao.service.PublicService; | ||
| 13 | +import com.zhonglai.luhui.device.domain.IotAlertLog; | ||
| 5 | import io.swagger.annotations.Api; | 14 | import io.swagger.annotations.Api; |
| 6 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | import org.springframework.security.access.prepost.PreAuthorize; | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 8 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 9 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 10 | -import org.springframework.web.bind.annotation.RestController; | 18 | +import org.springframework.web.bind.annotation.*; |
| 19 | + | ||
| 20 | + | ||
| 21 | +import javax.servlet.http.HttpServletRequest; | ||
| 22 | +import java.io.UnsupportedEncodingException; | ||
| 23 | +import java.net.URLDecoder; | ||
| 24 | +import java.util.HashMap; | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.Map; | ||
| 27 | + | ||
| 28 | +import java.security.MessageDigest; | ||
| 29 | +import java.security.NoSuchAlgorithmException; | ||
| 30 | +import java.util.Arrays; | ||
| 31 | +import java.util.stream.Collectors; | ||
| 32 | + | ||
| 33 | +import javax.crypto.Cipher; | ||
| 34 | +import javax.crypto.spec.IvParameterSpec; | ||
| 35 | +import javax.crypto.spec.SecretKeySpec; | ||
| 36 | +import java.security.MessageDigest; | ||
| 37 | +import java.security.NoSuchAlgorithmException; | ||
| 38 | +import java.util.Base64; | ||
| 39 | +import java.util.Arrays; | ||
| 40 | +import java.util.stream.Collectors; | ||
| 41 | + | ||
| 11 | 42 | ||
| 12 | /** | 43 | /** |
| 13 | * 服务器监控 | 44 | * 服务器监控 |
| @@ -17,8 +48,10 @@ import org.springframework.web.bind.annotation.RestController; | @@ -17,8 +48,10 @@ import org.springframework.web.bind.annotation.RestController; | ||
| 17 | @Api(tags = "服务器监控") | 48 | @Api(tags = "服务器监控") |
| 18 | @RestController | 49 | @RestController |
| 19 | @RequestMapping("/monitor/server") | 50 | @RequestMapping("/monitor/server") |
| 20 | -public class ServerController | 51 | +public class ServerController extends BaseController |
| 21 | { | 52 | { |
| 53 | + @Autowired | ||
| 54 | + private PublicService publicService; | ||
| 22 | @ApiOperation("获取详情") | 55 | @ApiOperation("获取详情") |
| 23 | @PreAuthorize("@ss.hasPermi('monitor:server:list')") | 56 | @PreAuthorize("@ss.hasPermi('monitor:server:list')") |
| 24 | @GetMapping() | 57 | @GetMapping() |
| @@ -28,4 +61,158 @@ public class ServerController | @@ -28,4 +61,158 @@ public class ServerController | ||
| 28 | server.copyTo(); | 61 | server.copyTo(); |
| 29 | return AjaxResult.success(server); | 62 | return AjaxResult.success(server); |
| 30 | } | 63 | } |
| 64 | + | ||
| 65 | + @ApiOperation("上传状态") | ||
| 66 | + @PostMapping("/upload") | ||
| 67 | + public AjaxResult upload(@RequestBody MonitorServerUploadDto monitorServerUploadDto) | ||
| 68 | + { | ||
| 69 | + String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); | ||
| 70 | + SysMonitorServer sysMonitorServer = new SysMonitorServer(); | ||
| 71 | + sysMonitorServer.setIp(ip); | ||
| 72 | + Long st = publicService.getObjectListTotle(sysMonitorServer, null); | ||
| 73 | + sysMonitorServer.setCpu_usage(new Double(monitorServerUploadDto.getCpu_usage()*100).intValue()); | ||
| 74 | + sysMonitorServer.setConnection_count(monitorServerUploadDto.getConnection_count()); | ||
| 75 | + sysMonitorServer.setMemory_usage(new Double(monitorServerUploadDto.getMemory_usage()*100).intValue()); | ||
| 76 | + sysMonitorServer.setDisk_usage(new Double(monitorServerUploadDto.getDisk_usage()*100).intValue()); | ||
| 77 | + if(st==0) | ||
| 78 | + { | ||
| 79 | + sysMonitorServer.setCreate_time(System.currentTimeMillis()); | ||
| 80 | + publicService.insert(sysMonitorServer); | ||
| 81 | + }else { | ||
| 82 | + publicService.updateObject(sysMonitorServer,"ip"); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + SysMonitorServerLog sysMonitorServerLog = new SysMonitorServerLog(); | ||
| 86 | + sysMonitorServerLog.setIp(ip); | ||
| 87 | + sysMonitorServerLog.setCpu_usage(sysMonitorServer.getCpu_usage()); | ||
| 88 | + sysMonitorServerLog.setConnection_count(sysMonitorServer.getConnection_count()); | ||
| 89 | + sysMonitorServerLog.setMemory_usage(sysMonitorServer.getMemory_usage()); | ||
| 90 | + sysMonitorServerLog.setDisk_usage(sysMonitorServer.getDisk_usage()); | ||
| 91 | + sysMonitorServerLog.setCreate_time(System.currentTimeMillis()); | ||
| 92 | + publicService.insert(sysMonitorServerLog); | ||
| 93 | + return AjaxResult.success(); | ||
| 94 | + } | ||
| 95 | + @ApiOperation("企业微信消息") | ||
| 96 | + @RequestMapping("/uploadWxMessage/{agentId}") | ||
| 97 | + public AjaxResult uploadWxMessage(@PathVariable String agentId) | ||
| 98 | + { | ||
| 99 | + | ||
| 100 | + return AjaxResult.success(); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public static void main(String[] args) throws UnsupportedEncodingException { | ||
| 104 | + String TOKEN = "DDbVb3cSiTAbCSgI4UndPlvy"; // 替换为你的token | ||
| 105 | + String ENCODING_AES_KEY = "FH1CDpqZhNkcXCWEYJOyAO4HLG2mxYrE1c4j83mXruB"; | ||
| 106 | + String msgSignature = "6cfbf56d42c00a182a6da650023ef5ba407cb203"; | ||
| 107 | + String timestamp = "1724921459"; | ||
| 108 | + String nonce = "1725665565"; | ||
| 109 | + String echoStr = "FQYmaDL0vzQPBz5rRVYYGVLx62EmD8krbPYO6RzVaAtsIuFz+n8nPZ8fPtnNTbMCiGaRrjZCYgbsaeDcqPqvNQ\u003d\u003d"; | ||
| 110 | + | ||
| 111 | + // URL解码 | ||
| 112 | + String decodedEchoStr = decodeEchoStr(echoStr); | ||
| 113 | + | ||
| 114 | + // 校验msg_signature | ||
| 115 | + boolean isValid = validateMsgSignature(TOKEN, timestamp, nonce, decodedEchoStr, msgSignature); | ||
| 116 | + if (isValid) { | ||
| 117 | + System.out.println("请求合法"); | ||
| 118 | + } else { | ||
| 119 | + System.out.println("请求不合法"); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + // 解密echostr | ||
| 123 | + String messageContent = decryptEchoStr(decodedEchoStr,ENCODING_AES_KEY); | ||
| 124 | + System.out.println("消息内容: " + messageContent); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + private static String decodeEchoStr(String echoStr) throws UnsupportedEncodingException { | ||
| 128 | + // 假设echoStr已经被Base64编码过,这里直接返回 | ||
| 129 | + return URLDecoder.decode(echoStr, "UTF-8"); // 实际上需要根据情况解码 | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + private static boolean validateMsgSignature(String token, String timestamp, String nonce, String msgEncrypt, String msgSignature) { | ||
| 133 | + try { | ||
| 134 | + String signature = sha1(Arrays.asList(token, timestamp, nonce, msgEncrypt).stream().sorted().collect(Collectors.joining())); | ||
| 135 | + return msgSignature.equals(signature); | ||
| 136 | + } catch (NoSuchAlgorithmException e) { | ||
| 137 | + e.printStackTrace(); | ||
| 138 | + return false; | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + private static String sha1(String input) throws NoSuchAlgorithmException { | ||
| 143 | + MessageDigest mDigest = MessageDigest.getInstance("SHA1"); | ||
| 144 | + byte[] result = mDigest.digest(input.getBytes()); | ||
| 145 | + StringBuilder sb = new StringBuilder(); | ||
| 146 | + for (byte aResult : result) { | ||
| 147 | + sb.append(Integer.toString((aResult & 0xff) + 0x100, 16).substring(1)); | ||
| 148 | + } | ||
| 149 | + return sb.toString(); | ||
| 150 | + } | ||
| 151 | + private static final String CORPID = "wx5823bf96d3bd56c7"; | ||
| 152 | + private static String decryptEchoStr(String encryptedMsg,String ENCODING_AES_KEY) { | ||
| 153 | + // 这里需要实现具体的解密逻辑 | ||
| 154 | + try { | ||
| 155 | + // 1. BASE64解码 | ||
| 156 | + byte[] base64Decoded = Base64.getDecoder().decode(encryptedMsg); | ||
| 157 | + | ||
| 158 | + // 2. AES解密 | ||
| 159 | + byte[] keyBytes = Base64.getDecoder().decode(ENCODING_AES_KEY + "="); | ||
| 160 | + SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); | ||
| 161 | + IvParameterSpec ivSpec = new IvParameterSpec(keyBytes, 0, 16); // 使用前16个字节作为IV | ||
| 162 | + | ||
| 163 | + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); | ||
| 164 | + cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); | ||
| 165 | + | ||
| 166 | + byte[] decrypted = cipher.doFinal(base64Decoded); | ||
| 167 | + | ||
| 168 | + // 3. 去除随机字节和msg_len | ||
| 169 | + byte[] content = Arrays.copyOfRange(decrypted, 16, decrypted.length); | ||
| 170 | + int msgLen = ((content[0] & 0xFF) << 24) | | ||
| 171 | + ((content[1] & 0xFF) << 16) | | ||
| 172 | + ((content[2] & 0xFF) << 8) | | ||
| 173 | + (content[3] & 0xFF); | ||
| 174 | + | ||
| 175 | + byte[] msg = Arrays.copyOfRange(content, 4, 4 + msgLen); | ||
| 176 | + byte[] receiveId = Arrays.copyOfRange(content, 4 + msgLen, content.length); | ||
| 177 | + | ||
| 178 | + // 4. 转换为字符串 | ||
| 179 | + String msgStr = new String(msg, "UTF-8"); | ||
| 180 | + String receiveIdStr = new String(receiveId, "UTF-8"); | ||
| 181 | + | ||
| 182 | + // 5. 验证receiveId | ||
| 183 | + if (receiveIdStr.equals(CORPID)) { | ||
| 184 | + return msgStr; | ||
| 185 | + } else { | ||
| 186 | + throw new IllegalArgumentException("ReceiveId 不匹配"); | ||
| 187 | + } | ||
| 188 | + } catch (Exception e) { | ||
| 189 | + e.printStackTrace(); | ||
| 190 | + return null; | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + @ApiOperation("获取状态列表") | ||
| 195 | + @GetMapping("/getSysMonitorServerList") | ||
| 196 | + public TableDataInfo getSysMonitorServerList(SysMonitorServer sysMonitorServer) throws Exception | ||
| 197 | + { | ||
| 198 | + startPage(); | ||
| 199 | + startOrderBy(); | ||
| 200 | + List<Map<String,Object>> list = publicService.getObjectList(sysMonitorServer,"*",null,null,0,0); | ||
| 201 | + return getDataTable(list); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + @ApiOperation("获取服务器状态曲线") | ||
| 205 | + @GetMapping("/getSysMonitorServerLogList") | ||
| 206 | + public TableDataInfo getSysMonitorServerLogList(String ip,Long startTime,Long endTime) throws Exception | ||
| 207 | + { | ||
| 208 | + SysMonitorServerLog sysMonitorServerLog = new SysMonitorServerLog(); | ||
| 209 | + sysMonitorServerLog.setIp(ip); | ||
| 210 | + | ||
| 211 | + Map<String, Object> whereMap = new HashMap<>(); | ||
| 212 | + whereMap.put("create_time","time="); | ||
| 213 | + sysMonitorServerLog.setCreate_time(startTime); | ||
| 214 | + whereMap.put("end_create_time",endTime); | ||
| 215 | + List<Map<String,Object>> list = publicService.getObjectList(sysMonitorServerLog,"*",whereMap,"create_time asc",0,0); | ||
| 216 | + return getDataTable(list); | ||
| 217 | + } | ||
| 31 | } | 218 | } |
lh-modules/lh-admin/src/main/java/com/zhonglai/luhui/admin/dto/MonitorServerUploadDto.java
0 → 100644
| 1 | +package com.zhonglai.luhui.admin.dto; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | + | ||
| 6 | +@ApiModel("服务器状态监控") | ||
| 7 | +public class MonitorServerUploadDto { | ||
| 8 | + @ApiModelProperty("CPU使用率(%%)") | ||
| 9 | + private Double cpu_usage; | ||
| 10 | + @ApiModelProperty("内存使用率(%%)") | ||
| 11 | + private Double memory_usage; | ||
| 12 | + @ApiModelProperty("磁盘使用率(%%)") | ||
| 13 | + private Double disk_usage; | ||
| 14 | + @ApiModelProperty("系统连接数(%%)") | ||
| 15 | + private Integer connection_count; | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + public Double getCpu_usage() { | ||
| 19 | + return cpu_usage; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public void setCpu_usage(Double cpu_usage) { | ||
| 23 | + this.cpu_usage = cpu_usage; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public Double getMemory_usage() { | ||
| 27 | + return memory_usage; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public void setMemory_usage(Double memory_usage) { | ||
| 31 | + this.memory_usage = memory_usage; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public Double getDisk_usage() { | ||
| 35 | + return disk_usage; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public void setDisk_usage(Double disk_usage) { | ||
| 39 | + this.disk_usage = disk_usage; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public Integer getConnection_count() { | ||
| 43 | + return connection_count; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public void setConnection_count(Integer connection_count) { | ||
| 47 | + this.connection_count = connection_count; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | +} |
| 1 | -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn com.zhonglai.luhui: debug # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-admin # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb,/data/** # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1 | ||
| 1 | +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn com.zhonglai.luhui: debug # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-admin # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/tool/gen/generatorCodeFromDb,/data/**,/monitor/server/upload,/monitor/server/getSysMonitorServerList,/monitor/server/getSysMonitorServerLogList # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1 |
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +# 定义API的URL | ||
| 4 | +API_URL="https://lh.admin.yu2le.com/api/monitor/server/upload" | ||
| 5 | + | ||
| 6 | +# 获取系统性能信息的函数 | ||
| 7 | +get_system_performance() { | ||
| 8 | + # 获取CPU使用率 | ||
| 9 | + CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}') | ||
| 10 | + | ||
| 11 | + # 获取内存使用率 | ||
| 12 | + MEMORY_USAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}') | ||
| 13 | + | ||
| 14 | + # 获取磁盘使用率 | ||
| 15 | + DISK_USAGE=$(df -h | grep '^/dev/' | grep -v 'boot' | awk '{print $5}' | tr -d '%' | paste -sd+ | bc) | ||
| 16 | + | ||
| 17 | + # 获取系统连接数 | ||
| 18 | + CONNECTION_COUNT=$(netstat -an | grep ESTABLISHED | wc -l) | ||
| 19 | + | ||
| 20 | + # 返回JSON格式的数据 | ||
| 21 | + echo "{\"cpu_usage\": \"$CPU_USAGE\", \"memory_usage\": \"$MEMORY_USAGE\", \"disk_usage\": \"$DISK_USAGE\", \"connection_count\": \"$CONNECTION_COUNT\"}" | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +# 获取当前系统性能数据 | ||
| 25 | +DATA=$(get_system_performance) | ||
| 26 | + | ||
| 27 | +echo $DATA | ||
| 28 | + | ||
| 29 | +# 使用curl将数据上传到指定的API | ||
| 30 | +curl -X POST -H "Content-Type: application/json" -d "$DATA" "$API_URL" |
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +# 定义脚本路径 | ||
| 4 | +SCRIPT_PATH="/opt/monitor.sh" | ||
| 5 | +CRON_LOG="/var/log/monitor.log" | ||
| 6 | + | ||
| 7 | +# 创建 monitor.sh 文件 | ||
| 8 | +( | ||
| 9 | + cat <<EOF | ||
| 10 | +#!/bin/bash | ||
| 11 | + | ||
| 12 | +# 定义API的URL | ||
| 13 | +API_URL="https://lh.admin.yu2le.com/api/monitor/server/upload" | ||
| 14 | + | ||
| 15 | +# 获取系统性能信息的函数 | ||
| 16 | +get_system_performance() { | ||
| 17 | + # 获取CPU使用率 | ||
| 18 | + CPU_USAGE=\$(top -bn1 | grep "Cpu(s)" | awk '{print \$2 + \$4}') | ||
| 19 | + | ||
| 20 | + # 获取内存使用率 | ||
| 21 | + MEMORY_USAGE=\$(free | grep Mem | awk '{print \$3/\$2 * 100.0}') | ||
| 22 | + | ||
| 23 | + # 获取磁盘使用率 | ||
| 24 | + DISK_USAGE=\$(df -h | grep '^/dev/' | grep -v 'boot' | awk '{print \$5}' | tr -d '%' | paste -sd+ | bc) | ||
| 25 | + | ||
| 26 | + # 获取系统连接数 | ||
| 27 | + CONNECTION_COUNT=\$(netstat -an | grep ESTABLISHED | wc -l) | ||
| 28 | + | ||
| 29 | + # 返回JSON格式的数据 | ||
| 30 | + echo "{\"cpu_usage\": \"\${CPU_USAGE}\", \"memory_usage\": \"\${MEMORY_USAGE}\", \"disk_usage\": \"\${DISK_USAGE}\", \"connection_count\": \"\${CONNECTION_COUNT}\"}" | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +# 获取当前系统性能数据 | ||
| 34 | +DATA=\$(get_system_performance) | ||
| 35 | + | ||
| 36 | +echo \$DATA | ||
| 37 | + | ||
| 38 | +# 使用curl将数据上传到指定的API | ||
| 39 | +curl -X POST -H "Content-Type: application/json" -d "\$DATA" --insecure "\$API_URL" | ||
| 40 | +EOF | ||
| 41 | +) > $SCRIPT_PATH | ||
| 42 | + | ||
| 43 | +# 设置脚本执行权限 | ||
| 44 | +chmod +x $SCRIPT_PATH | ||
| 45 | + | ||
| 46 | +# 添加定时任务 | ||
| 47 | +(crontab -l ; echo "*/1 * * * * $SCRIPT_PATH >> $CRON_LOG 2>&1") | crontab - | ||
| 48 | + | ||
| 49 | +# 重启 cron 服务 | ||
| 50 | +systemctl restart crond | ||
| 51 | + | ||
| 52 | +$SCRIPT_PATH | ||
| 53 | + | ||
| 54 | +echo "Monitor setup completed." | ||
| 55 | +# 解决:curl: (35) Peer reports incompatible or unsupported protocol version. 方法: yum update -y nss curl libcurl |
| @@ -53,6 +53,16 @@ public class IotTerminalController extends BaseController | @@ -53,6 +53,16 @@ public class IotTerminalController extends BaseController | ||
| 53 | return getDataTable(list); | 53 | return getDataTable(list); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | + @ApiOperation("根据deviceId查询终端列表") | ||
| 57 | + @GetMapping("/listByDeviceId/{deviceId}") | ||
| 58 | + public AjaxResult listByDeviceId(@PathVariable String deviceId) | ||
| 59 | + { | ||
| 60 | + IotTerminal iotTerminal = new IotTerminal(); | ||
| 61 | + iotTerminal.setDevice_id(deviceId); | ||
| 62 | + List<IotTerminal> list = iotTerminalService.selectIotTerminalListByUserId(iotTerminal); | ||
| 63 | + return AjaxResult.success(list); | ||
| 64 | + } | ||
| 65 | + | ||
| 56 | @ApiOperation("测试") | 66 | @ApiOperation("测试") |
| 57 | @GetMapping("/t1") | 67 | @GetMapping("/t1") |
| 58 | public TestDto t1() | 68 | public TestDto t1() |
| 1 | -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 18080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn com.zhonglai.luhui: debug # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login/ApiLogin/*,/content/**,/test/**,/fish/FishPriceCollection/* # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1 | ||
| 1 | +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 18080 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn com.zhonglai.luhui: debug # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-api # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login/ApiLogin/*,/content/**,/test/**,/fish/FishPriceCollection/*,/iot/IotTerminal/listByDeviceId/* # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-mqtt-service-deviceCommand-test send-tags: 1 |
-
请 注册 或 登录 后发表评论