分页优化

master
jiakun.lin 4 years ago
parent f7b9d63db4
commit 0bbfd18c70
  1. 14
      src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java
  2. 14
      src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java
  3. 65
      src/main/java/com/yipin/liuwanr/util/R.java

@ -2,6 +2,7 @@ package com.yipin.liuwanr.controller;
import com.yipin.liuwanr.entity.*;
import com.yipin.liuwanr.service.ProjectManagementService;
import com.yipin.liuwanr.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -56,7 +57,7 @@ public class ProjectManagementController {
*/
@ApiOperation(value = "项目管理列表", notes = "项目管理列表")
@GetMapping("/queryAllManagements")
Response queryAllManagements(
R queryAllManagements(
@ApiParam(name = "projectPermissions", value = "项目权限(0、练习 1、考核 2、竞赛)", required = false) @RequestParam(required = false) Integer projectPermissions,
@ApiParam(name = "founder", value = "项目创建人(0、系统 1、老师)", required = false) @RequestParam(required = false) String founder,
@ApiParam(name = "state", value = "项目状态(0、草稿箱 1、已发布)", required = false) @RequestParam(required = false) Integer state,
@ -65,7 +66,7 @@ public class ProjectManagementController {
@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId,
@ApiParam(name = "pageNo", value = "起始页数", required = true) @RequestParam Integer pageNo,
@ApiParam(name = "pageSize", value = "页数", required = true) @RequestParam Integer pageSize) {
Response resp = new Response();
R r = new R();
ProjectManagement vo = new ProjectManagement();
if (null != projectPermissions) {
vo.setProjectPermissions(projectPermissions);
@ -94,13 +95,12 @@ public class ProjectManagementController {
HashMap<String, Object> ret = service.queryAllManagements(vo);
int status = (int) ret.get("retcode");
if (status == 200) {
resp.setStatus(status);
resp.setMessage(ret.get("retvalue"));
r.put("status", 200);
r.put("pageInfo",ret.get("pageInfo"));
} else {
resp.setStatus(status);
resp.setErrmessage(ret.get("retvalue").toString());
R.error(500,ret.get("retvalue").toString());
}
return resp;
return r;
}
// /**
// * 首页面查询

@ -134,15 +134,27 @@ public class ProjectManagementService {
List<ProjectManagement> list = mapper.queryManagements(vo);
//管理员权限id
String adminId = "13";
//记录total
long total = 0;
//出现这种情况,管理员查询条数会为空
if (adminId.equals(vo.getFounder())){
//查完管理员,再查管理员+教师权限的 13,14
ProjectManagement vo1 = new ProjectManagement();
BeanUtils.copyProperties(vo,vo1);
vo1.setFounder("13,14");
//分页,进入这里 数据只会有管理员+老师的权限,list长度为0
PageHelper.startPage(vo.getPageNo(), vo.getPageSize());
List<ProjectManagement> list1 = mapper.queryManagements(vo1);
//拿取总条数,数据由外面pageInfo传
PageInfo pageInfo = new PageInfo(list1);
total = pageInfo.getTotal();
list.addAll(list1);
}
resp.put("retvalue",list);
PageInfo pageInfo = new PageInfo(list);
if (total != 0){
pageInfo.setTotal(total);
}
resp.put("pageInfo",pageInfo);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());

@ -0,0 +1,65 @@
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有侵权必究
*/
package com.yipin.liuwanr.util;
import java.util.HashMap;
import java.util.Map;
/**
* 返回数据
*
* @author Mark sunlightcs@gmail.com
*/
public class R extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
public R() {
put("status", 200);
put("errmessage", "success");
}
public static R error() {
return error(500, "未知异常,请联系管理员");
}
public static R error(String msg) {
return error(500, msg);
}
public static R error(int code, String msg) {
R r = new R();
r.put("status", code);
r.put("errmessage", msg);
return r;
}
public static R ok(String msg) {
R r = new R();
r.put("errmessage", msg);
return r;
}
public static R ok(Map<String, Object> map) {
R r = new R();
r.putAll(map);
return r;
}
public static R ok() {
return new R();
}
@Override
public R put(String key, Object value) {
super.put(key, value);
return this;
}
}
Loading…
Cancel
Save