Commit 3cd1434341d2dd68ac72c02bf028ed8e1dfe0d71

Authored by 648540858
1 parent bef419a6

添加用户操作

修正报警清理接口
sql/mysql.sql
... ... @@ -215,8 +215,9 @@ create table user
215 215 username varchar(255) not null,
216 216 password varchar(255) not null,
217 217 roleId int not null,
218   - create_time varchar(50) not null
  218 + create_time varchar(50) not null,
  219 + update_time varchar(50) not null
219 220 );
220 221  
221   -insert into user (username, password, roleId, create_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57');
  222 +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');
222 223  
... ...
src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java
... ... @@ -38,6 +38,6 @@ public interface IDeviceAlarmService {
38 38 * @param deviceIdList 制定需要清理的设备id
39 39 * @param time 不写时间则清空所有时间的
40 40 */
41   - void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time);
  41 + int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time);
42 42  
43 43 }
... ...
src/main/java/com/genersoft/iot/vmp/service/IUserService.java
... ... @@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.service;
2 2  
3 3 import com.genersoft.iot.vmp.storager.dao.dto.User;
4 4  
  5 +import java.util.List;
  6 +
5 7 public interface IUserService {
6 8  
7 9 User getUser(String username, String password);
... ... @@ -9,4 +11,12 @@ public interface IUserService {
9 11 boolean changePassword(int id, String password);
10 12  
11 13 User getUserByUsername(String username);
  14 +
  15 + void addUser(User user);
  16 +
  17 + void deleteUser(int id);
  18 +
  19 + List<User> getAllUsers();
  20 +
  21 + void updateUsers(User user);
12 22 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java
... ... @@ -31,7 +31,7 @@ public class DeviceAlarmServiceImpl implements IDeviceAlarmService {
31 31 }
32 32  
33 33 @Override
34   - public void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) {
35   - deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time);
  34 + public int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) {
  35 + return deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time);
36 36 }
37 37 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
... ... @@ -6,6 +6,8 @@ import com.genersoft.iot.vmp.storager.dao.dto.User;
6 6 import org.springframework.beans.factory.annotation.Autowired;
7 7 import org.springframework.stereotype.Service;
8 8  
  9 +import java.util.List;
  10 +
