org.jeecg.modules.system.entity.SysUser Java Examples

The following examples show how to use org.jeecg.modules.system.entity.SysUser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SysUserDepartServiceImpl.java    From teaching with Apache License 2.0 6 votes vote down vote up
/**
 * 根据部门id查询用户信息
 */
@Override
public List<SysUser> queryUserByDepId(String depId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.eq(SysUserDepart::getDepId, depId);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example #2
Source File: SysUserController.java    From teaching with Apache License 2.0 6 votes vote down vote up
/**
 * 获取用户列表  根据用户名和真实名 模糊匹配
 * @param keyword
 * @param pageNo
 * @param pageSize
 * @return
 */
@GetMapping("/appUserList")
public Result<?> appUserList(@RequestParam(name = "keyword", required = false) String keyword,
		@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
		@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
	try {
		//TODO 从查询效率上将不要用mp的封装的page分页查询 建议自己写分页语句
		LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<SysUser>();
		query.eq(SysUser::getActivitiSync, "1");
		query.eq(SysUser::getDelFlag,"0");
		query.and(i -> i.like(SysUser::getUsername, keyword).or().like(SysUser::getRealname, keyword));
		
		Page<SysUser> page = new Page<>(pageNo, pageSize);
		IPage<SysUser> res = this.sysUserService.page(page, query);
		return Result.ok(res);
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		return Result.error(500, "查询失败:" + e.getMessage());
	}
	
}
 
Example #3
Source File: ThirdLoginController.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping(value = "/getLoginUser/{token}", method = RequestMethod.GET)
@ResponseBody
public Result<JSONObject> getLoginUser(@PathVariable("token") String token) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	String username = JwtUtil.getUsername(token);
	
	//1. 校验用户是否有效
	SysUser sysUser = sysUserService.getUserByName(username);
	result = sysUserService.checkUserIsEffective(sysUser);
	if(!result.isSuccess()) {
		return result;
	}
	JSONObject obj = new JSONObject();
	//用户登录信息
	obj.put("userInfo", sysUser);
	//token 信息
	obj.put("token", token);
	result.setResult(obj);
	result.setSuccess(true);
	result.setCode(200);
	sysBaseAPI.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null);
	return result;
}
 
Example #4
Source File: SysUserDepartServiceImpl.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 根据部门id查询用户信息
 */
@Override
public List<SysUser> queryUserByDepId(String depId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.eq(SysUserDepart::getDepId, depId);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example #5
Source File: SysUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/queryById", method = RequestMethod.GET)
public Result<SysUser> queryById(@RequestParam(name = "id", required = true) String id) {
    Result<SysUser> result = new Result<SysUser>();
    SysUser sysUser = sysUserService.getById(id);
    if (sysUser == null) {
        result.error500("未找到对应实体");
    } else {
        result.setResult(sysUser);
        result.setSuccess(true);
    }
    return result;
}
 
Example #6
Source File: LoginController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 用户信息
 *
 * @param sysUser
 * @param result
 * @return
 */
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
	String syspassword = sysUser.getPassword();
	String username = sysUser.getUsername();
	// 生成token
	String token = JwtUtil.sign(username, syspassword);
       // 设置token缓存有效时间
	redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);

	//------------------------------------------------------------------------------------------
	LoginUser vo = new LoginUser();
	BeanUtils.copyProperties(sysUser,vo);
	vo.setPassword(SecureUtil.md5(sysUser.getPassword()));
	redisUtil.set(CacheConstant.SYS_USERS_CACHE_JWT +":" +token, vo);
	//------------------------------------------------------------------------------------------
	redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);

	// 获取用户部门信息
	JSONObject obj = new JSONObject();
	List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
	obj.put("departs", departs);
	if (departs == null || departs.size() == 0) {
		obj.put("multi_depart", 0);
	} else if (departs.size() == 1) {
		sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
		obj.put("multi_depart", 1);
	} else {
		obj.put("multi_depart", 2);
	}
	obj.put("token", token);
	obj.put("userInfo", sysUser);
	obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
	result.setResult(obj);
	result.success("登录成功");
	return result;
}
 
