From 3cd1434341d2dd68ac72c02bf028ed8e1dfe0d71 Mon Sep 17 00:00:00 2001 From: 648540858 <18010473990@163.com> Date: Thu, 5 Aug 2021 07:25:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=20=E4=BF=AE=E6=AD=A3=E6=8A=A5=E8=AD=A6=E6=B8=85?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql.sql | 5 +- .../iot/vmp/service/IDeviceAlarmService.java | 2 +- .../iot/vmp/service/IUserService.java | 10 +++ .../service/impl/DeviceAlarmServiceImpl.java | 4 +- .../iot/vmp/service/impl/UserServiceImpl.java | 23 +++++++ .../iot/vmp/storager/dao/UserMapper.java | 26 +++++--- .../iot/vmp/storager/dao/dto/User.java | 9 +++ .../gb28181/alarm/AlarmController.java | 20 +++--- .../vmp/service/impl/UserServiceImplTest.java | 61 +++++++++++++++++++ 9 files changed, 139 insertions(+), 21 deletions(-) create mode 100644 src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java diff --git a/sql/mysql.sql b/sql/mysql.sql index d5a84c37..e654e984 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -215,8 +215,9 @@ create table user username varchar(255) not null, password varchar(255) not null, roleId int not null, - create_time varchar(50) not null + create_time varchar(50) not null, + update_time varchar(50) not null ); -insert into user (username, password, roleId, create_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57'); +insert into user (username, password, roleId, create_time, update_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); diff --git a/src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java b/src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java index 5e3f681d..51e53d26 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java @@ -38,6 +38,6 @@ public interface IDeviceAlarmService { * @param deviceIdList 制定需要清理的设备id * @param time 不写时间则清空所有时间的 */ - void clearAlarmBeforeTime(Integer id, List deviceIdList, String time); + int clearAlarmBeforeTime(Integer id, List deviceIdList, String time); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java index cb6b6b7a..112af354 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java @@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.service; import com.genersoft.iot.vmp.storager.dao.dto.User; +import java.util.List; + public interface IUserService { User getUser(String username, String password); @@ -9,4 +11,12 @@ public interface IUserService { boolean changePassword(int id, String password); User getUserByUsername(String username); + + void addUser(User user); + + void deleteUser(int id); + + List getAllUsers(); + + void updateUsers(User user); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java index 0567b557..ead291c0 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java @@ -31,7 +31,7 @@ public class DeviceAlarmServiceImpl implements IDeviceAlarmService { } @Override - public void clearAlarmBeforeTime(Integer id, List deviceIdList, String time) { - deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); + public int clearAlarmBeforeTime(Integer id, List deviceIdList, String time) { + return deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java index 2539f5b5..e10fc795 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java @@ -6,6 +6,8 @@ import com.genersoft.iot.vmp.storager.dao.dto.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class UserServiceImpl implements IUserService { @@ -29,4 +31,25 @@ public class UserServiceImpl implements IUserService { public User getUserByUsername(String username) { return userMapper.getUserByUsername(username); } + + @Override + public void addUser(User user) { + userMapper.add(user); + } + @Override + public void deleteUser(int id) { + userMapper.delete(id); + } + + @Override + public List getAllUsers() { + return userMapper.selectAll(); + } + + @Override + public void updateUsers(User user) { + userMapper.update(user); + } + + } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java index 6ecc8280..e2176322 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java @@ -4,23 +4,28 @@ import com.genersoft.iot.vmp.storager.dao.dto.User; import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; +import java.util.List; + @Mapper @Repository public interface UserMapper { - @Insert("INSERT INTO user (username, password, roleId, create_time) VALUES" + - "('${username}', '${password}', '${roleId}', datetime('now','localtime'))") + @Insert("INSERT INTO user (username, password, roleId, create_time, update_time) VALUES" + + "('${username}', '${password}', '${roleId}', '${createTime}', '${updateTime}')") int add(User user); - @Update("UPDATE user " + - "SET username=#{username}, " + - "password=#{password}, " + - "roleId=#{roleId} " + - "WHERE id=#{id}") + @Update(value = {" "}) int update(User user); - @Delete("DELETE FROM user WHERE app=#{app} AND id=#{id}") - int delete(User user); + @Delete("DELETE FROM user WHERE id=#{id}") + int delete(int id); @Select("select * FROM user WHERE username=#{username} AND password=#{password}") User select(String username, String password); @@ -30,4 +35,7 @@ public interface UserMapper { @Select("select * FROM user WHERE username=#{username}") User getUserByUsername(String username); + + @Select("select * FROM user") + List selectAll(); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java index 697df043..b4a0289f 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java @@ -6,6 +6,7 @@ public class User { private String username; private String password; private String createTime; + private String updateTime; private int roleId; public int getId() { @@ -47,4 +48,12 @@ public class User { public void setRoleId(int roleId) { this.roleId = roleId; } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java index b1b62b14..434bbd49 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java @@ -60,7 +60,8 @@ public class AlarmController { @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class), }) public ResponseEntity> getAll( - int page, int count, + @RequestParam int page, + @RequestParam int count, @RequestParam(required = false) String deviceId, @RequestParam(required = false) String alarmPriority, @RequestParam(required = false) String alarmMethod, @@ -76,8 +77,8 @@ public class AlarmController { try { - format.parse(startTime); - format.parse(endTime); + if (startTime != null) format.parse(startTime); + if (endTime != null) format.parse(endTime); } catch (ParseException e) { return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } @@ -96,7 +97,7 @@ public class AlarmController { * @param time 结束时间(这个时间之前的报警会被删除) * @return */ - @ApiOperation("分页查询报警") + @ApiOperation("删除报警") @DeleteMapping("/delete") @ApiImplicitParams({ @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class), @@ -118,12 +119,17 @@ public class AlarmController { } catch (ParseException e) { return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } - String[] deviceIdArray = deviceIds.split(","); - List deviceIdList = Arrays.asList(deviceIdArray); - deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); + List deviceIdList = null; + if (deviceIds != null) { + String[] deviceIdArray = deviceIds.split(","); + deviceIdList = Arrays.asList(deviceIdArray); + } + + int count = deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); WVPResult wvpResult = new WVPResult(); wvpResult.setCode(0); wvpResult.setMsg("success"); + wvpResult.setData(count); return new ResponseEntity>(wvpResult, HttpStatus.OK); } diff --git a/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java b/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java new file mode 100644 index 00000000..eea7f041 --- /dev/null +++ b/src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java @@ -0,0 +1,61 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; +import com.genersoft.iot.vmp.service.IDeviceAlarmService; +import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.dto.User; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.Date; + + +@SpringBootTest +@RunWith(SpringRunner.class) +class UserServiceImplTest { + + @Resource + private IUserService userService; + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @org.junit.jupiter.api.Test + void getAllUser() { + System.out.println(userService.getAllUsers().size()); + } + + + @org.junit.jupiter.api.Test + void add() { + for (int i = 0; i < 10; i++) { + User user = new User(); + user.setUsername("admin_" + i); + user.setPassword("admin_password_" + i); + user.setRoleId((int)(Math.random()*4 + 1)); + user.setCreateTime(format.format(System.currentTimeMillis())); + user.setUpdateTime(format.format(System.currentTimeMillis())); + userService.addUser(user); + } + } + + @org.junit.jupiter.api.Test + void delete() { + userService.deleteUser(1002); + } + + @org.junit.jupiter.api.Test + void update() { + User user = new User(); + user.setId(1003); + user.setUsername("update" ); + user.setPassword("update"); + user.setRoleId((int)(Math.random()*4 + 1)); + user.setUpdateTime(format.format(System.currentTimeMillis())); + userService.updateUsers(user); + } + + +} \ No newline at end of file