|
|
package com.monitor.user.ctrl;
|
|
|
|
|
|
import com.model.User;
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.monitor.mysql.mapper.UserMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("user")
|
|
|
public class UserCtrl {
|
|
|
|
|
|
Logger log = LoggerFactory.getLogger(UserCtrl.class);
|
|
|
|
|
|
@Autowired
|
|
|
UserMapper userMapper;
|
|
|
|
|
|
@RequestMapping("/getAllUser")
|
|
|
@ResponseBody
|
|
|
public BaseResponse getAllUser() {
|
|
|
try{
|
|
|
List<User> list=userMapper.selectAll();
|
|
|
|
|
|
if (list == null || CollectionUtils.isEmpty(list)) {
|
|
|
return new BaseResponse<List<User>>();
|
|
|
}
|
|
|
|
|
|
return new BaseResponse<List<User>>(list);
|
|
|
}catch (Exception e){
|
|
|
log.error("getAllUser error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/getUserByName")
|
|
|
@ResponseBody
|
|
|
public BaseResponse getUserByName(String name) {
|
|
|
try{
|
|
|
User user=userMapper.selectByName(name);
|
|
|
return new BaseResponse<User>(user);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserByName error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/getUserById")
|
|
|
@ResponseBody
|
|
|
public BaseResponse getUserById(int id) {
|
|
|
try{
|
|
|
User user=userMapper.selectById(id);
|
|
|
return new BaseResponse<User>(user);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserById error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/insert")
|
|
|
@ResponseBody
|
|
|
public BaseResponse insert(@RequestBody User user) {
|
|
|
try{
|
|
|
int result = userMapper.insert(user);
|
|
|
return new BaseResponse<Integer>(result);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserById error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/updatePwd")
|
|
|
@ResponseBody
|
|
|
public BaseResponse updatePwd(@RequestBody User user) {
|
|
|
try{
|
|
|
int result = userMapper.updatePwd(user);
|
|
|
return new BaseResponse<Integer>(result);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserById error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/updateLevel")
|
|
|
@ResponseBody
|
|
|
public BaseResponse updateAuth(@RequestBody User user) {
|
|
|
try{
|
|
|
int result = userMapper.updateLevel(user);
|
|
|
return new BaseResponse<Integer>(result);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserById error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/deleteByName")
|
|
|
@ResponseBody
|
|
|
public BaseResponse deleteByName(String name) {
|
|
|
try{
|
|
|
int result = userMapper.deleteByName(name);
|
|
|
return new BaseResponse<Integer>(result);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserById error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/deleteById")
|
|
|
@ResponseBody
|
|
|
public BaseResponse deleteById(int id) {
|
|
|
try{
|
|
|
int result = userMapper.deleteById(id);
|
|
|
return new BaseResponse<Integer>(result);
|
|
|
}catch (Exception e){
|
|
|
log.error("getUserById error",e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|