Example #7
Source File: SysUserDepartServiceImpl.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode,String realname) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		LambdaQueryWrapper<SysUser> queryUser = new LambdaQueryWrapper<SysUser>();
		queryUser.in(SysUser::getId,userIdList);
		if(oConvertUtils.isNotEmpty(realname)){
			queryUser.like(SysUser::getRealname,realname.trim());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.list(queryUser);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example #8
Source File: SysUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门id查询用户信息
 *
 * @param id
 * @return
 */
@RequestMapping(value = "/queryUserByDepId", method = RequestMethod.GET)
public Result<List<SysUser>> queryUserByDepId(@RequestParam(name = "id", required = true) String id) {
    Result<List<SysUser>> result = new Result<>();
    //List<SysUser> userList = sysUserDepartService.queryUserByDepId(id);
    SysDepart sysDepart = sysDepartService.getById(id);
    List<SysUser> userList = sysUserDepartService.queryUserByDepCode(sysDepart.getOrgCode());

    //批量查询用户的所属部门
    //step.1 先拿到全部的 useids
    //step.2 通过 useids,一次性查询用户的所属部门名字
    List<String> userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList());
    if(userIds!=null && userIds.size()>0){
        Map<String,String>  useDepNames = sysUserService.getDepNamesByUserIds(userIds);
        userList.forEach(item->{
            //TODO 临时借用这个字段用于页面展示
            item.setOrgCode(useDepNames.get(item.getId()));
        });
    }

    try {
        result.setSuccess(true);
        result.setResult(userList);
        return result;
    } catch (Exception e) {
    	log.error(e.getMessage(), e);
        result.setSuccess(false);
        return result;
    }
}
 
Example #9
Source File: SysUserDepartServiceImpl.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode,String realname) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		LambdaQueryWrapper<SysUser> queryUser = new LambdaQueryWrapper<SysUser>();
		queryUser.in(SysUser::getId,userIdList);
		if(oConvertUtils.isNotEmpty(realname)){
			queryUser.like(SysUser::getRealname,realname.trim());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.list(queryUser);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example #10
Source File: SysUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 首页用户重置密码
 */
@RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
public Result<?> changPassword(@RequestBody JSONObject json) {
	String username = json.getString("username");
	String oldpassword = json.getString("oldpassword");
	String password = json.getString("password");
	String confirmpassword = json.getString("confirmpassword");
	SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
	if(user==null) {
		return Result.error("用户不存在!");
	}
	return sysUserService.resetPassword(username,oldpassword,password,confirmpassword);
}
 
Example #11
Source File: SysUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 还原被逻辑删除的用户
 *
 * @param userIds 被还原的用户ID,是个 list 集合
 * @return
 */
@PutMapping("/recycleBin")
public Result putRecycleBin(@RequestBody List<String> userIds, HttpServletRequest request) {
    if (userIds != null && userIds.size() > 0) {
        SysUser updateUser = new SysUser();
        updateUser.setUpdateBy(JwtUtil.getUserNameByToken(request));
        updateUser.setUpdateTime(new Date());
        sysUserService.revertLogicDeleted(userIds, updateUser);
    }
    return Result.ok("还原成功");
}
 
Example #12
Source File: LoginController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 用户信息
 *
 * @param sysUser
 * @param result
 * @return
 */
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
	String syspassword = sysUser.getPassword();
	String username = sysUser.getUsername();
	// 生成token
	String token = JwtUtil.sign(username, syspassword);
       // 设置token缓存有效时间
	redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
	redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);

	// 获取用户部门信息
	JSONObject obj = new JSONObject();
	List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
	obj.put("departs", departs);
	if (departs == null || departs.size() == 0) {
		obj.put("multi_depart", 0);
	} else if (departs.size() == 1) {
		sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
		obj.put("multi_depart", 1);
	} else {
		obj.put("multi_depart", 2);
	}
	obj.put("token", token);
	obj.put("userInfo", sysUser);
	obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
	result.setResult(obj);
	result.success("登录成功");
	return result;
}
 
Example #13
Source File: LoginController.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
/**
 * 用户信息
 *
 * @param sysUser
 * @param result
 * @return
 */
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
	String syspassword = sysUser.getPassword();
	String username = sysUser.getUsername();
	// 生成token
	String token = JwtUtil.sign(username, syspassword);
       // 设置token缓存有效时间
	redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
	redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);

	// 获取用户部门信息
	JSONObject obj = new JSONObject();
	List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
	obj.put("departs", departs);
	if (departs == null || departs.size() == 0) {
		obj.put("multi_depart", 0);
	} else if (departs.size() == 1) {
		sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
		obj.put("multi_depart", 1);
	} else {
		obj.put("multi_depart", 2);
	}
	obj.put("token", token);
	obj.put("userInfo", sysUser);
	result.setResult(obj);
	result.success("登录成功");
	return result;
}
 
