xiaoqiantx

This commit is contained in:
xiaoqiantx223 2024-07-17 17:23:45 +08:00
parent c3a8c17a65
commit a7b578c7a0
6 changed files with 113 additions and 2 deletions

View File

@ -8,4 +8,8 @@ auth:
- /swagger-ui.html
- /swagger-ui/**
- /doc.html
- /
- /
- /maku/t_user/login
- /maku/t_user/updateUser
- /maku/t_user/register
- /maku/t_user/logout

View File

@ -1,6 +1,7 @@
package net.maku.maku.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
@ -30,6 +31,23 @@ import java.util.List;
public class TBookController {
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")
@Operation(summary = "分页")
@PreAuthorize("hasAuthority('maku:t_book:page')")

View File

@ -1,8 +1,11 @@
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.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import net.maku.framework.common.cache.RedisCache;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
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.query.TUserQuery;
import net.maku.maku.vo.TUserVO;
import oracle.jdbc.proxy.annotation.Post;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -18,7 +23,7 @@ import jakarta.validation.Valid;
import java.util.List;
/**
*
*
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2024-07-16
@ -29,6 +34,55 @@ import java.util.List;
@AllArgsConstructor
public class TUserController {
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")
@Operation(summary = "分页")
@ -74,4 +128,6 @@ public class TUserController {
return Result.ok();
}
}

View File

@ -23,4 +23,5 @@ public interface TBookService extends BaseService<TBookEntity> {
void update(TBookVO vo);
void delete(List<Long> idList);
}

View File

@ -23,4 +23,9 @@ public interface TUserService extends BaseService<TUserEntity> {
void update(TUserVO vo);
void delete(List<Long> idList);
TUserEntity login(TUserEntity entity);
TUserVO updateUser(TUserVO vo);
}

View File

@ -1,5 +1,6 @@
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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.UUID;
/**
*
@ -27,6 +29,7 @@ import java.util.List;
@AllArgsConstructor
public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> implements TUserService {
@Override
public PageResult<TUserVO> page(TUserQuery query) {
IPage<TUserEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
@ -60,4 +63,28 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
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;
}
}