作者 钟来

bug修改

@@ -65,7 +65,7 @@ public class CaptchaConfig @@ -65,7 +65,7 @@ public class CaptchaConfig
65 // KAPTCHA_SESSION_KEY 65 // KAPTCHA_SESSION_KEY
66 properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); 66 properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath");
67 // 验证码文本生成器 67 // 验证码文本生成器
68 - properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.ruoyi.framework.config.KaptchaTextCreator"); 68 + properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.zhonglai.luhui.firewall.config.KaptchaTextCreator");
69 // 验证码文本字符间距 默认为2 69 // 验证码文本字符间距 默认为2
70 properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); 70 properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3");
71 // 验证码文本字符长度 默认为5 71 // 验证码文本字符长度 默认为5
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Component;
12 12
13 import java.util.Date; 13 import java.util.Date;
  14 +import java.util.HashMap;
14 import java.util.List; 15 import java.util.List;
15 import java.util.Map; 16 import java.util.Map;
16 17
@@ -21,13 +22,14 @@ import java.util.Map; @@ -21,13 +22,14 @@ import java.util.Map;
21 public class ServerAlarmTask { 22 public class ServerAlarmTask {
22 @Autowired 23 @Autowired
23 private PublicService publicService; 24 private PublicService publicService;
24 -  
25 //检测服务器运行状态 25 //检测服务器运行状态
26 - public void checkServerStatus(Integer cpu_usage, Integer memory_usage, Integer disk_usage, Integer connection_count) throws Exception {  
27 - List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `sys_monitor_server` WHERE cpu_usage>="+cpu_usage+" OR memory_usage>="+memory_usage+" OR disk_usage>="+disk_usage+" OR connection_count>="+connection_count); 26 + public void checkServerStatus(Integer cpu_usage, Integer memory_usage, Integer disk_usage, Integer connection_count,Integer hour) throws Exception {
  27 + List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `sys_monitor_server` WHERE (cpu_usage>="+cpu_usage+" OR memory_usage>="+memory_usage+" OR disk_usage>="+disk_usage+" OR connection_count>="+connection_count+")"+"AND (notification_time < " + (DateUtils.getNowTimeMilly() - hour*60*60) + ")");
  28 +
28 if(null != list && list.size()!=0) 29 if(null != list && list.size()!=0)
29 { 30 {
30 StringBuffer stringBuffer = new StringBuffer("**服务器运维状态:**"); 31 StringBuffer stringBuffer = new StringBuffer("**服务器运维状态:**");
  32 + StringBuffer ips = new StringBuffer("''");
31 for (Map<String,Object> map:list) 33 for (Map<String,Object> map:list)
32 { 34 {
33 SysMonitorServer sms = BeanUtil.mapToBean(map,SysMonitorServer.class,false,null); 35 SysMonitorServer sms = BeanUtil.mapToBean(map,SysMonitorServer.class,false,null);
@@ -88,6 +90,10 @@ public class ServerAlarmTask { @@ -88,6 +90,10 @@ public class ServerAlarmTask {
88 90
89 stringBuffer.append("\n"); 91 stringBuffer.append("\n");
90 stringBuffer.append(DateUtils.parseDateToStr("yyyy年MM月dd日HH时mm分ss秒",new Date())); 92 stringBuffer.append(DateUtils.parseDateToStr("yyyy年MM月dd日HH时mm分ss秒",new Date()));
  93 +
  94 + ips.append(",'");
  95 + ips.append(sms.getIp());
  96 + ips.append("'");
91 } 97 }
92 JSONObject jsonObject = new JSONObject(); 98 JSONObject jsonObject = new JSONObject();
93 jsonObject.put("msgtype","markdown"); 99 jsonObject.put("msgtype","markdown");
@@ -96,6 +102,8 @@ public class ServerAlarmTask { @@ -96,6 +102,8 @@ public class ServerAlarmTask {
96 text.put("mentioned_mobile_list",new String[]{"@all"}); 102 text.put("mentioned_mobile_list",new String[]{"@all"});
97 jsonObject.put("markdown",text); 103 jsonObject.put("markdown",text);
98 HttpUtil.post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0c811725-6ee8-4bb5-b7de-378b6fa5b9b0",jsonObject.toJSONString()); 104 HttpUtil.post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0c811725-6ee8-4bb5-b7de-378b6fa5b9b0",jsonObject.toJSONString());
  105 +
  106 + publicService.updateBySql("update `sys_monitor_server` set notification_time="+DateUtils.getNowTimeMilly()+" where ip in("+ips+")");
99 } 107 }
100 } 108 }
101 109
@@ -52,6 +52,7 @@ public class SecurityConfigService { @@ -52,6 +52,7 @@ public class SecurityConfigService {
52 defaultConfigHttpSecurity(httpSecurity); 52 defaultConfigHttpSecurity(httpSecurity);
53 53
54 httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); 54 httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
  55 +
55 // 添加JWT filter 56 // 添加JWT filter
56 httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); 57 httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
57 // 添加CORS filter 58 // 添加CORS filter
@@ -218,7 +218,15 @@ public class ServerController extends BaseController @@ -218,7 +218,15 @@ public class ServerController extends BaseController
218 whereMap.put("create_time","time="); 218 whereMap.put("create_time","time=");
219 sysMonitorServerLog.setCreate_time(startTime); 219 sysMonitorServerLog.setCreate_time(startTime);
220 whereMap.put("end_create_time",endTime); 220 whereMap.put("end_create_time",endTime);
221 - List<Map<String,Object>> list = publicService.getObjectList(sysMonitorServerLog,"*",whereMap,"create_time asc",0,0); 221 + List<Map<String,Object>> list = publicService.getObjectList(sysMonitorServerLog,"`id`,`ip`,`cpu_usage`,`memory_usage`,`disk_usage`,`connection_count`,`create_time`",whereMap,"create_time asc",0,0);
222 return getDataTable(list); 222 return getDataTable(list);
223 } 223 }
  224 +
  225 + @ApiOperation("获取服务器状态曲线详情")
  226 + @GetMapping("/getSysMonitorServerLogInfo/{id}")
  227 + public AjaxResult getSysMonitorServerLogInfo(@PathVariable Integer id)
  228 + {
  229 + SysMonitorServerLog sysMonitorServerLog = publicService.getObject(SysMonitorServerLog.class,"id",id+"");
  230 + return AjaxResult.success(sysMonitorServerLog);
  231 + }
224 } 232 }
@@ -53,6 +53,12 @@ @@ -53,6 +53,12 @@
53 <groupId>mysql</groupId> 53 <groupId>mysql</groupId>
54 <artifactId>mysql-connector-java</artifactId> 54 <artifactId>mysql-connector-java</artifactId>
55 </dependency> 55 </dependency>
  56 +
  57 + <!-- 防火墙 -->
  58 + <dependency>
  59 + <groupId>com.zhonglai.luhui</groupId>
  60 + <artifactId>lh-common-firewall</artifactId>
  61 + </dependency>
