package com.hotent.uc.controller;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.cache.annotation.CacheEvict;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.constants.CacheKeyConst;
import com.hotent.base.controller.BaseController2;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.FieldRelation;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.query.QueryOP;
import com.hotent.base.util.AppUtil;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.CommonResultUtil;
import com.hotent.base.util.FileUtil;
import com.hotent.base.util.HttpUtil;
import com.hotent.base.util.JsonUtil;
import com.hotent.base.util.RSAUtil;
import com.hotent.base.util.StringUtil;
import com.hotent.base.vo.AccountOrIdVo;
import com.hotent.base.vo.ClientInfo;
import com.hotent.uc.api.model.Group;
import com.hotent.uc.api.model.IUser;
import com.hotent.uc.exception.RequiredException;
import com.hotent.uc.manager.OrgJobManager;
import com.hotent.uc.manager.OrgManager;
import com.hotent.uc.manager.OrgPostManager;
import com.hotent.uc.manager.OrgUserManager;
import com.hotent.uc.manager.UcGroupManager;
import com.hotent.uc.manager.UserImportManager;
import com.hotent.uc.manager.UserManager;
import com.hotent.uc.manager.UserRoleManager;
import com.hotent.uc.manager.UserUnderManager;
import com.hotent.uc.manager.UserUniteManager;
import com.hotent.uc.model.Org;
import com.hotent.uc.model.OrgJob;
import com.hotent.uc.model.OrgPost;
import com.hotent.uc.model.UcGroup;
import com.hotent.uc.model.User;
import com.hotent.uc.model.UserGroup;
import com.hotent.uc.model.UserParams;
import com.hotent.uc.model.UserRole;
import com.hotent.uc.params.common.DataSyncObject;
import com.hotent.uc.params.common.DataSyncVo;
import com.hotent.uc.params.common.UserExportObject;
import com.hotent.uc.params.echarts.ChartOption;
import com.hotent.uc.params.group.GroupIdentity;
import com.hotent.uc.params.params.ParamObject;
import com.hotent.uc.params.user.TriggerVo;
import com.hotent.uc.params.user.UserImportVo;
import com.hotent.uc.params.user.UserMarkObject;
import com.hotent.uc.params.user.UserPolymer;
import com.hotent.uc.params.user.UserPwdObject;
import com.hotent.uc.params.user.UserRelObject;
import com.hotent.uc.params.user.UserStatusVo;
import com.hotent.uc.params.user.UserUnderVo;
import com.hotent.uc.params.user.UserVo;
import com.hotent.uc.service.UserManagerDetailsServiceImpl;
import com.hotent.uc.util.ContextUtil;
import com.hotent.uc.util.OrgUtil;
import com.hotent.uc.util.UpdateMethod;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * 用户组织模块接口
 * @author zhangxw
 *
 */
