添加了RequestPage包装类

master
ArgonarioD 2022-07-04 10:40:26 +08:00
parent 0a12db6dfe
commit f84a906204
6 changed files with 57 additions and 45 deletions

View File

@ -83,7 +83,7 @@ public class SerializeConfig {
@SuppressWarnings({"Convert2Diamond", "NullableProblems", "rawtypes"})
@Bean
public Converter<String, Map> MapConverter() {
public Converter<String, Map> mapConverter() {
return new Converter<String, Map>() {
@Autowired

View File

@ -2,8 +2,8 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.SortEntity;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -14,13 +14,13 @@ import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
/**
* @author
* @since 2022/6/30 11:24
* <!TODO>
*/
@RestController
@RequestMapping("/project")
@ -38,14 +38,11 @@ public class ProjectController {
@GetMapping
public ResponseList<ResultProject> getProjectListOfStaff(
@RequestHeader("Token") String token,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("pageCurrent") Integer pageCurrent,
@Valid RequestPage page,
@RequestParam("paramMap") Map<String, Object> paramMap
//@RequestParam("sort") SortEntity sortEntity
) {
SortEntity sortEntity = new SortEntity();
Page<ResultProject> page = projectService.getOnePageProject(token, pageCurrent, pageSize, paramMap, sortEntity);
return ResponseList.ofSuccess("成功返回列表", page);
Page<ResultProject> result = projectService.getOnePageProject(token, page, paramMap);
return ResponseList.ofSuccess("成功返回列表", result);
}
@ApiOperation("根据Token获取该员工的Project数")

View File

@ -1,26 +0,0 @@
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
/**
* @author
* @since 2022/7/4 9:25
*/
@Data
public class SortEntity {
String sortName;
Boolean ascOrder;
public <T> Page<T> sortPage(Page<T> page) {
if(ascOrder == null) return page;
if (ascOrder) {
return page.addOrder(OrderItem.asc(sortName));
} else {
return page.addOrder(OrderItem.desc(sortName));
}
}
}

View File

@ -2,9 +2,9 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.SortEntity;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
@ -18,7 +18,7 @@ public interface IProjectService extends IService<Project> {
Long getAllProjectOfStaff(String token) throws TokenException;
Page<ResultProject> getOnePageProject(String token, Integer pageCurrent, Integer pageSize, Map<String, Object> params, SortEntity sortEntity) throws TokenException;
Page<ResultProject> getOnePageProject(String token, RequestPage page, Map<String, Object> params) throws TokenException;
Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException;

View File

@ -2,7 +2,6 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.SortEntity;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper;
@ -10,6 +9,7 @@ import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -39,14 +39,11 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
@Override
public Page<ResultProject> getOnePageProject(
String token,
Integer pageCurrent,
Integer pageSize,
Map<String, Object> params,
SortEntity sortEntity
RequestPage page,
Map<String, Object> params
) throws TokenException {
Integer staffId = TokenUtils.getStaffId(token);
Page<ResultProject> page = new Page<>(pageCurrent, pageSize);
IPage<ResultProject> userPage = baseMapper.findMyProject(sortEntity.sortPage(page), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
IPage<ResultProject> userPage = baseMapper.findMyProject(page.getPage(), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
return (Page<ResultProject>) userPage;
}

View File

@ -0,0 +1,44 @@
package cn.edu.hfut.rmdjzz.projectmanagement.utils.http;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* @author
* @since 2022/7/4 10:24
*/
@NoArgsConstructor
@Data
public class RequestPage {
@NotNull
@Min(1)
Integer pageCurrent;
@NotNull
@Min(1)
Integer pageSize;
@ApiModelProperty("不传或传空时不排序,否则按照此字段排序")
String sortBy;
@ApiModelProperty("传true或空时为顺序排序否则倒序排序")
Boolean asc;
public <T> IPage<T> getPage() {
Page<T> page = new Page<>(pageCurrent, pageSize);
if (StringUtils.isNotBlank(sortBy)) {
String column = StringUtils.camelToUnderline(sortBy);
if (asc == null || asc) {
page.addOrder(OrderItem.asc(column));
} else {
page.addOrder(OrderItem.desc(column));
}
}
return page;
}
}