|
@@ -1,21 +1,19 @@
|
|
|
package com.xy.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.github.yitter.idgen.YitIdHelper;
|
|
|
import com.xy.dto.SysSystemUserDto;
|
|
|
import com.xy.entity.SysSystemUser;
|
|
|
import com.xy.mapper.SysSystemUserMapper;
|
|
|
import com.xy.service.SysSystemUserService;
|
|
|
import com.xy.utils.R;
|
|
|
-import com.xy.utils.SaTokenUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.Data;
|
|
|
-import lombok.experimental.Accessors;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
import static com.xy.utils.Beans.copy;
|
|
|
|
|
@@ -31,18 +29,45 @@ import static com.xy.utils.Beans.copy;
|
|
|
@Api(tags = "权限用户接口")
|
|
|
public class SysSystemUserServiceImpl extends ServiceImpl<SysSystemUserMapper, SysSystemUser> implements SysSystemUserService {
|
|
|
|
|
|
+ @Override
|
|
|
+ @ApiOperation("登录")
|
|
|
+ public R<String> login(SysSystemUserDto sysSystemUserDto) {
|
|
|
+ //校验账密
|
|
|
+ SysSystemUser sysSystemUser = getOne(new LambdaQueryWrapper<SysSystemUser>()
|
|
|
+ .eq(SysSystemUser::getAccount, sysSystemUserDto.getAccount())
|
|
|
+ .eq(SysSystemUser::getPassword, SecureUtil.md5(sysSystemUserDto.getPassword()))
|
|
|
+ );
|
|
|
+ if (sysSystemUser == null) {
|
|
|
+ return R.fail("账号或密码错误");
|
|
|
+ }
|
|
|
+ if (!sysSystemUser.getStatus()) {
|
|
|
+ return R.fail("账号已被封禁");
|
|
|
+ }
|
|
|
+ //生成token
|
|
|
+ StpUtil.login(sysSystemUser.getId());
|
|
|
+ //更新登录信息
|
|
|
+ updateById(new SysSystemUser()
|
|
|
+ .setId(sysSystemUser.getId())
|
|
|
+ .setLastLoginTime(LocalDateTime.now())
|
|
|
+ .setLoginNum(sysSystemUser.getLoginNum() + 1)
|
|
|
+ );
|
|
|
+ return R.ok(StpUtil.getTokenValue());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@ApiOperation("注册")
|
|
|
- public R<Boolean> register(@RequestBody @Validated SysSystemUserDto sysSystemUserDto) {
|
|
|
- Object loginId = SaTokenUtils.getId();
|
|
|
+ public R<Boolean> register(SysSystemUserDto sysSystemUserDto) {
|
|
|
+ //校验重复
|
|
|
long count = count(new LambdaQueryWrapper<SysSystemUser>()
|
|
|
.eq(SysSystemUser::getAccount, sysSystemUserDto.getAccount())
|
|
|
- .eq(SysSystemUser::getId, loginId)
|
|
|
);
|
|
|
if (count > 0) {
|
|
|
- return R.fail("账户已存在");
|
|
|
+ return R.fail("账号已存在");
|
|
|
}
|
|
|
- SysSystemUser sysSystemUser = copy(SysSystemUser.class, sysSystemUserDto).create(Long.parseLong(loginId.toString()));
|
|
|
+ //注册
|
|
|
+ SysSystemUser sysSystemUser = copy(SysSystemUser.class, sysSystemUserDto)
|
|
|
+ .setPassword(SecureUtil.md5(sysSystemUserDto.getPassword()))
|
|
|
+ .create(null);
|
|
|
save(sysSystemUser);
|
|
|
return R.ok();
|
|
|
}
|