尝试增加排序返回

master
yang.yongquan 2022-07-04 10:15:05 +08:00
parent 6eb7c68a18
commit 0a12db6dfe
5 changed files with 42 additions and 6 deletions

View File

@ -2,6 +2,7 @@ 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.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;
@ -19,6 +20,7 @@ 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")
@ -39,8 +41,10 @@ public class ProjectController {
@RequestParam("pageSize") Integer pageSize, @RequestParam("pageSize") Integer pageSize,
@RequestParam("pageCurrent") Integer pageCurrent, @RequestParam("pageCurrent") Integer pageCurrent,
@RequestParam("paramMap") Map<String, Object> paramMap @RequestParam("paramMap") Map<String, Object> paramMap
) { //@RequestParam("sort") SortEntity sortEntity
Page<ResultProject> page = projectService.getOnePageProject(token, pageCurrent, pageSize, paramMap); ) {
SortEntity sortEntity = new SortEntity();
Page<ResultProject> page = projectService.getOnePageProject(token, pageCurrent, pageSize, paramMap, sortEntity);
return ResponseList.ofSuccess("成功返回列表", page); return ResponseList.ofSuccess("成功返回列表", page);
} }

View File

@ -8,6 +8,7 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
/** /**
* @author * @author
@ -43,4 +44,5 @@ public class Project {
@TableLogic @TableLogic
private Boolean deleted; private Boolean deleted;
private Integer projectCreator; private Integer projectCreator;
private LocalDateTime projectCreateTime;
} }

View File

@ -0,0 +1,26 @@
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,6 +2,7 @@ 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 com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -17,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) throws TokenException; Page<ResultProject> getOnePageProject(String token, Integer pageCurrent, Integer pageSize, Map<String, Object> params, SortEntity sortEntity) throws TokenException;
Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException; Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException;

View File

@ -2,6 +2,7 @@ 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;
@ -40,11 +41,12 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
String token, String token,
Integer pageCurrent, Integer pageCurrent,
Integer pageSize, 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);
IPage<ResultProject> page = new Page<>(pageCurrent, pageSize); Page<ResultProject> page = new Page<>(pageCurrent, pageSize);
IPage<ResultProject> userPage = baseMapper.findMyProject(page, staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params)); IPage<ResultProject> userPage = baseMapper.findMyProject(sortEntity.sortPage(page), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
return (Page<ResultProject>) userPage; return (Page<ResultProject>) userPage;
} }
@ -71,6 +73,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
public Boolean createProject(String token, Project project) throws TokenException, BadRequestException { public Boolean createProject(String token, Project project) throws TokenException, BadRequestException {
project.setProjectId(null); project.setProjectId(null);
project.setCompleted(false); project.setCompleted(false);
project.setProjectCreateTime(null);
project.setProjectCreator(TokenUtils.getStaffId(token)); project.setProjectCreator(TokenUtils.getStaffId(token));
project.setProjectCloseTime(null); project.setProjectCloseTime(null);
if (project.getExpectedCompletion() == null) { if (project.getExpectedCompletion() == null) {