添加了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"}) @SuppressWarnings({"Convert2Diamond", "NullableProblems", "rawtypes"})
@Bean @Bean
public Converter<String, Map> MapConverter() { public Converter<String, Map> mapConverter() {
return new Converter<String, Map>() { return new Converter<String, Map>() {
@Autowired @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.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject; 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.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.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* @author * @author
* @since 2022/6/30 11:24 * @since 2022/6/30 11:24
* <!TODO>
*/ */
@RestController @RestController
@RequestMapping("/project") @RequestMapping("/project")
@ -38,14 +38,11 @@ public class ProjectController {
@GetMapping @GetMapping
public ResponseList<ResultProject> getProjectListOfStaff( public ResponseList<ResultProject> getProjectListOfStaff(
@RequestHeader("Token") String token, @RequestHeader("Token") String token,
@RequestParam("pageSize") Integer pageSize, @Valid RequestPage page,
@RequestParam("pageCurrent") Integer pageCurrent,
@RequestParam("paramMap") Map<String, Object> paramMap @RequestParam("paramMap") Map<String, Object> paramMap
//@RequestParam("sort") SortEntity sortEntity ) {
) { Page<ResultProject> result = projectService.getOnePageProject(token, page, paramMap);
SortEntity sortEntity = new SortEntity(); return ResponseList.ofSuccess("成功返回列表", result);
Page<ResultProject> page = projectService.getOnePageProject(token, pageCurrent, pageSize, paramMap, sortEntity);
return ResponseList.ofSuccess("成功返回列表", page);
} }
@ApiOperation("根据Token获取该员工的Project数") @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.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject; 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.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException; 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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
@ -18,7 +18,7 @@ public interface IProjectService extends IService<Project> {
Long getAllProjectOfStaff(String token) throws TokenException; 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; 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.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject; 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.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper; 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.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils; 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.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -39,14 +39,11 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
@Override @Override
public Page<ResultProject> getOnePageProject( public Page<ResultProject> getOnePageProject(
String token, String token,
Integer pageCurrent, RequestPage page,
Integer pageSize, Map<String, Object> params
Map<String, Object> params,
SortEntity sortEntity
) throws TokenException { ) throws TokenException {
Integer staffId = TokenUtils.getStaffId(token); Integer staffId = TokenUtils.getStaffId(token);
Page<ResultProject> page = new Page<>(pageCurrent, pageSize); IPage<ResultProject> userPage = baseMapper.findMyProject(page.getPage(), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
IPage<ResultProject> userPage = baseMapper.findMyProject(sortEntity.sortPage(page), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
return (Page<ResultProject>) userPage; 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;
}
}