作者 钟来

bug修改

... ... @@ -65,7 +65,7 @@ public class CaptchaConfig
// KAPTCHA_SESSION_KEY
properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath");
// 验证码文本生成器
properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.ruoyi.framework.config.KaptchaTextCreator");
properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.zhonglai.luhui.firewall.config.KaptchaTextCreator");
// 验证码文本字符间距 默认为2
properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3");
// 验证码文本字符长度 默认为5
... ...
... ... @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
... ... @@ -21,13 +22,14 @@ import java.util.Map;
public class ServerAlarmTask {
@Autowired
private PublicService publicService;
//检测服务器运行状态
public void checkServerStatus(Integer cpu_usage, Integer memory_usage, Integer disk_usage, Integer connection_count) throws Exception {
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);
public void checkServerStatus(Integer cpu_usage, Integer memory_usage, Integer disk_usage, Integer connection_count,Integer hour) throws Exception {
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) + ")");
if(null != list && list.size()!=0)
{
StringBuffer stringBuffer = new StringBuffer("**服务器运维状态:**");
StringBuffer ips = new StringBuffer("''");
for (Map<String,Object> map:list)
{
SysMonitorServer sms = BeanUtil.mapToBean(map,SysMonitorServer.class,false,null);
... ... @@ -88,6 +90,10 @@ public class ServerAlarmTask {
stringBuffer.append("\n");
stringBuffer.append(DateUtils.parseDateToStr("yyyy年MM月dd日HH时mm分ss秒",new Date()));
ips.append(",'");
ips.append(sms.getIp());
ips.append("'");
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("msgtype","markdown");
... ... @@ -96,6 +102,8 @@ public class ServerAlarmTask {
text.put("mentioned_mobile_list",new String[]{"@all"});
jsonObject.put("markdown",text);
HttpUtil.post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0c811725-6ee8-4bb5-b7de-378b6fa5b9b0",jsonObject.toJSONString());
publicService.updateBySql("update `sys_monitor_server` set notification_time="+DateUtils.getNowTimeMilly()+" where ip in("+ips+")");
}
}
... ...
... ... @@ -52,6 +52,7 @@ public class SecurityConfigService {
defaultConfigHttpSecurity(httpSecurity);
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
// 添加JWT filter
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
// 添加CORS filter
... ...
... ... @@ -218,7 +218,15 @@ public class ServerController extends BaseController
whereMap.put("create_time","time=");
sysMonitorServerLog.setCreate_time(startTime);
whereMap.put("end_create_time",endTime);
List<Map<String,Object>> list = publicService.getObjectList(sysMonitorServerLog,"*",whereMap,"create_time asc",0,0);
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);
return getDataTable(list);
}
@ApiOperation("获取服务器状态曲线详情")
@GetMapping("/getSysMonitorServerLogInfo/{id}")
public AjaxResult getSysMonitorServerLogInfo(@PathVariable Integer id)
{
SysMonitorServerLog sysMonitorServerLog = publicService.getObject(SysMonitorServerLog.class,"id",id+"");
return AjaxResult.success(sysMonitorServerLog);
}
}
... ...
... ... @@ -53,6 +53,12 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 防火墙 -->
<dependency>
<groupId>com.zhonglai.luhui</groupId>
<artifactId>lh-common-firewall</artifactId>
</dependency>
</dependencies>
<build>
... ...
... ... @@ -15,6 +15,7 @@ import org.springframework.context.annotation.ComponentScan;
"com.zhonglai.luhui.sys",
"com.zhonglai.luhui.redis",
"com.zhonglai.luhui.security",
"com.zhonglai.luhui.firewall",
"com.zhonglai.luhui.login",
})
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
... ...
package com.zhonglai.luhui.login.controller;
import com.google.code.kaptcha.Producer;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.sign.Base64;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.zhonglai.luhui.redis.service.RedisCache;
import com.zhonglai.luhui.sys.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
* 验证码操作处理
*
* @author ruoyi
*/
@Api(tags = "验证码操作处理")
@RestController
public class CaptchaController
{
@Resource(name = "captchaProducer")
private Producer captchaProducer;
@Resource(name = "captchaProducerMath")
private Producer captchaProducerMath;
@Autowired
private RedisCache redisCache;
@Autowired
private ISysConfigService configService;
/**
* 生成验证码
*/
@ApiOperation("生成验证码")
@GetMapping("/captchaImage")
public AjaxResult getCode(HttpServletResponse response) throws IOException
{
AjaxResult ajax = AjaxResult.success();
boolean captchaOnOff = configService.selectCaptchaOnOff();
ajax.put("captchaOnOff", captchaOnOff);
if (!captchaOnOff)
{
return ajax;
}
// 保存验证码信息
String uuid = IdUtils.simpleUUID();
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String capStr = null, code = null;
BufferedImage image = null;
// 生成验证码
String captchaType = RuoYiConfig.getCaptchaType();
if ("math".equals(captchaType))
{
String capText = captchaProducerMath.createText();
capStr = capText.substring(0, capText.lastIndexOf("@"));
code = capText.substring(capText.lastIndexOf("@") + 1);
image = captchaProducerMath.createImage(capStr);
}
else if ("char".equals(captchaType))
{
capStr = code = captchaProducer.createText();
image = captchaProducer.createImage(capStr);
}
redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
// 转换流信息写出
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
try
{
ImageIO.write(image, "jpg", os);
}
catch (IOException e)
{
return AjaxResult.error(e.getMessage());
}
ajax.put("uuid", uuid);
ajax.put("img", Base64.encode(os.toByteArray()));
return ajax;
}
}
... ...