Example #14
Source File: TestWebController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@PostMapping("/login")
public ResponseBean login(@RequestParam("username") String username,
                          @RequestParam("password") String password) {
	SysUser user = userService.getUserByName(username);
	if(user==null) {
		return new ResponseBean(200, "用户不存在!", JwtUtil.sign(username, user.getPassword()));
	}
	String passwordEncode = PasswordUtil.encrypt(username, password, user.getSalt());
    if (passwordEncode.equals(user.getPassword())) {
        return new ResponseBean(200, "Login success", JwtUtil.sign(username, user.getPassword()));
    } else {
        throw new UnauthorizedException();
    }
}
 
Example #15
Source File: LoginController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 用户信息
 *
 * @param sysUser
 * @param result
 * @return
 */
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
	String syspassword = sysUser.getPassword();
	String username = sysUser.getUsername();
	// 生成token
	String token = JwtUtil.sign(username, syspassword);
       // 设置token缓存有效时间
	redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
	redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);

	// 获取用户部门信息
	JSONObject obj = new JSONObject();
	List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
	obj.put("departs", departs);
	if (departs == null || departs.size() == 0) {
		obj.put("multi_depart", 0);
	} else if (departs.size() == 1) {
		sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
		obj.put("multi_depart", 1);
	} else {
		obj.put("multi_depart", 2);
	}
	obj.put("token", token);
	obj.put("userInfo", sysUser);
	result.setResult(obj);
	result.success("登录成功");
	return result;
}
 
Example #16
Source File: LoginController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 手机号登录接口
 * 
 * @param jsonObject
 * @return
 */
@ApiOperation("手机号登录接口")
@PostMapping("/phoneLogin")
public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
	Result<JSONObject> result = new Result<JSONObject>();
	String phone = jsonObject.getString("mobile");
	
	//校验用户有效性
	SysUser sysUser = sysUserService.getUserByPhone(phone);
	result = sysUserService.checkUserIsEffective(sysUser);
	if(!result.isSuccess()) {
		return result;
	}
	
	String smscode = jsonObject.getString("captcha");
	Object code = redisUtil.get(phone);
	if (!smscode.equals(code)) {
		result.setMessage("手机验证码错误");
		return result;
	}
	//用户信息
	userInfo(sysUser, result);
	//添加日志
	sysBaseAPI.addLog("用户名: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null);

	return result;
}
 
Example #17
Source File: TeachingUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/info")
Result<SysUser> info() {
    Result<SysUser> result = new Result();
    LoginUser loginUser = getCurrentUser();
    SysUser user = sysUserService.getById(loginUser.getId());
    result.setResult(user);
    return result;
}
 
Example #18
Source File: TestWebController.java    From teaching with Apache License 2.0 5 votes vote down vote up
@PostMapping("/login")
public ResponseBean login(@RequestParam("username") String username,
                          @RequestParam("password") String password) {
	SysUser user = userService.getUserByName(username);
	if(user==null) {
		return new ResponseBean(200, "用户不存在!", JwtUtil.sign(username, user.getPassword()));
	}
	String passwordEncode = PasswordUtil.encrypt(username, password, user.getSalt());
    if (passwordEncode.equals(user.getPassword())) {
        return new ResponseBean(200, "Login success", JwtUtil.sign(username, user.getPassword()));
    } else {
        throw new UnauthorizedException();
    }
}
 
Example #19
Source File: SysUserDepartServiceImpl.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example #20
Source File: SysUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * @功能:根据id 批量查询
 * @param userIds
 * @return
 */
@RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
public Result<Collection<SysUser>> queryByIds(@RequestParam String userIds) {
	Result<Collection<SysUser>> result = new Result<>();
	String[] userId = userIds.split(",");
	Collection<String> idList = Arrays.asList(userId);
	Collection<SysUser> userRole = sysUserService.listByIds(idList);
	result.setSuccess(true);
	result.setResult(userRole);
	return result;
}
 
Example #21
Source File: SysUserController.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 根据 orgCode 查询用户,包括子部门下的用户
 * 若某个用户包含多个部门,则会显示多条记录,可自行处理成单条记录
 */
