| | |
| | | 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'); |
| | | |
| | |
| | | * @param deviceIdList 制定需要清理的设备id |
| | | * @param time 不写时间则清空所有时间的 |
| | | */ |
| | | void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); |
| | | int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); |
| | | |
| | | } |
| | |
| | | |
| | | import com.genersoft.iot.vmp.storager.dao.dto.User; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface IUserService { |
| | | |
| | | User getUser(String username, String password); |
| | |
| | | boolean changePassword(int id, String password); |
| | | |
| | | User getUserByUsername(String username); |
| | | |
| | | void addUser(User user); |
| | | |
| | | void deleteUser(int id); |
| | | |
| | | List<User> getAllUsers(); |
| | | |
| | | void updateUsers(User user); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) { |
| | | deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); |
| | | public int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) { |
| | | return deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); |
| | | } |
| | | } |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | 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<User> getAllUsers() { |
| | | return userMapper.selectAll(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateUsers(User user) { |
| | | userMapper.update(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 = {" <script>" + |
| | | "UPDATE user " + |
| | | "SET update_time='${updateTime}' " + |
| | | "<if test=\"roleId != null\">, roleId='${roleId}'</if>" + |
| | | "<if test=\"password != null\">, password='${password}'</if>" + |
| | | "<if test=\"username != null\">, username='${username}'</if>" + |
| | | "WHERE id=#{id}" + |
| | | " </script>"}) |
| | | 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); |
| | |
| | | |
| | | @Select("select * FROM user WHERE username=#{username}") |
| | | User getUserByUsername(String username); |
| | | |
| | | @Select("select * FROM user") |
| | | List<User> selectAll(); |
| | | } |
| | |
| | | private String username; |
| | | private String password; |
| | | private String createTime; |
| | | private String updateTime; |
| | | private int roleId; |
| | | |
| | | public int getId() { |
| | |
| | | public void setRoleId(int roleId) { |
| | | this.roleId = roleId; |
| | | } |
| | | |
| | | public String getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(String updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | } |
| | |
| | | @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class), |
| | | }) |
| | | public ResponseEntity<PageInfo<DeviceAlarm>> 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, |
| | |
| | | |
| | | |
| | | 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); |
| | | } |
| | |
| | | * @param time 结束时间(这个时间之前的报警会被删除) |
| | | * @return |
| | | */ |
| | | @ApiOperation("分页查询报警") |
| | | @ApiOperation("删除报警") |
| | | @DeleteMapping("/delete") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class), |
| | |
| | | } catch (ParseException e) { |
| | | return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); |
| | | } |
| | | String[] deviceIdArray = deviceIds.split(","); |
| | | List<String> deviceIdList = Arrays.asList(deviceIdArray); |
| | | deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); |
| | | List<String> 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<String>>(wvpResult, HttpStatus.OK); |
| | | } |
| | | |
New file |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |