|
@@ -1,67 +1,81 @@
|
|
|
package com.yonge.cooleshow.auth.web.controller;
|
|
|
|
|
|
-import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
|
|
|
-import com.yonge.cooleshow.auth.api.dto.UpdatePasswordDto;
|
|
|
-import com.yonge.cooleshow.auth.api.dto.UserSetReq;
|
|
|
-import com.yonge.cooleshow.auth.api.vo.UserSetVo;
|
|
|
-import com.yonge.cooleshow.common.constant.CommonConstants;
|
|
|
-import com.yonge.toolset.thirdparty.user.realname.RealnameAuthenticationPlugin;
|
|
|
-import com.yonge.toolset.utils.idcard.IdcardInfoExtractor;
|
|
|
-import com.yonge.toolset.utils.idcard.IdcardValidator;
|
|
|
-import com.yonge.toolset.utils.string.StringUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+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.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
|
|
|
+import com.yonge.cooleshow.auth.api.dto.SysUserQueryInfo;
|
|
|
+import com.yonge.cooleshow.auth.api.dto.UpdatePasswordDto;
|
|
|
+import com.yonge.cooleshow.auth.api.dto.UserSetReq;
|
|
|
+import com.yonge.cooleshow.auth.api.entity.SysRole;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.auth.api.vo.UserSetVo;
|
|
|
+import com.yonge.cooleshow.auth.core.service.CustomTokenServices;
|
|
|
+import com.yonge.cooleshow.auth.service.SysConfigService;
|
|
|
import com.yonge.cooleshow.auth.service.SysRoleService;
|
|
|
import com.yonge.cooleshow.auth.service.SysUserRoleService;
|
|
|
import com.yonge.cooleshow.auth.service.SysUserService;
|
|
|
-import com.yonge.cooleshow.auth.web.controller.queryInfo.SysUserQueryInfo;
|
|
|
+import com.yonge.cooleshow.auth.web.controller.queryInfo.RoleQueryInfo;
|
|
|
+import com.yonge.cooleshow.common.constant.CommonConstants;
|
|
|
+import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.cooleshow.common.controller.BaseController;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.cooleshow.common.exception.BizException;
|
|
|
-import com.yonge.cooleshow.common.page.QueryInfo;
|
|
|
import com.yonge.cooleshow.common.security.AuthUser;
|
|
|
import com.yonge.cooleshow.common.security.SecurityConstants;
|
|
|
import com.yonge.cooleshow.common.security.SecurityUtils;
|
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
+import com.yonge.toolset.thirdparty.user.realname.RealnameAuthenticationPlugin;
|
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
|
-
|
|
|
-import javax.validation.Valid;
|
|
|
+import com.yonge.toolset.utils.idcard.IdcardInfoExtractor;
|
|
|
+import com.yonge.toolset.utils.idcard.IdcardValidator;
|
|
|
+import com.yonge.toolset.utils.string.StringUtil;
|
|
|
|
|
|
@RestController()
|
|
|
@RequestMapping("user")
|
|
|
@Api(tags = "会员服务")
|
|
|
public class UserController extends BaseController {
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysUserService sysUserService;
|
|
|
@Autowired
|
|
|
private SysRoleService sysRoleService;
|
|
|
- /*@Autowired
|
|
|
- private ImFeignService imFeignService;*/
|
|
|
@Autowired
|
|
|
private SysUserRoleService sysUserRoleService;
|
|
|
@Autowired
|
|
|
private IdGeneratorService smsCodeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomTokenServices tokenService;
|
|
|
+
|
|
|
@Value("${message.debugMode}")
|
|
|
private boolean debugMode;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RealnameAuthenticationPlugin realnameAuthenticationPlugin;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
|
|
|
@ApiOperation(value = "分页查询用户信息")
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "userType", value = "用户类型", required = false, dataType = "String"),
|
|
@@ -73,6 +87,7 @@ public class UserController extends BaseController {
|
|
|
return succeed(sysUserService.queryPage(queryInfo));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@ApiOperation(value = "查询用户信息接口")
|
|
|
@GetMapping("/query")
|
|
|
@PreAuthorize("@pcs.hasPermissions('user/query')")
|
|
@@ -118,10 +133,10 @@ public class UserController extends BaseController {
|
|
|
}
|
|
|
|
|
|
@PostMapping(value = "/updateSysUser", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public boolean updateSysUser(@RequestBody SysUser user) {
|
|
|
+ public HttpResponseResult<Boolean> updateSysUser(@RequestBody SysUser user) {
|
|
|
user.setUpdateTime(new Date());
|
|
|
sysUserService.update(user);
|
|
|
- return true;
|
|
|
+ return HttpResponseResult.succeed(true);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "新增用户")
|
|
@@ -130,10 +145,30 @@ public class UserController extends BaseController {
|
|
|
return succeed(sysUserService.add(sysUser));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "设置密码")
|
|
|
+ @ApiOperation(value = "设置用户密码")
|
|
|
@PostMapping(value = "/setPassword", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String"),
|
|
|
- @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String")})
|
|
|
+ @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long")})
|
|
|
+ public Object setPassword(String password, Long id) {
|
|
|
+ if (StringUtils.isEmpty(password) || null == id) {
|
|
|
+ return failed("参数校验失败");
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserService.get(id);
|
|
|
+ if (sysUser == null) {
|
|
|
+ return failed("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ password = new BCryptPasswordEncoder().encode(password);
|
|
|
+ sysUser.setPassword(password);
|
|
|
+ sysUser.setUpdateTime(new Date());
|
|
|
+ sysUserService.update(sysUser);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "设置用户名密码")
|
|
|
+ @PostMapping(value = "/setUsernameAndPassword", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String"),
|
|
|
+ @ApiImplicitParam(name = "username", value = "用户名", dataType = "String")})
|
|
|
public Object setPassword(String password, String username) {
|
|
|
if (StringUtils.isEmpty(password)) {
|
|
|
return failed("参数校验失败");
|
|
@@ -146,9 +181,10 @@ public class UserController extends BaseController {
|
|
|
if (sysUser == null) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
- if (sysUser.getUserType().contains("TEACHER") || sysUser.getUserType().contains("SYSTEM")) {
|
|
|
- sysUser.setRealName(username);
|
|
|
- } else {
|
|
|
+ if(!StringUtil.isEmpty(username)){
|
|
|
+ if (sysUser.getUserType().contains("SYSTEM")) {
|
|
|
+ sysUser.setRealName(username);
|
|
|
+ }
|
|
|
sysUser.setUsername(username);
|
|
|
}
|
|
|
/*if(StringUtils.isEmpty(sysUser.getImToken())){
|
|
@@ -199,8 +235,7 @@ public class UserController extends BaseController {
|
|
|
if (sysUser == null) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
- String oldPassword = new BCryptPasswordEncoder().encode(updatePasswordDto.getOldPassword());
|
|
|
- if (!oldPassword.equals(sysUser.getPassword())) {
|
|
|
+ if (!new BCryptPasswordEncoder().matches(updatePasswordDto.getOldPassword(), sysUser.getPassword())) {
|
|
|
return failed("原密码错误");
|
|
|
}
|
|
|
sysUser.setPassword(new BCryptPasswordEncoder().encode(updatePasswordDto.getNewPasswordFirst()));
|
|
@@ -276,10 +311,22 @@ public class UserController extends BaseController {
|
|
|
if (sysUser == null) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
- if (sysUser.getId() != userId) {
|
|
|
+ if (sysUser.getId() != userId.longValue()) {
|
|
|
return failed("非法操作");
|
|
|
}
|
|
|
sysUser.setLockFlag(lockFlag);
|
|
|
+
|
|
|
+ if(lockFlag == 1){
|
|
|
+ if(sysUser.getUserType().contains("STUDENT")){
|
|
|
+ tokenService.revokeToken("STUDENT", sysUser.getPhone());
|
|
|
+ }
|
|
|
+ if(sysUser.getUserType().contains("TEACHER")){
|
|
|
+ tokenService.revokeToken("TEACHER", sysUser.getPhone());
|
|
|
+ }
|
|
|
+ if(sysUser.getUserType().contains("SYSTEM")){
|
|
|
+ tokenService.revokeToken("SYSTEM", sysUser.getPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
sysUser.setUpdateTime(new Date());
|
|
|
sysUserService.update(sysUser);
|
|
|
return succeed();
|
|
@@ -301,7 +348,7 @@ public class UserController extends BaseController {
|
|
|
if (sysUser == null) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
- if (sysUser.getId() != userId) {
|
|
|
+ if (sysUser.getId() != userId.longValue()) {
|
|
|
return failed("非法操作");
|
|
|
}
|
|
|
|
|
@@ -324,12 +371,13 @@ public class UserController extends BaseController {
|
|
|
throw new BizException("出生日期不可超过当前时间");
|
|
|
}
|
|
|
//手机号不能被占用
|
|
|
- if(!StringUtil.isEmpty(sysUser.getPhone())){
|
|
|
+ if (!StringUtil.isEmpty(sysUser.getPhone())) {
|
|
|
SysUser newSysUser = sysUserService.queryByPhone(sysUser.getPhone());
|
|
|
if (newSysUser != null && !newSysUser.getId().equals(sysUser.getId())) {
|
|
|
return failed("手机号被占用");
|
|
|
}
|
|
|
}
|
|
|
+ sysUser.setIsSuperAdmin(null);
|
|
|
sysUserService.updateBaseInfo(sysUser);
|
|
|
return succeed();
|
|
|
}
|
|
@@ -387,13 +435,14 @@ public class UserController extends BaseController {
|
|
|
@ApiOperation(value = "获取用户角色列表")
|
|
|
@GetMapping("/getRole")
|
|
|
@PreAuthorize("@pcs.hasPermissions('user/getRole')")
|
|
|
- public Object getRole() {
|
|
|
+ public HttpResponseResult<List<SysRole>> getRole() {
|
|
|
AuthUser user = SecurityUtils.getUser();
|
|
|
if (user != null) {
|
|
|
SysUser sysUser = sysUserService.get(user.getUserId());
|
|
|
if (sysUser.getIsSuperAdmin()) {
|
|
|
- QueryInfo queryInfo = new QueryInfo();
|
|
|
+ RoleQueryInfo queryInfo = new RoleQueryInfo();
|
|
|
queryInfo.setRows(9999);
|
|
|
+ queryInfo.setIsEnable(true);
|
|
|
return succeed(sysRoleService.queryPage(queryInfo).getRows());
|
|
|
}
|
|
|
return succeed(sysRoleService.findRoleByUserId(user.getUserId()));
|
|
@@ -406,12 +455,11 @@ public class UserController extends BaseController {
|
|
|
@ApiImplicitParam(name = "roleIds", value = "角色id,逗号分隔", required = true, dataType = "String")})
|
|
|
@PostMapping(value = "/addRole", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
|
|
@PreAuthorize("@pcs.hasPermissions('user/addRole')")
|
|
|
- public Object getRole(String userId, String roleIds) {
|
|
|
+ public HttpResponseResult<Boolean> getRole(String userId, String roleIds) {
|
|
|
if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(roleIds)) {
|
|
|
return failed(SecurityConstants.PARAM_VERIFY_EXCEPTION);
|
|
|
}
|
|
|
- sysUserRoleService.batchInsert(Long.parseLong(userId), roleIds);
|
|
|
- return succeed();
|
|
|
+ return status(sysUserRoleService.batchInsert(Long.parseLong(userId), roleIds));
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "用户角色删除")
|
|
@@ -437,7 +485,7 @@ public class UserController extends BaseController {
|
|
|
return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
}
|
|
|
SysUser user = sysUserService.get(authUser.getUserId());
|
|
|
- if (user == null) {
|
|
|
+ if (user == null || null == user.getId()) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
IdcardValidator idcardValidator = new IdcardValidator();
|
|
@@ -449,13 +497,28 @@ public class UserController extends BaseController {
|
|
|
//通过身份证号获取身份信息
|
|
|
IdcardInfoExtractor idcardInfoExtractor = new IdcardInfoExtractor(realNameAuthDto.getIdCardNo(), validatedAllIdcard);
|
|
|
//todo 通过环境,不做实名判断
|
|
|
- boolean verify = realnameAuthenticationPlugin.verify(realNameAuthDto.getRealName(), realNameAuthDto.getIdCardNo());
|
|
|
- if (!verify) {
|
|
|
+ try {
|
|
|
+ boolean verify = realnameAuthenticationPlugin.verify(realNameAuthDto.getRealName(), realNameAuthDto.getIdCardNo());
|
|
|
+ if (!verify) {
|
|
|
+ return failed("未通过实名认证");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
return failed("未通过实名认证");
|
|
|
}
|
|
|
+
|
|
|
if (realNameAuthDto.getSave()) {
|
|
|
+ String defaultHeard = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD);
|
|
|
+ if (StringUtil.isEmpty(user.getAvatar()) || user.getAvatar().equals(defaultHeard)) {
|
|
|
+ user.setAvatar(
|
|
|
+ 0 == idcardInfoExtractor.getGender() ? sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_GIRL) : sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_BOY));
|
|
|
+ }
|
|
|
+ realNameAuthDto.setUserId(user.getId());
|
|
|
+ realNameAuthDto.setGender(idcardInfoExtractor.getGender());
|
|
|
+ realNameAuthDto.setBirthday(idcardInfoExtractor.getBirthday());
|
|
|
+ realNameAuthDto.setAvatar(user.getAvatar());
|
|
|
//实名认证通过后立刻保存
|
|
|
- sysUserService.updateUserCard(realNameAuthDto, idcardInfoExtractor);
|
|
|
+ sysUserService.updateUserCard(realNameAuthDto);
|
|
|
}
|
|
|
return succeed(idcardInfoExtractor);
|
|
|
}
|
|
@@ -468,7 +531,7 @@ public class UserController extends BaseController {
|
|
|
return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
}
|
|
|
SysUser user = sysUserService.get(authUser.getUserId());
|
|
|
- if (user == null) {
|
|
|
+ if (user == null || null == user.getId()) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
UserSetVo detail = sysUserService.getSetDetail(user.getId());
|
|
@@ -483,11 +546,38 @@ public class UserController extends BaseController {
|
|
|
return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
}
|
|
|
SysUser user = sysUserService.get(authUser.getUserId());
|
|
|
- if (user == null) {
|
|
|
+ if (user == null || null == user.getId()) {
|
|
|
return failed("用户不存在");
|
|
|
}
|
|
|
//设置
|
|
|
sysUserService.submitSetDetail(setReq, user.getId());
|
|
|
return succeed(sysUserService.getSetDetail(user.getId()));
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping(value = "/bindOpenId")
|
|
|
+ public HttpResponseResult<Boolean> bindOpenId(@RequestBody SysUser param) {
|
|
|
+ AuthUser authUser = SecurityUtils.getUser();
|
|
|
+ if (authUser == null) {
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
+ }
|
|
|
+ SysUser user = sysUserService.get(authUser.getUserId());
|
|
|
+ if (user == null || null == user.getId()) {
|
|
|
+ return failed("用户不存在");
|
|
|
+ }
|
|
|
+ user.setWechatId(
|
|
|
+ StringUtil.isEmpty(param.getWechatId()) ? user.getWxOpenid() : param.getWechatId()
|
|
|
+ );
|
|
|
+ user.setQqOpenid(
|
|
|
+ StringUtil.isEmpty(param.getQqOpenid()) ? user.getQqOpenid() : param.getQqOpenid()
|
|
|
+ );
|
|
|
+ user.setUpdateTime(new Date());
|
|
|
+ sysUserService.update(user);
|
|
|
+ return HttpResponseResult.succeed(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询平台用户信息")
|
|
|
+ @PostMapping(value = "/list")
|
|
|
+ public HttpResponseResult<List<SysUser>> page(@RequestBody SysUserQueryInfo queryInfo) {
|
|
|
+ return succeed(sysUserService.queryEmployeeList(queryInfo));
|
|
|
+ }
|
|
|
}
|