@RestController
@RequestMapping("/api/user/v2/")
@Api(tags="用户管理2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class UserController2 extends BaseController2<UserManager, User> {
	 @Autowired
	 UserManager userService;
	 @Autowired
	 UserImportManager userImportService;
	 @Autowired
	 UserManagerDetailsServiceImpl userManagerDetailsServiceImpl;
	 @Autowired
	 UserRoleManager userRoleService;
	 @Autowired
	 OrgManager orgManager;
	 @Autowired
	 OrgUserManager orgUserManager;
	 @Autowired
	 OrgPostManager orgPostManager;
	 @Autowired
	 OrgJobManager orgJobManager;
	 @Autowired
	 UcGroupManager ucGroupManager;

	 @Resource
	 UserUnderManager userUnderManager;
	 @Resource
	 UserUniteManager userUniteManager;

	 
	/**
	 * 查询用户
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUserPage",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取用户列表（带分页信息，UserVo对象）", httpMethod = "POST", notes = "获取用户列表（带分页信息，UserVo对象）")
	public CommonResult<PageList<UserVo>> getUserPage(@ApiParam(name="queryFilter",value="通用查询对象")
	 @RequestBody QueryFilter queryFilter) throws Exception{
		PageList<User> query = userService.query(queryFilter);
		PageList<UserVo> userVoPageList = convertVoPageList(query);
		return CommonResult.<PageList<UserVo>>ok().value(userVoPageList);
	}

	
	@RequestMapping(value="users/getOrgUserQuery",method=RequestMethod.POST, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "获取用户列表（根据维度、组织、岗位、职务、角色进行过滤）", httpMethod = "POST", notes = "获取用户列表（根据维度、组织、岗位、职务、角色进行过滤）")
	public CommonResult<PageList<User>> getOrgUserQuery(@ApiParam(name="queryFilter",value="通用查询对象") @RequestBody QueryFilter<User> queryFilter) throws Exception{
		IPage<User> list = userService.getOrgUserQuery(queryFilter);
		PageList<User> userPageList = new PageList<>(list);
		return CommonResult.<PageList<User>>ok().value(userPageList);

	}


	@RequestMapping(value="users/getAllUser",method=RequestMethod.GET, produces = {
			"application/json; charset=utf-8" })
	@ApiOperation(value = "获取系统中所有用户", httpMethod = "GET", notes = "获取系统中所有用户")
	public CommonResult<List<User>> getAllUser() throws Exception{
		List<User> userList = userService.getAll();
		return CommonResult.<List<User>>ok().value(userList);
	}







	/**
	 * 查询用户
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/queryByType",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据状态获取用户列表（带分页信息）", httpMethod = "POST", notes = "获取用户列表")
	public CommonResult<PageList<UserVo>> queryByType(@ApiParam(name="queryFilter",value="通用查询对象") @RequestBody QueryFilter queryFilter) throws Exception{
		queryFilter.addFilter("ucuser.IS_DELE_", User.DELETE_NO, QueryOP.EQUAL, FieldRelation.AND, "delete_group");
        queryFilter.addFilter("ucuser.STATUS_", User.STATUS_NORMAL, QueryOP.EQUAL, FieldRelation.AND, "delete_group");
		PageList<User> query = userService.queryByType(queryFilter);
		PageList<UserVo> userVoPageList = convertVoPageList(query);
		return CommonResult.<PageList<UserVo>>ok().value(userVoPageList);
	}
	
	/**
	 * 添加用户
	 * @param user
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping(value="user/addUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "添加用户", httpMethod = "POST", notes = "添加用户")
	public CommonResult<String> addUser(@ApiParam(name="user",value="用户参数对象", required = true) @RequestBody @Valid UserVo user) throws Exception{
		userService.addUser(user);
		return CommonResult.<String>ok().message("用户添加成功！");
	}
	
	@RequestMapping(value="user/saveUser",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "修改，保存用户(包括角色、组织和岗位信息)", httpMethod = "POST", notes = "添加用户(包括角色、组织和岗位信息)")
	@UpdateMethod(type=UserPolymer.class)
	public CommonResult<String> saveUser(@ApiParam(name="userPolymer",value="用户参数对象", required = true) @RequestBody UserPolymer userPolymer) throws Exception{
		userService.saveUser(userPolymer);
		return CommonResult.<String>ok().message("用户保存成功！");
	}
	
	@RequestMapping(value="user/saveUserBaseInfo",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "修改用户基本信息", httpMethod = "POST", notes = "修改用户基本信息")
	@UpdateMethod(type=UserVo.class)
	public CommonResult<String> saveUserBaseInfo(@ApiParam(name="vo",value="用户参数对象", required = true) @RequestBody UserVo vo) throws Exception{
		userService.saveUser(vo);
		return CommonResult.<String>ok().message("用户保存成功！");
	}
	
	/**
	 * 根据用户帐号删除用户
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/deleteUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户标识删除用户（多个用,号隔开）", httpMethod = "POST", notes = "根据用户标识（多个用,号隔开）删除用户，参数 （任传一个）")
	public CommonResult<String> deleteUser(@ApiParam(name="userMark",value="用户标识") @RequestBody(required=false) UserMarkObject userMark) throws Exception{
		CommonResult<String> commonResult = userService.deleteUser(userMark);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 根据用户id删除用户
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/deleteUserByIds",method=RequestMethod.DELETE, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户id删除用户（多个用,号隔开）", httpMethod = "DELETE", notes = "根据用户id（多个用,号隔开）删除用户，参数 （任传一个）")
	public CommonResult<String> deleteUserByIds(@ApiParam(name="ids",value="用户标识") @RequestParam(required=false) String ids) throws Exception{
		CommonResult<String> commonResult = userService.deleteUserByIds(ids);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 更新用户，不会更新id、密码、帐号信息
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/updateUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "更新用户（更新部分信息）", httpMethod = "POST", notes = "更新用户（不会更新id、密码、帐号、头像、来源、是否删除、版本号信息）")
	@UpdateMethod(type=UserVo.class)
	@CacheEvict(value = CacheKeyConst.EIP_UC_USER_NAME, key = "#user.account")
	public CommonResult<String> updateUser(@ApiParam(name="user",value="用户参数对象", required = true) @RequestBody  UserVo user) throws Exception{
		userService.updateUser(user);
		return CommonResult.<String>ok().message("用户更新成功！");
	}
	
	
	/**
	 * 获取用户信息
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getUser",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户标识获取用户信息", httpMethod = "GET", notes = "获取用户信息，参数 （任传一个）{\"account\":\"用户账号\",\"userNumber\":\"用户工号\"}")
	public CommonResult<UserVo> getUser(@ApiParam(name="account",value="用户账号") @RequestParam(required=true) String account,
			@ApiParam(name="userNumber",value="用户工号") @RequestParam(required=false) String userNumber) throws Exception{
		UserVo userVo = userService.getUser(getJsonString(account, userNumber));
		return CommonResult.<UserVo>ok().value(userVo);
	}
	
	@RequestMapping(value="user/getByAccount",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号获取用户信息", httpMethod = "POST", notes = "根据用户账号获取用户信息")
	public CommonResult<User> getByAccount(@ApiParam(name="account",value="用户账号") @RequestParam(required=true) Optional<String> account) throws Exception{
		User user = userService.getByAccount(account.orElse(ContextUtil.getCurrentUser().getAccount()));
		return CommonResult.<User>ok().value(user);
	}
	
	@RequestMapping(value="user/getUserByAccounts",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据多个用户账号获取用户信息(以逗号隔开)", httpMethod = "GET", notes = "根据多个用户账号获取用户信息(以逗号隔开)")
	public CommonResult<List<UserVo>> getUserByAccounts(@ApiParam(name="accounts",value="用户账号") @RequestParam(required=true) String accounts) throws Exception{
		QueryFilter queryFilter = QueryFilter.build();
		queryFilter.addFilter("account_", accounts, QueryOP.IN);
		List<UserVo> users = userService.queryUser(queryFilter);
		return CommonResult.<List<UserVo>>ok().value(users);
	}
	
	@RequestMapping(value="user/loadUserByUsername",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	//@ApiOperation(value = "根据账号获取userDetails信息", httpMethod = "POST", notes = "根据账号获取userDetails信息")
	public CommonResult<IUser> loadUserByUsername(@ApiParam(name="account",value="用户账号") @RequestParam(required=true) String account) throws Exception{
		IUser user = (IUser) userManagerDetailsServiceImpl.loadUserByUsername(account);
		return CommonResult.<IUser>ok().value(user);
	}
	
	/**
	 * 用户修改密码
	 * @param userPwdObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/changUserPsd",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "用户修改密码", httpMethod = "POST", notes = "修改用户密码（账号和工号任传其一，两个都有值时，只用账号）")
	public CommonResult<String> changUserPsd(@ApiParam(name="userPwdObject",value="用户密码相关参数",required=true) @RequestBody UserPwdObject userPwdObject) throws Exception{
		userPwdObject.setNewPwd(RSAUtil.Decrypt(userPwdObject.getNewPwd()));
		userPwdObject.setOldPwd(RSAUtil.Decrypt(userPwdObject.getOldPwd()));
		// 将账号设置为当前用户的账号
		userPwdObject.setAccount(ContextUtil.getCurrentUser().getAccount());
		CommonResult<String> commonResult = userService.changUserPsd(userPwdObject);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	@RequestMapping(value="user/modifiUserPsd",method=RequestMethod.POST, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "用户修改密码", httpMethod = "POST", notes = "修改用户密码（账号和工号任传其一，两个都有值时，只用账号）")
	public CommonResult<String> modifiUserPsd(@ApiParam(name="userPwdObject",value="用户密码相关参数",required=true) @RequestBody UserPwdObject userPwdObject) throws Exception{
		CommonResult<String> commonResult = userService.changUserPsd(userPwdObject);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 管理员修改用户密码
	 * @param userPwdObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/updateUserPsw",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "管理员修改用户密码", httpMethod = "POST", notes = "管理员修改用户密码（不用传旧密码；账号和工号任传其一，两个都有值时，只用账号）")
	public CommonResult<String> updateUserPsw(@ApiParam(name="userPwdObject",value="用户密码相关参数",required=true) @RequestBody UserPwdObject userPwdObject) throws Exception{
		userPwdObject.setNewPwd(RSAUtil.Decrypt(userPwdObject.getNewPwd()));
		userPwdObject.setAccount(RSAUtil.Decrypt(userPwdObject.getAccount()));
		CommonResult<String> commonResult = userService.updateUserPsw(userPwdObject);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 导入用户
	 * @param user
	 * @param file
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/importExcelUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "导入Excel用户", httpMethod = "POST", notes = "导入Excel用户")
	public CommonResult<String> importExcelUser(@ApiParam(name="demCode",value="维度编码",required=true)  @RequestParam String demCode,
			@ApiParam(name="file",value="导入的Excel文件",required=true) @RequestBody MultipartFile file,
			@ApiParam(name="repeatConver",value="用户组织、岗位关系数据导入模式（覆盖：先删除旧的组织、岗位关系数据，再按excel中的数据生成新关系数据；新增：不删除旧数据，excel中的数据做新增处理（如果和旧的一样，不会增加多份））",required=false)  @RequestParam Optional<Boolean> repeatConver) throws Exception{
		CommonResult<String> commonResult = userImportService.importExcelUser(file, demCode, repeatConver.orElse(false));
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 保存用户参数
	 * @param user
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/saveUserParams",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "保存用户参数", httpMethod = "POST", notes = "保存用户参数")
	public CommonResult<String> saveUserParams(@ApiParam(name="account",value="用户账号",required=true)  @RequestParam String account,
			@ApiParam(name="params",value="用户参数",required=true) @RequestBody List<ParamObject> params) throws Exception{
		CommonResult<String> commonResult = userService.saveUserParams(account, params);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 根据用户账户获取用户所有参数
	 * @param account
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getUserParams",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账户获取用户所有参数", httpMethod = "GET", notes = "获取用户所有参数")
	public CommonResult<List<UserParams>> getUserParams(@ApiParam(name="account",value="用户账号",required=true) @RequestParam String account) throws Exception{
		List<UserParams> userParamsList = userService.getUserParams(account);
		return CommonResult.<List<UserParams>>ok().value(userParamsList);
	}
	
	/**
	 * 根据用户账户+参数编码获取用户所有参数
	 * @param account
	 * @param alias
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getParamByCode",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账户和参数编码获取用户所有参数", httpMethod = "GET", notes = "获取用户所有参数")
	public CommonResult<UserParams> getParamByCode(@ApiParam(name="account",value="用户账号",required=true) @RequestParam String account,@ApiParam(name="code",value="参数别名",required=true) @RequestParam String code) throws Exception{
		UserParams userParams = userService.getParamByCode(account, code);
		return CommonResult.<UserParams>ok().value(userParams);
	}
	
	/**
	 * 根据用户账号（或工号）、维度，获取用户所属主组织信息
	 * @param userRelObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userOrg/getMainOrgByDemCode",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号（或工号）、维度，获取用户所属主组织信息", httpMethod = "POST", notes = "获取用户所属主组织信息，参数对象的属性isMain与level是无效参数，该方法只获取主组织信息")
	public CommonResult<Org> getMainOrgByDemCode(@ApiParam(name = "userRelObject", value = "用户组织关系参数", required = true) @RequestBody UserRelObject userRelObject) throws Exception{
		CommonResult<Org> commonResult = userService.getMainOrgByDemCode(userRelObject);
		return CommonResultUtil.<Org>getResult(commonResult);
	}
	
	/**
	 * 根据用户账号（或工号）、维度，获取用户所属岗位信息
	 * @param userRelObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userPost/getUserPosts",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号（或工号）、维度，获取用户所属岗位信息", httpMethod = "POST", notes = "获取用户所属岗位信息")
	public CommonResult<List<OrgPost>> getUserPosts(@ApiParam(name = "userRelObject", value = "用户组织关系参数", required = true) @RequestBody UserRelObject userRelObject) throws Exception{
		List<OrgPost> orgPostList = userService.getUserPosts(userRelObject);
		return CommonResult.<List<OrgPost>>ok().value(orgPostList);
	}
	
	/**
	 * 根据用户账号（或工号）、维度，获取用户直属上级信息
	 * @param userRelObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userOrgs/getImmeSuperior",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号（或工号）、维度、级别，获取用户直属上级信息", httpMethod = "POST", notes = "获取用户直属上级信息（直属组织中的主负责人）")
	public CommonResult<Set<GroupIdentity>> getImmeSuperior(@ApiParam(name = "userRelObject", value = "用户组织关系参数", required = true) @RequestBody UserRelObject userRelObject) throws Exception{
		Set<GroupIdentity> groupIdentities = userService.getImmeSuperior(userRelObject);
		return CommonResult.<Set<GroupIdentity>>ok().value(groupIdentities);
	}
	
	
	/**
	 * 根据用户账号（或工号）、维度，获取用户直属下级信息
	 * @param userRelObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userOrgs/getImmeUnders",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号（或工号）、维度、级别，获取用户直属下级信息", httpMethod = "POST", notes = "获取用户直属下级（直属组织中的用户组织关系）信息（获取规则：用户所在组织，1、组织中有责任岗位，用户在责任岗位中；2、组织中没有责任岗位，该用户为（主）负责人）")
	public CommonResult<Set<GroupIdentity>> getImmeUnders(@ApiParam(name = "userRelObject", value = "用户组织关系参数", required = true) @RequestBody UserRelObject userRelObject) throws Exception{
		Set<GroupIdentity> groupIdentities = userService.getImmeUnders(userRelObject);
		return CommonResult.<Set<GroupIdentity>>ok().value(groupIdentities);
	}
	
	/**
	 * 根据用户账号（或工号）获取职务信息
	 * @param userMark
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userJob/getUserJobs",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号（或工号）获取用户职务信息", httpMethod = "GET", notes = "获取用户职务信息，参数 （任传一个）{\"account\":\"用户账号\",\"userNumber\":\"用户工号\"}")
	public CommonResult<List<OrgJob>> getUserJobs(@ApiParam(name="account",value="用户账号") @RequestParam(required=false) String account,
			@ApiParam(name="userNumber",value="用户工号") @RequestParam(required=false) String userNumber) throws Exception{
		List<OrgJob> orgJobList = userService.getUserJobs(getJsonString(account, userNumber));
		return CommonResult.<List<OrgJob>>ok().value(orgJobList);
	}
	
	/**
	 * 根据用户账号（或工号）获取群组信息
	 * @param userMark
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userGroup/getUserGroups",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号（或工号）获取用户群组信息", httpMethod = "GET", notes = "获取用户群组信息，参数 （任传一个）{\"account\":\"用户账号\",\"userNumber\":\"用户工号\"}")
	public CommonResult<List<UserGroup>> getUserGroups(@ApiParam(name="account",value="用户账号") @RequestParam(required=false) String account,
			@ApiParam(name="userNumber",value="用户工号") @RequestParam(required=false) String userNumber) throws Exception{
		List<UserGroup> userGroupList = userService.getUserGroups(getJsonString(account, userNumber));
		return CommonResult.<List<UserGroup>>ok().value(userGroupList);
	}
	
	/**
	 * 定时获取AD新增人员信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getNewUsersFromAD",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "定时获取AD新增人员信息", httpMethod = "GET", notes = "定时获取AD新增人员信息（获取传入时间及之后从AD域同步过来的人员列表）")
	public CommonResult<List<UserVo>> getNewUsersFromAD(@ApiParam(name="date",value="AD同步时间（如：2018-01-01 12:00:00或2018-01-01）",required=true) @RequestParam String date) throws Exception{
		List<UserVo> userVoList = userService.getNewUsersFromAD(date);
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}
	
	/**
	 * AD域同步
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/syncADUsers",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "AD域同步", httpMethod = "GET", notes = "定时AD域同步")
	public CommonResult<String> syncADUsers(@ApiParam(name = "action", value = "同步类型：“all”为全量，其他字符为增量", required = true) @RequestParam String action,HttpServletRequest request) throws Exception{
		String ip = OrgUtil.getIpAddress(request);
		CommonResult<String> commonResult = userImportService.syncADUsers(action, ip);
		return CommonResultUtil.<String>getResult(commonResult);
	}

	/**
	 * 根据角色编码、组织编码获取对应人员
	 * @param roleCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getByRoleCodeAndOrgCode",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据角色编码、组织编码获取对应人员", httpMethod = "GET", notes = "根据角色编码、组织编码获取对应人员")
	public CommonResult<Set<GroupIdentity>> getByRoleCodeAndOrgCode(@ApiParam(name="roleCode",value="角色编码",required=true)  @RequestParam String roleCode,
			@ApiParam(name="orgCode",value="组织编码",required=true)   @RequestParam String orgCode) throws Exception{
		if(StringUtil.isEmpty(roleCode)||StringUtil.isEmpty(orgCode)){
			throw new RequiredException("角色编码、组织编码不能为空！");
		}
		Set<GroupIdentity> groupIdentities = userService.getByRoleCodeAndOrgCode(roleCode, orgCode);
		return CommonResult.<Set<GroupIdentity>>ok().value(groupIdentities);
	}
	
	/**
	 * 根据职务编码、组织编码获取对应人员
	 * @param jobCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getByJobCodeAndOrgCode",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据职务编码、组织编码获取对应人员", httpMethod = "GET", notes = "根据职务编码、组织编码获取对应人员")
	public CommonResult<Set<GroupIdentity>> getByJobCodeAndOrgCode(@ApiParam(name="jobCode",value="职务编码",required=true)  @RequestParam String jobCode,
			@ApiParam(name="orgCode",value="组织编码",required=true)   @RequestParam String orgCode) throws Exception{
		if(StringUtil.isEmpty(jobCode)||StringUtil.isEmpty(orgCode)){
			throw new RequiredException("职务编码、组织编码不能为空！");
		}
		Set<GroupIdentity> groupIdentities = userService.getByJobCodeAndOrgCode(jobCode, orgCode);
		return CommonResult.<Set<GroupIdentity>>ok().value(groupIdentities);
	}
	
	/**
	 * 根据岗位编码、组织编码获取对应人员
	 * @param postCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getByPostCodeAndOrgCode",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据岗位编码、组织编码获取对应人员", httpMethod = "GET", notes = "根据岗位编码、组织编码获取对应人员")
	public CommonResult<Set<GroupIdentity>> getByPostCodeAndOrgCode(@ApiParam(name="postCode",value="岗位编码",required=true)  @RequestParam String postCode,
			@ApiParam(name="orgCode",value="组织编码",required=true)   @RequestParam String orgCode) throws Exception{
		if(StringUtil.isEmpty(postCode)||StringUtil.isEmpty(orgCode)){
			throw new RequiredException("岗位编码、组织编码不能为空！");
		}
		Set<GroupIdentity> groupIdentities = userService.getByPostCodeAndOrgCode(postCode, orgCode);
		return CommonResult.<Set<GroupIdentity>>ok().value(groupIdentities);
	}
	
	
	/**
	 *获取指定用户的所有上级（下属管理）
	 * @param postCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUpUsersByUser",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取指定用户的所有上级（下属管理）", httpMethod = "GET", notes = "获取指定用户的所有上级（下属管理）")
	public CommonResult<List<UserVo>> getUpUsersByUser(@ApiParam(name="account",value="账号",required=true)  @RequestParam String account) throws Exception{
		List<UserVo> userVoList = userService.getUpUsersByUser(account);
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}
	
	/**
	 *获取指定用户的所属上级（下属管理）
	 * @param postCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUpUserByUserAndOrg",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取指定用户在指定组织中的上级（下属管理）", httpMethod = "GET", notes = "获取指定用户在指定组织中的上级（下属管理）")
	public CommonResult<UserVo> getUpUserByUserAndOrg(@ApiParam(name="account",value="账号",required=true)  @RequestParam String account,
			@ApiParam(name="orgCode",value="组织编码",required=true)   @RequestParam String orgCode) throws Exception{
		if(StringUtil.isEmpty(account)||StringUtil.isEmpty(orgCode)){
			throw new RequiredException("用户帐号和组织编码不能为空！");
		}
		UserVo userVo = userService.getUpUserByUserAndOrg(account, orgCode);
		return CommonResult.<UserVo>ok().value(userVo);
	}
	
	
	/**
	 * 获取指定用户的所有下级（下属管理）
	 * @param postCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUnderUsersByUser",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取指定用户的所有下级（下属管理）", httpMethod = "GET", notes = "获取指定用户的所有下级（下属管理）")
	public CommonResult<List<UserVo>> getUnderUsersByUser(@ApiParam(name="account",value="账号",required=true)  @RequestParam String account) throws Exception{
		if(StringUtil.isEmpty(account)||StringUtil.isEmpty(account)){
			throw new RequiredException("用户帐号不能为空！");
		}
		List<UserVo> userVoList = userService.getUnderUsersByUser(account);
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}
	
	/**
	 * 获取指定用户在指定组织中的下级（下属管理）
	 * @param postCode
	 * @param orgCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUnderUserByUserAndOrg",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取指定用户在指定组织中的下级（下属管理）", httpMethod = "GET", notes = "获取指定用户在指定组织中的下级（下属管理）")
	public CommonResult<List<UserVo>> getUnderUserByUserAndOrg(@ApiParam(name="account",value="账号",required=true)  @RequestParam String account,
			@ApiParam(name="orgCode",value="组织编码",required=true)   @RequestParam String orgCode) throws Exception{
		List<UserVo> userVoList = userService.getUnderUserByUserAndOrg(account, orgCode);
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}
	
	/**
	 * 物理删除所有逻辑删除了的用户数据
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/deleteUserPhysical",method=RequestMethod.DELETE, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "物理删除所有逻辑删除了的用户数据", httpMethod = "DELETE", notes = "物理删除所有逻辑删除了的用户数据")
	public CommonResult<Integer> deleteUserPhysical() throws Exception{
		Integer num = userService.removePhysical();
		CommonResult<Integer> commonResult = OrgUtil.getRemovePhysiMsg(num);
		return CommonResultUtil.<Integer>getResult(commonResult);
	}
	
	/**
	 * 禁用用户
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/forbiddenUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户标识禁用用户（多个用,号隔开）", httpMethod = "POST", notes = "根据用户标识禁用用户（多个用,号隔开）参数 （任传一个）")
	public CommonResult<String> forbiddenUser(@ApiParam(name="userMark",value="用户标识") @RequestBody(required=false) UserMarkObject userMark) throws Exception{
		CommonResult<String> commonResult = userService.forbiddenUser(userMark);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 激活用户
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/activateUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户标识激活用户（多个用,号隔开）", httpMethod = "POST", notes = "根据用户标识激活用户（多个用,号隔开）参数 （任传一个）")
	public CommonResult<String> activateUser(@ApiParam(name="userMark",value="用户标识") @RequestBody(required=false) UserMarkObject userMark) throws Exception{
		CommonResult<String> commonResult = userService.activateUser(userMark);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 用户离职
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/leaveUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户标识用户离职（多个用,号隔开）", httpMethod = "POST", notes = "根据用户标识用户离职（多个用,号隔开）参数 （任传一个）")
	public CommonResult<String> leaveUser(@ApiParam(name="userMark",value="用户标识") @RequestBody(required=false) UserMarkObject userMark) throws Exception{
		CommonResult<String> commonResult = userService.leaveUser(userMark);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 通过岗位编码获取用户
	 * @param postCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUserByPost",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "通过岗位编码获取用户", httpMethod = "GET", notes = "通过岗位编码获取用户")
	public CommonResult<List<UserVo>> getUserByPost(@ApiParam(name="postCode",value="岗位编码(多个用”,“号分隔)",required=true)   @RequestParam String postCode) throws Exception{
		List<UserVo> userVoList = userService.getUserByPost(postCode);
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}
	
	@RequestMapping(value="users/exportUsers",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "导出用户组织数据", httpMethod = "POST", notes = "导出用户组织数据（可包含用户、机构、维度、组织、角色数据）")
	public void exportUsers(@ApiParam(name="isOrg",value="是否导出组织相关数据（包括维度、组织、职务、岗位已经之间的关系表数据）。默认为true",required=true)   @RequestParam Boolean isOrg,
			@ApiParam(name="isRole",value="是否导出角色以及用户角色关系数据。默认为true",required=true)   @RequestParam Boolean isRole,
			@ApiParam(name="isAll",value="是否导出查询条件的全部数据（false：只导出当前页）。默认为true",required=true)   @RequestParam Boolean isAll,
			@ApiParam(name="queryFilter",value="通用查询对象")@RequestBody QueryFilter queryFilter) throws Exception{
		HttpServletResponse response = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
		isOrg = BeanUtils.isEmpty(isOrg)?true:isOrg;
		isRole = BeanUtils.isEmpty(isRole)?true:isRole;
		isAll = BeanUtils.isEmpty(isAll)?true:isAll;
		String path = userService.exportUsers(isOrg, isRole, isAll, queryFilter);
		if(StringUtil.isNotEmpty(path)){
			String zipPath = path+".zip";
			File file = new File(zipPath);
			if(!file.exists()){
				throw new RuntimeException("生成zip文件失败！");
			}
			String zipName = file.getName();
			// 导出
			HttpUtil.downLoadFile(response, zipPath, zipName);
			// 删除导出的文件
			FileUtil.deleteFile(zipPath);
		}else{
			throw new RuntimeException("导出用户组织信息失败！");
		}
	}
	
	/**
	 * 导入用户
	 * @param user
	 * @param file
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/importZipUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "导入用户组织关系", httpMethod = "POST", notes = "导入用户组织关系")
	public CommonResult<String> importZipUser(@ApiParam(name="isNewCode",value="是否生成新编码。当编码在系统中已存在且对应名称不同时：true,编码加后缀生成新的编码导入；false：不导入数据及相关连数据。默认为true",required=true)   @RequestParam boolean isNewCode,
			@ApiParam(name="isCover",value="是否覆盖更新。如果编码和名称一样，则默认为同一条数据：true，将已导入数据为准，更新其他字段，false，不更新除关联字段以外的字段。默认为true",required=true)   @RequestParam boolean isCover,
			@ApiParam(name="isOrg",value="是否导入组织相关数据（包括维度、组织、职务、岗位已经之间的关系表数据）。默认为true",required=true)   @RequestParam boolean isOrg,
			@ApiParam(name="isRole",value="是否导入角色以及用户角色关系数据。默认为true",required=true)   @RequestParam boolean isRole,@ApiParam(name="file",value="导入的zip文件",required=true)   @RequestBody MultipartFile file) throws Exception{
		UserImportVo importVo = new UserImportVo();
		importVo.setNewCode(BeanUtils.isNotEmpty(isNewCode)?isNewCode:false);
		importVo.setCover(BeanUtils.isNotEmpty(isCover)?isCover:false);
		importVo.setOrg(BeanUtils.isNotEmpty(isOrg)?isOrg:false);
		importVo.setRole(BeanUtils.isNotEmpty(isRole)?isRole:false);
		CommonResult<String> commonResult = userImportService.importZipUser(file, importVo);
		return CommonResultUtil.<String>getResult(commonResult);
	} 
	
	/**
	 * 根据时间获取用户数据（数据同步）
	 * @param userExport
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUserByTime",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据时间获取用户数据（数据同步）", httpMethod = "POST", notes = "根据时间获取用户数据（数据同步）")
	public CommonResult<List<User>> getUserByTime(@ApiParam(name="userExport",value="获取用户参数",required=true) @RequestBody UserExportObject userExport) throws Exception{
		List<User> userList = userService.getUserByTime(userExport);
		return CommonResult.<List<User>>ok().value(userList);
	}
	
	/**
	 * 根据时间获取用户参数数据（数据同步）
	 * @param btime
	 * @param etime
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUserParamByTime",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据时间获取用户参数数据（数据同步）", httpMethod = "GET", notes = "根据时间获取用户参数数据（数据同步）")
	public CommonResult<List<UserParams>> getUserParamByTime(@ApiParam(name="btime",value="开始时间（格式：2018-01-01 12:00:00或2018-01-01）") @RequestParam(required=false) String btime,@ApiParam(name="etime",value="结束时间（格式：2018-02-01 12:00:00或2018-02-01）") @RequestParam(required=false) String etime) throws Exception{
		List<UserParams> userParamsList = userService.getUserParamByTime(btime, etime);
		return CommonResult.<List<UserParams>>ok().value(userParamsList);
	}
	
	/**
	 * 根据时间获取用户角色关系数据（数据同步）
	 * @param btime
	 * @param etime
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userRoles/getUserRoleByTime",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据时间获取用户角色关系数据（数据同步）", httpMethod = "GET", notes = "根据时间获取用户角色关系数据（数据同步）")
	public CommonResult<List<UserRole>> getUserRoleByTime(@ApiParam(name="btime",value="开始时间（格式：2018-01-01 12:00:00或2018-01-01）") @RequestParam(required=false) String btime,@ApiParam(name="etime",value="结束时间（格式：2018-02-01 12:00:00或2018-02-01）") @RequestParam(required=false) String etime) throws Exception{
		List<UserRole> userRoleList = userService.getUserRoleByTime(btime, etime);
		return CommonResult.<List<UserRole>>ok().value(userRoleList);
	}
	
	/**
	 * 根据时间获取用户角色关系数据（数据同步）
	 * @param btime
	 * @param etime
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="userRoles/userRolePage",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取用户的角色列表", httpMethod = "POST", notes = "获取用户的角色列表")
    public CommonResult<PageList<UserRole>> userRolePage(@ApiParam(name="queryFilter",value="通用查询对象") @RequestBody QueryFilter queryFilter) throws Exception{
        PageList<UserRole> userRolePage = userRoleService.getUserRolePage(queryFilter);
		return CommonResult.<PageList<UserRole>>ok().value(userRolePage);
    }


	/**
	 * 获取同步副本数据集合
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="dataSync/getSyncDataByTime",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取同步副本数据集合", httpMethod = "POST", notes = "获取同步副本数据集合（未填写开始和结束时间时为全量）")
	public CommonResult<DataSyncVo> getSyncDataByTime(@ApiParam(name="dataSync",value="副本数据同步获取参数类") @RequestBody(required=true) DataSyncObject dataSync) throws Exception{
		DataSyncVo syncDataByTime = userService.getSyncDataByTime(dataSync);
		return CommonResult.<DataSyncVo>ok().value(syncDataByTime);
	}
	
	/**
	 * 获取用户汇报关系图信息
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getUserRelCharts",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户标识获取用户汇报关系图信息", httpMethod = "GET", notes = "获取用户汇报关系图信息，参数 （账号、工号任传一个）")
	public CommonResult<ChartOption> getUserRelCharts(@ApiParam(name="account",value="用户账号") @RequestParam(required=false) String account,
			@ApiParam(name="userNumber",value="用户工号") @RequestParam(required=false) String userNumber) throws Exception{
		ChartOption chartOption = userService.getUserRelCharts(getJsonString(account, userNumber));
		return CommonResult.<ChartOption>ok().value(chartOption);

	}
	
	@RequestMapping(value="user/setStatus",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "批量设置用户状态", httpMethod = "POST", notes = "批量设置用户状态")
	public CommonResult<String> setStatus(@ApiParam(name="userStatusVo",value="用户状态变更请求参数") 
										  @RequestBody(required=true) UserStatusVo userStatusVo) throws Exception{
		userService.setStatus(userStatusVo);
		return CommonResult.<String>ok().message("设置成功！");
	}
	
	@RequestMapping(value="user/isAccountExist",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "查询账号是否已存在", httpMethod = "GET", notes = "查询账号是否已存在")
	public CommonResult<Boolean> isAccountExist(@ApiParam(name="account",value="账号")
												@RequestParam(required=true) String account) throws Exception{
		CommonResult<Boolean> commonResult = userService.isAccountExist(account);
		return CommonResultUtil.<Boolean>getResult(commonResult);
	}
	
	@RequestMapping(value="user/isUserNumberExist",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "查询工号是否已存在", httpMethod = "GET", notes = "查询工号是否已存在")
	public CommonResult<Boolean> isUserNumberExist(@ApiParam(name="account",value="账号")
												   @RequestParam(required=true) String account,
												   @ApiParam(name="userNumber",value="工号")
												   @RequestParam(required=true) String userNumber) throws Exception{
		CommonResult<Boolean> commonResult = userService.isUserNumberExist(account, userNumber);
		return CommonResultUtil.<Boolean>getResult(commonResult);
	}
	
	private PageList<UserVo> convertVoPageList(PageList<User> pageList){
		PageList<UserVo> voPageList = new PageList<UserVo>();
		 voPageList.setPage(pageList.getPage());
		 voPageList.setPageSize(pageList.getPageSize());
		 voPageList.setTotal(pageList.getTotal());
		 voPageList.setRows(OrgUtil.convertToUserVoList(pageList.getRows()));
		 return voPageList;
	 }
	
	private String getJsonString(String account,String userNumber) throws IOException{
		if(StringUtil.isEmpty(account)&&StringUtil.isEmpty(userNumber)){
			throw new RequiredException("帐号和工号必须填写其中一个，不能同时为空！");
		}
		ObjectNode json = JsonUtil.getMapper().createObjectNode();
		json.put("account", account);
		json.put("userNumber", userNumber);
		return JsonUtil.toJson(json);
	}
	
	/**
	 * 是否显示AD增量同步按钮
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/showADButton",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "用于是否显示AD增量同步按钮", httpMethod = "GET", notes = "用于是否显示AD增量同步按钮")
	public CommonResult<Boolean> showADButton() throws Exception{
		boolean flag = userService.showADButton();
		return CommonResult.<Boolean>ok().value(flag);
	}
	
	/**
	 * 修改个人密码
	 * @param userPwdObject
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/updateOneselfPsw",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "修改个人密码", httpMethod = "POST", notes = "用户修改个人密码）")
	public CommonResult<String> updateOneselfPsw(@ApiParam(name="userPwdObject",value="用户密码相关参数",required=true) @RequestBody UserPwdObject userPwdObject) throws Exception{
		CommonResult<String> commonResult = userService.updateOneselfPsw(userPwdObject);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	@RequestMapping(value="user/uploadPortrait",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "上传头像", httpMethod = "POST", notes = "上传头像")
	public CommonResult<String> uploadPortrait(@ApiParam(name="account",value="用户账号") 
											   @RequestParam(required=false) String account,
											   @ApiParam(name="file",value="上传的头像", required=true) 
											   @RequestParam MultipartFile file) throws Exception{
		CommonResult<String> commonResult = userService.uploadPortrait(account, file);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	@RequestMapping(value = "user/portrait/{account}/{filename:.+}", method = RequestMethod.GET)
	@ApiOperation(value = "下载头像", httpMethod = "GET", notes = "下载头像")
	public ResponseEntity<?> getFile(@PathVariable String account, @PathVariable String filename) {
		try {
			return ResponseEntity.ok(userService.downloadPortrait(account, filename));
		} catch (Exception e) {
			return ResponseEntity.notFound().build();
		}
	}
	
	/**
	 * 获取所有组织人员（带分页信息）
	 * @param queryFilter
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getAllOrgUsers",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取所有组织人员（带分页信息）", httpMethod = "POST", notes = "获取所有组织人员")
	public CommonResult<PageList<UserVo>> getAllOrgUsers(@ApiParam(name="queryFilter",value="通用查询对象")
	 @RequestBody QueryFilter queryFilter) throws Exception{
    	Page<User> query = (Page<User>)userService.getDemUserQuery(queryFilter);
		PageList<UserVo> userVoPageList = convertVoPageList(new PageList<User>(query));
		return CommonResult.<PageList<UserVo>>ok().value(userVoPageList);
	}
	
	@RequestMapping(value="user/setTrigger",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "修改计划定时任务执行时间", httpMethod = "POST", notes = "修改计划定时任务执行时间")
	public CommonResult<String> setTrigger(@ApiParam(name="triggerVo",value="计划定时任务vo类") 
										  @RequestBody(required=true) TriggerVo triggerVo,HttpServletRequest request) throws Exception{
		String ip = OrgUtil.getIpAddress(request);
		CommonResult<String> commonResult = userService.setTrigger(triggerVo, ip);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 获取用户信息
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getUserById",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户id获取用户信息", httpMethod = "GET", notes = "根据用户id获取用户信息")
	public CommonResult<UserVo> getUserById(@ApiParam(name="userId",value="用户ID") @RequestParam(required=false) String userId) throws Exception{
		CommonResult<UserVo> commonResult = userService.getUserById(userId);
		return CommonResultUtil.<UserVo>getResult(commonResult);
	}
	
	/**
	 * 根据email查询用户信息
	 * @param json
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getUserByEmail",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据email查询用户信息", httpMethod = "GET", notes = "根据email查询用户信息")
	public CommonResult<List<User>> getUserByEmail(@ApiParam(name="email",value="用户账号") @RequestParam(required=true) String email
			 ) throws Exception{
		List<User> userList = userService.getByUserEmail(email);
		return CommonResult.<List<User>>ok().value(userList);
	}
	
	@RequestMapping(value = "users/getCharges", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取用户主组织", httpMethod = "GET", notes = "获取用户主组织")
	public CommonResult<List<User>> getCharges(
		@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam String userId,
		@ApiParam(name = "isMain", value = "是否主负责人", required = true) @RequestParam Boolean isMain,
		@ApiParam(name = "isP", value = "是否上级部门", required = true) @RequestParam Boolean isP
		)throws Exception {
		List<User> list = new ArrayList<User>();
		Org org = orgManager.getMainGroup(userId, null);
		if(BeanUtils.isNotEmpty(org)){
			list = userService.getChargesByOrg(isP?org.getParentId():org.getCode(), isMain);
		}
		return CommonResult.<List<User>>ok().value(list);
	}
	
	@RequestMapping(value = "user/isAdmin", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取当前用户是否超级管理员", httpMethod = "GET", notes = "获取用户主组织")
	public CommonResult<Boolean> isAdmin()throws Exception {
		User user = ContextUtil.getCurrentUser();
		return CommonResult.<Boolean>ok().value(user.isAdmin()).message("获取成功！");
	}
	
	@RequestMapping(value = "users/getSuperFromUnder", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "通过组织中的下属设置获取上级人员", httpMethod = "GET", notes = "通过组织中的下属设置获取上级人员")
	public CommonResult<List<User>> getSuperFromUnder(
		@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam String userId,
		@ApiParam(name = "orgId", value = "组织id或编码", required = false) @RequestParam(required=false) String orgId,
		@ApiParam(name = "demId", value = "维度id或编码", required = false) @RequestParam(required=false) String demId
		)throws Exception {
		List<User> userList = userService.getSuperFromUnder(userId, orgId, demId);
		return CommonResult.<List<User>>ok().value(userList);
	}

	@RequestMapping(value = "users/getSuperiorFromUnder", method = RequestMethod.GET, produces = {
			"application/json; charset=utf-8" })
	@ApiOperation(value = "通过组织中的下属设置获取上级人员", httpMethod = "GET", notes = "通过组织中的下属设置获取上级人员")
	public CommonResult<List<User>> getSuperiorFromUnder(
			@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam String userId,
			@ApiParam(name = "demId", value = "维度id或编码", required = false) @RequestParam(required=false) String demId
	)throws Exception {
		List<User> userList = userService.getSuperiorFromUnder(userId, demId);
		return CommonResult.<List<User>>ok().value(userList);

	}
	
	@RequestMapping(value = "user/getUserMsg", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取app用户信息", httpMethod = "GET", notes = "获取app用户信息")
	public ResponseEntity<?> getUserMsg(
			@ApiParam(name = "account", value = "用户别名", required = false) @RequestParam String account
		)throws Exception {
		ResponseEntity<?> appUserMsg = userService.getAppUserMsg(account);
		return appUserMsg;
	}
	
	@RequestMapping(value = "user/getOrgMsg", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取app用户组织信息", httpMethod = "GET", notes = "获取app用户组织信息")
	public ResponseEntity<?> getOrgMsg(@ApiParam(name = "orgCode", value = "组织别名", required = false) @RequestParam String orgCode) throws Exception{
		ResponseEntity<?> appOrgMsg = userService.getAppOrgMsg(orgCode);
		return appOrgMsg;
	}
	
	@RequestMapping(value = "user/getUnderUsers", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取app用户的所有下属", httpMethod = "GET", notes = "获取app用户的所有下属")
	public ResponseEntity<?> getUnderUsers(@ApiParam(name = "userId", value = "用户id", required = false) @RequestParam String userId) throws Exception{
		try {
			List<User> list = userService.getUnderUsersByUserId(userId);
			return ResponseEntity.ok(list);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseEntity.notFound().build();
		}
	}
	
	@RequestMapping(value = "user/updateUserMessage", method = RequestMethod.POST, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "修改用户资料参数", httpMethod = "POST", notes = "修改用户资料参数")
	public Map<String,Object> updateUserMessage(@ApiParam(name = "params", value = "修改用户资料参数", required = false) @RequestBody Map<String,Object> params) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			if(!params.containsKey("account")){
				throw new Exception("缺少account参数");
			}
			User user = userService.getByAccount(params.get("account").toString());
			boolean flag = false;
			if(params.containsKey("mobile")) {
				flag = true;
				user.setMobile(params.get("mobile").toString());
			}
			if(params.containsKey("email")) {
				flag = true;
				user.setEmail(params.get("email").toString());
			}
			if(params.containsKey("fullname")) {
				flag = true;
				user.setFullname(params.get("fullname").toString());
			}
			if(params.containsKey("photo")) {
				flag = true;
				String fileId = params.getOrDefault("photo", "").toString();
				if(!"".equals(fileId)){
					String photo = "/system/file/v1/downloadFile?fileId="+fileId;
					user.setPhoto(photo);
					map.put("photo", photo);
				}
			}
			if(flag){
				userService.update(user);
			}
			map.put("success",true);
		} catch (Exception e) {
			map.put("success",false);
			map.put("message","系统错误");
			e.printStackTrace();
		}
		return map;
	}


	@RequestMapping(value="user/bindOpenId",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    @ApiOperation(value = "绑定公众号openid", httpMethod = "GET", notes = "绑定公众号openid")
    public CommonResult<String> bindOpenId(@ApiParam(name="account",value="用户账号") @RequestParam String account,
                                         @ApiParam(name="openid",value="用户openid") @RequestParam String openid) throws Exception{
		CommonResult<String> commonResult = userService.bindOpenId(account, openid);
		return CommonResultUtil.<String>getResult(commonResult);
	}


    @RequestMapping(value="user/bindMpOpenId",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    @ApiOperation(value = "绑定小程序openid", httpMethod = "GET", notes = "绑定小程序openid")
    public CommonResult<String> bindMpOpenId(@ApiParam(name="account",value="用户账号") @RequestParam String account,
    		@ApiParam(name="mpOpenid",value="mpOpenid") @RequestParam String mpOpenid) throws Exception{
		CommonResult<String> commonResult = userService.bindMpOpenId(account, mpOpenid);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	@RequestMapping(value = "user/getUserDetailed", method = RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取app用户的所有下属", httpMethod = "GET", notes = "按用户id查询所属组织")
	public Map<String,Object> getUserDetailed(@ApiParam(name = "userId", value = "用户id", required = false) @RequestParam String userId) throws Exception{
		Map<String, Object> map = userService.getUserDetailed(userId);
		return map;
	}
	
	/**
	 * 根据用户id获取用户所在部门负责人
	 * @param 用户账号
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getDepHeader",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户id获取用户所在部门负责人", httpMethod = "GET", notes = "根据用户id获取用户所在部门负责人（不传为当前人）")
	public CommonResult<List<UserVo>>  getDepHeader(@ApiParam(name = "userId", value = "用户id", required = false) @RequestParam Optional<String> userId,
			                          @ApiParam(name = "isMain", value = "是否只取主负责人", required = false) @RequestParam Optional<Boolean> isMain) throws Exception{
		String uid = userId.orElse(ContextUtil.getCurrentUserId());
		List<UserVo> userVoList = userService.getDepHeader(uid, isMain.orElse(false));
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}
	
	/**
	 * 根据部门id获取部门负责人
	 * @param 部门id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getDepHeaderByOrg",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据部门id获取部门负责人", httpMethod = "GET", notes = "根据部门id获取部门负责人")
	public CommonResult<List<UserVo>> getDepHeaderByOrg(@ApiParam(name = "orgId", value = "部门id", required = false) @RequestParam String orgId,
			                               @ApiParam(name = "isMain", value = "是否只取主负责人", required = false) @RequestParam Optional<Boolean> isMain) throws Exception{
		List<UserVo> userVoList = userService.getDepHeaderByOrg(orgId, isMain.orElse(false));
		return CommonResult.<List<UserVo>>ok().value(userVoList);

	}
	
	/**
	 * 根据用户id和用户组类型获取其相关用户组
	 * @param 部门id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="user/getGroupsByUidAndType",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户id和用户组类型获取其相关用户组", httpMethod = "GET", notes = "根据用户id和用户组类型获取其相关用户组")
	public CommonResult<List<Group>>  getGroupsByUidAndType(@ApiParam(name = "userId", value = "用户id", required = false) @RequestParam String userId,
			                                @ApiParam(name = "type", value = "类型", required = false) @RequestParam String type) throws Exception{
		List<Group> groupList = userService.getGroupsByUserId(userId, type);
		return CommonResult.<List<Group>>ok().value(groupList);

	}
	
	/**
	 * 查询用户组织关系
	 * @param queryFilter
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="user/queryOrgUserRel",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户id和用户组类型获取其相关用户组", httpMethod = "POST", notes = "根据用户id和用户组类型获取其相关用户组")
	public List queryOrgUserRel(@ApiParam(name="queryFilter",value="通用查询对象") @RequestBody QueryFilter queryFilter) throws Exception{
		return userService.queryOrgUserRel(queryFilter);
	}

	@RequestMapping(value = "user/getDetailByAccountOrId", method = RequestMethod.POST, produces = {
			"application/json; charset=utf-8" })
	@ApiOperation(value = "根据用户账号获取用户信息", httpMethod = "POST", notes = "根据用户账号获取用户信息")
	public Map<String, Object> getDetailByAccountOrId(
			@ApiParam(name = "account", value = "用户账号") @RequestBody AccountOrIdVo accountOrIdVo) throws Exception {
		return userService.getUserDetailByAccountOrId(accountOrIdVo.getAccountOrId());
	}
	
	/**
	 * 模糊查询获取用户列表
	 * @param key
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUserByNameaAndEmal",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "查询条件", httpMethod = "GET", notes = "模糊查询获取用户列表")
	public CommonResult<List<User>> getUserByNameaAndEmal(@ApiParam(name="key",value="查询条件", required = false)  @RequestParam String query) throws Exception{
		List<User> userList = userService.getUserByName(query);
		return CommonResult.<List<User>>ok().value(userList);

	}
	
	/**
	 * 根据节点处理人对象抽取处理人
	 * @param queryFilter
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/calculateNodeUser",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据节点处理人对象抽取处理人", httpMethod = "POST", notes = "根据节点处理人对象抽取处理人")
	public Map<String, Object> calculateNodeUser(@ApiParam(name="nodeMap",value="通用查询对象")
	 @RequestBody Map<String, Object> nodeMap) throws Exception{
		Map<String, Object> calculateNodeUser = userService.calculateNodeUser(nodeMap);
    	return calculateNodeUser;
	}

//    @RequestMapping(value = "users/syncUserToWx", method = RequestMethod.POST, produces = {"application/json; charset=utf-8" })
//    @ApiOperation(value = "根据用户ID同步微信通讯录", httpMethod = "POST", notes = "根据用户ID同步微信通讯录")
//    public CommonResult<String> syncUserToWx(@ApiParam(name="userId",value="查询条件", required = false)  @RequestParam String userId) throws Exception {
//        try {
//            String[] lAryId = StringUtil.getStringAryByStr(userId);
//            iwxUserService.syncUserToWx(lAryId);
//            return new CommonResult<String>(true,"同步用户成功");
//        } catch (Exception e) {
//            return new CommonResult<String>(false, "同步用户失败:"+e.getMessage());
//        }
//    }
    
    @RequestMapping(value = "user/getUserByOpenId", method = RequestMethod.GET, produces = {"application/json; charset=utf-8" })
    @ApiOperation(value = "根据微信公众号openId获取用户信息", httpMethod = "GET", notes = "根据微信公众号openId获取用户信息")
    public CommonResult<UserVo> getUserByOpenId(@ApiParam(name="openId",value="公众号openId", required = false)  @RequestParam String openId) throws Exception {
		CommonResult<UserVo> commonResult = userService.getUserByOpenId(openId);
		return CommonResultUtil.<UserVo>getResult(commonResult);
    }
    
    @RequestMapping(value = "user/getUserByMpOpenId", method = RequestMethod.GET, produces = {"application/json; charset=utf-8" })
    @ApiOperation(value = "根据微信公众号openId获取用户信息", httpMethod = "GET", notes = "根据微信公众号openId获取用户信息")
    public CommonResult<User> getUserByMpOpenId(@ApiParam(name="openId",value="公众号openId", required = false)  @RequestParam String openId) throws Exception {
		User user = userService.getUserByMpOpenId(openId);
		return CommonResult.<User>ok().value(user);
    }

    
    @RequestMapping(value = "user/getUserRightMapByIds", method = RequestMethod.GET, produces = {"application/json; charset=utf-8" })
    @ApiOperation(value = "根据传入的用户id集合，获取用户的权限集合", httpMethod = "GET", notes = "根据传入的用户id集合，获取用户的权限集合")
    public Map<String, Map<String, String>> getUserRightMapByIds(@ApiParam(name="ids",value="用户id集合")  @RequestParam(required = false) Optional<String> ids) throws Exception {
    	String[] split = ids.orElse("").split(",");
    	List<String> asList = Arrays.asList(split);
    	Set<String> hashSet = new HashSet<>(asList);
    	return userService.getUserRightMapByIds(hashSet);
    }

    @RequestMapping(value="user/getUserByIds",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    @ApiOperation(value = "根据多个用户id获取用户信息(以逗号隔开)", httpMethod = "GET", notes = "根据多个用户id获取用户信息(以逗号隔开)")
    public CommonResult<List<UserVo>> getUserByIds(@ApiParam(name="ids",value="用户id") @RequestParam(required=true) String ids) throws Exception{
        QueryFilter queryFilter = QueryFilter.build();
        queryFilter.addFilter("ID_", ids, QueryOP.IN);
        List<UserVo> users = userService.queryUser(queryFilter);
		return CommonResult.<List<UserVo>>ok().value(users);
    }

    @RequestMapping(value = "user/getUserByMobile", method = RequestMethod.GET, produces = {"application/json; charset=utf-8" })
    @ApiOperation(value = "根据手机号获取用户信息", httpMethod = "GET", notes = "根据手机号获取用户信息")
	public CommonResult<UserVo> getUserByMobile(String mobile) {
		CommonResult<UserVo> commonResult = userService.getUserByMobile(mobile);
		return CommonResultUtil.<UserVo>getResult(commonResult);
	}
    
    @RequestMapping(value="user/addUserFromExterUni",method=RequestMethod.POST, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "添加用户", httpMethod = "POST", notes = "添加用户")
	public CommonResult<User> addUserFromExterUni(@ApiParam(name = "newUser", value = "用户", required = true) @RequestBody UserVo newUser) throws Exception {
		User user = userService.addUser(newUser);
		return CommonResult.<User>ok().value(user);

	}
    @RequestMapping(value = "user/getUserInfoBySignData", method = RequestMethod.POST, produces = {"application/json; charset=utf-8" })
    @ApiOperation(value = "根据签署数据获取用户信息", httpMethod = "POST", notes = "根据签署数据获取用户信息")
	public ArrayNode getUserInfoBySignData(ArrayNode customSignDatas) throws Exception {
    	return userService.getUserInfoBySignData(customSignDatas);
	}

	@RequestMapping(value = "user/getTokenByUserUserName", method = RequestMethod.POST)
	@ApiOperation(value = "根据用户的用户名，拿到用户的Token信息，实现系统内登录", httpMethod = "POST", notes = "获取Token信息")
	public CommonResult<String> getTokenByUserUserName(@ApiParam(name="username",value="用户名") @RequestParam(required=false) String username){
		CommonResult<String> commonResult = userService.getTokenByUserName(username);
		return CommonResultUtil.<String>getResult(commonResult);
	}

	@RequestMapping(value = "user/excelExport", method = RequestMethod.POST, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "导出用户", httpMethod = "POST", notes = "导出用户")
	public void excelExport(@ApiParam(name="users", value = "用户") @RequestBody List<String> users,
									HttpServletResponse httpServletResponse) throws Exception{
		userService.userExport(users,httpServletResponse);
	}


	@PostMapping(value = "user/setUnderUser",produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "设置下属用户", httpMethod = "POST", notes = "设置下属用户")
	public CommonResult<String> setUnderUser(@RequestBody UserUnderVo userUnderVo) throws Exception{
		userUnderManager.setUnderUser(userUnderVo);
		return CommonResult.<String>ok().message("下属设置成功");
	}

	@GetMapping(value = "user/superior",produces = {"application/json; charset=utf-8" })
	public CommonResult<UserVo> getSuperior(@RequestParam("underId") String underId, @RequestParam("demId") String demId) throws Exception{
		 User superior = userUnderManager.getSuperior(underId, demId);
		 UserVo userVo = OrgUtil.convertToUserVo(superior);
		return CommonResult.<UserVo>ok().value(userVo);
	}
	/**
	 * 设置或更新用户设备信息
	 * @param clientInfo
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "user/updateClientInfo",produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "设置或更新用户设备信息", httpMethod = "POST", notes = "设置或更新用户设备信息")
	public CommonResult<String> updateClientInfo(@RequestBody ClientInfo clientInfo) throws Exception{
		User user = userService.getByAccount(clientInfo.getAccount());
		String clientId = clientInfo.getClientId()!=null ? clientInfo.getClientId() : "";
		String clientToken = clientInfo.getClientToken()!=null ? clientInfo.getClientToken() : "";
		if(BeanUtils.isNotEmpty(clientId)
			&& (!clientId.equals(user.getClientId()) || !clientToken.equals(user.getClientToken()))){
			user.setClientId(clientId);
			user.setClientToken(clientToken);
			userService.update(user);
			this.deleteUserFromCache(clientInfo.getAccount());
		}
		return CommonResult.<String>ok().message("信息设备信息成功");
	}
	/**
	 * 删除缓存的用户详情
	 * <p>该方法没有方法体，通过注解在切面中删除缓存数据</p>
	 * @param userAccount
	 */
	private void deleteUserFromCache(String userAccount) {
		UserController2 bean = AppUtil.getBean(getClass());
		bean.removeUserFromCache(userAccount);
	}
	
	/**
	 * 根据用户账号删除缓存用户信息
	 * @param username 用户账号
	 */
	@CacheEvict(value = CacheKeyConst.EIP_UC_USER_NAME, key = "#username")
	protected void removeUserFromCache(String username) {}
	
	@PostMapping(value = "/shift/users",produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "获取排班用户", httpMethod = "POST", notes = "获取排班用户")
	public CommonResult<PageList> getShiftUser(@RequestBody QueryFilter queryFilter) throws Exception{
		IPage page = userService.selectShiftUser(queryFilter);
		PageList pageList = new PageList<>(page);
		return CommonResult.<PageList>ok().value(pageList);
	}
	/**
	 * 获取还没进行微信同步的用户
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUsersNotYetSyncWxWork",method=RequestMethod.GET, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "获取还没进行微信同步的用户", httpMethod = "GET", notes = "获取还没进行微信同步的用户")
	public CommonResult<List<User>> getUsersNotYetSyncWxWork() throws Exception{
		List<User> userList = userService.getUsersNotYetSyncWxWork();
		return CommonResult.<List<User>>ok().value(userList);

	}
	/**
	 * 获取还没进行钉钉的用户
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/getUsersNotYetSyncDingtalk",method=RequestMethod.GET, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "获取还没进行钉钉的用户", httpMethod = "GET", notes = "获取还没进行钉钉的用户")
	public CommonResult<List<User>> getUsersNotYetSyncDingtalk() throws Exception{
		List<User> userList = userService.getUsersNotYetSyncDingtalk();
		return CommonResult.<List<User>>ok().value(userList);

	}
	/**
	 * 根据微信通讯录的userid获取绑定的用户的用户信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="getUserByWxWorkId",method=RequestMethod.GET, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "根据微信通讯录的userid获取绑定的用户的用户信息", httpMethod = "GET", notes = "根据微信通讯录的userid获取绑定的用户的用户信息")
	public CommonResult<User> getUserByWxWorkId(@RequestParam(value="wxWorkId",required=true) String wxWorkId) throws Exception{
		User user = userService.getUserByWxWorkId(wxWorkId);
		return CommonResult.<User>ok().value(user);
	}
	/**
	 * 根据钉钉通讯录的userid获取绑定的用户的用户信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="getUserByDingtalkId",method=RequestMethod.GET, produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "根据钉钉通讯录的userid获取绑定的用户的用户信息", httpMethod = "GET", notes = "根据钉钉通讯录的userid获取绑定的用户的用户信息")
	public CommonResult<User> getUserByDingtalkId(@RequestParam(value="dingtalkId",required=true) String dingtalkId) throws Exception{
		User user = userService.getUserByDingtalkId(dingtalkId);
		return CommonResult.<User>ok().value(user);

	}

	/**
	 *获取用户列表（带分页和主组织信息）
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="users/queryUserWithMainOrgPost",method=RequestMethod.POST, produces = {
			"application/json; charset=utf-8" })
	@ApiOperation(value = "获取用户列表（带分页和主组织信息）", httpMethod = "POST", notes = "获取用户列表（带分页和主组织信息）")
	public PageList<Map<String, Object>> queryUserWithMainOrgPost(@ApiParam(name="isMobile",value="是否是手机端") @RequestParam Optional<Boolean> isMobile,@ApiParam(name="queryFilter",value="通用查询对象") @RequestBody QueryFilter queryFilter) throws Exception{
		if(isMobile.orElse(false) && (queryFilter.getQuerys().size()==0 || BeanUtils.isEmpty(queryFilter.getQuerys()))){
			//如果是手机端端 并且有我的群组
			QueryWrapper wrapper = new QueryWrapper();
			wrapper.eq("create_by_",ContextUtil.getCurrentUserId());
			List<UcGroup> list = ucGroupManager.list(wrapper);
			if(!list.isEmpty()){
				List<String> groupIds=new ArrayList();
				list.forEach(item->groupIds.add(item.getId()));
				queryFilter.addFilter("GROUP_ID_",groupIds,QueryOP.IN);
				return userService.loadUsersByGropuId(queryFilter);
			}else{
				return userService.queryUserWithMainOrgPost(queryFilter);
			}
		}
		return userService.queryUserWithMainOrgPost(queryFilter);
	}

	@RequestMapping(value="users/loadUsersByGropuId",method=RequestMethod.POST, produces = {
			"application/json; charset=utf-8" })
	@ApiOperation(value = "获取用户列表（带分页和主组织信息）", httpMethod = "POST", notes = "获取用户列表（带分页和主组织信息）")
	public PageList<Map<String, Object>> loadUsersByGropuId(@ApiParam(name="queryFilter",value="通用查询对象") @RequestBody QueryFilter queryFilter) throws Exception{
		return userService.loadUsersByGropuId(queryFilter);
	}
	


	@RequestMapping(value = "users/getByCompanyRole", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
	@ApiOperation(value = "获取在改组织下的角色用户", httpMethod = "GET", notes = "获取在改组织下的角色用户")
	public CommonResult<List<User>> getByCompanyRole(@ApiParam(name = "company", value = "组织编码") @RequestParam(required = true) String company,
													 @ApiParam(name = "role", value = "角色编码") @RequestParam(required = true) String role) throws Exception {
		List<User> userList = baseService.getByCompanyRole(company, role);
		return CommonResult.<List<User>>ok().value(userList);
	}

	@RequestMapping(value = "users/getLeaderStep", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
	@ApiOperation(value = "获取当前发起人的递归上级", httpMethod = "GET", notes = "获取当前发起人的递归上级")
	public CommonResult<List<UserVo>> getLeaderStep(@ApiParam(name = "userId", value = "用户Id") @RequestParam(required = true) String userId,
									  @ApiParam(name = "grade", value = "组织级别") @RequestParam(required = true) Integer grade,
									  @ApiParam(name = "res", value = "是否需要上级领导") @RequestParam(required = true) boolean res) throws Exception {
		List<UserVo> userVoList = userService.getLeaderStep(userId, grade, res);
		return CommonResult.<List<UserVo>>ok().value(userVoList);
	}

	@RequestMapping(value = "users/getFgUsers", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
	@ApiOperation(value = "通过组织中的下属设置获取上级人员", httpMethod = "GET", notes = "通过组织中的下属设置获取上级人员")
	public CommonResult<List<User>> getFgUsers(@ApiParam(name = "orgId", value = "组织Id", required = true) @RequestParam String orgId,
											   @ApiParam(name = "orgParam", value = "组织扩展参数别名", required = false) @RequestParam String orgParam,
											   @ApiParam(name = "userParam", value = "用户扩展参数别名", required = false) @RequestParam String userParam) throws Exception {
		List<User> userList = baseService.getFgUsers(orgId, orgParam, userParam);
		return CommonResult.<List<User>>ok().value(userList);

	}

	@RequestMapping(value="users/getLeaderStepByOrgId",method=RequestMethod.GET, produces = {"application/json;charset=utf-8"})
	@ApiOperation(value = "根据组织ID获取逐级审批", httpMethod = "GET", notes = "根据组织ID获取逐级审批")
	public CommonResult<List<UserVo>> getLeaderStepByOrgId(@ApiParam(name = "orgId", value = "用户Id") @RequestParam(required = true) String orgId,
											 @ApiParam(name = "grade", value = "组织级别") @RequestParam(required = true) Integer grade) throws Exception {
		List<UserVo> userVoList = userService.getLeaderStepByOrgId(orgId, grade);
		return CommonResult.<List<UserVo>>ok().value(userVoList);

	}

	@RequestMapping(value="user/getUsersByCodes",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" })
	@ApiOperation(value = "根据多个用户code获取用户信息(以逗号隔开)", httpMethod = "GET", notes = "根据多个用户code获取用户信息(以逗号隔开)")
	public CommonResult<List<UserVo>> getUsersByCodes(@ApiParam(name="codes",value="用户codes") @RequestParam(required=true) String codes) throws Exception{
		QueryFilter queryFilter = QueryFilter.build();
		queryFilter.addFilter("CODE_", codes, QueryOP.IN);
		List<UserVo> users = userService.queryUser(queryFilter);
		return CommonResult.<List<UserVo>>ok().value(users);
	}
}
