代码更新
parent
31155a12a6
commit
50767b8b9a
|
@ -0,0 +1,31 @@
|
|||
package com.zhilian.business.controller;
|
||||
|
||||
import com.zhilian.business.domain.BreakLog;
|
||||
import com.zhilian.business.service.BreakLogService;
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName BreakLogController
|
||||
* @Description TODO
|
||||
* @Author YuanYongH
|
||||
* @Date 2024/4/8 20:48
|
||||
*/
|
||||
@RestController
|
||||
public class BreakLogController {
|
||||
|
||||
@Autowired
|
||||
private BreakLogService breakLogService;
|
||||
|
||||
@PostMapping("log")
|
||||
public Result<List<BreakLog>> breakLog() {
|
||||
List<BreakLog> list = breakLogService.breakLog();
|
||||
Result<List<BreakLog>> success = Result.success(list);
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.zhilian.business.mapper;
|
||||
|
||||
import com.zhilian.business.domain.BreakLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName BreakLogMapper
|
||||
* @Description TODO
|
||||
* @Author YuanYongH
|
||||
* @Date 2024/4/8 20:49
|
||||
*/
|
||||
@Mapper
|
||||
public interface BreakLogMapper {
|
||||
List<BreakLog> breakLog();
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.zhilian.business.service;
|
||||
|
||||
import com.zhilian.business.domain.BreakLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName BreakLogService
|
||||
* @Description TODO
|
||||
* @Author YuanYongH
|
||||
* @Date 2024/4/8 20:49
|
||||
*/
|
||||
public interface BreakLogService {
|
||||
List<BreakLog> breakLog();
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.zhilian.business.service.impl;
|
||||
|
||||
import com.zhilian.business.domain.BreakLog;
|
||||
import com.zhilian.business.mapper.BreakLogMapper;
|
||||
import com.zhilian.business.service.BreakLogService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName BreakLogServiceImpl
|
||||
* @Description 定时扫描故障状态
|
||||
* @Author YuanYongH
|
||||
* @Date 2024/4/8 20:49
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class BreakLogServiceImpl implements BreakLogService {
|
||||
@Autowired
|
||||
private BreakLogMapper breakLogMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String ,String> redisTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public List<BreakLog> breakLog() {
|
||||
BreakLog breakLog = new BreakLog();
|
||||
// 10秒
|
||||
final long timeInterval = 10000;
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true){
|
||||
breakLogMapper.breakLog();
|
||||
log.info("扫描故障状态");
|
||||
String breakState = breakLog.getBreakState();
|
||||
if (breakState != null){
|
||||
// 判断故障状态
|
||||
if (breakLog.getBreakState().equals("0")){
|
||||
log.info("正常");
|
||||
}else if (breakLog.getBreakState().equals("1")){
|
||||
log.info("故障");
|
||||
}else {
|
||||
log.info("未知");
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
Thread.sleep(timeInterval);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// 开启线程
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
// 返回故障日志
|
||||
return breakLogMapper.breakLog();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhilian.business.mapper.BreakLogMapper">
|
||||
|
||||
<select id="breakLog" resultType="com.zhilian.business.domain.BreakLog">
|
||||
select * from business_break_log
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,23 @@
|
|||
package com.zhilian.resolver;
|
||||
|
||||
import com.zhilian.common.security.annotation.EnableCustomConfig;
|
||||
import com.zhilian.common.security.annotation.EnableMyFeignClients;
|
||||
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @ClassName ZhiLianResolverApplication
|
||||
* @Description TODO
|
||||
* @Author YuanYongH
|
||||
* @Date 2024/4/8 17:25
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class ZhiLianResolverApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ZhiLianResolverApplication.class,args);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue