import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import java.util.List; | |||||
/** | /** | ||||
* 用户前端控制器 | * 用户前端控制器 | ||||
* | * | ||||
/** | /** | ||||
* 删除用户 | * 删除用户 | ||||
* | * | ||||
* @param userIds 用户ID | |||||
* @param idList 用户ID | |||||
* @return | * @return | ||||
*/ | */ | ||||
@DeleteMapping("/delete/{userIds}") | |||||
public JsonResult deleteByIds(@PathVariable("userIds") String[] userIds) { | |||||
return userService.deleteByIds(userIds); | |||||
@DeleteMapping("/delete/{idList}") | |||||
public JsonResult deleteByIdList(@PathVariable("idList") List<String> idList) { | |||||
return userService.deleteByIdList(idList); | |||||
} | } | ||||
/** | /** | ||||
* 设置状态 | * 设置状态 | ||||
* | * | ||||
* @param entity 实体对象 | |||||
* @param id | |||||
* @param status | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
@PutMapping("/edit/status") | |||||
public JsonResult status(@RequestBody User entity) { | |||||
return userService.updeateStatus(entity); | |||||
@PutMapping("/edit/status/{id}/{status}") | |||||
public JsonResult status(@PathVariable("id") String id, @PathVariable("status") Integer status) { | |||||
return userService.updeateStatus(id, status); | |||||
} | } | ||||
/** | /** | ||||
* 重置密码 | * 重置密码 | ||||
* | * | ||||
* @param request 参数 | |||||
* @param id | |||||
* @return | * @return | ||||
*/ | */ | ||||
@PutMapping("/resetPwd") | |||||
public JsonResult resetPwd(@RequestBody UserResetPwdRequest request) { | |||||
return userService.resetPwd(request); | |||||
@PutMapping("/resetPwd/{id}") | |||||
public JsonResult resetPwd(@PathVariable("id") String id) { | |||||
return userService.resetPwd(id); | |||||
} | } | ||||
/** | /** |
import com.baomidou.mybatisplus.annotation.*; | import com.baomidou.mybatisplus.annotation.*; | ||||
import com.fasterxml.jackson.annotation.JsonFormat; | import com.fasterxml.jackson.annotation.JsonFormat; | ||||
import lombok.Builder; | |||||
import lombok.Data; | import lombok.Data; | ||||
import lombok.EqualsAndHashCode; | import lombok.EqualsAndHashCode; | ||||
import lombok.experimental.Accessors; | import lombok.experimental.Accessors; | ||||
* @since 2020-10-30 | * @since 2020-10-30 | ||||
*/ | */ | ||||
@Data | @Data | ||||
@Builder | |||||
@EqualsAndHashCode(callSuper = false) | @EqualsAndHashCode(callSuper = false) | ||||
@Accessors(chain = true) | @Accessors(chain = true) | ||||
@TableName("th_oauth_user") | @TableName("th_oauth_user") |
EDIT_IS_FAILED(1240800, "修改数据失败"), | EDIT_IS_FAILED(1240800, "修改数据失败"), | ||||
ID_IS_NULL(1240801, "任务问题id为空"), | ID_IS_NULL(1240801, "任务问题id为空"), | ||||
QUESTION_NAME_IS_NULL(1240802, "问题类型id为空"), | |||||
QUESTION_NAME_IS_NULL(1240802, "问题类型为空"), | |||||
INSPECTION_FILE_IS_NOT_EXIST(1240803, "任务问题不存在"), | INSPECTION_FILE_IS_NOT_EXIST(1240803, "任务问题不存在"), | ||||
QUESTION_TYPE_IS_NOT_EXIST(1240804, "问题类型不存在"); | QUESTION_TYPE_IS_NOT_EXIST(1240804, "问题类型不存在"); | ||||
package com.tuoheng.admin.enums.code.user; | |||||
/** | |||||
* 新增用户返回码 | |||||
* 模块代码:10(部门管理) | |||||
* 接口代码:01 (新增用户) | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
public enum AddUserCodeEnum { | |||||
ADD_IS_FAILED(1100100, "添加失败"), | |||||
PHONE_NOT_IMATCH(1100101, "手机号不匹配"), | |||||
USERNAME_ALREADY_EXISTS(1100102, "系统中已经存在该用户名"); | |||||
/** | |||||
* 错误码 | |||||
*/ | |||||
private int code; | |||||
/** | |||||
* 错误信息 | |||||
*/ | |||||
private String msg; | |||||
AddUserCodeEnum(int code, String msg){ | |||||
this.code = code; | |||||
this.msg = msg; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMsg() { | |||||
return msg; | |||||
} | |||||
public void setMsg(String msg) { | |||||
this.msg = msg; | |||||
} | |||||
} |
package com.tuoheng.admin.enums.code.user; | |||||
/** | |||||
* 删除用户返回码 | |||||
* 模块代码:10(部门管理) | |||||
* 接口代码:02 (删除用户) | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
public enum DeleteUserCodeEnum { | |||||
DELETE_IS_FAILED(1100200, "删除失败"), | |||||
USER_ID_IS_NULL(1100201, "用户ID为空"), | |||||
USER_IS_NOT_EXIST(1100202, "用户不存在"); | |||||
/** | |||||
* 错误码 | |||||
*/ | |||||
private int code; | |||||
/** | |||||
* 错误信息 | |||||
*/ | |||||
private String msg; | |||||
DeleteUserCodeEnum(int code, String msg){ | |||||
this.code = code; | |||||
this.msg = msg; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMsg() { | |||||
return msg; | |||||
} | |||||
public void setMsg(String msg) { | |||||
this.msg = msg; | |||||
} | |||||
} |
package com.tuoheng.admin.enums.code.user; | |||||
/** | |||||
* 删除用户返回码 | |||||
* 模块代码:10(部门管理) | |||||
* 接口代码:03 (删除用户) | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
public enum EditUserCodeEnum { | |||||
EDIT_IS_FAILED(1100300, "修改失败"), | |||||
USER_ID_IS_NULL(1100301, "用户ID为空"), | |||||
PHONE_NOT_IMATCH(1100302, "手机号不匹配"), | |||||
USER_IS_NOT_EXIST(1100303, "用户不存在"), | |||||
USERNAME_ALREADY_EXISTS(1100304, "系统中已经存在该用户名"); | |||||
/** | |||||
* 错误码 | |||||
*/ | |||||
private int code; | |||||
/** | |||||
* 错误信息 | |||||
*/ | |||||
private String msg; | |||||
EditUserCodeEnum(int code, String msg){ | |||||
this.code = code; | |||||
this.msg = msg; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMsg() { | |||||
return msg; | |||||
} | |||||
public void setMsg(String msg) { | |||||
this.msg = msg; | |||||
} | |||||
} |
package com.tuoheng.admin.enums.code.user; | |||||
/** | |||||
* 修改用户密码返回码 | |||||
* 模块代码:10(部门管理) | |||||
* 接口代码:04 (修改用户密码) | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
public enum EditUserPasswordCodeEnum { | |||||
EDIT_IS_FAILED(1100400, "修改失败"), | |||||
USER_ID_IS_NULL(1100401, "用户ID为空"), | |||||
USER_IS_NOT_EXIST(1100402, "用户不存在"), | |||||
NON_TENANT_USER(1100403, "当前用户非本租户用户"); | |||||
/** | |||||
* 错误码 | |||||
*/ | |||||
private int code; | |||||
/** | |||||
* 错误信息 | |||||
*/ | |||||
private String msg; | |||||
EditUserPasswordCodeEnum(int code, String msg){ | |||||
this.code = code; | |||||
this.msg = msg; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMsg() { | |||||
return msg; | |||||
} | |||||
public void setMsg(String msg) { | |||||
this.msg = msg; | |||||
} | |||||
} |
package com.tuoheng.admin.enums.code.user; | |||||
/** | |||||
* 修改用户状态返回码 | |||||
* 模块代码:10(部门管理) | |||||
* 接口代码:05 (修改用户状态) | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
public enum EditUserStatusCodeEnum { | |||||
EDIT_IS_FAILED(1100500, "修改失败"), | |||||
USER_ID_IS_NULL(1100501, "用户ID为空"), | |||||
USER_IS_NOT_EXIST(1100502, "用户不存在"); | |||||
/** | |||||
* 错误码 | |||||
*/ | |||||
private int code; | |||||
/** | |||||
* 错误信息 | |||||
*/ | |||||
private String msg; | |||||
EditUserStatusCodeEnum(int code, String msg){ | |||||
this.code = code; | |||||
this.msg = msg; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMsg() { | |||||
return msg; | |||||
} | |||||
public void setMsg(String msg) { | |||||
this.msg = msg; | |||||
} | |||||
} |
package com.tuoheng.admin.enums.code.user; | |||||
/** | |||||
* 根据ID查询用户信息返回码 | |||||
* 模块代码:10(部门管理) | |||||
* 接口代码:06 (根据ID查询用户信息) | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
public enum QueryUserInfoByIdCodeEnum { | |||||
QUERY_ID_IS_NULL(1100600, "查询失败"), | |||||
USER_ID_IS_NULL(1100601, "用户ID为空"), | |||||
USER_IS_NOT_EXIST(1100602, "用户不存在"), | |||||
NON_TENANT_USER(1100603, "当前用户非本租户用户"); | |||||
/** | |||||
* 错误码 | |||||
*/ | |||||
private int code; | |||||
/** | |||||
* 错误信息 | |||||
*/ | |||||
private String msg; | |||||
QueryUserInfoByIdCodeEnum(int code, String msg){ | |||||
this.code = code; | |||||
this.msg = msg; | |||||
} | |||||
public int getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(int code) { | |||||
this.code = code; | |||||
} | |||||
public String getMsg() { | |||||
return msg; | |||||
} | |||||
public void setMsg(String msg) { | |||||
this.msg = msg; | |||||
} | |||||
} |
/** | /** | ||||
* 根据部门ID查询用户列表返回码 | * 根据部门ID查询用户列表返回码 | ||||
* 模块代码:10(部门管理) | * 模块代码:10(部门管理) | ||||
* 接口代码:01 (据部门ID查询用户列表) | |||||
* 接口代码:07 (据部门ID查询用户列表) | |||||
* | * | ||||
* @author wanjing | * @author wanjing | ||||
* @team tuoheng | * @team tuoheng | ||||
*/ | */ | ||||
public enum QueryUserListByDeptIdCodeEnum { | public enum QueryUserListByDeptIdCodeEnum { | ||||
DEPT_ID_IS_NULL(1100101, "部门ID为空"), | |||||
DEPT_IS_NOT_EXIST(1100102, "部门不存在"); | |||||
DEPT_ID_IS_NULL(1100701, "部门ID为空"), | |||||
DEPT_IS_NOT_EXIST(1100702, "部门不存在"); | |||||
/** | /** | ||||
* 错误码 | * 错误码 |
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
import com.tuoheng.admin.entity.User; | import com.tuoheng.admin.entity.User; | ||||
import java.util.Map; | |||||
/** | /** | ||||
* 后台用户管理表 Mapper 接口 | * 后台用户管理表 Mapper 接口 | ||||
* | * | ||||
*/ | */ | ||||
public interface UserMapper extends BaseMapper<User> { | public interface UserMapper extends BaseMapper<User> { | ||||
Integer updateByIdList(Map<String, Object> map); | |||||
} | } |
@Qualifier("restTemplate") | @Qualifier("restTemplate") | ||||
private RestTemplate restTemplate; | private RestTemplate restTemplate; | ||||
public JsonResult addUser(User user, Tenant tenant) { | |||||
OidcCreateUserRequest request = extracted(user, tenant); | |||||
public JsonResult add(User user, Tenant tenant) { | |||||
OidcCreateUserRequest request = this.buildOidcCreateUserRequest(user, tenant); | |||||
//设置请求头 | //设置请求头 | ||||
HttpHeaders resultRequestHeader = new HttpHeaders(); | HttpHeaders resultRequestHeader = new HttpHeaders(); | ||||
resultRequestHeader.add("Authorization", "Bearer " + SecurityUserUtils.token()); | resultRequestHeader.add("Authorization", "Bearer " + SecurityUserUtils.token()); | ||||
* @param user | * @param user | ||||
* @return | * @return | ||||
*/ | */ | ||||
private OidcCreateUserRequest extracted(User user, Tenant tenant) { | |||||
private OidcCreateUserRequest buildOidcCreateUserRequest(User user, Tenant tenant) { | |||||
OidcCreateUserRequest oidcCreateUserRequest = new OidcCreateUserRequest(); | OidcCreateUserRequest oidcCreateUserRequest = new OidcCreateUserRequest(); | ||||
oidcCreateUserRequest.setUsername(user.getUsername()); | oidcCreateUserRequest.setUsername(user.getUsername()); | ||||
if (StringUtils.isNotEmpty(user.getPassword())) { | if (StringUtils.isNotEmpty(user.getPassword())) { |
package com.tuoheng.admin.service.third.oidc; | |||||
import com.tuoheng.admin.constant.OidcUrlConstant; | |||||
import com.tuoheng.admin.entity.User; | |||||
import com.tuoheng.admin.request.oidc.OidcUpdateUserPasswordRequest; | |||||
import com.tuoheng.common.core.config.common.CommonConfig; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import com.tuoheng.common.core.utils.SecurityUserUtils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Qualifier; | |||||
import org.springframework.http.HttpEntity; | |||||
import org.springframework.http.HttpHeaders; | |||||
import org.springframework.http.HttpMethod; | |||||
import org.springframework.http.ResponseEntity; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.client.RestTemplate; | |||||
@Slf4j | |||||
@Service | |||||
public class EditOidcUserPasswordService { | |||||
@Autowired | |||||
@Qualifier("restTemplate") | |||||
private RestTemplate restTemplate; | |||||
public JsonResult editUserPassword(User user) { | |||||
OidcUpdateUserPasswordRequest oidcUpdateUserPasswordRequest = new OidcUpdateUserPasswordRequest(); | |||||
oidcUpdateUserPasswordRequest.setUsername(user.getUsername()); | |||||
// 重置密码123456 | |||||
oidcUpdateUserPasswordRequest.setPassword("123456"); | |||||
//设置请求头 | |||||
org.springframework.http.HttpHeaders resultRequestHeader = new HttpHeaders(); | |||||
resultRequestHeader.add("Authorization", "Bearer " + SecurityUserUtils.token()); | |||||
HttpEntity httpEntity = new HttpEntity(oidcUpdateUserPasswordRequest, resultRequestHeader); | |||||
//设置地址,飞手小程序 经过网关 | |||||
String url = CommonConfig.oidcUrl + OidcUrlConstant.USER_UPDATEPASS; | |||||
ResponseEntity<JsonResult> response; | |||||
try { | |||||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.error("oidc修改用户密码失败"); | |||||
return JsonResult.error("oidc修改用户密码失败"); | |||||
} | |||||
if (null == response || !response.hasBody()) { | |||||
log.error("oidc修改用户密码响应失败"); | |||||
return JsonResult.error("oidc修改用户密码失败"); | |||||
} | |||||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||||
log.error("oidc修改用户密码失败" + response.getBody()); | |||||
return JsonResult.error(response.getBody().getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
} |
package com.tuoheng.admin.service.third.oidc; | |||||
import com.tuoheng.admin.constant.OidcUrlConstant; | |||||
import com.tuoheng.admin.dto.ClientRoleDto; | |||||
import com.tuoheng.admin.entity.Tenant; | |||||
import com.tuoheng.admin.entity.User; | |||||
import com.tuoheng.admin.enums.ClientEnum; | |||||
import com.tuoheng.admin.request.oidc.OidcCreateUserRequest; | |||||
import com.tuoheng.admin.request.oidc.OidcUpdateUserRequest; | |||||
import com.tuoheng.common.core.config.common.CommonConfig; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import com.tuoheng.common.core.utils.SecurityUserUtils; | |||||
import com.tuoheng.common.core.utils.StringUtils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Qualifier; | |||||
import org.springframework.http.*; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.client.RestTemplate; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
@Slf4j | |||||
@Service | |||||
public class EditOidcUserService { | |||||
@Autowired | |||||
@Qualifier("restTemplate") | |||||
private RestTemplate restTemplate; | |||||
public JsonResult edit(User user) { | |||||
//修改用户角色 | |||||
OidcUpdateUserRequest oidcUpdateUserRequest = buildOidcUpdateUserRequest(user); | |||||
//设置请求头 | |||||
HttpHeaders resultRequestHeader = new HttpHeaders(); | |||||
resultRequestHeader.add("Authorization", "Bearer " + SecurityUserUtils.token()); | |||||
//resultRequestHeader.add("Authorization", "Bearer "+ "eyJraWQiOiJiZDhjZWUwNi0yY2E1LTQzZDYtYTA2OC1kOWM5ZDFhZmYxYzYiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImF1ZCI6InR1b2hlbmctZHNwLXdlYiIsIm5iZiI6MTY2NzIwOTU4NSwib1VzZXJJZCI6MTIsInNjb3BlIjpbImFkbWluIl0sImlzcyI6Imh0dHA6XC9cL29pZGMuZGV2LnQtYWFyb24uY29tIiwiY2xpZW50Um9sZUxpc3QiOltdLCJleHAiOjE2NjcyOTU5ODUsImlhdCI6MTY2NzIwOTU4NSwidXNlcm5hbWUiOiJhZG1pbiJ9.bfZceQpXwlR22Q1tODDGXgFQ718iXPL9aGKF_truMkSUj96h_a0DOqoCjtAELo0r703o9jEFb0pUzERvaOVK-IhL_z37rmf2kVRnM7yy_cOnpNa6yhD7c0UpqRN-2L8QPpQcWzmEUtvEp4icS_zFOp-lN_A0J6jpoGhpYbqiZCUn_1_ojRX9iGc6JzzaVPRgsHgrwt1g2mMrQWhoG7_4sIyWEM4y1RimUaEDCDjuFko3HWh8qLfTLMMSML0Zt1ovSRSVLCFmAOROeerNpte6UuzWrcsIpckBLmr-uNFVu8SZOZ1UE4W5_LHTztAel8JtZx84Q1Aaoy9TM9h_pv2jCg"); | |||||
HttpEntity httpEntity = new HttpEntity(oidcUpdateUserRequest, resultRequestHeader); | |||||
//设置地址(飞手平台) | |||||
String url = CommonConfig.oidcUrl + OidcUrlConstant.USER_UPDATEROLE; | |||||
ResponseEntity<JsonResult> response = null; | |||||
try { | |||||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.error("oidc修改用户信息响应失败"); | |||||
return JsonResult.error("oidc修改用户信息响应失败"); | |||||
} | |||||
if (null == response || !response.hasBody()) { | |||||
log.error("oidc修改用户信息响应失败"); | |||||
return JsonResult.error("oidc修改用户信息响应失败"); | |||||
} | |||||
if (response.getBody().getCode() != JsonResult.SUCCESS) { | |||||
log.error("oidc修改用户响应失败" + response.getBody()); | |||||
return JsonResult.error(response.getBody().getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
/** | |||||
* 封装请求->oidc认证信息 | |||||
* | |||||
* @param user | |||||
* @return | |||||
*/ | |||||
private OidcUpdateUserRequest buildOidcUpdateUserRequest(User user) { | |||||
OidcUpdateUserRequest oidcUpdateUserRequest = new OidcUpdateUserRequest(); | |||||
oidcUpdateUserRequest.setUsername(user.getUsername()); | |||||
List<ClientRoleDto> clientRoleDtoList = new ArrayList<>(); | |||||
ClientRoleDto clientRoleDto; | |||||
String[] clientIdArr = user.getClientId().split(","); | |||||
for (String clientIdStr : clientIdArr) { | |||||
int clientId = Integer.valueOf(clientIdStr); | |||||
ClientEnum clientEnum = ClientEnum.parse(clientId); | |||||
if (null != clientEnum) { | |||||
clientRoleDto = new ClientRoleDto(); | |||||
clientRoleDto.setClientId(clientEnum.getDescription()); | |||||
clientRoleDto.setRoleId(user.getRoleId()); | |||||
clientRoleDtoList.add(clientRoleDto); | |||||
} | |||||
} | |||||
oidcUpdateUserRequest.setClientRoleDtoList(clientRoleDtoList); | |||||
return oidcUpdateUserRequest; | |||||
} | |||||
} |
JsonResult addUser(User user, Tenant tenant); | JsonResult addUser(User user, Tenant tenant); | ||||
JsonResult editUser(User user); | |||||
JsonResult editUserPassword(User user); | |||||
} | } |
@Autowired | @Autowired | ||||
private AddOidcUserService addOidcUserService; | private AddOidcUserService addOidcUserService; | ||||
@Autowired | |||||
private EditOidcUserService editOidcUserService; | |||||
@Autowired | |||||
private EditOidcUserPasswordService editOidcUserPasswordService; | |||||
public JsonResult addUser(User user, Tenant tenant) { | public JsonResult addUser(User user, Tenant tenant) { | ||||
return addOidcUserService.addUser(user, tenant); | |||||
return addOidcUserService.add(user, tenant); | |||||
} | } | ||||
public JsonResult editUser(User user) { | |||||
return editOidcUserService.edit(user); | |||||
} | |||||
public JsonResult editUserPassword(User user) { | |||||
return editOidcUserPasswordService.editUserPassword(user); | |||||
} | |||||
} | } |
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import java.util.List; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* 后台用户管理表 服务类 | * 后台用户管理表 服务类 | ||||
/** | /** | ||||
* 删除用户 | * 删除用户 | ||||
* | * | ||||
* @param userIds 用户ID | |||||
* @param idList 用户ID | |||||
* @return | * @return | ||||
*/ | */ | ||||
JsonResult deleteByIds(String[] userIds); | |||||
JsonResult deleteByIdList(List<String> idList); | |||||
/** | /** | ||||
* 设置状态 | * 设置状态 | ||||
* @param entity 实体对象 | * @param entity 实体对象 | ||||
* @return | * @return | ||||
*/ | */ | ||||
JsonResult updeateStatus(User entity); | |||||
JsonResult updeateStatus(String id, Integer status); | |||||
/** | /** | ||||
* 重置密码 | * 重置密码 | ||||
* @param request 参数 | * @param request 参数 | ||||
* @return | * @return | ||||
*/ | */ | ||||
JsonResult resetPwd(UserResetPwdRequest request); | |||||
JsonResult resetPwd(String id); | |||||
/** | /** | ||||
* 根据部门id查询用户列表 | * 根据部门id查询用户列表 |
import com.tuoheng.admin.entity.User; | import com.tuoheng.admin.entity.User; | ||||
import com.tuoheng.admin.request.user.QueryUserPageListRequest; | import com.tuoheng.admin.request.user.QueryUserPageListRequest; | ||||
import com.tuoheng.admin.request.user.UserResetPwdRequest; | import com.tuoheng.admin.request.user.UserResetPwdRequest; | ||||
import com.tuoheng.admin.service.user.add.AddUserService; | |||||
import com.tuoheng.admin.service.user.delete.DeleteUserService; | |||||
import com.tuoheng.admin.service.user.query.QueryUserInfoByIdService; | |||||
import com.tuoheng.admin.service.user.query.QueryUserListByDeptIdService; | import com.tuoheng.admin.service.user.query.QueryUserListByDeptIdService; | ||||
import com.tuoheng.admin.service.user.query.QueryUserPageListService; | import com.tuoheng.admin.service.user.query.QueryUserPageListService; | ||||
import com.tuoheng.admin.service.user.update.UpdateUserPasswordService; | |||||
import com.tuoheng.admin.service.user.update.UpdateUserService; | |||||
import com.tuoheng.admin.service.user.update.UpdateUserStatusService; | |||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.web.bind.annotation.PathVariable; | import org.springframework.web.bind.annotation.PathVariable; | ||||
import org.springframework.web.bind.annotation.RequestBody; | import org.springframework.web.bind.annotation.RequestBody; | ||||
import java.util.List; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
@Autowired | @Autowired | ||||
private QueryUserListByDeptIdService queryUserListByDeptIdService; | private QueryUserListByDeptIdService queryUserListByDeptIdService; | ||||
@Autowired | |||||
private AddUserService addUserService; | |||||
@Autowired | |||||
private UpdateUserService updateUserService; | |||||
@Autowired | |||||
private DeleteUserService deleteUserService; | |||||
@Autowired | |||||
private UpdateUserStatusService updateUserStatusService; | |||||
@Autowired | |||||
private UpdateUserPasswordService updateUserPasswordService; | |||||
@Autowired | |||||
private QueryUserInfoByIdService queryUserInfoByIdService; | |||||
/** | /** | ||||
* 获取用户分页列表 | * 获取用户分页列表 | ||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult detail(@PathVariable("id") String id) { | |||||
return null; | |||||
public JsonResult detail(String id) { | |||||
return queryUserInfoByIdService.getUserInfo(id); | |||||
} | } | ||||
/** | /** | ||||
* 添加用户 | * 添加用户 | ||||
* | * | ||||
* @param entity 实体对象 | |||||
* @param user 实体对象 | |||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult add(@RequestBody User entity) { | |||||
return null; | |||||
public JsonResult add(@RequestBody User user) { | |||||
return addUserService.add(user); | |||||
} | } | ||||
/** | /** | ||||
* 编辑用户 | * 编辑用户 | ||||
* | * | ||||
* @param entity 实体对象 | |||||
* @param user 实体对象 | |||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult edit(@RequestBody User entity) { | |||||
return null; | |||||
public JsonResult edit(User user) { | |||||
return updateUserService.update(user); | |||||
} | } | ||||
/** | /** | ||||
* 删除用户 | * 删除用户 | ||||
* | * | ||||
* @param userIds 用户ID | |||||
* @param idList 用户ID | |||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult deleteByIds(String[] userIds) { | |||||
return null; | |||||
public JsonResult deleteByIdList(List<String> idList) { | |||||
return deleteUserService.deleteByIdList(idList); | |||||
} | } | ||||
/** | /** | ||||
* 设置状态 | * 设置状态 | ||||
* | * | ||||
* @param entity 实体对象 | |||||
* @param id | |||||
* @param status | |||||
* | |||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult updeateStatus(User entity) { | |||||
return null; | |||||
public JsonResult updeateStatus(String id, Integer status) { | |||||
return updateUserStatusService.update(id, status); | |||||
} | } | ||||
/** | /** | ||||
* 重置密码 | * 重置密码 | ||||
* | * | ||||
* @param request 参数 | |||||
* @param id | |||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public JsonResult resetPwd(UserResetPwdRequest request) { | |||||
return null; | |||||
public JsonResult resetPwd(String id) { | |||||
return updateUserPasswordService.resetPwd(id); | |||||
} | } | ||||
import com.tuoheng.admin.entity.Tenant; | import com.tuoheng.admin.entity.Tenant; | ||||
import com.tuoheng.admin.entity.User; | import com.tuoheng.admin.entity.User; | ||||
import com.tuoheng.admin.enums.code.dept.AddDeptCodeEnum; | import com.tuoheng.admin.enums.code.dept.AddDeptCodeEnum; | ||||
import com.tuoheng.admin.enums.code.user.AddUserCodeEnum; | |||||
import com.tuoheng.admin.mapper.TenantMapper; | import com.tuoheng.admin.mapper.TenantMapper; | ||||
import com.tuoheng.admin.mapper.UserMapper; | import com.tuoheng.admin.mapper.UserMapper; | ||||
import com.tuoheng.admin.request.dept.AddDeptRequest; | import com.tuoheng.admin.request.dept.AddDeptRequest; | ||||
@Autowired | @Autowired | ||||
private TenantMapper tenantMapper; | private TenantMapper tenantMapper; | ||||
@Autowired | @Autowired | ||||
private OidcService oidcService; | private OidcService oidcService; | ||||
Tenant tenant = tenantMapper.selectById(tenantId); | Tenant tenant = tenantMapper.selectById(tenantId); | ||||
// 添加oidc | // 添加oidc | ||||
oidcService.addUser(user, tenant); | |||||
result = oidcService.addUser(user, tenant); | |||||
if (0 != result.getCode()) { | |||||
log.info("添加用户业务接口:添加oidc数据失败:{}", result.getMsg()); | |||||
return result; | |||||
} | |||||
this.buildUser(user, tenantId); | this.buildUser(user, tenantId); | ||||
// result = this.saveOrUpdate(user); | |||||
// if (!result) { | |||||
// return JsonResult.error(); | |||||
// } | |||||
// // 删除已存在的用户角色关系数据 | |||||
// userRoleService.deleteUserRole(user.getId()); | |||||
// | |||||
// // 插入用户角色关系数据 | |||||
// //userRoleService.insertUserRole(entity.getId(), entity.getRoleIds()); | |||||
// UserRole userRole = new UserRole(); | |||||
// //租户id | |||||
// userRole.setTenantId(user.getTenantId()); | |||||
// userRole.setUserId(user.getId()); | |||||
// userRole.setRoleId(user.getRoleId()); | |||||
// userRoleService.save(userRole); | |||||
Integer rowCount = userMapper.insert(user); | |||||
if (rowCount <= 0) { | |||||
return JsonResult.error(AddUserCodeEnum.ADD_IS_FAILED.getCode(), AddUserCodeEnum.ADD_IS_FAILED.getMsg()); | |||||
} | |||||
return JsonResult.success(); | return JsonResult.success(); | ||||
//校验手机号 | //校验手机号 | ||||
boolean flag = CommonUtils.isMobile(user.getMobile()); | boolean flag = CommonUtils.isMobile(user.getMobile()); | ||||
if (!flag) { | if (!flag) { | ||||
return JsonResult.error("该用户手机号格式有误"); | |||||
return JsonResult.error(AddUserCodeEnum.PHONE_NOT_IMATCH.getCode(), AddUserCodeEnum.PHONE_NOT_IMATCH.getMsg()); | |||||
} | } | ||||
} | } | ||||
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() | Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() | ||||
.eq(User::getTenantId, tenantId) | .eq(User::getTenantId, tenantId) | ||||
.eq(User::getUsername, user.getUsername()) | .eq(User::getUsername, user.getUsername()) | ||||
.eq(User::getMark, 1)); | .eq(User::getMark, 1)); | ||||
if (count > 0) { | if (count > 0) { | ||||
return JsonResult.error("系统中已经存在相同的账号信息"); | |||||
return JsonResult.error(AddUserCodeEnum.USERNAME_ALREADY_EXISTS.getCode(), AddUserCodeEnum.USERNAME_ALREADY_EXISTS.getMsg()); | |||||
} | } | ||||
return JsonResult.success(); | return JsonResult.success(); | ||||
} | } | ||||
//id | //id | ||||
user.setCreateUser(CurrentUserUtil.getUserId()); | user.setCreateUser(CurrentUserUtil.getUserId()); | ||||
user.setTenantId(tenantId); | user.setTenantId(tenantId); | ||||
user.setCityName(this.selectCityName(user)); | |||||
user.setCityName(""); | |||||
user.setCreateUser(CurrentUserUtil.getUserId()); | user.setCreateUser(CurrentUserUtil.getUserId()); | ||||
user.setCreateTime(DateUtils.now()); | user.setCreateTime(DateUtils.now()); | ||||
} | } | ||||
/** | |||||
* 用于新增修改终端用户 回显所管辖区域名称 | |||||
* | |||||
* @param user | |||||
* @return | |||||
*/ | |||||
private String selectCityName(User user) { | |||||
//根据用户查询出对应的角色 | |||||
// QueryWrapper<City> queryWrapper = new QueryWrapper<>(); | |||||
// | |||||
// Role role = roleMapper.selectById(user.getRoleId()); | |||||
// String userCityCode = ""; | |||||
// if (!StringUtils.isEmpty(user.getStreetCode()) && ("006".equals(role.getCode()) || role.getCode().equals("007"))) { | |||||
// String citys = ""; | |||||
// String[] s = user.getStreetCode().split(","); | |||||
// for (String scode : s) { | |||||
// queryWrapper = new QueryWrapper<>(); | |||||
// queryWrapper.eq("citycode", scode); | |||||
// queryWrapper.eq("mark", 1); | |||||
// List<City> listStreet = cityMapper.selectList(queryWrapper); | |||||
// if (listStreet.size() > 0) { | |||||
// for (City cityone : listStreet) { | |||||
// citys += cityone.getName() + ","; | |||||
// } | |||||
// } | |||||
// } | |||||
// return citys.substring(0, citys.length() - 1); | |||||
// } else if (!StringUtils.isEmpty(user.getDistrictCode()) && (role.getCode().equals("004") || role.getCode().equals("007"))) { | |||||
// userCityCode = user.getDistrictCode(); | |||||
// } else if (!StringUtils.isEmpty(user.getCityCode()) && (role.getCode().equals("003") || role.getCode().equals("007"))) { | |||||
// userCityCode = user.getCityCode(); | |||||
// } else if (!StringUtils.isEmpty(user.getProvinceCode())) { | |||||
// userCityCode = user.getProvinceCode(); | |||||
// } | |||||
// queryWrapper.eq("citycode", userCityCode); | |||||
// List<City> list = cityMapper.selectList(queryWrapper); | |||||
// if (list.size() > 0) { | |||||
// return list.get(0).getName(); | |||||
// } else { | |||||
// return null; | |||||
// } | |||||
return ""; | |||||
} | |||||
} | } |
package com.tuoheng.admin.service.user.delete; | |||||
import cn.hutool.core.collection.CollectionUtil; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |||||
import com.tuoheng.admin.entity.User; | |||||
import com.tuoheng.admin.enums.InspectionFileStatusEnum; | |||||
import com.tuoheng.admin.enums.code.user.DeleteUserCodeEnum; | |||||
import com.tuoheng.admin.enums.code.user.EditUserCodeEnum; | |||||
import com.tuoheng.admin.mapper.UserMapper; | |||||
import com.tuoheng.admin.service.third.oidc.OidcService; | |||||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||||
import com.tuoheng.common.core.config.common.CommonConfig; | |||||
import com.tuoheng.common.core.utils.CommonUtils; | |||||
import com.tuoheng.common.core.utils.DateUtils; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import com.tuoheng.common.core.utils.StringUtils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.bind.annotation.PathVariable; | |||||
import java.util.HashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
/** | |||||
* 删除用户业务层处理 | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class DeleteUserService { | |||||
@Autowired | |||||
private UserMapper userMapper; | |||||
/** | |||||
* 修改用户数据 | |||||
* | |||||
* @return | |||||
*/ | |||||
public JsonResult deleteByIdList(List<String> idList) { | |||||
log.info("进入删除用户业务接口"); | |||||
String tenantId = CurrentUserUtil.getTenantId(); | |||||
JsonResult result = this.check(tenantId, idList); | |||||
if (0 != result.getCode()) { | |||||
log.info("删除用户业务接口:校验失败:{}", result.getMsg()); | |||||
return result; | |||||
} | |||||
Map<String, Object> map = new HashMap<>(); | |||||
map.put("mark", 0); | |||||
map.put("updateUser", CurrentUserUtil.getUserId()); | |||||
map.put("updateTime", DateUtils.now()); | |||||
map.put("idList", idList); | |||||
Integer rowCount = userMapper.updateByIdList(map); | |||||
if (rowCount <= 0) { | |||||
return JsonResult.error(DeleteUserCodeEnum.DELETE_IS_FAILED.getCode(), DeleteUserCodeEnum.DELETE_IS_FAILED.getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
/** | |||||
* 检查参数 | |||||
* @param tenantId | |||||
* @param idList | |||||
* @return | |||||
*/ | |||||
private JsonResult check(String tenantId, List<String> idList) { | |||||
if (CollectionUtil.isEmpty(idList)) { | |||||
return JsonResult.error(DeleteUserCodeEnum.USER_ID_IS_NULL.getCode(), DeleteUserCodeEnum.USER_ID_IS_NULL.getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
/** | |||||
* | |||||
* 构建实体字段数据 | |||||
* | |||||
* @param user | |||||
*/ | |||||
private void buildUser(User user) { | |||||
if (StringUtils.isNotNull(user.getAvatar()) && user.getAvatar().contains(CommonConfig.imageURL)) { | |||||
user.setAvatar(user.getAvatar().replaceAll(CommonConfig.imageURL, "")); | |||||
} else { | |||||
//添加默认头像 | |||||
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png"); | |||||
} | |||||
user.setCityName(""); | |||||
user.setUpdateUser(CurrentUserUtil.getUserId()); | |||||
user.setUpdateTime(DateUtils.now()); | |||||
} | |||||
} |
package com.tuoheng.admin.service.user.query; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.tuoheng.admin.entity.User; | |||||
import com.tuoheng.admin.enums.code.user.QueryUserInfoByIdCodeEnum; | |||||
import com.tuoheng.admin.mapper.UserMapper; | |||||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import com.tuoheng.common.core.utils.StringUtils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
/** | |||||
* 根据用户Id查询用户信息业务层处理 | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class QueryUserInfoByIdService { | |||||
@Autowired | |||||
private UserMapper userMapper; | |||||
/** | |||||
* 获取部门树形列表 | |||||
* | |||||
* @return | |||||
*/ | |||||
public JsonResult getUserInfo(String id) { | |||||
log.info("进入根据用户Id查询用户信息业务"); | |||||
JsonResult result = this.check(id); | |||||
if (0 != result.getCode()) { | |||||
log.info("根据用户Id查询用户信息业务:校验失败:{}", result.getMsg()); | |||||
return result; | |||||
} | |||||
User user = (User) result.getData(); | |||||
return JsonResult.success(user); | |||||
} | |||||
/** | |||||
* 检查参数 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
private JsonResult check(String id) { | |||||
if (StringUtils.isEmpty(id)) { | |||||
return JsonResult.error(QueryUserInfoByIdCodeEnum.USER_ID_IS_NULL.getCode(), QueryUserInfoByIdCodeEnum.USER_ID_IS_NULL.getMsg()); | |||||
} | |||||
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||||
.eq(User::getId, id) | |||||
.eq(User::getMark, 1)); | |||||
if (ObjectUtil.isNull(user)) { | |||||
return JsonResult.error(QueryUserInfoByIdCodeEnum.USER_IS_NOT_EXIST.getCode(), QueryUserInfoByIdCodeEnum.USER_IS_NOT_EXIST.getMsg()); | |||||
} | |||||
if (!user.getTenantId().equals(CurrentUserUtil.getTenantId())) { | |||||
return JsonResult.error(QueryUserInfoByIdCodeEnum.NON_TENANT_USER.getCode(), QueryUserInfoByIdCodeEnum.NON_TENANT_USER.getMsg()); | |||||
} | |||||
return JsonResult.success(user); | |||||
} | |||||
} |
* @return | * @return | ||||
*/ | */ | ||||
public JsonResult getListByDeptId(String deptId) { | public JsonResult getListByDeptId(String deptId) { | ||||
log.info("进入根据部门id查询用户列表业业务"); | |||||
log.info("进入根据部门id查询用户列表业务"); | |||||
JsonResult result = this.check(deptId); | JsonResult result = this.check(deptId); | ||||
if (0 != result.getCode()) { | if (0 != result.getCode()) { | ||||
log.info("根据根据部门id查询用户列表业业务:校验失败:{}", result.getMsg()); | log.info("根据根据部门id查询用户列表业业务:校验失败:{}", result.getMsg()); |
* @return | * @return | ||||
*/ | */ | ||||
public JsonResult getPageList(QueryUserPageListRequest request) { | public JsonResult getPageList(QueryUserPageListRequest request) { | ||||
log.info("进入查询用户分页列表业务业务"); | |||||
log.info("进入查询用户分页列表业务"); | |||||
JsonResult result = this.check(request); | JsonResult result = this.check(request); | ||||
if (0 != result.getCode()) { | if (0 != result.getCode()) { | ||||
log.info("查询用户分页列表业务:校验失败:{}", result.getMsg()); | log.info("查询用户分页列表业务:校验失败:{}", result.getMsg()); |
package com.tuoheng.admin.service.user.update; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.tuoheng.admin.entity.User; | |||||
import com.tuoheng.admin.enums.code.user.EditUserPasswordCodeEnum; | |||||
import com.tuoheng.admin.mapper.UserMapper; | |||||
import com.tuoheng.admin.service.third.oidc.OidcService; | |||||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||||
import com.tuoheng.common.core.utils.CommonUtils; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import com.tuoheng.common.core.utils.StringUtils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
/** | |||||
* 修改用户密码业务层处理 | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class UpdateUserPasswordService { | |||||
@Autowired | |||||
private UserMapper userMapper; | |||||
@Autowired | |||||
private OidcService oidcService; | |||||
/** | |||||
* 修改用户密码数据 | |||||
* | |||||
* @return | |||||
*/ | |||||
public JsonResult resetPwd(String id) { | |||||
log.info("进入修改用户密码业务接口: id={}, status={}", id); | |||||
JsonResult result = this.check(id); | |||||
if (0 != result.getCode()) { | |||||
log.info("修改用户密码业务接口:校验失败:{}", result.getMsg()); | |||||
return result; | |||||
} | |||||
User user = (User) result.getData(); | |||||
// 修改oidc用户密码 | |||||
result = oidcService.editUserPassword(user); | |||||
if (0 != result.getCode()) { | |||||
log.info("修改用户密码业务接口:修改oidc用户密码失败:{}", result.getMsg()); | |||||
return result; | |||||
} | |||||
user.setPassword(CommonUtils.password("123456")); | |||||
Integer rowCount = userMapper.updateById(user); | |||||
if (rowCount <= 0) { | |||||
return JsonResult.error(EditUserPasswordCodeEnum.EDIT_IS_FAILED.getCode(), EditUserPasswordCodeEnum.EDIT_IS_FAILED.getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
/** | |||||
* 检查参数 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
private JsonResult check(String id) { | |||||
if (StringUtils.isEmpty(id)) { | |||||
return JsonResult.error(EditUserPasswordCodeEnum.USER_ID_IS_NULL.getCode(), EditUserPasswordCodeEnum.USER_ID_IS_NULL.getMsg()); | |||||
} | |||||
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||||
.eq(User::getId, id) | |||||
.eq(User::getMark, 1)); | |||||
if (ObjectUtil.isNull(user)) { | |||||
return JsonResult.error(EditUserPasswordCodeEnum.USER_IS_NOT_EXIST.getCode(), EditUserPasswordCodeEnum.USER_IS_NOT_EXIST.getMsg()); | |||||
} | |||||
if (!user.getTenantId().equals(CurrentUserUtil.getTenantId())) { | |||||
return JsonResult.error(EditUserPasswordCodeEnum.NON_TENANT_USER.getCode(), EditUserPasswordCodeEnum.NON_TENANT_USER.getMsg()); | |||||
} | |||||
return JsonResult.success(user); | |||||
} | |||||
} |
package com.tuoheng.admin.service.user.update; | package com.tuoheng.admin.service.user.update; | ||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
import com.tuoheng.admin.entity.User; | import com.tuoheng.admin.entity.User; | ||||
import com.tuoheng.admin.enums.code.user.AddUserCodeEnum; | |||||
import com.tuoheng.admin.enums.code.user.EditUserCodeEnum; | |||||
import com.tuoheng.admin.mapper.UserMapper; | import com.tuoheng.admin.mapper.UserMapper; | ||||
import com.tuoheng.admin.service.third.oidc.OidcService; | |||||
import com.tuoheng.admin.utils.CurrentUserUtil; | import com.tuoheng.admin.utils.CurrentUserUtil; | ||||
import com.tuoheng.common.core.config.common.CommonConfig; | import com.tuoheng.common.core.config.common.CommonConfig; | ||||
import com.tuoheng.common.core.utils.CommonUtils; | import com.tuoheng.common.core.utils.CommonUtils; | ||||
@Autowired | @Autowired | ||||
private UserMapper userMapper; | private UserMapper userMapper; | ||||
@Autowired | |||||
private OidcService oidcService; | |||||
/** | /** | ||||
* 修改用户数据 | * 修改用户数据 | ||||
* | * | ||||
String tenantId = CurrentUserUtil.getTenantId(); | String tenantId = CurrentUserUtil.getTenantId(); | ||||
JsonResult result = this.check(tenantId, user); | JsonResult result = this.check(tenantId, user); | ||||
if (0 != result.getCode()) { | if (0 != result.getCode()) { | ||||
log.info("添加修改用户业务接口:校验失败:{}", result.getMsg()); | |||||
log.info("修改用户业务接口:校验失败:{}", result.getMsg()); | |||||
return result; | return result; | ||||
} | } | ||||
// 添加oidc | |||||
//id | |||||
user.setCreateUser(CurrentUserUtil.getUserId()); | |||||
// 设置密码 | |||||
if (StringUtils.isNotEmpty(user.getPassword())) { | |||||
user.setPassword(CommonUtils.password(user.getPassword())); | |||||
} else { | |||||
//默认为123456密码 | |||||
user.setPassword(CommonUtils.password("123456")); | |||||
// 修改oidc | |||||
result = oidcService.editUser(user); | |||||
if (0 != result.getCode()) { | |||||
log.info("修改用户业务接口:修改oidc数据失败:{}", result.getMsg()); | |||||
return result; | |||||
} | } | ||||
if (StringUtils.isNotNull(user.getAvatar()) && user.getAvatar().contains(CommonConfig.imageURL)) { | |||||
user.setAvatar(user.getAvatar().replaceAll(CommonConfig.imageURL, "")); | |||||
} else { | |||||
//添加默认头像 | |||||
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png"); | |||||
} | |||||
this.buildUser(user); | |||||
if (StringUtils.isNotEmpty(user.getMobile())) { | |||||
//校验手机号 | |||||
boolean flag = CommonUtils.isMobile(user.getMobile()); | |||||
if (!flag) { | |||||
return JsonResult.error("该用户手机号格式有误"); | |||||
} | |||||
Integer rowCount = userMapper.updateById(user); | |||||
if (rowCount <= 0) { | |||||
return JsonResult.error(); | |||||
} | } | ||||
// user.setTenantId(CurrentUserUtil.getTenantId()); | |||||
// user.setCityName(selectCityName(user)); | |||||
// user.setCreateUser(CurrentUserUtil.getUserId()); | |||||
// user.setCreateTime(DateUtils.now()); | |||||
// | |||||
// result = this.saveOrUpdate(user); | |||||
// if (!result) { | |||||
// return JsonResult.error(); | |||||
// } | |||||
// // 删除已存在的用户角色关系数据 | |||||
// userRoleService.deleteUserRole(user.getId()); | |||||
// | |||||
// // 插入用户角色关系数据 | |||||
// //userRoleService.insertUserRole(entity.getId(), entity.getRoleIds()); | |||||
// UserRole userRole = new UserRole(); | |||||
// //租户id | |||||
// userRole.setTenantId(user.getTenantId()); | |||||
// userRole.setUserId(user.getId()); | |||||
// userRole.setRoleId(user.getRoleId()); | |||||
// userRoleService.save(userRole); | |||||
return JsonResult.success(); | return JsonResult.success(); | ||||
} | } | ||||
/** | /** | ||||
* 检查参数 | * 检查参数 | ||||
* @return | * @return | ||||
*/ | */ | ||||
private JsonResult check(String tenantId, User user) { | private JsonResult check(String tenantId, User user) { | ||||
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() | |||||
if (StringUtils.isNotEmpty(user.getMobile())) { | |||||
//校验手机号 | |||||
boolean flag = CommonUtils.isMobile(user.getMobile()); | |||||
if (!flag) { | |||||
return JsonResult.error(EditUserCodeEnum.PHONE_NOT_IMATCH.getCode(), EditUserCodeEnum.PHONE_NOT_IMATCH.getMsg()); | |||||
} | |||||
} | |||||
User userTmp = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||||
.eq(User::getTenantId, tenantId) | .eq(User::getTenantId, tenantId) | ||||
.eq(User::getUsername, user.getUsername()) | |||||
.eq(User::getId, user.getId()) | |||||
.eq(User::getMark, 1)); | .eq(User::getMark, 1)); | ||||
if (ObjectUtil.isNull(userTmp)) { | |||||
return JsonResult.error("该用户不存在"); | |||||
} | |||||
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() | |||||
.eq(User::getTenantId, tenantId) | |||||
.eq(User::getUsername, user.getUsername()) | |||||
.eq(User::getMark, 1)); | |||||
if (count > 0) { | if (count > 0) { | ||||
return JsonResult.error("系统中已经存在相同的账号信息"); | |||||
return JsonResult.error(EditUserCodeEnum.USERNAME_ALREADY_EXISTS.getCode(), EditUserCodeEnum.USERNAME_ALREADY_EXISTS.getMsg()); | |||||
} | } | ||||
return JsonResult.success(); | return JsonResult.success(); | ||||
} | } | ||||
/** | |||||
* | |||||
* 构建实体字段数据 | |||||
* | |||||
* @param user | |||||
*/ | |||||
private void buildUser(User user) { | |||||
if (StringUtils.isNotNull(user.getAvatar()) && user.getAvatar().contains(CommonConfig.imageURL)) { | |||||
user.setAvatar(user.getAvatar().replaceAll(CommonConfig.imageURL, "")); | |||||
} else { | |||||
//添加默认头像 | |||||
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png"); | |||||
} | |||||
user.setCityName(""); | |||||
user.setUpdateUser(CurrentUserUtil.getUserId()); | |||||
user.setUpdateTime(DateUtils.now()); | |||||
} | |||||
} | } |
package com.tuoheng.admin.service.user.update; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.tuoheng.admin.entity.User; | |||||
import com.tuoheng.admin.enums.code.user.EditUserStatusCodeEnum; | |||||
import com.tuoheng.admin.mapper.UserMapper; | |||||
import com.tuoheng.admin.service.third.oidc.OidcService; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import com.tuoheng.common.core.utils.StringUtils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
/** | |||||
* 修改用户状态业务层处理 | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-12-16 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class UpdateUserStatusService { | |||||
@Autowired | |||||
private UserMapper userMapper; | |||||
@Autowired | |||||
private OidcService oidcService; | |||||
/** | |||||
* 修改用户状态数据 | |||||
* | |||||
* @return | |||||
*/ | |||||
public JsonResult update(String id, Integer status) { | |||||
log.info("进入修改用户状态业务接口: id={}, status={}", id, status); | |||||
JsonResult result = this.check(id); | |||||
if (0 != result.getCode()) { | |||||
log.info("修改用户状态业务接口:校验失败:{}", result.getMsg()); | |||||
return result; | |||||
} | |||||
User user = User.builder().build().setId(id).setStatus(status); | |||||
Integer rowCount = userMapper.updateById(user); | |||||
if (rowCount <= 0) { | |||||
return JsonResult.error(EditUserStatusCodeEnum.EDIT_IS_FAILED.getCode(), EditUserStatusCodeEnum.EDIT_IS_FAILED.getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
/** | |||||
* 检查参数 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
private JsonResult check(String id) { | |||||
if (StringUtils.isEmpty(id)) { | |||||
return JsonResult.error(EditUserStatusCodeEnum.USER_ID_IS_NULL.getCode(), EditUserStatusCodeEnum.USER_ID_IS_NULL.getMsg()); | |||||
} | |||||
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||||
.eq(User::getId, id) | |||||
.eq(User::getMark, 1)); | |||||
if (ObjectUtil.isNull(user)) { | |||||
return JsonResult.error(EditUserStatusCodeEnum.USER_IS_NOT_EXIST.getCode(), EditUserStatusCodeEnum.USER_IS_NOT_EXIST.getMsg()); | |||||
} | |||||
return JsonResult.success(); | |||||
} | |||||
} |
id, tenant_id, code, realname, nickname, gender, avatar, mobile, email, birthday, dept_id, province_code, city_code, district_code, street_code, address, city_name, username, password, type, driver_type, driver_code, salt, intro, status, note, sort, login_num, login_ip, login_time, create_user, create_time, update_user, update_time, role_id, client_id, mark | id, tenant_id, code, realname, nickname, gender, avatar, mobile, email, birthday, dept_id, province_code, city_code, district_code, street_code, address, city_name, username, password, type, driver_type, driver_code, salt, intro, status, note, sort, login_num, login_ip, login_time, create_user, create_time, update_user, update_time, role_id, client_id, mark | ||||
</sql> | </sql> | ||||
<update id="updateByIdList" parameterType="hashmap"> | |||||
update th_oauth_user | |||||
<trim prefix="SET" suffixOverrides=","> | |||||
<if test="mark != null"> mark = #{mark}, </if> | |||||
<if test="updateUser != null and updateUser != ''"> update_user = #{updateUser}, </if> | |||||
<if test="updateTime != null"> update_time = #{updateTime}, </if> | |||||
</trim> | |||||
<where> | |||||
<if test="idList != null and idList.size() > 0"> | |||||
and id in | |||||
<foreach collection="idList" item="id" separator="," open="(" close=")"> | |||||
#{id} | |||||
</foreach> | |||||
</if> | |||||
</where> | |||||
</update> | |||||
</mapper> | </mapper> |