Commit 1443f018 authored by zengtianlai3's avatar zengtianlai3

添加判空

parent 97631822
...@@ -5,10 +5,7 @@ import iot.sixiang.license.model.ResResult; ...@@ -5,10 +5,7 @@ import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.vo.AlarmVo; import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmService; import iot.sixiang.license.service.AlarmService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
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; import java.util.List;
...@@ -27,14 +24,9 @@ public class AlarmController { ...@@ -27,14 +24,9 @@ public class AlarmController {
@Autowired @Autowired
private AlarmService alarmService; private AlarmService alarmService;
@PostMapping("add")
public void addAlarm(){
alarmService.addAlarm(1,"test","ssssssss");
}
@GetMapping("list") @GetMapping("list")
public ResResult getAlarmList() { public ResResult getAlarmList(@RequestParam(value = "userId", defaultValue = "0") int userId) {
List<AlarmVo> alarmList = alarmService.getAlarmList(); List<AlarmVo> alarmList = alarmService.getAlarmList(userId);
return ResResult.success().record(alarmList); return ResResult.success().record(alarmList);
} }
} }
......
...@@ -3,13 +3,12 @@ package iot.sixiang.license.controller; ...@@ -3,13 +3,12 @@ package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.BaseResult; 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 iot.sixiang.license.service.AlarmReadService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* <p> * <p>
...@@ -26,25 +25,15 @@ public class AlarmReadController { ...@@ -26,25 +25,15 @@ public class AlarmReadController {
@Autowired @Autowired
private AlarmReadService alarmReadService; private AlarmReadService alarmReadService;
@PostMapping("add") @PostMapping("read")
public BaseResult addAlarmRead(@RequestBody JSONObject jsonObject){ public BaseResult readAlarm(@RequestBody JSONObject jsonObject){
int alarmId = jsonObject.getInteger("alarmId"); int userId = jsonObject.getIntValue("userId");
int typeId = jsonObject.getInteger("typeId"); boolean res = alarmReadService.readAlarm(userId);
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) { if (res) {
return BaseResult.success(); return BaseResult.success();
} else { } else {
return BaseResult.fail(); return BaseResult.fail();
} }
} }
@GetMapping("list")
public ResResult getAlarmReadList() {
List<AlarmVo> alarmReadList = alarmReadService.getAlarmReadList();
return ResResult.success().record(alarmReadList);
}
} }
...@@ -36,7 +36,7 @@ public class ApplyController { ...@@ -36,7 +36,7 @@ public class ApplyController {
public BaseResult addUser(@RequestBody JSONObject jsonObject) { public BaseResult addUser(@RequestBody JSONObject jsonObject) {
String appName = jsonObject.getString("appName"); String appName = jsonObject.getString("appName");
String appKey = jsonObject.getString("appKey"); String appKey = jsonObject.getString("appKey");
int userId = jsonObject.getInteger("userId"); int userId = jsonObject.getIntValue("userId");
boolean res = applyService.addApply(appName, appKey, userId); boolean res = applyService.addApply(appName, appKey, userId);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
...@@ -52,7 +52,7 @@ public class ApplyController { ...@@ -52,7 +52,7 @@ public class ApplyController {
* @return * @return
*/ */
@GetMapping("list") @GetMapping("list")
public PageResult getUserList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, public PageResult getUserList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName",required = false) String appName) { @RequestParam(value = "appName",required = false) String appName) {
PageInfoModel<AppVo> records = applyService.getAppList(pageNo,pageSize,appName); PageInfoModel<AppVo> records = applyService.getAppList(pageNo,pageSize,appName);
int total = records.getTotal(); int total = records.getTotal();
......
...@@ -34,8 +34,8 @@ public class DeviceController { ...@@ -34,8 +34,8 @@ public class DeviceController {
*/ */
@PostMapping("add") @PostMapping("add")
public BaseResult addDevice(@RequestBody JSONObject jsonObject) { public BaseResult addDevice(@RequestBody JSONObject jsonObject) {
int appId = jsonObject.getInteger("appId"); int appId = jsonObject.getIntValue("appId");
int count = jsonObject.getInteger("count"); int count = jsonObject.getIntValue("count");
boolean res = deviceService.addDevice(appId,count); boolean res = deviceService.addDevice(appId,count);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
...@@ -53,8 +53,8 @@ public class DeviceController { ...@@ -53,8 +53,8 @@ public class DeviceController {
* @return * @return
*/ */
@GetMapping("list") @GetMapping("list")
public PageResult getDeviceList(@RequestParam("pageNo") int pageNo, public PageResult getDeviceList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam("pageSize") int pageSize, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName",required = false) String appName, @RequestParam(value = "appName",required = false) String appName,
@RequestParam(value = "userName",required = false) String userName) { @RequestParam(value = "userName",required = false) String userName) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo,pageSize,appName,userName); PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo,pageSize,appName,userName);
......
...@@ -50,7 +50,7 @@ public class LicenseController { ...@@ -50,7 +50,7 @@ public class LicenseController {
* @return * @return
*/ */
@PostMapping("delete") @PostMapping("delete")
public BaseResult deleteLicense(@RequestParam("appId") String appId) { public BaseResult deleteLicense(@RequestParam(value = "appId", defaultValue = "0") String appId) {
boolean res = licenseService.deleteLicense(appId); boolean res = licenseService.deleteLicense(appId);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
......
...@@ -34,7 +34,7 @@ public class ServerController { ...@@ -34,7 +34,7 @@ public class ServerController {
@PostMapping("add") @PostMapping("add")
public BaseResult addServer(@RequestBody JSONObject jsonObject) { public BaseResult addServer(@RequestBody JSONObject jsonObject) {
String serverIp = jsonObject.getString("serverIp"); String serverIp = jsonObject.getString("serverIp");
int port = jsonObject.getInteger("port"); int port = jsonObject.getIntValue("port");
boolean res = serverService.addServer(serverIp,port); boolean res = serverService.addServer(serverIp,port);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
......
...@@ -86,8 +86,10 @@ public class UserController { ...@@ -86,8 +86,10 @@ public class UserController {
* @return * @return
*/ */
@GetMapping("list") @GetMapping("list")
public PageResult getUserList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize, public PageResult getUserList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "userName",required = false) String userName, @RequestParam(value = "company",required = false) String company) { @RequestParam(value = "pageSize",defaultValue = "0") int pageSize,
@RequestParam(value = "userName",required = false) String userName,
@RequestParam(value = "company",required = false) String company) {
PageInfoModel<UserVo> records = userService.getUserList(pageNo,pageSize,userName,company); PageInfoModel<UserVo> records = userService.getUserList(pageNo,pageSize,userName,company);
int total = records.getTotal(); int total = records.getTotal();
int pages = total/pageSize;//pages为总页数 int pages = total/pageSize;//pages为总页数
......
...@@ -11,9 +11,5 @@ public interface AlarmMapper extends BaseMapper<Alarm> { ...@@ -11,9 +11,5 @@ public interface AlarmMapper extends BaseMapper<Alarm> {
boolean addAlarm(int typeId, String title, String content); boolean addAlarm(int typeId, String title, String content);
List<AlarmVo> getAlarmList(); List<AlarmVo> getAlarmList(int userId);
// List<Alarm> getAlarmList(String id);
//
// Apply getApplyByAppName(String id);
} }
package iot.sixiang.license.mapper; package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.AlarmRead;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.model.vo.AlarmVo; import iot.sixiang.license.entity.AlarmRead;
import java.util.List;
/** /**
* <p> * <p>
...@@ -16,7 +13,5 @@ import java.util.List; ...@@ -16,7 +13,5 @@ import java.util.List;
*/ */
public interface AlarmReadMapper extends BaseMapper<AlarmRead> { public interface AlarmReadMapper extends BaseMapper<AlarmRead> {
boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId); boolean readAlarm(int alarmId,int typeId, String title, String content,int userId);
List<AlarmVo> getAlarmReadList();
} }
package iot.sixiang.license.model.msg;
import iot.sixiang.license.model.SamInfo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* Created by m33 on 2022/6/9 20:36
*/
@Data
public class SamInfoMsg {
List<SamInfo> list = new ArrayList<>();
}
...@@ -13,4 +13,7 @@ public class AlarmVo extends Alarm { ...@@ -13,4 +13,7 @@ public class AlarmVo extends Alarm {
private int level; private int level;
private String levelDescribe; private String levelDescribe;
private int readFlag;
} }
...@@ -9,6 +9,7 @@ import lombok.Data; ...@@ -9,6 +9,7 @@ import lombok.Data;
@Data @Data
public class AppVo extends Apply { public class AppVo extends Apply {
public int deviceCount; public int deviceCount;
public String userName; public String userName;
......
package iot.sixiang.license.service; package iot.sixiang.license.service;
import iot.sixiang.license.entity.AlarmRead;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.model.vo.AlarmVo; import iot.sixiang.license.entity.AlarmRead;
import java.util.List;
/** /**
* <p> * <p>
...@@ -16,7 +13,5 @@ import java.util.List; ...@@ -16,7 +13,5 @@ import java.util.List;
*/ */
public interface AlarmReadService extends IService<AlarmRead> { public interface AlarmReadService extends IService<AlarmRead> {
boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId); boolean readAlarm(int userId);
List<AlarmVo> getAlarmReadList();
} }
...@@ -10,7 +10,6 @@ public interface AlarmService extends IService<Alarm> { ...@@ -10,7 +10,6 @@ public interface AlarmService extends IService<Alarm> {
boolean addAlarm(int typeId, String title, String content); boolean addAlarm(int typeId, String title, String content);
List<AlarmVo> getAlarmList(); List<AlarmVo> getAlarmList(int userId);
// PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName);
} }
...@@ -2,6 +2,8 @@ package iot.sixiang.license.service.impl; ...@@ -2,6 +2,8 @@ package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.AlarmRead; import iot.sixiang.license.entity.AlarmRead;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.AlarmMapper;
import iot.sixiang.license.mapper.AlarmReadMapper; import iot.sixiang.license.mapper.AlarmReadMapper;
import iot.sixiang.license.model.vo.AlarmVo; import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmReadService; import iot.sixiang.license.service.AlarmReadService;
...@@ -21,16 +23,29 @@ import java.util.List; ...@@ -21,16 +23,29 @@ import java.util.List;
@Service @Service
public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead> implements AlarmReadService { public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead> implements AlarmReadService {
@Resource
AlarmMapper alarmMapper;
@Resource @Resource
AlarmReadMapper alarmReadMapper; AlarmReadMapper alarmReadMapper;
@Override @Override
public boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId) { public boolean readAlarm(int userId) {
return alarmReadMapper.addAlarmRead(alarmId,typeId,title,content,userId); if (userId == 0) {
} throw new IotLicenseException(400, "用户Id不能为空");
}
@Override List<AlarmVo> alarmList = alarmMapper.getAlarmList(userId);
public List<AlarmVo> getAlarmReadList() { for (AlarmVo alarm: alarmList) {
return alarmReadMapper.getAlarmReadList(); if (alarm.getReadFlag() == 0) {
int alarmId = alarm.getId();
int typeId = alarm.getTypeId();
String title = alarm.getTitle();
String content = alarm.getContent();
boolean res = alarmReadMapper.readAlarm(alarmId, typeId, title, content, userId);
if (!res) {
return false;
}
}
}
return true;
} }
} }
...@@ -2,6 +2,7 @@ package iot.sixiang.license.service.impl; ...@@ -2,6 +2,7 @@ package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Alarm; import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.AlarmMapper; import iot.sixiang.license.mapper.AlarmMapper;
import iot.sixiang.license.model.vo.AlarmVo; import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmService; import iot.sixiang.license.service.AlarmService;
...@@ -21,7 +22,10 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements ...@@ -21,7 +22,10 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements
} }
@Override @Override
public List<AlarmVo> getAlarmList() { public List<AlarmVo> getAlarmList(int userId) {
return alarmMapper.getAlarmList(); if (userId == 0) {
throw new IotLicenseException(400, "用户Id不能为空");
}
return alarmMapper.getAlarmList(userId);
} }
} }
...@@ -7,6 +7,7 @@ import iot.sixiang.license.mapper.ApplyMapper; ...@@ -7,6 +7,7 @@ import iot.sixiang.license.mapper.ApplyMapper;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo; import iot.sixiang.license.model.vo.AppVo;
import iot.sixiang.license.service.ApplyService; import iot.sixiang.license.service.ApplyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -31,6 +32,15 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements ...@@ -31,6 +32,15 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
@Override @Override
public boolean addApply(String appName, String appKey, int userId) { public boolean addApply(String appName, String appKey, int userId) {
if(StringUtils.isEmpty(appName)) {
throw new IotLicenseException(400,"应用名不能为空");
}
if(StringUtils.isEmpty(appKey)) {
throw new IotLicenseException(400,"应用key不能为空");
}
if(userId == 0) {
throw new IotLicenseException(400,"用户名不能为空");
}
Apply res = applyMapper.getApplyByAppName(appName); Apply res = applyMapper.getApplyByAppName(appName);
if (res != null) { if (res != null) {
throw new IotLicenseException(400,"应用名已存在"); throw new IotLicenseException(400,"应用名已存在");
...@@ -40,6 +50,15 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements ...@@ -40,6 +50,15 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
@Override @Override
public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName) { public PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName) {
if(pageNo == 0) {
throw new IotLicenseException(400,"pageNo不能为空");
}
if(pageSize == 0) {
throw new IotLicenseException(400, "pageSize不能为空");
}
if (StringUtils.isEmpty(appName)) {
throw new IotLicenseException(400, "应用名不能为空");
}
List<AppVo> records = applyMapper.getAppList(appName); List<AppVo> records = applyMapper.getAppList(appName);
records = records.stream().sorted(Comparator.comparing(AppVo::getAppId)).collect(Collectors.toList()); records = records.stream().sorted(Comparator.comparing(AppVo::getAppId)).collect(Collectors.toList());
List<AppVo> result = new ArrayList<>(); List<AppVo> result = new ArrayList<>();
......
...@@ -2,6 +2,7 @@ package iot.sixiang.license.service.impl; ...@@ -2,6 +2,7 @@ package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Device; import iot.sixiang.license.entity.Device;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.DeviceMapper; import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceVo; import iot.sixiang.license.model.vo.DeviceVo;
...@@ -31,6 +32,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -31,6 +32,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override @Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) { public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) {
if(pageNo == 0) {
throw new IotLicenseException(400,"pageNo不能为空");
}
if(pageSize == 0) {
throw new IotLicenseException(400, "pageSize不能为空");
}
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName,userName); List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName,userName);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getDeviceId)).collect(Collectors.toList()); deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getDeviceId)).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>(); List<DeviceVo> result = new ArrayList<>();
...@@ -46,6 +53,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -46,6 +53,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override @Override
public boolean addDevice(int appId, int count) { public boolean addDevice(int appId, int count) {
if (appId == 0) {
throw new IotLicenseException(400, "应用Id不能为空");
}
if (count == 0) {
throw new IotLicenseException(400, "count不能为零或空");
}
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String sn = CommonUtil.genRandomNum(18); String sn = CommonUtil.genRandomNum(18);
boolean res = deviceMapper.addDevice(sn,appId); boolean res = deviceMapper.addDevice(sn,appId);
......
...@@ -9,6 +9,7 @@ import iot.sixiang.license.model.PageInfoModel; ...@@ -9,6 +9,7 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.UserVo; import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService; import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.JsonUtil; import iot.sixiang.license.util.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -33,6 +34,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -33,6 +34,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override @Override
public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize,String userName, String company) { public PageInfoModel<UserVo> getUserList(int pageNo, int pageSize,String userName, String company) {
if(pageNo == 0) {
throw new IotLicenseException(400,"pageNo不能为空");
}
if(pageSize == 0) {
throw new IotLicenseException(400, "pageSize不能为空");
}
List<UserVo> records = userMapper.getUserList(userName,company); List<UserVo> records = userMapper.getUserList(userName,company);
records = records.stream().sorted(Comparator.comparing(UserVo::getUserId)).collect(Collectors.toList()); records = records.stream().sorted(Comparator.comparing(UserVo::getUserId)).collect(Collectors.toList());
List<UserVo> result = new ArrayList<>(); List<UserVo> result = new ArrayList<>();
...@@ -56,8 +63,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us ...@@ -56,8 +63,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override @Override
public boolean addUser(String userName, String company, String password) { public boolean addUser(String userName, String company, String password) {
if (JsonUtil.isNull(userName) || JsonUtil.isNull(company)) { if(StringUtils.isEmpty(userName)) {
return false; throw new IotLicenseException(400,"用户名不能为空");
}
if(StringUtils.isEmpty(company)) {
throw new IotLicenseException(400,"公司名不能为空");
} }
User res = userMapper.getUserByUserName(userName); User res = userMapper.getUserByUserName(userName);
if (res != null) { if (res != null) {
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
</insert> </insert>
<select id="getAlarmList" resultType="iot.sixiang.license.model.vo.AlarmVo"> <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 al.id,al.type_id,al.title,al.content,al.create_time,alt.level,
alt.level_describe,al.id IN(SELECT alarm_id FROM alarm_read WHERE user_id = #{userId}) read_flag
FROM alarm AS al JOIN alarm_type AS alt ON al.type_id = alt.id
</select> </select>
</mapper> </mapper>
...@@ -2,12 +2,7 @@ ...@@ -2,12 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.AlarmReadMapper"> <mapper namespace="iot.sixiang.license.mapper.AlarmReadMapper">
<insert id="addAlarmRead" parameterType="iot.sixiang.license.entity.AlarmRead"> <insert id="readAlarm" parameterType="iot.sixiang.license.entity.AlarmRead">
insert into alarm_read (alarm_id, type_id, title, content, create_time, user_id) values (#{alarmId},#{typeId},#{title},#{content},now(),#{userId}); insert into alarm_read (alarm_id, type_id, title, content, create_time, user_id) values (#{alarmId},#{typeId},#{title},#{content},now(),#{userId});
</insert> </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> </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