| | |
| | | import com.xiaopeng.common.core.enums.DisabledEnum; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.RSAUtil; |
| | | import com.xiaopeng.common.core.utils.SensitiveDataCryptoUtil; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | | import com.xiaopeng.common.core.web.controller.BaseController; |
| | | import com.xiaopeng.common.core.web.domain.AjaxResult; |
| | |
| | | import java.util.Objects; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | |
| | | /** |
| | | * 用户信息 |
| | |
| | | @Log(title = "帐号管理", businessType = BusinessType.INSERT) |
| | | @PostMapping("/api/v1/sys-user/add") |
| | | @ApiOperation(value = "添加帐号", tags = {"管理后台-帐号管理"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.ACCOUNT_MANAGEMENT, |
| | | operationType = AdminOperationType.ADD, |
| | | content = "添加帐号", |
| | | appendRequestData = true |
| | | ) |
| | | public AjaxResult add(@RequestBody SysUser user) { |
| | | if (StringUtils.isNotEmpty(user.getPhoneNumber()) && !userService.checkPhoneUnique(user)) { |
| | | throw new ServiceException("手机号已开通账号", I18nKeyConstant.ACCOUNT_PHONE_DUPLICATE); |
| | |
| | | @Log(title = "帐号管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/api/v1/sys-user/edit") |
| | | @ApiOperation(value = "编辑帐号", tags = {"管理后台-帐号管理"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.ACCOUNT_MANAGEMENT, |
| | | operationType = AdminOperationType.EDIT, |
| | | content = "编辑帐号", |
| | | appendRequestData = true |
| | | ) |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) { |
| | | userService.checkUserAllowed(user); |
| | | // userService.checkUserDataScope(user.getId()); |
| | | SysUser sysUser = userService.getOne(Wrappers.lambdaQuery(SysUser.class) |
| | | .eq(SysUser::getPhoneNumber, user.getPhoneNumber()) |
| | | .in(SysUser::getPhoneNumber, SensitiveDataCryptoUtil.queryValues(user.getPhoneNumber())) |
| | | .last("LIMIT 1")); |
| | | |
| | | if (StringUtils.isNotEmpty(user.getPhoneNumber()) && (Objects.nonNull(sysUser) && !user.getId().equals(sysUser.getId()) )) { |
| | |
| | | @Log(title = "帐号管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/api/v1/sys-user/{userIds}") |
| | | @ApiOperation(value = "删除账号", tags = {"管理后台-帐号管理"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.ACCOUNT_MANAGEMENT, |
| | | operationType = AdminOperationType.DELETE, |
| | | content = "删除账号", |
| | | appendRequestData = true |
| | | ) |
| | | public AjaxResult remove(@PathVariable Long[] userIds) { |
| | | if (ArrayUtils.contains(userIds, tokenService.getLoginUser())) { |
| | | throw new ServiceException("当前用户不能删除", I18nKeyConstant.ACCOUNT_CURRENT_USER_NOT_DELETE); |
| | |
| | | |
| | | @PostMapping("/api/v1/sys-user/switchStatus/{id}") |
| | | @ApiOperation(value = "账号管理--禁用/启用", tags = {"管理后台-帐号管理"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.ACCOUNT_MANAGEMENT, |
| | | operationType = AdminOperationType.SWITCH_STATUS, |
| | | content = "账号管理--禁用/启用", |
| | | appendRequestData = true |
| | | ) |
| | | public AjaxResult shopUserStart(@ApiParam(name = "id", value = "帐号ID") @PathVariable("id") Long id) { |
| | | SysUser sysUser = userService.getById(id); |
| | | if (sysUser.getStatus().equals(DisabledEnum.NO.getCode())) { |
| | |
| | | @Log(title = "帐号管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/api/v1/sys-user/rePassword") |
| | | @ApiOperation(value = "重置密码", tags = {"管理后台-帐号管理"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.ACCOUNT_MANAGEMENT, |
| | | operationType = AdminOperationType.RESET_PASSWORD, |
| | | content = "重置密码", |
| | | appendRequestData = true |
| | | ) |
| | | public AjaxResult resetPwd(@RequestBody UserPwdResetDTO dto) { |
| | | SysUser user = userService.getById(dto.getUserId()); |
| | | if (Objects.isNull(user)) { |
| | |
| | | @PostMapping("/queryUserByPhoneList") |
| | | public R<List<SysUser>> queryUserByPhoneList(@RequestBody List<String> phoneList){ |
| | | List<SysUser> list = userService.list(Wrappers.lambdaQuery(SysUser.class) |
| | | .in(SysUser::getPhoneNumber, phoneList)); |
| | | .in(SysUser::getPhoneNumber, buildPhoneQueryValues(phoneList))); |
| | | return R.ok(list); |
| | | } |
| | | |
| | |
| | | @PostMapping("/queryUserByPhone") |
| | | public R<SysUser> queryUserByPhone(@RequestBody String phone){ |
| | | SysUser user = userService.getOne(Wrappers.lambdaQuery(SysUser.class) |
| | | .eq(SysUser::getPhoneNumber, phone) |
| | | .in(SysUser::getPhoneNumber, SensitiveDataCryptoUtil.queryValues(phone)) |
| | | .last("LIMIT 1")); |
| | | return R.ok(user); |
| | | } |
| | | |
| | | private List<String> buildPhoneQueryValues(List<String> phoneList) { |
| | | if (phoneList == null) { |
| | | return java.util.Collections.emptyList(); |
| | | } |
| | | return phoneList.stream() |
| | | .filter(StringUtils::isNotBlank) |
| | | .flatMap(phone -> SensitiveDataCryptoUtil.queryValues(phone).stream()) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通过账号查询用户 |