|
@@ -1,22 +1,23 @@
|
|
|
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.core.metadata.IPage;
|
|
|
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 com.xy.utils.*;
|
|
|
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.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+
|
|
|
import static com.xy.utils.Beans.copy;
|
|
|
|
|
|
/**
|
|
@@ -31,20 +32,81 @@ 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());
|
|
|
+ //更新登录信息
|
|
|
+ SysSystemUserDto.UpdateDto updateDto = new SysSystemUserDto.UpdateDto()
|
|
|
+ .setIsLogin(true);
|
|
|
+ updateDto.setId(sysSystemUser.getId());
|
|
|
+ update(updateDto);
|
|
|
+ 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();
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("page")
|
|
|
+ @ApiOperation("分页查询")
|
|
|
+ public R<IPage<SysSystemUserDto.Vo>> page(@RequestBody SysSystemUserDto sysSystemUserDto) {
|
|
|
+ LambdaQueryWrapper<SysSystemUser> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(sysSystemUserDto, SysSystemUser.class)
|
|
|
+ .ge(SysSystemUser::getCreateTime, sysSystemUserDto.getBeginCreateTime().atTime(0, 0, 0))
|
|
|
+ .le(SysSystemUser::getCreateTime, sysSystemUserDto.getEndCreateTime().atTime(23, 59, 59))
|
|
|
+ .build()
|
|
|
+ .select(SysSystemUser.class, info -> !info.getColumn().equals(LambdaUtils.getProperty(SysSystemUser::getPassword)));
|
|
|
+ IPage<SysSystemUser> page = page(sysSystemUserDto.getPage(), lambdaQueryWrapper);
|
|
|
+ IPage<SysSystemUserDto.Vo> result = PlusBeans.copy(SysSystemUserDto.Vo.class, page);
|
|
|
+ return R.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("update")
|
|
|
+ @ApiOperation("修改")
|
|
|
+ public R<Boolean> update(@RequestBody SysSystemUserDto.UpdateDto updateDto) {
|
|
|
+ SysSystemUser sysSystemUser = new SysSystemUser()
|
|
|
+ .setId(updateDto.getId())
|
|
|
+ .setStatus(Emptys.check(updateDto.getStatus()) ? updateDto.getStatus() : null)
|
|
|
+ .setPassword(Emptys.check(updateDto.getIsAgainPwd()) && updateDto.getIsAgainPwd() ? "88888888" : null)
|
|
|
+ .setPassword(Emptys.check(updateDto.getPassword()) ? SecureUtil.md5(updateDto.getPassword()) : null);
|
|
|
+ //如果是登录则更新登录时间和次数
|
|
|
+ if (Emptys.check(updateDto.getIsLogin()) && updateDto.getIsLogin()) {
|
|
|
+ sysSystemUser.setLastLoginTime(LocalDateTime.now()).setLoginNum(getById(updateDto.getId()).getLoginNum() + 1);
|
|
|
+ } else {
|
|
|
+ sysSystemUser.update(Long.parseLong(SaTokenUtils.getId().toString()));
|
|
|
+ }
|
|
|
+ updateById(sysSystemUser);
|
|
|
+ //如果封禁账号则踢下线
|
|
|
+ if (Emptys.check(updateDto.getStatus()) && !updateDto.getStatus()) {
|
|
|
+ StpUtil.logout(SaTokenUtils.getId());
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
}
|