56 </dependencies> 62 </dependencies>
57 63
58 <build> 64 <build>
@@ -15,6 +15,7 @@ import org.springframework.context.annotation.ComponentScan; @@ -15,6 +15,7 @@ import org.springframework.context.annotation.ComponentScan;
15 "com.zhonglai.luhui.sys", 15 "com.zhonglai.luhui.sys",
16 "com.zhonglai.luhui.redis", 16 "com.zhonglai.luhui.redis",
17 "com.zhonglai.luhui.security", 17 "com.zhonglai.luhui.security",
  18 + "com.zhonglai.luhui.firewall",
18 "com.zhonglai.luhui.login", 19 "com.zhonglai.luhui.login",
19 }) 20 })
20 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) 21 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
  1 +package com.zhonglai.luhui.login.controller;
  2 +
  3 +import com.google.code.kaptcha.Producer;
  4 +import com.ruoyi.common.config.RuoYiConfig;
  5 +import com.ruoyi.common.constant.Constants;
  6 +import com.ruoyi.common.core.domain.AjaxResult;
  7 +import com.ruoyi.common.utils.sign.Base64;
  8 +import com.ruoyi.common.utils.uuid.IdUtils;
  9 +import com.zhonglai.luhui.redis.service.RedisCache;
  10 +import com.zhonglai.luhui.sys.service.ISysConfigService;
  11 +import io.swagger.annotations.Api;
  12 +import io.swagger.annotations.ApiOperation;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.util.FastByteArrayOutputStream;
  15 +import org.springframework.web.bind.annotation.GetMapping;
  16 +import org.springframework.web.bind.annotation.RestController;
  17 +
  18 +import javax.annotation.Resource;
  19 +import javax.imageio.ImageIO;
  20 +import javax.servlet.http.HttpServletResponse;
  21 +import java.awt.image.BufferedImage;
  22 +import java.io.IOException;
  23 +import java.util.concurrent.TimeUnit;
  24 +
  25 +/**
  26 + * 验证码操作处理
  27 + *
  28 + * @author ruoyi
  29 + */
  30 +@Api(tags = "验证码操作处理")
  31 +@RestController
  32 +public class CaptchaController
  33 +{
  34 + @Resource(name = "captchaProducer")
  35 + private Producer captchaProducer;
  36 +
  37 + @Resource(name = "captchaProducerMath")
  38 + private Producer captchaProducerMath;
  39 +
  40 + @Autowired
  41 + private RedisCache redisCache;
  42 +
  43 + @Autowired
  44 + private ISysConfigService configService;
  45 + /**
  46 + * 生成验证码
  47 + */
  48 + @ApiOperation("生成验证码")
  49 + @GetMapping("/captchaImage")
  50 + public AjaxResult getCode(HttpServletResponse response) throws IOException
  51 + {
  52 + AjaxResult ajax = AjaxResult.success();
  53 + boolean captchaOnOff = configService.selectCaptchaOnOff();
  54 + ajax.put("captchaOnOff", captchaOnOff);
  55 + if (!captchaOnOff)
  56 + {
  57 + return ajax;
  58 + }
  59 +
  60 + // 保存验证码信息
  61 + String uuid = IdUtils.simpleUUID();
  62 + String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
  63 +
  64 + String capStr = null, code = null;
  65 + BufferedImage image = null;
  66 +
  67 + // 生成验证码
  68 + String captchaType = RuoYiConfig.getCaptchaType();
  69 + if ("math".equals(captchaType))
  70 + {
  71 + String capText = captchaProducerMath.createText();
  72 + capStr = capText.substring(0, capText.lastIndexOf("@"));
  73 + code = capText.substring(capText.lastIndexOf("@") + 1);
  74 + image = captchaProducerMath.createImage(capStr);
  75 + }
  76 + else if ("char".equals(captchaType))
  77 + {
  78 + capStr = code = captchaProducer.createText();
  79 + image = captchaProducer.createImage(capStr);
  80 + }
  81 +
  82 + redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
  83 + // 转换流信息写出
  84 + FastByteArrayOutputStream os = new FastByteArrayOutputStream();
  85 + try
  86 + {
  87 + ImageIO.write(image, "jpg", os);
  88 + }
  89 + catch (IOException e)
  90 + {
  91 + return AjaxResult.error(e.getMessage());
  92 + }
  93 +
  94 + ajax.put("uuid", uuid);
  95 + ajax.put("img", Base64.encode(os.toByteArray()));
  96 + return ajax;
  97 + }
  98 +
  99 +}