@GetMapping("/queryByOrgCode")
public Result<?> queryByDepartId(
        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "orgCode") String orgCode,
        SysUser userParams
) {
    IPage<SysUserSysDepartModel> pageList = sysUserService.queryUserByOrgCode(orgCode, userParams, new Page(pageNo, pageSize));
    return Result.ok(pageList);
}
 
Example #22
Source File: SysUserController.java    From teaching with Apache License 2.0 4 votes vote down vote up
/**
 * 部门用户列表
 */
@RequestMapping(value = "/departUserList", method = RequestMethod.GET)
public Result<IPage<SysUser>> departUserList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
    Result<IPage<SysUser>> result = new Result<IPage<SysUser>>();
    Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
    String depId = req.getParameter("depId");
    String username = req.getParameter("username");
    //根据部门ID查询,当前和下级所有的部门IDS
    List<String> subDepids = new ArrayList<>();
    //部门id为空时,查询我的部门下所有用户
    if(oConvertUtils.isEmpty(depId)){
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        int userIdentity = user.getIdentity() != null?user.getIdentity():CommonConstant.USER_IDENTITY_1;
        if(oConvertUtils.isNotEmpty(userIdentity) && userIdentity == CommonConstant.USER_IDENTITY_2 ){
            subDepids = sysDepartService.getMySubDepIdsByDepId(user.getDepartIds());
        }
    }else{
        subDepids = sysDepartService.getSubDepIdsByDepId(depId);
    }
    if(subDepids != null && subDepids.size()>0){
        IPage<SysUser> pageList = sysUserService.getUserByDepIds(page,subDepids,username);
        //批量查询用户的所属部门
        //step.1 先拿到全部的 useids
        //step.2 通过 useids,一次性查询用户的所属部门名字
        List<String> userIds = pageList.getRecords().stream().map(SysUser::getId).collect(Collectors.toList());
        if(userIds!=null && userIds.size()>0){
            Map<String, String> useDepNames = sysUserService.getDepNamesByUserIds(userIds);
            pageList.getRecords().forEach(item -> {
                //批量查询用户的所属部门
                item.setOrgCode(useDepNames.get(item.getId()));
            });
        }
        result.setSuccess(true);
        result.setResult(pageList);
    }else{
        result.setSuccess(true);
        result.setResult(null);
    }
    return result;
}
 
Example #23
Source File: SysUserController.java    From teaching with Apache License 2.0 4 votes vote down vote up
/**
 * 根据 orgCode 查询用户,包括子部门下的用户
 * 针对通讯录模块做的接口,将多个部门的用户合并成一条记录,并转成对前端友好的格式
 */
@GetMapping("/queryByOrgCodeForAddressList")
public Result<?> queryByOrgCodeForAddressList(
        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "orgCode",required = false) String orgCode,
        SysUser userParams
) {
    IPage page = new Page(pageNo, pageSize);
    IPage<SysUserSysDepartModel> pageList = sysUserService.queryUserByOrgCode(orgCode, userParams, page);
    List<SysUserSysDepartModel> list = pageList.getRecords();

    // 记录所有出现过的 user, key = userId
    Map<String, JSONObject> hasUser = new HashMap<>(list.size());

    JSONArray resultJson = new JSONArray(list.size());

    for (SysUserSysDepartModel item : list) {
        String userId = item.getSysUser().getId();
        // userId
        JSONObject getModel = hasUser.get(userId);
        // 之前已存在过该用户,直接合并数据
        if (getModel != null) {
            String departName = getModel.get("departName").toString();
            getModel.put("departName", (departName + " | " + item.getSysDepart().getDepartName()));
        } else {
            // 将用户对象转换为json格式,并将部门信息合并到 json 中
            JSONObject json = JSON.parseObject(JSON.toJSONString(item.getSysUser()));
            json.remove("id");
            json.put("userId", userId);
            json.put("departId", item.getSysDepart().getId());
            json.put("departName", item.getSysDepart().getDepartName());

            resultJson.add(json);
            hasUser.put(userId, json);
        }
    }

    IPage<JSONObject> result = new Page<>(pageNo, pageSize, pageList.getTotal());
    result.setRecords(resultJson.toJavaList(JSONObject.class));
    return Result.ok(result);
}
 
