6 changed files with 221 additions and 0 deletions
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
package com.cloud.kicc.system.api.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.cloud.kicc.common.data.entity.CommonEntity; |
||||
import io.swagger.annotations.ApiModel; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
*<p> |
||||
* SSO用户统一表 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @Since: 2023/8/6 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@TableName("sys_sso_user") |
||||
@ApiModel(description = "SSO用户表") |
||||
public class SsoUser extends CommonEntity { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** 用户ID */ |
||||
private String id; |
||||
|
||||
/** 用户名 */ |
||||
private String userName; |
||||
|
||||
/** 昵称 */ |
||||
private String nickName; |
||||
|
||||
/** 密码 */ |
||||
private String password; |
||||
|
||||
/** 用户邮箱 */ |
||||
private String email; |
||||
|
||||
/** 手机号码 */ |
||||
private String phone; |
||||
|
||||
/** 用户性别(0男 1女 2未知) */ |
||||
private String sex; |
||||
|
||||
/** 头像路径 */ |
||||
private String avatar; |
||||
|
||||
/** 最后登陆IP */ |
||||
private String loginIp; |
||||
|
||||
/** 最后登陆时间 */ |
||||
private LocalDateTime loginTime; |
||||
|
||||
/** 权限标识集合 */ |
||||
@TableField(exist = false) |
||||
private String[] permissions; |
||||
|
||||
/** 新密码 */ |
||||
@TableField(exist = false) |
||||
private String newPassword; |
||||
} |
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
package com.cloud.kicc.system.controller; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.cloud.kicc.common.core.api.R; |
||||
import com.cloud.kicc.common.core.constant.AppConstants; |
||||
import com.cloud.kicc.common.log.annotation.SysLog; |
||||
import com.cloud.kicc.common.security.util.SecurityUtils; |
||||
import com.cloud.kicc.system.api.entity.SsoUser; |
||||
import com.cloud.kicc.system.api.entity.User; |
||||
import com.cloud.kicc.system.service.ISsoUserService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
||||
import org.springframework.security.crypto.password.PasswordEncoder; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
*<p> |
||||
* SSO用户统一控制器 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @Since: 2023/8/6 |
||||
*/ |
||||
@RestController |
||||
@RequiredArgsConstructor |
||||
@RequestMapping(AppConstants.APP_SYSTEM + "/ssoUser") |
||||
public class SsoUserController { |
||||
|
||||
private final ISsoUserService iSsoUserService; |
||||
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder(); |
||||
|
||||
private LambdaQueryWrapper<SsoUser> getQueryWrapper(SsoUser ssoUser) { |
||||
return new LambdaQueryWrapper<SsoUser>() |
||||
.like(StrUtil.isNotBlank(ssoUser.getUserName()), SsoUser::getUserName, ssoUser.getUserName()) |
||||
.like(StrUtil.isNotBlank(ssoUser.getNickName()), SsoUser::getNickName, ssoUser.getNickName()) |
||||
.eq(StrUtil.isNotBlank(ssoUser.getId()), SsoUser::getId, ssoUser.getId()) |
||||
.between(StrUtil.isAllNotBlank(ssoUser.getBeginTime(), ssoUser.getEndTime()), SsoUser::getCreateTime, ssoUser.getBeginTime(), ssoUser.getEndTime()); |
||||
} |
||||
|
||||
@GetMapping("/list") |
||||
public R list(Page page, SsoUser ssoUser) { |
||||
IPage<User> results = iSsoUserService.page(page, getQueryWrapper(ssoUser)); |
||||
return R.ok(results.getRecords(), results.getTotal()); |
||||
} |
||||
|
||||
@GetMapping("/{id:\\w+}") |
||||
public R getById(@PathVariable("id") String id) { |
||||
return R.ok(iSsoUserService.getById(id)); |
||||
} |
||||
|
||||
|
||||
@PostMapping("/save") |
||||
public R save(@Validated @RequestBody SsoUser ssoUser) { |
||||
ssoUser.setPassword(ENCODER.encode(ssoUser.getPassword())); |
||||
iSsoUserService.save(ssoUser); |
||||
return R.ok(); |
||||
} |
||||
|
||||
@PutMapping("/update") |
||||
public R update(@Validated @RequestBody SsoUser ssoUser) { |
||||
iSsoUserService.updateById(ssoUser); |
||||
return R.ok(); |
||||
} |
||||
|
||||
@DeleteMapping("/remove/{id:[\\w,]+}") |
||||
public R remove(@PathVariable String[] id) { |
||||
iSsoUserService.removeByIds(Arrays.asList(id)); |
||||
return R.ok(); |
||||
} |
||||
|
||||
@PutMapping("/resetPwd") |
||||
public R resetPwd(@Validated @RequestBody SsoUser ssoUser) { |
||||
iSsoUserService.update(Wrappers.<SsoUser>update().lambda().eq(SsoUser::getId, ssoUser.getId()).set(SsoUser::getPassword, ENCODER.encode(ssoUser.getNewPassword()))); |
||||
return R.ok(); |
||||
} |
||||
|
||||
@PutMapping("/updatePwd") |
||||
public R updatePwd(@Validated @RequestBody SsoUser ssoUser) { |
||||
SsoUser originUser = iSsoUserService.getById(SecurityUtils.getUser().getId()); |
||||
if (originUser != null && StrUtil.equals(ENCODER.encode(ssoUser.getPassword()), originUser.getPassword())) { |
||||
iSsoUserService.update(Wrappers.<SsoUser>update().lambda().eq(SsoUser::getId, originUser.getId()).set(SsoUser::getPassword, ssoUser.getPassword())); |
||||
return R.ok(); |
||||
} else { |
||||
return R.error("原密码有误,请重试"); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package com.cloud.kicc.system.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.cloud.kicc.system.api.entity.SsoUser; |
||||
|
||||
/** |
||||
*<p> |
||||
* SSO用户统一 Mapper 接口 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @Since: 2023/8/6 |
||||
*/ |
||||
public interface SsoUserMapper extends BaseMapper<SsoUser> { |
||||
|
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package com.cloud.kicc.system.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.cloud.kicc.system.api.entity.SsoUser; |
||||
|
||||
/** |
||||
*<p> |
||||
* SSO用户统一 服务层 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @Since: 2023/8/6 |
||||
*/ |
||||
public interface ISsoUserService extends IService<SsoUser> { |
||||
|
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
package com.cloud.kicc.system.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.cloud.kicc.system.api.entity.SsoUser; |
||||
import com.cloud.kicc.system.mapper.SsoUserMapper; |
||||
import com.cloud.kicc.system.service.ISsoUserService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
*<p> |
||||
* SSO用户统一 实现类 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @Since: 2023/8/6 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class SsoUserServiceImpl extends ServiceImpl<SsoUserMapper, SsoUser> implements ISsoUserService { |
||||
|
||||
} |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.cloud.kicc.system.mapper.SsoUserMapper"> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue