From 02d4b201166a1322e2dfaa29af4d10fb48f8b7c7 Mon Sep 17 00:00:00 2001 From: mzh820631607 Date: Wed, 28 Oct 2020 20:02:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20=E5=92=8C=E5=88=9B=E5=BB=BA=E5=AE=9E=E9=AA=8C?= =?UTF-8?q?=E7=9A=84=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectManagementController.java | 99 ++++++++++++++- .../mapper/ProjectManagementMapper.java | 26 +++- .../service/ProjectManagementService.java | 41 ++++++- src/main/resources/application.properties | 2 +- .../yipin/liuwanr/Project_ManagementTest.java | 115 +++++++++--------- 5 files changed, 217 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java b/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java index 2c365c5..1dc5638 100644 --- a/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java +++ b/src/main/java/com/yipin/liuwanr/controller/ProjectManagementController.java @@ -70,9 +70,7 @@ public class ProjectManagementController { @ApiParam(name = "state", value = "项目状态(0、草稿箱 1、已发布)", required = false) @RequestParam(required = false) Integer state, @ApiParam(name = "projectName", value = "项目名称", required = false) @RequestParam(required = false) String projectName, @ApiParam(name = "systemId", value = "系统id", required = true) @RequestParam Integer systemId, - @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) { + @ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId) { Response resp = new Response(); ProjectManagement vo = new ProjectManagement(); if (null != projectPermissions) { @@ -93,7 +91,7 @@ public class ProjectManagementController { if (null != userId) { vo.setUserId(userId); } - HashMap ret = service.queryAllManagements(vo, pageNo, pageSize); + HashMap ret = service.queryAllManagements(vo); int status = (int) ret.get("retcode"); if (status == 200) { resp.setStatus(status); @@ -104,6 +102,99 @@ public class ProjectManagementController { } return resp; } +// /** +// * 首页面查询 +// *

+// * +// * @param projectPermissions:权限 +// * @param founder:创建人 +// * @param state:状态 +// * @param projectName:项目名称 +// * @param systemId +// * @return +// */ +// @ApiOperation(value = "项目管理列表", notes = "项目管理列表") +// @GetMapping("/queryAllManagements") +// Response 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) Integer founder, +// @ApiParam(name = "state", value = "项目状态(0、草稿箱 1、已发布)", required = false) @RequestParam(required = false) Integer state, +// @ApiParam(name = "projectName", value = "项目名称", required = false) @RequestParam(required = false) String projectName, +// @ApiParam(name = "systemId", value = "系统id", required = true) @RequestParam Integer systemId, +// @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(); +// ProjectManagement vo = new ProjectManagement(); +// if (null != projectPermissions) { +// vo.setProjectPermissions(projectPermissions); +// } +// if (null != founder) { +// vo.setFounder(founder); +// } +// if (null != state) { +// vo.setState(state); +// } +// if (null != systemId) { +// vo.setSystemId(systemId); +// } +// if (null != projectName && projectName != "") { +// vo.setProjectName(projectName); +// } +// if (null != userId) { +// vo.setUserId(userId); +// } +// HashMap ret = service.queryAllManagements(vo, pageNo, pageSize); +// int status = (int) ret.get("retcode"); +// if (status == 200) { +// resp.setStatus(status); +// resp.setMessage(ret.get("retvalue")); +// } else { +// resp.setStatus(status); +// resp.setErrmessage(ret.get("retvalue").toString()); +// } +// return resp; +// } + /** + * 页面查询,排除练习 + *

+ * + * @param systemId + * @return + */ + @ApiOperation(value = "项目列表(排除练习)", notes = "项目列表(用于创建实验,排除练习项目)") + @GetMapping("/queryManagements") + Response queryManagements( + @ApiParam(name = "systemId", value = "系统id", required = true) @RequestParam(required = false) Integer systemId, + @ApiParam(name = "userId", value = "用户id", required = true) @RequestParam(required = false) Integer userId, + @ApiParam(name = "pageNo", value = "第几页,页码", required = true) @RequestParam Integer pageNo, + @ApiParam(name = "pageSize", value = "每页展示的数据条数", required = true) @RequestParam Integer pageSize) { + Response resp = new Response(); + ProjectManagement vo = new ProjectManagement(); + if (null != systemId) { + vo.setSystemId(systemId); + } + if (null != userId) { + vo.setUserId(userId); + } + HashMap ret = service.queryManagements(vo,pageNo,pageSize); + int status = (int) ret.get("retcode"); + if (status == 200) { + resp.setStatus(status); + resp.setMessage(ret.get("retvalue")); + } else { + resp.setStatus(status); + resp.setErrmessage(ret.get("retvalue").toString()); + } + return resp; + } + + + + + + + /** * 批量删除 diff --git a/src/main/java/com/yipin/liuwanr/mapper/ProjectManagementMapper.java b/src/main/java/com/yipin/liuwanr/mapper/ProjectManagementMapper.java index 03eea6b..f53a0c6 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/ProjectManagementMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/ProjectManagementMapper.java @@ -52,7 +52,7 @@ public interface ProjectManagementMapper { // " and founder=#{founder}", // " and (userId=#{userId} or founder = 0)", // " and founder=#{founder}",//服务端跳项目管理 - " and userId=#{userId}",//教师端,一开始进入项目管理,看见自己创建的和其他人看见的 + " and (userId=#{userId} or roleId not like '%3%')",//教师端,一开始进入项目管理,看见自己创建的和其他人看见的 " and founder=#{founder}",//教师选择创建人为系统 // " and userId=#{userId}",//教师选则创建人为老师 " and state=#{state}", @@ -61,6 +61,30 @@ public interface ProjectManagementMapper { " ORDER BY creationTime desc", ""}) List queryManagements(ProjectManagement management); +// @Select({""}) +// List queryManagements(ProjectManagement management); + + @Select({""}) + List queryManagementsExportTest(ProjectManagement management); /** diff --git a/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java b/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java index 4ed8177..2a69546 100644 --- a/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java +++ b/src/main/java/com/yipin/liuwanr/service/ProjectManagementService.java @@ -69,12 +69,12 @@ public class ProjectManagementService { /** - * 分页查询+条件查询 + * 条件查询 * * @param vo * @return */ - public HashMap queryAllManagements(ProjectManagement vo, Integer pageNo, Integer pageSize) { + public HashMap queryManagements(ProjectManagement vo, Integer pageNo, Integer pageSize) { HashMap resp = new HashMap(); try { //获取用户的角色信息 @@ -93,7 +93,7 @@ public class ProjectManagementService { } PageHelper.startPage(pageNo, pageSize); //条件查询 - List list = mapper.queryManagements(vo); + List list = mapper.queryManagementsExportTest(vo); PageInfo info = new PageInfo(list); resp.put("retvalue", new PageResult(info.getTotal(), list)); resp.put("retcode", 200); @@ -105,6 +105,41 @@ public class ProjectManagementService { } return resp; } + /** + * 分页查询+条件查询 + * + * @param vo + * @return + */ + public HashMap queryAllManagements(ProjectManagement vo) { + HashMap resp = new HashMap(); + try { + //获取用户的角色信息 + Integer roleId = mapper.queryRoleId(vo.getUserId()); + if (null != roleId) { + //角色不对(学生没有权限) + if (roleId == 4) { + resp.put("retcode", 300); + resp.put("retvalue", "抱歉,您的权限不能访问该地址!"); + return resp; + } + //角色等于管理员或者超级管理员 + else if (roleId == 1 ) { + vo.setUserId(null); + } + } + //条件查询 + List list = mapper.queryManagements(vo); + resp.put("retvalue",list); + resp.put("retcode", 200); + } catch (Exception e) { + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "Inquiry Failed"); + return resp; + } + return resp; + } /** diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9230663..642b17a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,6 +6,6 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jackson.default-property-inclusion=non-null server.port=1010 -server.servlet.context-path= +server.servlet.context-path=/project logging.level.com.yipin.liuwanr.mapper=debug diff --git a/src/test/java/com/yipin/liuwanr/Project_ManagementTest.java b/src/test/java/com/yipin/liuwanr/Project_ManagementTest.java index 4cb1957..1c61b82 100644 --- a/src/test/java/com/yipin/liuwanr/Project_ManagementTest.java +++ b/src/test/java/com/yipin/liuwanr/Project_ManagementTest.java @@ -39,63 +39,64 @@ public class Project_ManagementTest { /** * 分页查询+条件查询 */ - @Test - public void testQueryAllManagements() { - - Integer projectPermissions = null; - Integer founder = null; - Integer state = null; - String projectName = null; - Integer systemId = 1; - Integer userId = 4; - - ProjectManagement vo = new ProjectManagement(); - if (null != projectPermissions) { - vo.setProjectPermissions(projectPermissions); - } - if (null != founder) { - vo.setFounder(founder); - } - if (null != state) { - vo.setState(state); - } - if (null != systemId) { - vo.setSystemId(systemId); - } - if (null != projectName && projectName != "") { - vo.setProjectName(projectName); - } - if (null != userId) { - vo.setUserId(userId); - } - - Integer pageNo = 1; - Integer pageSize = 10; - - HashMap map = managementService.queryAllManagements(vo, pageNo, pageSize); - - Integer retcode = (Integer) map.get("retcode"); - - System.out.println(retcode); - - if (retcode == 200) { - PageResult pageResult = (PageResult) map.get("retvalue"); - - Long total = pageResult.getTotal(); - - System.out.println("total = " + total); - - List rows = (List) pageResult.getRows(); - - rows.forEach(item -> { - System.out.println(item.toString()); - }); - - } else { - String msg = (String) map.get("retvalue"); - System.out.println(msg); - } - } +// @Test +// public void testQueryAllManagements() { +// +// Integer projectPermissions = null; +// Integer founder = null; +// Integer state = null; +// String projectName = null; +// Integer systemId = 1; +// Integer userId = 4; +// +// ProjectManagement vo = new ProjectManagement(); +// if (null != projectPermissions) { +// vo.setProjectPermissions(projectPermissions); +// } +// if (null != founder) { +// vo.setFounder(founder); +// } +// if (null != state) { +// vo.setState(state); +// } +// if (null != systemId) { +// vo.setSystemId(systemId); +// } +// if (null != projectName && projectName != "") { +// vo.setProjectName(projectName); +// } +// if (null != userId) { +// vo.setUserId(userId); +// } +// +// Integer pageNo = 1; +// Integer pageSize = 10; +// +// HashMap map = managementService.queryAllManagements(vo); +//// HashMap map = managementService.queryAllManagements(vo, pageNo, pageSize); +// +// Integer retcode = (Integer) map.get("retcode"); +// +// System.out.println(retcode); +// +// if (retcode == 200) { +// PageResult pageResult = (PageResult) map.get("retvalue"); +// +// Long total = pageResult.getTotal(); +// +// System.out.println("total = " + total); +// +// List rows = (List) pageResult.getRows(); +// +// rows.forEach(item -> { +// System.out.println(item.toString()); +// }); +// +// } else { +// String msg = (String) map.get("retvalue"); +// System.out.println(msg); +// } +// } /**