Browse Source

添加用户操作

修正报警清理接口
pull/151/head
648540858 3 years ago
parent
commit
3cd1434341
  1. 5
      sql/mysql.sql
  2. 2
      src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java
  3. 10
      src/main/java/com/genersoft/iot/vmp/service/IUserService.java
  4. 4
      src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java
  5. 23
      src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
  6. 26
      src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
  7. 9
      src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java
  8. 20
      src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
  9. 61
      src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java

5
sql/mysql.sql

@ -215,8 +215,9 @@ create table user
username varchar(255) not null, username varchar(255) not null,
password varchar(255) not null, password varchar(255) not null,
roleId int 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');

2
src/main/java/com/genersoft/iot/vmp/service/IDeviceAlarmService.java

@ -38,6 +38,6 @@ public interface IDeviceAlarmService {
* @param deviceIdList 制定需要清理的设备id * @param deviceIdList 制定需要清理的设备id
* @param time 不写时间则清空所有时间的 * @param time 不写时间则清空所有时间的
*/ */
void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time);
} }

10
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 com.genersoft.iot.vmp.storager.dao.dto.User;
import java.util.List;
public interface IUserService { public interface IUserService {
User getUser(String username, String password); User getUser(String username, String password);
@ -9,4 +11,12 @@ public interface IUserService {
boolean changePassword(int id, String password); boolean changePassword(int id, String password);
User getUserByUsername(String username); User getUserByUsername(String username);
void addUser(User user);
void deleteUser(int id);
List<User> getAllUsers();
void updateUsers(User user);
} }

4
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java

@ -31,7 +31,7 @@ public class DeviceAlarmServiceImpl implements IDeviceAlarmService {
} }
@Override @Override
public void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) { public int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) {
deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); return deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time);
} }
} }

23
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class UserServiceImpl implements IUserService { public class UserServiceImpl implements IUserService {
@ -29,4 +31,25 @@ public class UserServiceImpl implements IUserService {
public User getUserByUsername(String username) { public User getUserByUsername(String username) {
return userMapper.getUserByUsername(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<User> getAllUsers() {
return userMapper.selectAll();
}
@Override
public void updateUsers(User user) {
userMapper.update(user);
}
} }

26
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.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper @Mapper
@Repository @Repository
public interface UserMapper { public interface UserMapper {
@Insert("INSERT INTO user (username, password, roleId, create_time) VALUES" + @Insert("INSERT INTO user (username, password, roleId, create_time, update_time) VALUES" +
"('${username}', '${password}', '${roleId}', datetime('now','localtime'))") "('${username}', '${password}', '${roleId}', '${createTime}', '${updateTime}')")
int add(User user); int add(User user);
@Update("UPDATE user " + @Update(value = {" <script>" +
"SET username=#{username}, " + "UPDATE user " +
"password=#{password}, " + "SET update_time='${updateTime}' " +
"roleId=#{roleId} " + "<if test=\"roleId != null\">, roleId='${roleId}'</if>" +
"WHERE id=#{id}") "<if test=\"password != null\">, password='${password}'</if>" +
"<if test=\"username != null\">, username='${username}'</if>" +
"WHERE id=#{id}" +
" </script>"})
int update(User user); int update(User user);
@Delete("DELETE FROM user WHERE app=#{app} AND id=#{id}") @Delete("DELETE FROM user WHERE id=#{id}")
int delete(User user); int delete(int id);
@Select("select * FROM user WHERE username=#{username} AND password=#{password}") @Select("select * FROM user WHERE username=#{username} AND password=#{password}")
User select(String username, String password); User select(String username, String password);
@ -30,4 +35,7 @@ public interface UserMapper {
@Select("select * FROM user WHERE username=#{username}") @Select("select * FROM user WHERE username=#{username}")
User getUserByUsername(String username); User getUserByUsername(String username);
@Select("select * FROM user")
List<User> selectAll();
} }

9
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java

@ -6,6 +6,7 @@ public class User {
private String username; private String username;
private String password; private String password;
private String createTime; private String createTime;
private String updateTime;
private int roleId; private int roleId;
public int getId() { public int getId() {
@ -47,4 +48,12 @@ public class User {
public void setRoleId(int roleId) { public void setRoleId(int roleId) {
this.roleId = roleId; this.roleId = roleId;
} }
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
} }

20
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), @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class),
}) })
public ResponseEntity<PageInfo<DeviceAlarm>> getAll( public ResponseEntity<PageInfo<DeviceAlarm>> getAll(
int page, int count, @RequestParam int page,
@RequestParam int count,
@RequestParam(required = false) String deviceId, @RequestParam(required = false) String deviceId,
@RequestParam(required = false) String alarmPriority, @RequestParam(required = false) String alarmPriority,
@RequestParam(required = false) String alarmMethod, @RequestParam(required = false) String alarmMethod,
@ -76,8 +77,8 @@ public class AlarmController {
try { try {
format.parse(startTime); if (startTime != null) format.parse(startTime);
format.parse(endTime); if (endTime != null) format.parse(endTime);
} catch (ParseException e) { } catch (ParseException e) {
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
} }
@ -96,7 +97,7 @@ public class AlarmController {
* @param time 结束时间(这个时间之前的报警会被删除) * @param time 结束时间(这个时间之前的报警会被删除)
* @return * @return
*/ */
@ApiOperation("分页查询报警") @ApiOperation("删除报警")
@DeleteMapping("/delete") @DeleteMapping("/delete")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class), @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class),
@ -118,12 +119,17 @@ public class AlarmController {
} catch (ParseException e) { } catch (ParseException e) {
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
} }
String[] deviceIdArray = deviceIds.split(","); List<String> deviceIdList = null;
List<String> deviceIdList = Arrays.asList(deviceIdArray); if (deviceIds != null) {
deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); String[] deviceIdArray = deviceIds.split(",");
deviceIdList = Arrays.asList(deviceIdArray);
}
int count = deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
WVPResult wvpResult = new WVPResult(); WVPResult wvpResult = new WVPResult();
wvpResult.setCode(0); wvpResult.setCode(0);
wvpResult.setMsg("success"); wvpResult.setMsg("success");
wvpResult.setData(count);
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK); return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
} }

61
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);
}
}
Loading…
Cancel
Save