From 0bbfd18c70fa1f1643ab016c762fb572624678b8 Mon Sep 17 00:00:00 2001 From: "jiakun.lin" Date: Tue, 23 Mar 2021 09:40:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectManagementController.java | 14 ++-- .../service/ProjectManagementService.java | 14 +++- src/main/java/com/yipin/liuwanr/util/R.java | 65 +++++++++++++++++++ 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/yipin/liuwanr/util/R.java diff --git a/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java b/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java index dae0ed0..9d5a97c 100644 --- a/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java +++ b/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.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 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; } // /** // * 首页面查询 diff --git a/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java b/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java index 5f80b62..1776d69 100644 --- a/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java +++ b/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java @@ -134,15 +134,27 @@ public class ProjectManagementService { List 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 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()); diff --git a/src/main/java/com/yipin/liuwanr/util/R.java b/src/main/java/com/yipin/liuwanr/util/R.java new file mode 100644 index 0000000..5af5173 --- /dev/null +++ b/src/main/java/com/yipin/liuwanr/util/R.java @@ -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 { + 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 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; + } +}