Compare commits
No commits in common. "95f4d10901a8674d5e2858b27720cb6d21d39a77" and "615322087ed2415337033054924d66a454dbee72" have entirely different histories.
95f4d10901
...
615322087e
@ -1,13 +1,13 @@
|
|||||||
package github.benjamin.equipreservebackend.controller;
|
package github.benjamin.equipreservebackend.controller;
|
||||||
|
|
||||||
import github.benjamin.equipreservebackend.dto.TeamDTO;
|
import github.benjamin.equipreservebackend.mapper.TeamMapper;
|
||||||
import github.benjamin.equipreservebackend.response.ResponseResult;
|
import github.benjamin.equipreservebackend.response.ResponseResult;
|
||||||
import github.benjamin.equipreservebackend.service.TeamService;
|
import github.benjamin.equipreservebackend.service.TeamService;
|
||||||
import github.benjamin.equipreservebackend.vo.TeamLabelVO;
|
|
||||||
import github.benjamin.equipreservebackend.vo.TeamVO;
|
import github.benjamin.equipreservebackend.vo.TeamVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -18,35 +18,9 @@ public class TeamController {
|
|||||||
|
|
||||||
private final TeamService teamService;
|
private final TeamService teamService;
|
||||||
|
|
||||||
@GetMapping("/team-label")
|
|
||||||
public ResponseResult<List<TeamLabelVO>> getTeamLabel() {
|
|
||||||
return ResponseResult.success(teamService.getTeamLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/teams")
|
@GetMapping("/teams")
|
||||||
public ResponseResult<List<TeamVO>> getTeams() {
|
public ResponseResult<List<TeamVO>> getTeams() {
|
||||||
return ResponseResult.success(teamService.getTeams());
|
return ResponseResult.success(teamService.getTeams());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
|
||||||
@DeleteMapping("/team/{id}")
|
|
||||||
public ResponseResult<?> deleteTeam(@PathVariable("id") Long id) {
|
|
||||||
teamService.deleteTeam(id);
|
|
||||||
return ResponseResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
|
||||||
@PostMapping("/team")
|
|
||||||
public ResponseResult<?> addTeam(@RequestBody TeamDTO dto) {
|
|
||||||
teamService.addTeam(dto.getName());
|
|
||||||
return ResponseResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
|
||||||
@PutMapping("/team/{id}")
|
|
||||||
public ResponseResult<?> updateTeam(@PathVariable Long id,
|
|
||||||
@RequestBody TeamDTO dto) {
|
|
||||||
teamService.updateTeam(id, dto.getName());
|
|
||||||
return ResponseResult.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package github.benjamin.equipreservebackend.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class TeamDTO {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
}
|
|
@ -2,20 +2,16 @@ package github.benjamin.equipreservebackend.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("teams")
|
@TableName("teams")
|
||||||
@NoArgsConstructor
|
|
||||||
public class Team {
|
public class Team {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
|
private Long leaderId;
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createdTime;
|
||||||
|
|
||||||
public Team(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,17 @@ package github.benjamin.equipreservebackend.exception;
|
|||||||
|
|
||||||
import github.benjamin.equipreservebackend.response.ResponseCode;
|
import github.benjamin.equipreservebackend.response.ResponseCode;
|
||||||
import github.benjamin.equipreservebackend.response.ResponseResult;
|
import github.benjamin.equipreservebackend.response.ResponseResult;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.authorization.AuthorizationDeniedException;
|
import org.springframework.security.authorization.AuthorizationDeniedException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(ApiException.class)
|
@ExceptionHandler(ApiException.class)
|
||||||
public ResponseResult<?> handleApiException(ApiException e) {
|
public ResponseResult<?> handleApiException(ApiException e) {
|
||||||
log.error("[API异常] 错误代码: {}, 错误信息: {}", e.getCode(), e.getMessage(), e);
|
|
||||||
return ResponseResult.fail(e.getCode(), e.getMessage());
|
return ResponseResult.fail(e.getCode(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,20 +22,10 @@ public class GlobalExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseResult<?> handleException(Exception e, HttpServletRequest request) {
|
public ResponseResult<?> handleException(Exception e) {
|
||||||
log.error("[系统异常] 请求地址: {}, 方法: {}, 异常信息: {}, 请求参数: {}",
|
// TODO 日志
|
||||||
request.getRequestURI(),
|
e.printStackTrace();
|
||||||
request.getMethod(),
|
|
||||||
e.getMessage(),
|
|
||||||
getRequestParams(request),
|
|
||||||
e);
|
|
||||||
return ResponseResult.fail(ResponseCode.UNKNOWN_ERROR,"服务器内部异常,请联系开发人员");
|
return ResponseResult.fail(ResponseCode.UNKNOWN_ERROR,"服务器内部异常,请联系开发人员");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRequestParams(HttpServletRequest request) {
|
|
||||||
Map<String, String[]> paramMap = request.getParameterMap();
|
|
||||||
return paramMap.entrySet().stream()
|
|
||||||
.map(entry -> entry.getKey() + "=" + Arrays.toString(entry.getValue()))
|
|
||||||
.collect(Collectors.joining(", ", "{", "}"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,8 @@ package github.benjamin.equipreservebackend.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import github.benjamin.equipreservebackend.entity.Team;
|
import github.benjamin.equipreservebackend.entity.Team;
|
||||||
import github.benjamin.equipreservebackend.vo.TeamVO;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface TeamMapper extends BaseMapper<Team> {
|
public interface TeamMapper extends BaseMapper<Team> {
|
||||||
List<TeamVO> getTeams();
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,9 @@
|
|||||||
package github.benjamin.equipreservebackend.service;
|
package github.benjamin.equipreservebackend.service;
|
||||||
|
|
||||||
import github.benjamin.equipreservebackend.vo.TeamLabelVO;
|
|
||||||
import github.benjamin.equipreservebackend.vo.TeamVO;
|
import github.benjamin.equipreservebackend.vo.TeamVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TeamService {
|
public interface TeamService {
|
||||||
List<TeamLabelVO> getTeamLabel();
|
|
||||||
|
|
||||||
List<TeamVO> getTeams();
|
List<TeamVO> getTeams();
|
||||||
|
|
||||||
void deleteTeam(Long id);
|
|
||||||
|
|
||||||
void addTeam(String name);
|
|
||||||
|
|
||||||
void updateTeam(Long id, String name);
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package github.benjamin.equipreservebackend.service.impl;
|
package github.benjamin.equipreservebackend.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
||||||
import github.benjamin.equipreservebackend.entity.Team;
|
import github.benjamin.equipreservebackend.entity.Team;
|
||||||
import github.benjamin.equipreservebackend.mapper.TeamMapper;
|
import github.benjamin.equipreservebackend.mapper.TeamMapper;
|
||||||
import github.benjamin.equipreservebackend.service.TeamService;
|
import github.benjamin.equipreservebackend.service.TeamService;
|
||||||
import github.benjamin.equipreservebackend.vo.TeamLabelVO;
|
|
||||||
import github.benjamin.equipreservebackend.vo.TeamVO;
|
import github.benjamin.equipreservebackend.vo.TeamVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -18,32 +16,10 @@ public class TeamServiceImpl implements TeamService {
|
|||||||
private final TeamMapper teamMapper;
|
private final TeamMapper teamMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TeamLabelVO> getTeamLabel() {
|
public List<TeamVO> getTeams() {
|
||||||
|
|
||||||
List<Team> teams = teamMapper.selectList(null);
|
List<Team> teams = teamMapper.selectList(null);
|
||||||
|
|
||||||
return teams.stream().map(TeamLabelVO::new).toList();
|
return teams.stream().map(TeamVO::new).toList();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TeamVO> getTeams() {
|
|
||||||
return teamMapper.getTeams();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteTeam(Long id) {
|
|
||||||
teamMapper.deleteById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTeam(String name) {
|
|
||||||
teamMapper.insert(new Team(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateTeam(Long id, String name) {
|
|
||||||
teamMapper.update(new LambdaUpdateWrapper<Team>()
|
|
||||||
.eq(Team::getId, id)
|
|
||||||
.set(Team::getName, name));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package github.benjamin.equipreservebackend.vo;
|
|
||||||
|
|
||||||
import github.benjamin.equipreservebackend.entity.Team;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class TeamLabelVO {
|
|
||||||
|
|
||||||
private String label;
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
public TeamLabelVO(Team t) {
|
|
||||||
this.label = t.getName();
|
|
||||||
this.value = t.getId().toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,18 @@
|
|||||||
package github.benjamin.equipreservebackend.vo;
|
package github.benjamin.equipreservebackend.vo;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import github.benjamin.equipreservebackend.entity.Team;
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
public class TeamVO {
|
public class TeamVO {
|
||||||
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
private String label;
|
||||||
private Long id;
|
private String value;
|
||||||
private String name;
|
|
||||||
private Integer size;
|
|
||||||
|
|
||||||
|
public TeamVO(Team t) {
|
||||||
|
this.label = t.getName();
|
||||||
|
this.value = t.getId().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ spring:
|
|||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
username: your-username
|
username: your-username
|
||||||
password: your-password
|
password: your-password
|
||||||
url: jdbc:mysql://127.0.0.1:3306/equip_reserve?serverTimeZone=Asia/Shanghai
|
url: jdbc:mysql://127.0.0.1:3306/equip_reserve?serverTimeZone=UTC
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
max-file-size: 15MB
|
max-file-size: 15MB
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
|
|
||||||
<mapper namespace="github.benjamin.equipreservebackend.mapper.TeamMapper">
|
|
||||||
|
|
||||||
<select id="getTeams" resultType="github.benjamin.equipreservebackend.vo.TeamVO">
|
|
||||||
SELECT
|
|
||||||
t.id AS id,
|
|
||||||
t.name AS name,
|
|
||||||
COUNT(u.id) AS size
|
|
||||||
FROM
|
|
||||||
teams t
|
|
||||||
LEFT JOIN
|
|
||||||
users u ON t.id = u.team_id
|
|
||||||
GROUP BY
|
|
||||||
t.id, t.name
|
|
||||||
ORDER BY t.name
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
Loading…
x
Reference in New Issue
Block a user