|
@ -1,220 +0,0 @@
|
|
|
package com.yihu.wlyy.controller.manager.user;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.wlyy.controller.BaseController;
|
|
|
import com.yihu.wlyy.entity.User;
|
|
|
import com.yihu.wlyy.service.manager.user.UserService;
|
|
|
import com.yihu.wlyy.util.Envelop;
|
|
|
import com.yihu.wlyy.util.MD5;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by yww on 2016/12/6.
|
|
|
*/
|
|
|
@Controller
|
|
|
@RequestMapping(value = "admin/user")
|
|
|
public class UserController extends BaseController {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
@RequestMapping(value = "initial", method = RequestMethod.GET)
|
|
|
public String listPageInit(){
|
|
|
return "user/user_list";
|
|
|
}
|
|
|
@RequestMapping(value = "infoInit",method = RequestMethod.GET)
|
|
|
public String infoPageInit(Long id,String mode){
|
|
|
request.setAttribute("id",id);
|
|
|
request.setAttribute("mode",mode);
|
|
|
return "user/user_modify";
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "userList")
|
|
|
@ResponseBody
|
|
|
public String searchList(
|
|
|
@RequestParam(value = "code",required = false) String code,
|
|
|
@RequestParam(value = "name",required = false) String name,
|
|
|
@RequestParam(value = "mobile",required = false) String mobile,
|
|
|
@RequestParam(value= "page",required = false) Integer page,
|
|
|
@RequestParam(value = "rows",required = false) Integer pageSize){
|
|
|
try{
|
|
|
Page<User> userPage = userService.searchList(code, name, mobile, page, pageSize);
|
|
|
return write(200,"操作成功",page,pageSize,userPage);
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "user")
|
|
|
@ResponseBody
|
|
|
public String getUser(
|
|
|
@ApiParam(name = "id", defaultValue = "2")
|
|
|
@RequestParam(name = "id", required = true) Long id) {
|
|
|
try{
|
|
|
User user = userService.retrieve(id);
|
|
|
return write(200,"操作成功","data",user);
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "isCodeExist")
|
|
|
@ResponseBody
|
|
|
public String isCodeExist(String code){
|
|
|
List<User> users = userService.findByField("code", code);
|
|
|
if(users != null && users.size()>0){
|
|
|
return "true";
|
|
|
}
|
|
|
return "false";
|
|
|
|
|
|
}
|
|
|
@RequestMapping(value = "isMobileExist")
|
|
|
@ResponseBody
|
|
|
public String isMobileExist(String mobile){
|
|
|
List<User> users = userService.findByField("mobile", mobile);
|
|
|
if(users != null && users.size()>0){
|
|
|
return "true";
|
|
|
}
|
|
|
return "false";
|
|
|
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "delete")
|
|
|
@ResponseBody
|
|
|
public String deleteUser(Long id){
|
|
|
try{
|
|
|
if (id == null) {
|
|
|
return error(-1, "id不能为空!");
|
|
|
}
|
|
|
User user = userService.retrieve(id);
|
|
|
if (StringUtils.equals(user.getCode(), "admin")) {
|
|
|
return error(-1, "超级管理员admin不允许删除!");
|
|
|
}
|
|
|
userService.deleteUser(id);
|
|
|
return write(200,"操作成功!");
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "create")
|
|
|
@ResponseBody
|
|
|
public String createUser(String jsonData){
|
|
|
try{
|
|
|
User user = objectMapper.readValue(jsonData, User.class);
|
|
|
String mobile = user.getMobile();
|
|
|
if(mobile == null){
|
|
|
return write(-1,"手机号不能为空");
|
|
|
}
|
|
|
user.setCzrq(new Date());
|
|
|
String password=user.getMobile().substring(5);
|
|
|
String salt= UUID.randomUUID().toString().replace("-", "");
|
|
|
password = MD5.GetMD5Code(password+salt);
|
|
|
user.setPassword(password);
|
|
|
user.setSalt(salt);
|
|
|
User userNew = userService.save(user);
|
|
|
return write(200,"操作成功!");
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@RequestMapping(value = "update")
|
|
|
@ResponseBody
|
|
|
public String updateUser(String jsonData){
|
|
|
try{
|
|
|
User user = objectMapper.readValue(jsonData, User.class);
|
|
|
String mobile = user.getMobile();
|
|
|
if(mobile == null){
|
|
|
return write(-1,"手机号不能为空");
|
|
|
}
|
|
|
User userNew = userService.retrieve(user.getId());
|
|
|
userNew.setCode(user.getCode());
|
|
|
userNew.setName(user.getName());
|
|
|
userNew.setType(user.getType());
|
|
|
userNew.setMobile(user.getMobile());
|
|
|
userNew.setOrganizationId(user.getOrganizationId());
|
|
|
userNew.setRoles(user.getRoles());
|
|
|
//修改手机号对应初始化密码(因暂未提供修改密码操作)-手机号后六位
|
|
|
if(userNew.getMobile() != user.getMobile()){
|
|
|
String password=mobile.substring(5);
|
|
|
String salt= UUID.randomUUID().toString().replace("-", "");
|
|
|
password = MD5.GetMD5Code(password+salt);
|
|
|
userNew.setPassword(password);
|
|
|
userNew.setSalt(salt);
|
|
|
}
|
|
|
userNew = userService.save(userNew);
|
|
|
return write(200,"操作成功!");
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//初始化密码
|
|
|
@RequestMapping(value = "initPwd")
|
|
|
@ResponseBody
|
|
|
public String initPwd(
|
|
|
@RequestParam(value = "mobile",required = true)String mobile){
|
|
|
try{
|
|
|
boolean res = userService.initPwd(mobile);
|
|
|
if(!res){
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
return write(200,"操作成功!");
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//修改密码
|
|
|
@RequestMapping(value = "changePwd")
|
|
|
@ResponseBody
|
|
|
public String changePwd(
|
|
|
@RequestParam(value = "mobile")String mobile,
|
|
|
@RequestParam(value = "oldPwd")String oldPwd,
|
|
|
@RequestParam(value = "newPwd")String newPwd){
|
|
|
try {
|
|
|
return write(200,"操作成功");
|
|
|
}catch (Exception ex){
|
|
|
error(ex);
|
|
|
return error(-1, "操作失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据姓名获取所有有效用户列表(用于分页下拉框)
|
|
|
@RequestMapping("/searchUsers")
|
|
|
@ResponseBody
|
|
|
public Object searchUsers(String searchNm, int page, int rows) {
|
|
|
try {
|
|
|
Page<User> users = userService.searchUsers(searchNm, page, rows);
|
|
|
return write(200, "操作成功", page, rows, users);
|
|
|
} catch (Exception ex) {
|
|
|
error(ex);
|
|
|
return error(-1,"操作失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|