xiaoqiantx
This commit is contained in:
parent
c3a8c17a65
commit
a7b578c7a0
|
@ -9,3 +9,7 @@ auth:
|
||||||
- /swagger-ui/**
|
- /swagger-ui/**
|
||||||
- /doc.html
|
- /doc.html
|
||||||
- /
|
- /
|
||||||
|
- /maku/t_user/login
|
||||||
|
- /maku/t_user/updateUser
|
||||||
|
- /maku/t_user/register
|
||||||
|
- /maku/t_user/logout
|
|
@ -1,6 +1,7 @@
|
||||||
package net.maku.maku.controller;
|
package net.maku.maku.controller;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
|
@ -30,6 +31,23 @@ import java.util.List;
|
||||||
public class TBookController {
|
public class TBookController {
|
||||||
private final TBookService tBookService;
|
private final TBookService tBookService;
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "列表")
|
||||||
|
public Result<List<TBookEntity>> list() {
|
||||||
|
List<TBookEntity> list = tBookService.list();
|
||||||
|
|
||||||
|
return Result.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
@Operation(summary = "书籍")
|
||||||
|
@Parameter
|
||||||
|
public Result<TBookEntity> getById(@PathVariable Long id){
|
||||||
|
TBookEntity entity = tBookService.getById(id);
|
||||||
|
|
||||||
|
return Result.ok(entity);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
@PreAuthorize("hasAuthority('maku:t_book:page')")
|
@PreAuthorize("hasAuthority('maku:t_book:page')")
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package net.maku.maku.controller;
|
package net.maku.maku.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.maku.framework.common.cache.RedisCache;
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
import net.maku.framework.common.utils.Result;
|
import net.maku.framework.common.utils.Result;
|
||||||
import net.maku.maku.convert.TUserConvert;
|
import net.maku.maku.convert.TUserConvert;
|
||||||
|
@ -10,7 +13,9 @@ import net.maku.maku.entity.TUserEntity;
|
||||||
import net.maku.maku.service.TUserService;
|
import net.maku.maku.service.TUserService;
|
||||||
import net.maku.maku.query.TUserQuery;
|
import net.maku.maku.query.TUserQuery;
|
||||||
import net.maku.maku.vo.TUserVO;
|
import net.maku.maku.vo.TUserVO;
|
||||||
|
import oracle.jdbc.proxy.annotation.Post;
|
||||||
import org.springdoc.core.annotations.ParameterObject;
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -29,6 +34,55 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TUserController {
|
public class TUserController {
|
||||||
private final TUserService tUserService;
|
private final TUserService tUserService;
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
|
||||||
|
@PostMapping("/register")
|
||||||
|
@Operation(summary = "注册")
|
||||||
|
public ResponseEntity<Result<String>> register(@RequestBody TUserEntity entity) {
|
||||||
|
TUserEntity existingUser = tUserService.login(entity);
|
||||||
|
if (existingUser != null) {
|
||||||
|
return ResponseEntity.badRequest().body(Result.error("用户名已存在"));
|
||||||
|
} else {
|
||||||
|
tUserService.save(entity);
|
||||||
|
return ResponseEntity.ok(Result.ok("注册成功"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
@Operation(summary = "登录")
|
||||||
|
public Result login(@RequestBody TUserEntity entity){
|
||||||
|
TUserEntity entity1 = tUserService.login(entity);
|
||||||
|
if(ObjectUtils.isNotNull(entity1)){
|
||||||
|
return Result.ok(entity1);
|
||||||
|
}else {
|
||||||
|
return Result.error("登录失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/updateUser")
|
||||||
|
@Operation(summary = "修改")
|
||||||
|
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
|
||||||
|
TUserVO tUserVO = tUserService.updateUser(vo);
|
||||||
|
|
||||||
|
return Result.ok(tUserVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/logout")
|
||||||
|
@Operation(summary = "退出登录")
|
||||||
|
public Result<String> logout(HttpServletRequest request) {
|
||||||
|
String token = request.getHeader("token");
|
||||||
|
if (token == null) {
|
||||||
|
return Result.error("token为空");
|
||||||
|
}
|
||||||
|
Object o = redisCache.get(token);
|
||||||
|
if (o != null) {
|
||||||
|
redisCache.delete(token);
|
||||||
|
return Result.ok("退出登录");
|
||||||
|
}
|
||||||
|
return Result.error("登录失败");
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
|
@ -74,4 +128,6 @@ public class TUserController {
|
||||||
|
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,4 +23,5 @@ public interface TBookService extends BaseService<TBookEntity> {
|
||||||
void update(TBookVO vo);
|
void update(TBookVO vo);
|
||||||
|
|
||||||
void delete(List<Long> idList);
|
void delete(List<Long> idList);
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,4 +23,9 @@ public interface TUserService extends BaseService<TUserEntity> {
|
||||||
void update(TUserVO vo);
|
void update(TUserVO vo);
|
||||||
|
|
||||||
void delete(List<Long> idList);
|
void delete(List<Long> idList);
|
||||||
|
|
||||||
|
TUserEntity login(TUserEntity entity);
|
||||||
|
|
||||||
|
TUserVO updateUser(TUserVO vo);
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package net.maku.maku.service.impl;
|
package net.maku.maku.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -27,6 +29,7 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> implements TUserService {
|
public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> implements TUserService {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<TUserVO> page(TUserQuery query) {
|
public PageResult<TUserVO> page(TUserQuery query) {
|
||||||
IPage<TUserEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
IPage<TUserEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
|
@ -60,4 +63,28 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
|
||||||
removeByIds(idList);
|
removeByIds(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TUserEntity login(TUserEntity entity) {
|
||||||
|
LambdaQueryWrapper<TUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TUserEntity::getUsername, entity.getUsername());
|
||||||
|
wrapper.eq(TUserEntity::getPassword, entity.getPassword());
|
||||||
|
TUserEntity user = getOne(wrapper);
|
||||||
|
if (ObjectUtils.isNotNull(user)){
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
user.setAvatar(uuid.toString());
|
||||||
|
updateById(user);
|
||||||
|
return user;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TUserVO updateUser(TUserVO vo) {
|
||||||
|
TUserEntity entity =new TUserEntity();
|
||||||
|
entity.setUsername(vo.getUsername());
|
||||||
|
entity.setPassword(vo.getPassword());
|
||||||
|
updateById(entity);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user