Example #24
Source File: CasClientController.java    From jeecg-boot-with-activiti with MIT License 4 votes vote down vote up
@GetMapping("/validateLogin")
public Object validateLogin(@RequestParam(name="ticket") String ticket,
							@RequestParam(name="service") String service,
							HttpServletRequest request,
							HttpServletResponse response) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	log.info("Rest api login.");
	try {
		String validateUrl = prefixUrl+"/p3/serviceValidate";
		String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service);
		log.info("res."+res);
		final String error = XmlUtils.getTextForElement(res, "authenticationFailure");
		if(StringUtils.isNotEmpty(error)) {
			throw new Exception(error);
		}
		final String principal = XmlUtils.getTextForElement(res, "user");
		if (StringUtils.isEmpty(principal)) {
            throw new Exception("No principal was found in the response from the CAS server.");
        }
		log.info("-------token----username---"+principal);
	    //1. 校验用户是否有效
  		SysUser sysUser = sysUserService.getUserByName(principal);
  		result = sysUserService.checkUserIsEffective(sysUser);
  		if(!result.isSuccess()) {
  			return result;
  		}
 		String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword());
 		// 设置超时时间
 		redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
 		redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
  		//获取用户部门信息
		JSONObject obj = new JSONObject();
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		obj.put("departs", departs);
		if (departs == null || departs.size() == 0) {
			obj.put("multi_depart", 0);
		} else if (departs.size() == 1) {
			sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode());
			obj.put("multi_depart", 1);
		} else {
			obj.put("multi_depart", 2);
		}
		obj.put("token", token);
		obj.put("userInfo", sysUser);
		result.setResult(obj);
		result.success("登录成功");
  		
	} catch (Exception e) {
		//e.printStackTrace();
		result.error500(e.getMessage());
	}
	return new HttpEntity<>(result);
}
 
