Commit 42f05db9 authored by zengtianlai3's avatar zengtianlai3

minitor接口开发

parent 04bffc10
package iot.sixiang.license.controller;
import iot.sixiang.license.entity.Monitor;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-10
*/
@RestController
@RequestMapping("/iot_license/monitor")
public class MonitorController {
@Autowired
private MonitorService monitorService;
@PostMapping("add")
public boolean addMonitor(){
return monitorService.addMonitor(20);
}
@GetMapping("list")
public ResResult getMonitorList(@RequestParam("type") int type) {
LocalDate localDate = LocalDate.now();
LocalDate endDate = LocalDate.now();
switch (type) {
case 0: localDate = LocalDate.now();break;
case 1: localDate = localDate.plusDays(-1);break;
case 2: localDate = localDate.plusDays(-6);break;
case 3: localDate = localDate.plusDays(-29);break;
}
List<Monitor> monitorList = monitorService.getMonitorList(localDate, endDate);
return ResResult.success().record(monitorList);
}
}
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDate;
/**
* <p>
*
* </p>
*
* @author m33
* @since 2022-06-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Monitor implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 年月日
*/
private LocalDate date;
/**
* 时
*/
private Integer hour;
/**
* 在线数量
*/
private Integer count;
}
......@@ -20,18 +20,17 @@ public class ForwardConnectionListener extends BaseConnectionListener {
@Autowired
private AlarmService alarmService;
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
//TODO 中转失败进行告警
//TODO 失败进行告警
InetSocketAddress socketAddress = (InetSocketAddress)channelFuture.channel().remoteAddress();
String remoteIp = socketAddress.getHostString();
String remotePort = String.valueOf(socketAddress.getPort());
int typeId = 1;
String title = "中转失败";
String content = "中转到服务器:" + remoteIp + ":"+ remotePort +"失败";
String title = "连接服器失败";
String content = "连接服务器:" + remoteIp + ":"+ remotePort +"失败";
alarmService.addAlarm(typeId,title,content);
//TODO forward client连接失败,则强制踢掉设备客户端
......
......@@ -7,14 +7,13 @@ import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@Slf4j
@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
//@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
public class JwtFilter implements Filter {
......
package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Monitor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.time.LocalDate;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author m33
* @since 2022-06-10
*/
public interface MonitorMapper extends BaseMapper<Monitor> {
boolean addMonitor(LocalDate date, int hour, int count);
List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate);
}
package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Monitor;
import java.time.LocalDate;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author m33
* @since 2022-06-10
*/
public interface MonitorService extends IService<Monitor> {
boolean addMonitor(int count);
List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate);
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Monitor;
import iot.sixiang.license.mapper.MonitorMapper;
import iot.sixiang.license.service.MonitorService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author m33
* @since 2022-06-10
*/
@Service
public class MonitorServiceImpl extends ServiceImpl<MonitorMapper, Monitor> implements MonitorService {
@Resource
MonitorMapper monitorMapper;
@Override
public boolean addMonitor(int count) {
LocalDate date = LocalDate.now();
LocalTime localTime = LocalTime.now();
int hour = localTime.getHour();
return monitorMapper.addMonitor(date, hour, count);
}
@Override
public List<Monitor> getMonitorList(LocalDate localDate, LocalDate endDate) {
return monitorMapper.getMonitorList(localDate,endDate);
}
}
......@@ -47,7 +47,7 @@ public class CodeGenerator {
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("alarm_type");
strategy.setInclude("monitor");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀
......
spring:
profiles:
active: test
active: dev
application:
name: iot_license #当前服务的名称
\ No newline at end of file
<?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="iot.sixiang.license.mapper.MonitorMapper">
<insert id="addMonitor" parameterType="iot.sixiang.license.entity.Monitor">
insert into monitor (date, hour, count) values (#{date},#{hour},#{count});
</insert>
<select id="getMonitorList" resultType="iot.sixiang.license.entity.Monitor">
select id, date, hour, count from monitor where date between #{localDate} and #{endDate}
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment