Commit 512f3299 authored by zengtianlai3's avatar zengtianlai3

Merge branch 'm33' into 'master'

添加判空

See merge request !16
parents 97631822 1443f018
......@@ -5,10 +5,7 @@ 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 org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -27,14 +24,9 @@ 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();
public ResResult getAlarmList(@RequestParam(value = "userId", defaultValue = "0") int userId) {
List<AlarmVo> alarmList = alarmService.getAlarmList(userId);
return ResResult.success().record(alarmList);
}
}
......
......@@ -3,13 +3,12 @@ package iot.sixiang.license.controller;
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 java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
......@@ -26,25 +25,15 @@ 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);
@PostMapping("read")
public BaseResult readAlarm(@RequestBody JSONObject jsonObject){
int userId = jsonObject.getIntValue("userId");
boolean res = alarmReadService.readAlarm(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);
}
}
......@@ -36,7 +36,7 @@ public class ApplyController {
public BaseResult addUser(@RequestBody JSONObject jsonObject) {
String appName = jsonObject.getString("appName");
String appKey = jsonObject.getString("appKey");
int userId = jsonObject.getInteger("userId");
int userId = jsonObject.getIntValue("userId");
boolean res = applyService.addApply(appName, appKey, userId);
if (res) {
return BaseResult.success();
......@@ -52,7 +52,7 @@ public class ApplyController {
* @return
*/
@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) {
PageInfoModel<AppVo> records = applyService.getAppList(pageNo,pageSize,appName);
int total = records.getTotal();
......
......@@ -34,8 +34,8 @@ public class DeviceController {
*/
@PostMapping("add")
public BaseResult addDevice(@RequestBody JSONObject jsonObject) {
int appId = jsonObject.getInteger("appId");
int count = jsonObject.getInteger("count");
int appId = jsonObject.getIntValue("appId");
int count = jsonObject.getIntValue("count");
boolean res = deviceService.addDevice(appId,count);
if (res) {
return BaseResult.success();
......@@ -53,8 +53,8 @@ public class DeviceController {
* @return
*/
@GetMapping("list")
public PageResult getDeviceList(@RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize,
public PageResult getDeviceList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName",required = false) String appName,
@RequestParam(value = "userName",required = false) String userName) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo,pageSize,appName,userName);
......
......@@ -50,7 +50,7 @@ public class LicenseController {
* @return
*/
@PostMapping("delete")
public BaseResult deleteLicense(@RequestParam("appId") String appId) {
public BaseResult deleteLicense(@RequestParam(value = "appId", defaultValue = "0") String appId) {
boolean res = licenseService.deleteLicense(appId);
if (res) {
return BaseResult.success();
......
......@@ -34,7 +34,7 @@ public class ServerController {
@PostMapping("add")
public BaseResult addServer(@RequestBody JSONObject jsonObject) {
String serverIp = jsonObject.getString("serverIp");
int port = jsonObject.getInteger("port");
int port = jsonObject.getIntValue("port");
boolean res = serverService.addServer(serverIp,port);
if (res) {
return BaseResult.success();
......
......@@ -86,8 +86,10 @@ public class UserController {
* @return
*/
@GetMapping("list")
public PageResult getUserList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize,
@RequestParam(value = "userName",required = false) String userName, @RequestParam(value = "company",required = false) String company) {
public PageResult getUserList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@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);
int total = records.getTotal();
int pages = total/pageSize;//pages为总页数
......
......@@ -11,9 +11,5 @@ 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);
List<AlarmVo> getAlarmList(int userId);
}
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;
import iot.sixiang.license.entity.AlarmRead;
/**
* <p>
......@@ -16,7 +13,5 @@ import java.util.List;
*/
public interface AlarmReadMapper extends BaseMapper<AlarmRead> {
boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId);
List<AlarmVo> getAlarmReadList();
boolean readAlarm(int alarmId,int typeId, String title, String content,int userId);
}
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 {
private int level;
private String levelDescribe;
private int readFlag;
}
......@@ -9,6 +9,7 @@ import lombok.Data;
@Data
public class AppVo extends Apply {
public int deviceCount;
public String userName;
......
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;
import iot.sixiang.license.entity.AlarmRead;
/**
* <p>
......@@ -16,7 +13,5 @@ import java.util.List;
*/
public interface AlarmReadService extends IService<AlarmRead> {
boolean addAlarmRead(int alarmId, int typeId, String title, String content, int userId);
List<AlarmVo> getAlarmReadList();
boolean readAlarm(int userId);
}
......@@ -10,7 +10,6 @@ public interface AlarmService extends IService<Alarm> {
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;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmReadService;
......@@ -21,16 +23,29 @@ import java.util.List;
@Service
public class AlarmReadServiceImpl extends ServiceImpl<AlarmReadMapper, AlarmRead> implements AlarmReadService {
@Resource
AlarmMapper alarmMapper;
@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();
public boolean readAlarm(int userId) {
if (userId == 0) {
throw new IotLicenseException(400, "用户Id不能为空");
}
List<AlarmVo> alarmList = alarmMapper.getAlarmList(userId);
for (AlarmVo alarm: alarmList) {
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;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.AlarmMapper;
import iot.sixiang.license.model.vo.AlarmVo;
import iot.sixiang.license.service.AlarmService;
......@@ -21,7 +22,10 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements
}
@Override
public List<AlarmVo> getAlarmList() {
return alarmMapper.getAlarmList();
public List<AlarmVo> getAlarmList(int userId) {
if (userId == 0) {
throw new IotLicenseException(400, "用户Id不能为空");
}
return alarmMapper.getAlarmList(userId);
}
}
......@@ -7,6 +7,7 @@ import iot.sixiang.license.mapper.ApplyMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo;
import iot.sixiang.license.service.ApplyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -31,6 +32,15 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
@Override
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);
if (res != null) {
throw new IotLicenseException(400,"应用名已存在");
......@@ -40,6 +50,15 @@ public class ApplyServiceImpl extends ServiceImpl<ApplyMapper, Apply> implements
@Override
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);
records = records.stream().sorted(Comparator.comparing(AppVo::getAppId)).collect(Collectors.toList());
List<AppVo> result = new ArrayList<>();
......
......@@ -2,6 +2,7 @@ package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceVo;
......@@ -31,6 +32,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override
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);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getDeviceId)).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>();
......@@ -46,6 +53,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override
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++) {
String sn = CommonUtil.genRandomNum(18);
boolean res = deviceMapper.addDevice(sn,appId);
......
......@@ -9,6 +9,7 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.UserVo;
import iot.sixiang.license.service.UserService;
import iot.sixiang.license.util.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -33,6 +34,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
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);
records = records.stream().sorted(Comparator.comparing(UserVo::getUserId)).collect(Collectors.toList());
List<UserVo> result = new ArrayList<>();
......@@ -56,8 +63,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
public boolean addUser(String userName, String company, String password) {
if (JsonUtil.isNull(userName) || JsonUtil.isNull(company)) {
return false;
if(StringUtils.isEmpty(userName)) {
throw new IotLicenseException(400,"用户名不能为空");
}
if(StringUtils.isEmpty(company)) {
throw new IotLicenseException(400,"公司名不能为空");
}
User res = userMapper.getUserByUserName(userName);
if (res != null) {
......
......@@ -7,7 +7,8 @@
</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 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>
</mapper>
......@@ -2,12 +2,7 @@
<!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">
<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>
<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