Commit 03b53d9c authored by zengtianlai3's avatar zengtianlai3

完成alarm等接口

parent 9bbdf799
package iot.sixiang.license.controller;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
......@@ -14,8 +21,21 @@ import org.springframework.web.bind.annotation.RestController;
* @since 2022-06-10
*/
@RestController
@RequestMapping("/license/alarm")
@RequestMapping("/iot_license/alarm")
public class AlarmController {
@Autowired
private AlarmService alarmService;
@PostMapping("add")
public void addAlarm(){
alarmService.addAlarm(1,"test","ssssssss");
}
@GetMapping("list")
public ResResult getAlarmList() {
List<AlarmVo> alarmList = alarmService.getAlarmList();
return ResResult.success().record(alarmList);
}
}
package iot.sixiang.license.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
......@@ -14,8 +20,31 @@ import org.springframework.web.bind.annotation.RestController;
* @since 2022-06-10
*/
@RestController
@RequestMapping("/license/alarm_read")
@RequestMapping("/iot_license/alarm_read")
public class AlarmReadController {
@Autowired
private AlarmReadService alarmReadService;
@PostMapping("add")
public BaseResult addAlarmRead(@RequestBody JSONObject jsonObject){
int alarmId = jsonObject.getInteger("alarmId");
int typeId = jsonObject.getInteger("typeId");
String title = jsonObject.getString("title");
String content = jsonObject.getString("content");
int userId = jsonObject.getInteger("userId");
boolean res = alarmReadService.addAlarmRead(alarmId,typeId,title,content,userId);
if (res) {
return BaseResult.success();
} else {
return BaseResult.fail();
}
}
@GetMapping("list")
public ResResult getAlarmReadList() {
List<AlarmVo> alarmReadList = alarmReadService.getAlarmReadList();
return ResResult.success().record(alarmReadList);
}
}
......@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
* @since 2022-06-10
*/
@RestController
@RequestMapping("/license/alarm_type")
@RequestMapping("/iot_license/alarm_type")
public class AlarmTypeController {
}
......
......@@ -7,7 +7,6 @@ import iot.sixiang.license.service.AlarmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -43,9 +42,4 @@ public class OperateController {
return ResResult.success().record(records);
}
@PostMapping("alarm/add")
public void addlog(){
alarmService.addAlarm(1,"test","ssssssss");
}
}
......@@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
......@@ -14,5 +17,9 @@ public class Alarm {
@TableId(type = IdType.AUTO)
private Integer id;
private int typeId;
private String title;
private String content;
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
}
package iot.sixiang.license.entity;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
......@@ -22,14 +26,20 @@ public class AlarmRead implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 告警唯一id
* 告警已读唯一id
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 告警id
*/
private int alarmId;
/**
* 告警类型id
*/
private Integer typeId;
private int typeId;
/**
* 告警标题
......@@ -44,7 +54,8 @@ public class AlarmRead implements Serializable {
/**
* 创建时间
*/
private LocalDateTime createTime;
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 阅读用户id
......
......@@ -2,11 +2,12 @@ package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
......@@ -36,7 +37,7 @@ public class AlarmType implements Serializable {
/**
* 等级描述
*/
private String levleDescribe;
private String levelDescribe;
}
......@@ -2,12 +2,17 @@ package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.model.vo.AlarmVo;
import java.util.List;
public interface AlarmMapper extends BaseMapper<Alarm> {
boolean addAlarm(int typeId, String title, String content);
List<AlarmVo> getAlarmList();
// List<Alarm> getAlarmList(String id);
//
// Apply getApplyByAppName(String id);
......
......@@ -2,6 +2,9 @@ package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.AlarmRead;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.model.vo.AlarmVo;
import java.util.List;
/**
* <p>
......@@ -13,4 +16,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface AlarmReadMapper extends BaseMapper<AlarmRead> {
boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId);
List<AlarmVo> getAlarmReadList();
}
package iot.sixiang.license.model.vo;
import iot.sixiang.license.entity.Alarm;
import lombok.Data;
/**
* Created by m33 on 2022/6/10 11:58
*/
@Data
public class AlarmVo extends Alarm {
private int level;
private String levelDescribe;
}
......@@ -2,6 +2,9 @@ package iot.sixiang.license.service;
import iot.sixiang.license.entity.AlarmRead;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.model.vo.AlarmVo;
import java.util.List;
/**
* <p>
......@@ -13,4 +16,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface AlarmReadService extends IService<AlarmRead> {
boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId);
List<AlarmVo> getAlarmReadList();
}
......@@ -2,10 +2,15 @@ package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.model.vo.AlarmVo;
import java.util.List;
public interface AlarmService extends IService<Alarm> {
boolean addAlarm(int typeId, String title, String content);
List<AlarmVo> getAlarmList();
// PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName);
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.AlarmRead;
import iot.sixiang.license.mapper.AlarmReadMapper;
import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmReadService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* 服务实现类
......@@ -17,4 +21,16 @@ import org.springframework.stereotype.Service;
@Service
public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead> implements AlarmReadService {
@Resource
AlarmReadMapper alarmReadMapper;
@Override
public boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId) {
return alarmReadMapper.addAlarmRead(alarmId,typeId,title,content,userId);
}
@Override
public List<AlarmVo> getAlarmReadList() {
return alarmReadMapper.getAlarmReadList();
}
}
......@@ -2,15 +2,13 @@ package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.entity.Apply;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.AlarmMapper;
import iot.sixiang.license.mapper.ApplyMapper;
import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.service.ApplyService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements AlarmService {
......@@ -21,4 +19,9 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements
public boolean addAlarm(int typeId, String title, String content) {
return alarmMapper.addAlarm(typeId, title, content);
}
@Override
public List<AlarmVo> getAlarmList() {
return alarmMapper.getAlarmList();
}
}
......@@ -6,5 +6,8 @@
insert into alarm (type_id, title, content, create_time) values (#{typeId},#{title},#{content},now());
</insert>
<select id="getAlarmList" resultType="iot.sixiang.license.model.vo.AlarmVo">
SELECT al.id,al.type_id,al.title,content,DATE_FORMAT(al.create_time,'%Y-%m-%d %H:%I:%S') create_time,alt.level,level_describe FROM alarm AS al JOIN alarm_type AS alt ON al.type_id = alt.id
</select>
</mapper>
......@@ -3,7 +3,11 @@
<mapper namespace="iot.sixiang.license.mapper.AlarmReadMapper">
<insert id="addAlarmRead" parameterType="iot.sixiang.license.entity.AlarmRead">
insert into alarm (type_id, title, content, create_time) values (#{typeId},#{title},#{content},now());
insert into alarm_read (alarm_id, type_id, title, content, create_time, user_id) values (#{alarmId},#{typeId},#{title},#{content},now(),#{userId});
</insert>
<select id="getAlarmReadList" resultType="iot.sixiang.license.entity.AlarmRead">
SELECT id,alarm_id,type_id,title,content,DATE_FORMAT(create_time,'%Y-%m-%d %H:%I:%S') create_time,us.user_id,user_name FROM alarm_read AS al JOIN user AS us ON us.user_id = al.user_id
</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