Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / UserController.java
package com.newfiber.api.pc.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.commons.PageRequestObject;
import com.newfiber.api.core.commons.PageResultObject;
import com.newfiber.api.core.utils.StringUtil;
import com.newfiber.api.pc.dao.Data_User_InfoDao;
import com.newfiber.api.pc.dto.UserInfoDto;
import com.newfiber.api.pc.model.entity.Data_User_Info;
import com.newfiber.api.pc.model.entity.UserInfo;
import com.newfiber.api.pc.model.vo.UserNoVo;
import com.newfiber.api.pc.model.vo.UserVo;
import com.newfiber.api.pc.service.Data_User_InfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/users")
@Api(value = "UserManagerController",tags = "SYS-06、系统管理-用户管理", position = 106)
public class UserController {

		@Autowired
		private Data_User_InfoService infoService;
		@Autowired
		private Data_User_InfoDao userInfoDao;

	
	
	    //用户列表管理
		@PostMapping(value = "/UserManager",produces = "application/json;charset=utf-8")
		@SysLog(actionType="4",value = "用户列表管理")
		@ApiOperation("获取用户列表")
		public RespBodyObj<Page<UserInfo>> GetUserManager(@RequestBody ReqBodyObj<String> params){
			int pageSize=params.getSize();
			int pageNo=(params.getCurrent()-1)*pageSize;
			Page<UserInfo> result = new Page<>();
			try {
				String userName = params.getData();
				List<UserInfo> userInfoList = userInfoDao.selectUserInfoList(userName,null,pageNo,pageSize);
				List<UserInfo> userInfOTotal = userInfoDao.selectUserInfoList(userName,null,null,pageSize);
				if(userInfoList != null && userInfoList.size() > 0){
					result.setTotal(userInfOTotal.size());
					result.setRecords(userInfoList);
					return RespBodyObj.ok(result);
				}else{
					return RespBodyObj.ok(result);
				}
			} catch (Exception e) {
				e.printStackTrace();
				return RespBodyObj.error("查询失败");
			}
	
		}

	//用户列表管理
	@PostMapping(value = "/getPhoneUsers",produces = "application/json;charset=utf-8")
	@SysLog(actionType="4",value = "获取有手机号的用户")
	@ApiOperation("获取有手机号的用户")
	public RespBodyObj<List<UserInfo>> getPhoneUsers(@RequestBody ReqBodyObj<String> params){
		int pageSize=params.getSize();
		int pageNo=(params.getCurrent()-1)*pageSize;
		Page<UserInfo> result = new Page<>();
		try {
			String userName = params.getData();
			List<UserInfo> userInfoList = userInfoDao.selectUserInfoList(userName,null,pageNo,pageSize);

			if(userInfoList != null && userInfoList.size() > 0){
				userInfoList=	userInfoList.stream().filter(e-> StringUtil.isNotEmpty(e.getPhoneNum())).collect(Collectors.toList());
				return RespBodyObj.ok(userInfoList);
			}else{
				return RespBodyObj.ok(userInfoList);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("查询失败");
		}
	}
		
		//新增用户
		@PostMapping(value="AddUserinfo",produces = "application/json;charset=utf-8")
		@SysLog(actionType="1",value = "新增用户")
		@ApiOperation("用户管理-新增用户")
		public RespBodyObj AddUser(@RequestBody UserInfoDto params){
			List<Data_User_Info> infolist = userInfoDao.selectUser(params.getUserNo());
			String path = "";
			try {
					if(params.getHighestAuthority() != null && params.getHighestAuthority().equals("yes")){
						//是否存在总河长
						int flag = userInfoDao.gethighestAuthorityTotal();
						if(flag>0) return  RespBodyObj.error("已存在总河长,不能设置为总河长!");
					}
					if(infolist.size()==0){
						infoService.addUser(params);
						return  RespBodyObj.ok("新增成功!");
					}else{
						return  RespBodyObj.error("该用户名被使用");
					}
				} catch (Exception e) {
					e.printStackTrace();
				return  RespBodyObj.error("新增失败!");
			}
			
	
		
		}
		//查看用户信息
		@PostMapping(value="/GetUser",produces = "application/json;charset=utf-8")
		@SysLog(actionType="4",value = "查看用户信息")
		@ApiOperation("查看用户信息")
		public RespBodyObj<Data_User_Info> GetUser(@RequestParam("userNo") String userNo){
			try {
				Data_User_Info json=infoService.GetUser(userNo);
				return RespBodyObj.ok(json);
			} catch (Exception e) {
				e.printStackTrace();
				return RespBodyObj.error("查询失败!");
			}
		}
		//修改用户信息
		@PostMapping(value="/UpdateUser",produces = "application/json;charset=utf-8")
		@ResponseBody
		@SysLog(actionType="3",value = "修改用户信息")
		public RespBodyObj UpdateUser(@RequestBody UserInfoDto params){
			String path = "";
			try {
				if(params.getHighestAuthority() != null && params.getHighestAuthority().equals("yes")){
					//是否存在总河长
					int flag = userInfoDao.gethighestAuthorityTotal();
					if(flag>0) return  RespBodyObj.error("已存在总河长,不能设置为总河长!");
				}
				infoService.updateUser(params);
				return RespBodyObj.ok("修改成功!");
				} catch (Exception e) {
				e.printStackTrace();
				return RespBodyObj.error("修改失败!");
			}
		}
		
		
		//删除用户
		@PostMapping(value="/deleteUser",produces = "application/json;charset=utf-8")
		@SysLog(actionType="2",value = "删除用户")
		@ApiOperation("用户管理-删除用户")
		public RespBodyObj deleteUser(@RequestParam("userNo")String userNo){
				try {
					if(userNo!=null&&userNo!=""){
					infoService.deleteUsers(userNo);
					return RespBodyObj.ok("删除成功!");
					}else{
					return RespBodyObj.error("未选中删除项!");
				
					}
				} catch (Exception e) {
					e.printStackTrace();
					return RespBodyObj.ok("删除失败!");
				}
		}



		@PostMapping("/getNoProjectUser")
		@ApiOperation("查询当前传入用户编号数据之外的所有用户数据")
		public PageResultObject<UserVo>  selectNoProjectUser(@RequestBody PageRequestObject<UserNoVo> pageRequestObject){
			return infoService.selectNoProjectUser(pageRequestObject);
		}

		@PostMapping("/getProjectUser")
		@ApiOperation("查询当前传入用户编号数据")
		public PageResultObject<UserVo> selectProjectUser(@RequestBody PageRequestObject<UserNoVo> pageRequestObject){
			return infoService.selectProjectUser(pageRequestObject);
		}
}