|
@@ -3,15 +3,18 @@ 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.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.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
@@ -46,11 +49,10 @@ public class SysSystemUserServiceImpl extends ServiceImpl<SysSystemUserMapper, S
|
|
|
//生成token
|
|
|
StpUtil.login(sysSystemUser.getId());
|
|
|
//更新登录信息
|
|
|
- updateById(new SysSystemUser()
|
|
|
- .setId(sysSystemUser.getId())
|
|
|
- .setLastLoginTime(LocalDateTime.now())
|
|
|
- .setLoginNum(sysSystemUser.getLoginNum() + 1)
|
|
|
- );
|
|
|
+ SysSystemUserDto.UpdateDto updateDto = new SysSystemUserDto.UpdateDto()
|
|
|
+ .setIsLogin(true);
|
|
|
+ updateDto.setId(sysSystemUser.getId());
|
|
|
+ update(updateDto);
|
|
|
return R.ok(StpUtil.getTokenValue());
|
|
|
}
|
|
|
|
|
@@ -72,4 +74,39 @@ public class SysSystemUserServiceImpl extends ServiceImpl<SysSystemUserMapper, S
|
|
|
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();
|
|
|
+ }
|
|
|
+
|
|
|
}
|