feat: 新增从项目 id 获取项目详细信息的接口,并实现
This commit is contained in:
parent
3d7f457ef3
commit
fd22ba9dc6
|
@ -51,7 +51,6 @@ public class ProjectController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id 要查询的 id
|
* @param id 要查询的 id
|
||||||
* @return {@link BaseResponse}
|
* @return {@link BaseResponse}
|
||||||
|
@ -77,28 +76,34 @@ public class ProjectController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/project/get/custom")
|
@GetMapping("/project/get/custom")
|
||||||
public BaseResponse projectGetCustom(
|
public BaseResponse projectGetCustom(
|
||||||
@RequestParam(required = false) List<String> tags,
|
@RequestParam(required = false) List<String> tags,
|
||||||
@RequestParam(required = false) List<String> isFinish,
|
@RequestParam(required = false) List<String> isFinish,
|
||||||
@RequestParam(required = false, defaultValue = "1") Integer page,
|
@RequestParam(required = false, defaultValue = "1") Integer page,
|
||||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
|
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
|
||||||
log.info("请求接口[GET]: /project/get/custom");
|
log.info("请求接口[GET]: /project/get/custom");
|
||||||
return projectService.tGet(tags, isFinish, page, pageSize);
|
return projectService.tGet(tags, isFinish, page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 我负责的界面的获取项目
|
* 根据项目 id 获取项目详细信息
|
||||||
|
* <hr/>
|
||||||
|
* 根据项目 id 获取项目的详细信息,在地址后面有 projectId 的 path 部分需要补充完整(不可缺少)
|
||||||
*
|
*
|
||||||
|
* @param projectId 项目 id
|
||||||
|
* @param request 请求
|
||||||
* @return {@link BaseResponse}
|
* @return {@link BaseResponse}
|
||||||
*/
|
*/
|
||||||
@GetMapping("/project/get")
|
@GetMapping("/project/get/{projectId}")
|
||||||
public BaseResponse projectGet(
|
public BaseResponse getProjectById(
|
||||||
@RequestParam(required = false) List<String> tags,
|
@PathVariable String projectId,
|
||||||
@RequestParam(required = false) List<String> isFinish,
|
HttpServletRequest request
|
||||||
@RequestParam(required = false, defaultValue = "1") Integer page,
|
) {
|
||||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
|
||||||
HttpServletRequest request) {
|
|
||||||
log.info("请求接口[GET]: /project/get");
|
log.info("请求接口[GET]: /project/get");
|
||||||
return projectService.get(request, tags, isFinish, page, pageSize);
|
// 对 projectId 进行判断
|
||||||
|
if (!projectId.matches("^[0-9]+$")) {
|
||||||
|
return ResultUtil.error("参数 projectId 不是一个数字", ErrorCode.PARAMETER_ERROR);
|
||||||
|
}
|
||||||
|
return projectService.getProjectById(request, Long.parseLong(projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,12 +113,12 @@ public class ProjectController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/project/child/get")
|
@GetMapping("/project/child/get")
|
||||||
public BaseResponse projectWorkGet(
|
public BaseResponse projectWorkGet(
|
||||||
@RequestParam(required = false) List<String> tags,
|
@RequestParam(required = false) List<String> tags,
|
||||||
@RequestParam(required = false) List<String> isFinish,
|
@RequestParam(required = false) List<String> isFinish,
|
||||||
@RequestParam(required = false) Integer is,
|
@RequestParam(required = false) Integer is,
|
||||||
@RequestParam(required = false, defaultValue = "1") Integer page,
|
@RequestParam(required = false, defaultValue = "1") Integer page,
|
||||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
log.info("请求接口[GET]: /project/work/get");
|
log.info("请求接口[GET]: /project/work/get");
|
||||||
return projectService.workGet(request, tags, isFinish, is, page, pageSize);
|
return projectService.workGet(request, tags, isFinish, is, page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package com.jsl.oa.model.dodata;
|
package com.jsl.oa.model.dodata;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>project 数据表</h1>
|
* <h1>project 数据表</h1>
|
||||||
* <hr/>
|
* <hr/>
|
||||||
* 映射 oa_project 数据表内容进入自定义实体类
|
* 映射 oa_project 数据表内容进入自定义实体类, 该实体类用于存储数据表中的数据。
|
||||||
*
|
*
|
||||||
* @author 筱锋xiao_lfeng
|
* @author 筱锋xiao_lfeng
|
||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
|
@ -18,24 +17,99 @@ import java.sql.Timestamp;
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
||||||
public class ProjectDO {
|
public class ProjectDO {
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
* <hr/>
|
||||||
|
* 主键,自增
|
||||||
|
*/
|
||||||
private Long id;
|
private Long id;
|
||||||
private Long principalId;
|
/**
|
||||||
private String tags;
|
* 项目名称
|
||||||
private Integer cycle;
|
* <hr/>
|
||||||
|
* 项目名称,最长 255 字符
|
||||||
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
private String file;
|
/**
|
||||||
|
* 项目负责人
|
||||||
|
* <hr/>
|
||||||
|
* 项目负责人,关联 user 表
|
||||||
|
*/
|
||||||
|
private Long principalId;
|
||||||
|
/**
|
||||||
|
* 项目描述
|
||||||
|
* <hr/>
|
||||||
|
* 项目描述,需要存储 json 数据
|
||||||
|
*/
|
||||||
private String description;
|
private String description;
|
||||||
private Integer isDelete;
|
/**
|
||||||
|
* 项目标签
|
||||||
|
* <hr/>
|
||||||
|
* 项目标签,需要存储 json 数据(项目类型:web,大数据等)
|
||||||
|
*/
|
||||||
|
private String tags;
|
||||||
|
/**
|
||||||
|
* 项目周期
|
||||||
|
* <hr/>
|
||||||
|
* 项目周期,单位:天
|
||||||
|
*/
|
||||||
|
private Integer cycle;
|
||||||
|
/**
|
||||||
|
* 项目工作量
|
||||||
|
* <hr/>
|
||||||
|
* 项目工作量,单位:人天
|
||||||
|
*/
|
||||||
private Integer workLoad;
|
private Integer workLoad;
|
||||||
|
/**
|
||||||
|
* 项目文件
|
||||||
|
* <hr/>
|
||||||
|
* 项目文件,需要存储 json 数据(文件名:UUID 生成值)。对于 JSON 内部只需要存储 UUID 信息以及加上文件尾缀即可。
|
||||||
|
* <p>
|
||||||
|
* 例如:[UUID].pdf, [UUID].png, [UUID].docx
|
||||||
|
*/
|
||||||
|
private String files;
|
||||||
|
/**
|
||||||
|
* 项目开始时间
|
||||||
|
* <hr/>
|
||||||
|
* 项目开始时间, 格式:yyyy-MM-dd
|
||||||
|
*/
|
||||||
|
private Date beginTime;
|
||||||
|
/**
|
||||||
|
* 项目完成时间
|
||||||
|
* <hr/>
|
||||||
|
* 项目完成时间, 格式:yyyy-MM-dd
|
||||||
|
*/
|
||||||
|
private Date completeTime;
|
||||||
|
/**
|
||||||
|
* 项目截止时间
|
||||||
|
* <hr/>
|
||||||
|
* 项目截止时间, 格式:yyyy-MM-dd
|
||||||
|
* <p>
|
||||||
|
* 项目截止时间为最终的截止时间,即甲方要求的最终结束周期
|
||||||
|
*/
|
||||||
|
private Date deadline;
|
||||||
|
/**
|
||||||
|
* 项目状态
|
||||||
|
* <hr/>
|
||||||
|
* 项目状态(draft: 草稿,progress: 进行,pause: 暂停,abnormal: 异常,complete: 完成)
|
||||||
|
*/
|
||||||
private String status;
|
private String status;
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC")
|
/**
|
||||||
private Timestamp beginTime;
|
* 创建时间
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC")
|
* <hr/>
|
||||||
private Timestamp completeTime;
|
* 创建时间,格式:1234567890123
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC")
|
*/
|
||||||
private Timestamp deadline;
|
|
||||||
private Timestamp createdAt;
|
private Timestamp createdAt;
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
* <hr/>
|
||||||
|
* 更新时间,格式:1234567890123
|
||||||
|
*/
|
||||||
private Timestamp updatedAt;
|
private Timestamp updatedAt;
|
||||||
|
/**
|
||||||
|
* 是否删除
|
||||||
|
* <hr/>
|
||||||
|
* 是否删除(0: 否,1: 是)
|
||||||
|
*/
|
||||||
|
private Boolean isDelete;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,6 @@ public interface ProjectService {
|
||||||
|
|
||||||
BaseResponse editHeader(HttpServletRequest request, ProjectShowVO projectShowVO, Integer id);
|
BaseResponse editHeader(HttpServletRequest request, ProjectShowVO projectShowVO, Integer id);
|
||||||
|
|
||||||
BaseResponse get(
|
|
||||||
HttpServletRequest request,
|
|
||||||
List<String> tags,
|
|
||||||
List<String> isFinish,
|
|
||||||
Integer page,
|
|
||||||
Integer pageSize);
|
|
||||||
|
|
||||||
BaseResponse getByName(String name);
|
BaseResponse getByName(String name);
|
||||||
|
|
||||||
BaseResponse projectDelete(HttpServletRequest request, List<Long> id);
|
BaseResponse projectDelete(HttpServletRequest request, List<Long> id);
|
||||||
|
@ -35,12 +28,12 @@ public interface ProjectService {
|
||||||
BaseResponse projectAdd(HttpServletRequest request, ProjectInfoVO projectVO);
|
BaseResponse projectAdd(HttpServletRequest request, ProjectInfoVO projectVO);
|
||||||
|
|
||||||
BaseResponse workGet(
|
BaseResponse workGet(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
List<String> tags,
|
List<String> tags,
|
||||||
List<String> isFinish,
|
List<String> isFinish,
|
||||||
Integer is,
|
Integer is,
|
||||||
Integer page,
|
Integer page,
|
||||||
Integer pageSize);
|
Integer pageSize);
|
||||||
|
|
||||||
BaseResponse projectWorkAdd(HttpServletRequest request, ProjectWorkVO projectWorkVO);
|
BaseResponse projectWorkAdd(HttpServletRequest request, ProjectWorkVO projectWorkVO);
|
||||||
|
|
||||||
|
@ -53,4 +46,15 @@ public interface ProjectService {
|
||||||
BaseResponse getWorkById(Integer id);
|
BaseResponse getWorkById(Integer id);
|
||||||
|
|
||||||
BaseResponse projectPrincipalGet();
|
BaseResponse projectPrincipalGet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从项目 id 获取项目的详细信息
|
||||||
|
* <hr/>
|
||||||
|
* 根据项目所属 id 获取项目的详细信息,根据用户所属角色组的不同返回不同的内容
|
||||||
|
*
|
||||||
|
* @param request 获取请求体
|
||||||
|
* @param projectId 项目 id
|
||||||
|
* @return 根据用户所属角色组的不同返回不同的内容
|
||||||
|
*/
|
||||||
|
BaseResponse getProjectById(HttpServletRequest request, Long projectId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,13 +136,13 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
|
|
||||||
ProjectDO projectDO = projectDAO.getProjectById(projectId);
|
ProjectDO projectDO = projectDAO.getProjectById(projectId);
|
||||||
|
|
||||||
if (projectDO.getFile() == null || projectDO.getFile().equals("{}")) {
|
if (projectDO.getFiles() == null || projectDO.getFiles().equals("{}")) {
|
||||||
return ResultUtil.success(null);
|
return ResultUtil.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将文件内容转换为 JSON 数组
|
// 将文件内容转换为 JSON 数组
|
||||||
try {
|
try {
|
||||||
Object fileJson = new ObjectMapper().readValue(projectDO.getFile(), Object.class);
|
Object fileJson = new ObjectMapper().readValue(projectDO.getFiles(), Object.class);
|
||||||
return ResultUtil.success(fileJson);
|
return ResultUtil.success(fileJson);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
return ResultUtil.error(ErrorCode.PROJECT_FILE_JSON_ERROR);
|
return ResultUtil.error(ErrorCode.PROJECT_FILE_JSON_ERROR);
|
||||||
|
@ -183,6 +183,22 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
return ResultUtil.success(userMapper.getPrincipal());
|
return ResultUtil.success(userMapper.getPrincipal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseResponse getProjectById(HttpServletRequest request, Long projectId) {
|
||||||
|
// 对项目 id 进行数据库校验
|
||||||
|
ProjectDO getProject = projectDAO.getProjectById(projectId);
|
||||||
|
if (getProject == null) {
|
||||||
|
return ResultUtil.error(ErrorCode.PROJECT_NOT_EXIST);
|
||||||
|
}
|
||||||
|
// 检查项目是否被删除
|
||||||
|
if (getProject.getIsDelete()) {
|
||||||
|
return ResultUtil.error("项目已删除", ErrorCode.PROJECT_NOT_EXIST);
|
||||||
|
}
|
||||||
|
// 对项目具体信息进行检查
|
||||||
|
// TODO: [10001] 需要检查普通用户是否有权限可以看到这一篇项目内容
|
||||||
|
return ResultUtil.success(getProject);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse projectEdit(HttpServletRequest request, @NotNull ProjectEditVO projectEdit, Long projectId) {
|
public BaseResponse projectEdit(HttpServletRequest request, @NotNull ProjectEditVO projectEdit, Long projectId) {
|
||||||
log.info("\t> 执行 Service 层 ProjectService.projectEdit 方法");
|
log.info("\t> 执行 Service 层 ProjectService.projectEdit 方法");
|
||||||
|
@ -294,56 +310,6 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseResponse get(
|
|
||||||
HttpServletRequest request,
|
|
||||||
List<String> tags,
|
|
||||||
List<String> isFinish,
|
|
||||||
Integer page,
|
|
||||||
Integer pageSize
|
|
||||||
) {
|
|
||||||
log.info("\t> 执行 Service 层 ProjectService.get 方法");
|
|
||||||
|
|
||||||
//获取用户
|
|
||||||
Long userId = Processing.getAuthHeaderToUserId(request);
|
|
||||||
//根据标签查询
|
|
||||||
if (tags != null && !tags.isEmpty()) {
|
|
||||||
List<ProjectDO> projectDOList = projectDAO.get(userId, tags, isFinish);
|
|
||||||
|
|
||||||
List<ProjectSimpleVO> projectSimpleVOList = new ArrayList<>();
|
|
||||||
for (ProjectDO projectDO : projectDOList) {
|
|
||||||
ProjectSimpleVO projectSimpleVO1 = new ProjectSimpleVO();
|
|
||||||
Processing.projectTosimply(projectSimpleVO1, projectDO, userDAO, objectMapper);
|
|
||||||
projectSimpleVOList.add(projectSimpleVO1);
|
|
||||||
}
|
|
||||||
//分页返回
|
|
||||||
int start = (page - 1) * pageSize;
|
|
||||||
int end = start + pageSize;
|
|
||||||
List<ProjectSimpleVO> pageData = projectSimpleVOList.subList(start,
|
|
||||||
Math.min(end, projectSimpleVOList.size()));
|
|
||||||
return ResultUtil.success(pageData);
|
|
||||||
}
|
|
||||||
|
|
||||||
//根据状态查询
|
|
||||||
if (isFinish != null && !isFinish.isEmpty()) {
|
|
||||||
List<ProjectDO> projectDOList = projectDAO.get(userId, tags, isFinish);
|
|
||||||
List<ProjectSimpleVO> projectSimpleVOList = new ArrayList<>();
|
|
||||||
for (ProjectDO projectDO : projectDOList) {
|
|
||||||
ProjectSimpleVO projectSimpleVO1 = new ProjectSimpleVO();
|
|
||||||
Processing.projectTosimply(projectSimpleVO1, projectDO, userDAO, objectMapper);
|
|
||||||
projectSimpleVOList.add(projectSimpleVO1);
|
|
||||||
}
|
|
||||||
//分页返回
|
|
||||||
int start = (page - 1) * pageSize;
|
|
||||||
int end = start + pageSize;
|
|
||||||
List<ProjectSimpleVO> pageData = projectSimpleVOList.subList(start,
|
|
||||||
Math.min(end, projectSimpleVOList.size()));
|
|
||||||
return ResultUtil.success(pageData);
|
|
||||||
}
|
|
||||||
return ResultUtil.success(projectMapper.get(userId));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse workGet(
|
public BaseResponse workGet(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
|
@ -374,7 +340,6 @@ public class ProjectServiceImpl implements ProjectService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseResponse getByName(String name) {
|
public BaseResponse getByName(String name) {
|
||||||
log.info("\t> 执行 Service 层 ProjectService.getByName 方法");
|
log.info("\t> 执行 Service 层 ProjectService.getByName 方法");
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.jsl.oa.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Getter
|
@Getter
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class BaseResponse {
|
public class BaseResponse {
|
||||||
|
@ -16,12 +18,6 @@ public class BaseResponse {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
log.info("==================================================");
|
||||||
|
|
||||||
public BaseResponse(String output, Integer code, String message) {
|
|
||||||
this.output = output;
|
|
||||||
this.code = code;
|
|
||||||
this.message = message;
|
|
||||||
this.data = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +1,101 @@
|
||||||
package com.jsl.oa.utils;
|
package com.jsl.oa.utils;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jetbrains.annotations.Contract;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>结果工具类</h1>
|
* <h1>结果工具类</h1>
|
||||||
* <hr/>
|
* <hr/>
|
||||||
* 用于返回结果
|
* 用于返回结果
|
||||||
*
|
*
|
||||||
|
* @author xiao_lfeng
|
||||||
* @version v1.1.0
|
* @version v1.1.0
|
||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
* @author xiao_lfeng
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ResultUtil {
|
public class ResultUtil {
|
||||||
|
|
||||||
@Contract(" -> new")
|
|
||||||
public static @NotNull BaseResponse success() {
|
public static @NotNull BaseResponse success() {
|
||||||
log.info("成功: Success[200] {}", "操作成功");
|
log.info("成功: Success[200] 操作成功 - 不带数据");
|
||||||
log.info("==================================================");
|
log.info("==================================================");
|
||||||
return new BaseResponse("Success", 200, "操作成功", null);
|
return new BaseResponse("Success", 200, "操作成功", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("_ -> new")
|
|
||||||
public static @NotNull BaseResponse success(String message) {
|
public static @NotNull BaseResponse success(String message) {
|
||||||
log.info("成功: Success[200] {}", message);
|
log.info("成功: Success[200] {} - 不带数据", message);
|
||||||
log.info("==================================================");
|
|
||||||
return new BaseResponse("Success", 200, message, null);
|
return new BaseResponse("Success", 200, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract(value = "_ -> new", pure = true)
|
|
||||||
public static @NotNull BaseResponse success(Object data) {
|
public static @NotNull BaseResponse success(Object data) {
|
||||||
log.info("成功: Success[200] {}", "操作成功");
|
log.info("成功: Success[200] 操作成功 - 带数据");
|
||||||
log.info("==================================================");
|
|
||||||
return new BaseResponse("Success", 200, "操作成功", data);
|
return new BaseResponse("Success", 200, "操作成功", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract(value = "_, _ -> new", pure = true)
|
|
||||||
public static @NotNull BaseResponse success(String message, Object data) {
|
public static @NotNull BaseResponse success(String message, Object data) {
|
||||||
log.info("成功: Success[200] {}", message);
|
log.info("成功: Success[200] {} - 带数据", message);
|
||||||
log.info("==================================================");
|
|
||||||
return new BaseResponse("Success", 200, message, data);
|
return new BaseResponse("Success", 200, message, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("_ -> new")
|
public static @NotNull BaseResponse error(@NotNull String errorMessage, @NotNull ErrorCode errorCode) {
|
||||||
|
log.warn("失败: 错误码[" + errorCode.getCode() + "] {} - {} - {}",
|
||||||
|
errorCode.getOutput(),
|
||||||
|
errorCode.getMessage(),
|
||||||
|
errorMessage
|
||||||
|
);
|
||||||
|
HashMap<String, String> map = new HashMap<>();
|
||||||
|
map.put("errorMessage", errorMessage);
|
||||||
|
return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage(), map);
|
||||||
|
}
|
||||||
|
|
||||||
public static @NotNull BaseResponse error(@NotNull ErrorCode errorCode) {
|
public static @NotNull BaseResponse error(@NotNull ErrorCode errorCode) {
|
||||||
log.warn("失败: 错误码[" + errorCode.getCode() + "] {} - {}", errorCode.getOutput(), errorCode.getMessage());
|
logBack(errorCode.getCode(), errorCode.getOutput(), errorCode.getMessage(), null);
|
||||||
log.info("==================================================");
|
HashMap<String, String> map = new HashMap<>();
|
||||||
return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage());
|
map.put("errorMessage", errorCode.getMessage());
|
||||||
|
return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage(), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("_, _ -> new")
|
|
||||||
public static @NotNull BaseResponse error(@NotNull ErrorCode errorCode, Object data) {
|
public static @NotNull BaseResponse error(@NotNull ErrorCode errorCode, Object data) {
|
||||||
log.warn("失败: 错误码[" + errorCode.getCode() + "] {} - {}", errorCode.getOutput(), errorCode.getMessage());
|
logBack(errorCode.getCode(), errorCode.getOutput(), errorCode.getMessage(), data);
|
||||||
log.info("==================================================");
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage(), data);
|
map.put("errorMessage", errorCode.getMessage());
|
||||||
|
map.put("errorData", data);
|
||||||
|
return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage(), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract(value = "_, _, _, _ -> new", pure = true)
|
|
||||||
public static @NotNull BaseResponse error(String output, Integer code, String message, Object data) {
|
public static @NotNull BaseResponse error(String output, Integer code, String message, Object data) {
|
||||||
log.warn("失败: 错误码[" + code + "] {} - {}", output, message);
|
logBack(code, output, message, data);
|
||||||
log.info("==================================================");
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
return new BaseResponse(output, code, message, data);
|
map.put("errorMessage", message);
|
||||||
|
map.put("errorData", data);
|
||||||
|
return new BaseResponse(output, code, message, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull ResponseEntity<BaseResponse> error(String output, Integer code, String message) {
|
public static @NotNull ResponseEntity<BaseResponse> error(String output, Integer code, String message) {
|
||||||
log.warn("失败: 错误码[" + code + "] {} - {}", output, message);
|
logBack(code, output, message, null);
|
||||||
log.info("==================================================");
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
map.put("errorMessage", message);
|
||||||
return ResponseEntity.status(500)
|
return ResponseEntity.status(500)
|
||||||
.body(new BaseResponse(output, code, message));
|
.body(new BaseResponse(output, code, message, map));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>日志记录</h1>
|
||||||
|
* <hr/>
|
||||||
|
* 用户返回错误相关的日志内容
|
||||||
|
*
|
||||||
|
* @param code 错误码
|
||||||
|
* @param output 英文输出状态信息
|
||||||
|
* @param message 中文解释消息
|
||||||
|
* @param data 是否有数据
|
||||||
|
*/
|
||||||
|
private static void logBack(Integer code, String output, String message, Object data) {
|
||||||
|
if (data != null) {
|
||||||
|
log.warn("失败: 错误码[{}] {} - {} - 带数据", code, output, message);
|
||||||
|
} else {
|
||||||
|
log.warn("失败: 错误码[{}] {} - {} - 不带数据", code, output, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user