9 11 @Service
10 12 public class UserServiceImpl implements IUserService {
11 13  
... ... @@ -29,4 +31,25 @@ public class UserServiceImpl implements IUserService {
29 31 public User getUserByUsername(String username) {
30 32 return userMapper.getUserByUsername(username);
31 33 }
  34 +
  35 + @Override
  36 + public void addUser(User user) {
  37 + userMapper.add(user);
  38 + }
  39 + @Override
  40 + public void deleteUser(int id) {
  41 + userMapper.delete(id);
  42 + }
  43 +
  44 + @Override
  45 + public List<User> getAllUsers() {
  46 + return userMapper.selectAll();
  47 + }
  48 +
  49 + @Override
  50 + public void updateUsers(User user) {
  51 + userMapper.update(user);
  52 + }
  53 +
  54 +
32 55 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
... ... @@ -4,23 +4,28 @@ import com.genersoft.iot.vmp.storager.dao.dto.User;
4 4 import org.apache.ibatis.annotations.*;
5 5 import org.springframework.stereotype.Repository;
6 6  
  7 +import java.util.List;
  8 +
7 9 @Mapper
8 10 @Repository
9 11 public interface UserMapper {
10 12  
11   - @Insert("INSERT INTO user (username, password, roleId, create_time) VALUES" +
12   - "('${username}', '${password}', '${roleId}', datetime('now','localtime'))")
  13 + @Insert("INSERT INTO user (username, password, roleId, create_time, update_time) VALUES" +
  14 + "('${username}', '${password}', '${roleId}', '${createTime}', '${updateTime}')")
13 15 int add(User user);
14 16  
15   - @Update("UPDATE user " +
16   - "SET username=#{username}, " +
17   - "password=#{password}, " +
18   - "roleId=#{roleId} " +
19   - "WHERE id=#{id}")
  17 + @Update(value = {" <script>" +
  18 + "UPDATE user " +
  19 + "SET update_time='${updateTime}' " +
  20 + "<if test=\"roleId != null\">, roleId='${roleId}'</if>" +
  21 + "<if test=\"password != null\">, password='${password}'</if>" +
  22 + "<if test=\"username != null\">, username='${username}'</if>" +
  23 + "WHERE id=#{id}" +
  24 + " </script>"})
20 25 int update(User user);
21 26  
22   - @Delete("DELETE FROM user WHERE app=#{app} AND id=#{id}")
23   - int delete(User user);
  27 + @Delete("DELETE FROM user WHERE id=#{id}")
  28 + int delete(int id);
24 29  
25 30 @Select("select * FROM user WHERE username=#{username} AND password=#{password}")
26 31 User select(String username, String password);
... ... @@ -30,4 +35,7 @@ public interface UserMapper {
30 35  
31 36 @Select("select * FROM user WHERE username=#{username}")
32 37 User getUserByUsername(String username);
  38 +
  39 + @Select("select * FROM user")
  40 + List<User> selectAll();
33 41 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java
... ... @@ -6,6 +6,7 @@ public class User {
6 6 private String username;
7 7 private String password;
8 8 private String createTime;
  9 + private String updateTime;
9 10 private int roleId;
10 11  
11 12 public int getId() {
... ... @@ -47,4 +48,12 @@ public class User {
47 48 public void setRoleId(int roleId) {
48 49 this.roleId = roleId;
49 50 }
  51 +
  52 + public String getUpdateTime() {
  53 + return updateTime;
  54 + }
  55 +
  56 + public void setUpdateTime(String updateTime) {
  57 + this.updateTime = updateTime;
  58 + }
50 59 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
... ... @@ -60,7 +60,8 @@ public class AlarmController {
60 60 @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class),
61 61 })
62 62 public ResponseEntity<PageInfo<DeviceAlarm>> getAll(
63   - int page, int count,
  63 + @RequestParam int page,
  64 + @RequestParam int count,
64 65 @RequestParam(required = false) String deviceId,
65 66 @RequestParam(required = false) String alarmPriority,
66 67 @RequestParam(required = false) String alarmMethod,
... ... @@ -76,8 +77,8 @@ public class AlarmController {
76 77  
77 78  
78 79 try {
79   - format.parse(startTime);
80   - format.parse(endTime);
  80 + if (startTime != null) format.parse(startTime);
  81 + if (endTime != null) format.parse(endTime);
81 82 } catch (ParseException e) {
82 83 return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
83 84 }
... ... @@ -96,7 +97,7 @@ public class AlarmController {
96 97 * @param time 结束时间(这个时间之前的报警会被删除)
97 98 * @return
98 99 */
99   - @ApiOperation("分页查询报警")
  100 + @ApiOperation("删除报警")
100 101 @DeleteMapping("/delete")
101 102 @ApiImplicitParams({
102 103 @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class),
... ... @@ -118,12 +119,17 @@ public class AlarmController {
118 119 } catch (ParseException e) {
119 120 return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
120 121 }
121   - String[] deviceIdArray = deviceIds.split(",");
122   - List<String> deviceIdList = Arrays.asList(deviceIdArray);
123   - deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
  122 + List<String> deviceIdList = null;
  123 + if (deviceIds != null) {
  124 + String[] deviceIdArray = deviceIds.split(",");
  125 + deviceIdList = Arrays.asList(deviceIdArray);
  126 + }
  127 +
  128 + int count = deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
124 129 WVPResult wvpResult = new WVPResult();
125 130 wvpResult.setCode(0);
126 131 wvpResult.setMsg("success");
  132 + wvpResult.setData(count);
127 133 return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
128 134 }
129 135  
... ...
src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  4 +import com.genersoft.iot.vmp.service.IDeviceAlarmService;
  5 +import com.genersoft.iot.vmp.service.IUserService;
  6 +import com.genersoft.iot.vmp.storager.dao.dto.User;
  7 +import org.junit.runner.RunWith;
  8 +import org.springframework.boot.test.context.SpringBootTest;
  9 +import org.springframework.test.context.junit4.SpringRunner;
  10 +
  11 +import javax.annotation.Resource;
  12 +import java.text.SimpleDateFormat;
  13 +import java.util.Date;
  14 +
  15 +
  16 +@SpringBootTest
  17 +@RunWith(SpringRunner.class)
  18 +class UserServiceImplTest {
  19 +
  20 + @Resource
  21 + private IUserService userService;
  22 +
  23 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  24 +
  25 + @org.junit.jupiter.api.Test
  26 + void getAllUser() {
  27 + System.out.println(userService.getAllUsers().size());
  28 + }
  29 +
  30 +
  31 + @org.junit.jupiter.api.Test
  32 + void add() {
  33 + for (int i = 0; i < 10; i++) {
  34 + User user = new User();
  35 + user.setUsername("admin_" + i);
  36 + user.setPassword("admin_password_" + i);
  37 + user.setRoleId((int)(Math.random()*4 + 1));
  38 + user.setCreateTime(format.format(System.currentTimeMillis()));
  39 + user.setUpdateTime(format.format(System.currentTimeMillis()));
  40 + userService.addUser(user);
  41 + }
  42 + }
  43 +
  44 + @org.junit.jupiter.api.Test
  45 + void delete() {
  46 + userService.deleteUser(1002);
  47 + }
  48 +
  49 + @org.junit.jupiter.api.Test
  50 + void update() {
  51 + User user = new User();
  52 + user.setId(1003);
  53 + user.setUsername("update" );
  54 + user.setPassword("update");
  55 + user.setRoleId((int)(Math.random()*4 + 1));
  56 + user.setUpdateTime(format.format(System.currentTimeMillis()));
  57 + userService.updateUsers(user);
  58 + }
  59 +
  60 +
  61 +}
0 62 \ No newline at end of file
... ...