Example #25
Source File: LoginController.java    From jeecg-cloud with Apache License 2.0 4 votes vote down vote up
/**
 * app登录
 * @param sysLoginModel
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/mLogin", method = RequestMethod.POST)
public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	String username = sysLoginModel.getUsername();
	String password = sysLoginModel.getPassword();
	
	//1. 校验用户是否有效
	SysUser sysUser = sysUserService.getUserByName(username);
	result = sysUserService.checkUserIsEffective(sysUser);
	if(!result.isSuccess()) {
		return result;
	}
	
	//2. 校验用户名或密码是否正确
	String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
	String syspassword = sysUser.getPassword();
	if (!syspassword.equals(userpassword)) {
		result.error500("用户名或密码错误");
		return result;
	}
	
	String orgCode = sysUser.getOrgCode();
	if(oConvertUtils.isEmpty(orgCode)) {
		//如果当前用户无选择部门 查看部门关联信息
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		if (departs == null || departs.size() == 0) {
			result.error500("用户暂未归属部门,不可登录!");
			return result;
		}
		orgCode = departs.get(0).getOrgCode();
		sysUser.setOrgCode(orgCode);
		this.sysUserService.updateUserDepart(username, orgCode);
	}
	JSONObject obj = new JSONObject();
	//用户登录信息
	obj.put("userInfo", sysUser);
	
	// 生成token
	String token = JwtUtil.sign(username, syspassword);
	// 设置超时时间
	redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
	redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
	//token 信息
	obj.put("token", token);
	result.setResult(obj);
	result.setSuccess(true);
	result.setCode(200);
	sysBaseAPI.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null);
	return result;
}
 
Example #26
Source File: TeachingWorkServiceImpl.java    From teaching with Apache License 2.0 4 votes vote down vote up
@Override
public int sendWork(StudentWorkSendVO studentWorkSendVO) {
	int count = 0;
	List<String> studentIds = studentWorkSendVO.getUserIdList();
	String workId = studentWorkSendVO.getSendWorkId();
	TeachingWork sourceWork = this.getById(workId);
	if (sourceWork == null){
		return 0;
	}
	List<TeachingWork> workList = new ArrayList<>();
	//遍历学生ID
	for (String userId: studentIds){
		SysUser user = sysUserMapper.selectById(userId);
		if (user == null){ continue; }
		TeachingWork work = new TeachingWork();
		BeanUtils.copyProperties(sourceWork, work);
		work.setUserId(userId);
		work.setCreateTime(new Date());
		work.setCreateBy(user.getUsername());
		work.setUpdateTime(null);
		work.setUpdateBy(null);
		work.setViewNum(0);
		work.setDelFlag(0);
		work.setId(null);
		//覆盖老作业
		List<TeachingWork> oldWork = teachingWorkMapper.selectByMap(new HashMap<String, Object>(){{
			put("work_name", sourceWork.getWorkName());
			put("user_id", userId);
		}});
		if (oldWork.size() > 0){
			work.setId(oldWork.get(0).getId());
		}else{
			work.setId(null);
		}
		workList.add(work);
		try{
			this.saveOrUpdate(work);
			count++;
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	return count;
}
 
Example #27
Source File: LoginController.java    From teaching with Apache License 2.0 4 votes vote down vote up
/**
 * app登录
 * @param sysLoginModel
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/mLogin", method = RequestMethod.POST)
public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception {
	Result<JSONObject> result = new Result<JSONObject>();
	String username = sysLoginModel.getUsername();
	String password = sysLoginModel.getPassword();
	
	//1. 校验用户是否有效
	SysUser sysUser = sysUserService.getUserByName(username);
	result = sysUserService.checkUserIsEffective(sysUser);
	if(!result.isSuccess()) {
		return result;
	}
	
	//2. 校验用户名或密码是否正确
	String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
	String syspassword = sysUser.getPassword();
	if (!syspassword.equals(userpassword)) {
		result.error500("用户名或密码错误");
		return result;
	}
	
	String orgCode = sysUser.getOrgCode();
	if(oConvertUtils.isEmpty(orgCode)) {
		//如果当前用户无选择部门 查看部门关联信息
		List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
		if (departs == null || departs.size() == 0) {
			result.error500("用户暂未归属部门,不可登录!");
			return result;
		}
		orgCode = departs.get(0).getOrgCode();
		sysUser.setOrgCode(orgCode);
		this.sysUserService.updateUserDepart(username, orgCode);
	}
	JSONObject obj = new JSONObject();
	//用户登录信息
	obj.put("userInfo", sysUser);
	
	// 生成token
	String token = JwtUtil.sign(username, syspassword);
	// 设置超时时间
	redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
	redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
	//token 信息
	obj.put("token", token);
	result.setResult(obj);
	result.setSuccess(true);
	result.setCode(200);
	sysBaseAPI.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null);
	return result;
}
 
Example #28
Source File: LoginController.java    From teaching with Apache License 2.0 4 votes vote down vote up
@ApiOperation("登录接口")
@RequestMapping(value = "/login", method = RequestMethod.POST)
public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){
	Result<JSONObject> result = new Result<JSONObject>();
	String username = sysLoginModel.getUsername();
	String password = sysLoginModel.getPassword();
	//update-begin--Author:scott  Date:20190805 for:暂时注释掉密码加密逻辑,有点问题
	//前端密码加密,后端进行密码解密
	//password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密
	//update-begin--Author:scott  Date:20190805 for:暂时注释掉密码加密逻辑,有点问题

	//update-begin-author:taoyan date:20190828 for:校验验证码
       String captcha = sysLoginModel.getCaptcha();
       if(captcha==null){
           result.error500("验证码无效");
           return result;
       }
       String lowerCaseCaptcha = captcha.toLowerCase();
	String realKey = MD5Util.MD5Encode(lowerCaseCaptcha+sysLoginModel.getCheckKey(), "utf-8");
	Object checkCode = redisUtil.get(realKey);
	if(checkCode==null || !checkCode.equals(lowerCaseCaptcha)) {
		result.error500("验证码错误");
		return result;
	}
	//update-end-author:taoyan date:20190828 for:校验验证码
	
	//1. 校验用户是否有效
	SysUser sysUser = sysUserService.getUserByName(username);
	result = sysUserService.checkUserIsEffective(sysUser);
	if(!result.isSuccess()) {
		return result;
	}
	
	//2. 校验用户名或密码是否正确
	String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
	String syspassword = sysUser.getPassword();
	if (!syspassword.equals(userpassword)) {
		result.error500("用户名或密码错误");
		return result;
	}
			
	//用户登录信息
	userInfo(sysUser, result);
	sysBaseAPI.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null);

	return result;
}
 
Example #29
Source File: ISysUserService.java    From jeecg-boot with Apache License 2.0 2 votes vote down vote up
/**
 * 根据手机号获取用户名和密码
 */
public SysUser getUserByPhone(String phone);
 
Example #30
Source File: ISysUserService.java    From jeecg-boot-with-activiti with MIT License 2 votes vote down vote up
/**
 * 根据手机号获取用户名和密码
 */
public SysUser getUserByPhone(String phone);