From b4f5918b649b5c0d46a9484f95d136ef66bd73e0 Mon Sep 17 00:00:00 2001 From: 277 <2286974448@qq.com> Date: Wed, 22 Sep 2021 11:54:04 +0000 Subject: [PATCH 01/13] =?UTF-8?q?update=20src/main/java/com/example/meetin?= =?UTF-8?q?groom/controller/RoleController.java.=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=8B=E8=A7=92=E8=89=B2=E9=A1=B5=E7=9A=84?= =?UTF-8?q?=E5=85=A8=E5=B1=80api=EF=BC=8C=E4=BD=BF=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=89=8D=E4=B8=8D=E7=94=A8=E5=8A=A0/api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/meetingroom/controller/RoleController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/meetingroom/controller/RoleController.java b/src/main/java/com/example/meetingroom/controller/RoleController.java index c2c13ff..bfc09ca 100644 --- a/src/main/java/com/example/meetingroom/controller/RoleController.java +++ b/src/main/java/com/example/meetingroom/controller/RoleController.java @@ -19,7 +19,7 @@ import java.util.Map; */ @RestController @CrossOrigin -@RequestMapping("/api") +// @RequestMapping("") public class RoleController { @Autowired @@ -37,7 +37,7 @@ public class RoleController { * 查询所有权限,用于员工表权限修改 */ // @RequestMapping(value = "/seleteRoleList",method = RequestMethod.GET) - @GetMapping("/role") + @GetMapping("/api/role") public ResultVo seleteRoleList(){ List roleList = roleService.selectRoleList(); -- Gitee From 44fd6bfbbe71975c1a6d433180645858ccb987d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cfeng=E2=80=9D?= <“feng@123.com”> Date: Wed, 22 Sep 2021 23:37:08 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9:=E4=BB=8EshiroSession?= =?UTF-8?q?=E4=B8=AD=E8=8E=B7=E5=8F=96role=E5=92=8Cid=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?:=E5=88=A4=E6=96=AD=E5=BD=93=E6=95=B0=E6=8D=AE=E6=95=B0?= =?UTF-8?q?=E4=B8=BA0=E6=97=B6=EF=BC=8C=E4=B9=9F=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E6=95=B0=E6=8D=AE=EF=BC=8C=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AFnull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meetingroom/controller/RoomOrderController.java | 10 ++++++---- .../meetingroom/service/impl/RoomOrderServiceImpl.java | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/meetingroom/controller/RoomOrderController.java b/src/main/java/com/example/meetingroom/controller/RoomOrderController.java index c9f70a2..6cdb49e 100644 --- a/src/main/java/com/example/meetingroom/controller/RoomOrderController.java +++ b/src/main/java/com/example/meetingroom/controller/RoomOrderController.java @@ -2,6 +2,7 @@ package com.example.meetingroom.controller; import com.example.meetingroom.service.RoomOrderService; import com.example.meetingroom.vo.*; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -130,13 +131,14 @@ public class RoomOrderController { public ResultVo selectOrder(@PathVariable String selectType, @PathVariable Integer lineNum, @PathVariable Integer pageNum){ //普通管理员0,超级管理员1,普通员工也是0,员工用不到role,因为他只需要查他自己,role是为了分辨超管和普管,因为超管可以看到被逻辑删除的数据,普管不可以 - // Integer role =SecurityUtils.getSubject().getSession().getAttribute("identity").equals("普通管理员")?0:1; + Integer role = ((String)SecurityUtils.getSubject().getSession().getAttribute("identity")).equals("普通管理员")?0:1; //用户id - //String userId = (String) SecurityUtils.getSubject().getSession().getAttribute("userid"); + String userId = (String) SecurityUtils.getSubject().getSession().getAttribute("id"); + //还没合体所以,先用默认参数 +// Integer role=1; +// String userId = "1"; - Integer role=1; - String userId = "1"; //判断参数是否合法 PageVo pageVo = roomOrderService.checkParams(selectType,lineNum,pageNum,role,userId); diff --git a/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java index 2fe53f5..009cfdd 100644 --- a/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java @@ -162,6 +162,10 @@ public class RoomOrderServiceImpl implements RoomOrderService { Integer counts = selectCounts(selectType,role,userId); //总页数 Integer pageCount = selectPages(lineNum,counts); + //判断总记录是否为0 + if(counts == 0){ + return new PageVo(0,0,0,0); + } //判断参数 if(lineNum<0 || pageNum<0 || pageNum>pageCount){ return null; -- Gitee From 132ffdfe84822ebb802475886c8279d3628b0bf4 Mon Sep 17 00:00:00 2001 From: xuan <255124139@qq.com> Date: Thu, 23 Sep 2021 09:01:37 +0800 Subject: [PATCH 03/13] =?UTF-8?q?*=20=E9=99=88=E7=82=AB=E5=8D=87=20*=201?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E5=96=84=E4=BA=86=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20*=202=EF=BC=8C=E7=A6=81=E6=AD=A2=E8=B6=85=E6=99=AE?= =?UTF-8?q?=E7=AE=A1=E5=B0=86=E5=91=98=E5=B7=A5=E4=BF=A1=E6=81=AF=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=88=96=E4=BF=AE=E6=94=B9=E8=B6=85=E7=AE=A1=E6=9D=83?= =?UTF-8?q?=E9=99=90=20*=203=EF=BC=8C=E8=B6=85=E7=AE=A1=E7=8B=AC=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=E7=9A=84=E6=8E=A5=E5=8F=A3=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=20/api=20=E5=8A=A0=20super=20=E5=8F=98=E6=88=90=20/ap?= =?UTF-8?q?i/super?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DepartController.java | 10 +-- .../controller/EmployeeInfoController.java | 73 +++++++++++-------- .../EmployeeRegisterController.java | 44 +++++------ .../controller/RoleController.java | 4 +- .../controller/RoomInfoController.java | 12 +-- .../example/meetingroom/dao/DepartDao.java | 2 +- .../meetingroom/dao/EmployeeInfoDao.java | 7 ++ .../meetingroom/service/DepartService.java | 2 +- .../service/EmployeeInfoService.java | 2 + .../meetingroom/service/RoleService.java | 6 ++ .../service/impl/DepartServiceImpl.java | 2 +- .../service/impl/EmployeeInfoServiceImpl.java | 10 +++ .../service/impl/RoleServiceImpl.java | 19 +++++ src/main/resources/application.yaml | 6 +- src/main/resources/mapper/DepartMapper.xml | 2 +- .../resources/mapper/EmployeeInfoMapper.xml | 7 ++ .../MeetingroomApplicationTests.java | 13 +--- 17 files changed, 132 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/example/meetingroom/controller/DepartController.java b/src/main/java/com/example/meetingroom/controller/DepartController.java index 757fd1a..d564899 100644 --- a/src/main/java/com/example/meetingroom/controller/DepartController.java +++ b/src/main/java/com/example/meetingroom/controller/DepartController.java @@ -32,7 +32,7 @@ public class DepartController { * 用于超管新增部门信息 */ // @RequestMapping(value = "/depart",method = RequestMethod.POST) - @PostMapping("/depart") + @PostMapping("/super/depart") public ResultVo insertDepart(@RequestBody Depart depart){ judge = departService.insertDepart(depart); @@ -53,7 +53,7 @@ public class DepartController { * 用于超管对会议室信息的修改操作 */ // @RequestMapping(value = "/updateDepart",method = RequestMethod.PUT) - @PutMapping("/depart") + @PutMapping("/super/depart") public ResultVo updateDepart(@RequestBody Depart depart){ judge = departService.updateDepart(depart); @@ -73,8 +73,7 @@ public class DepartController { * @return ResultVo 统一消息回复 * 用于超管对会议室信息的删除操作 */ -// @RequestMapping(value = "/deleteDepart",method = RequestMethod.DELETE) - @DeleteMapping("/depart/{id}") + @DeleteMapping("/super/depart/{id}") public ResultVo deleteDepart(@PathVariable("id")String id){ judge = departService.deleteDepart(id); @@ -90,9 +89,8 @@ public class DepartController { /** * @return ResultVo 统一消息回复 - * 用于向超管展示部门信息 + * 用于向管理员展示部门信息 */ -// @RequestMapping(value = "/selectDepartList",method = RequestMethod.GET) @GetMapping("/depart") public ResultVo selectDepartList(){ diff --git a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java index 291cf14..e960299 100644 --- a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java @@ -3,6 +3,7 @@ package com.example.meetingroom.controller; import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.service.EmployeeInfoService; import com.example.meetingroom.service.RoleService; +import com.example.meetingroom.service.impl.RoleServiceImpl; import com.example.meetingroom.vo.EmployeeInfoVo; import com.example.meetingroom.vo.PageVo_xuan; import com.example.meetingroom.vo.ResultVo; @@ -33,6 +34,9 @@ public class EmployeeInfoController { @Autowired private EmployeeInfoService employeeInfoService; + @Autowired + private RoleService roleService; + //用于判断是否成功 private Integer judge; @@ -46,20 +50,15 @@ public class EmployeeInfoController { public ResultVo selectEmployeeInfoPage(@PathVariable("currentPage")Integer currentPage , @PathVariable("currentCount")Integer currentCount,HttpServletRequest request){ -// Object role = request.getSession().getAttribute("identity"); - + // 授权 + Integer role = roleService.superOrCommon(); -// if (role == "???"){ -// PageVo_xuan EmployeeInfoList = employeeInfoService.selectEmployeeInfoPage(currentPage, currentCount,1); -// }else { -// PageVo_xuan EmployeeInfoList = employeeInfoService.selectEmployeeInfoPage(currentPage, currentCount,0); -// -// } + SecurityUtils.getSubject().getSession().getAttribute("identity"); Map map = new HashMap<>(); PageVo_xuan EmployeeInfoList = null; try { - EmployeeInfoList = employeeInfoService.selectEmployeeInfoPage(currentPage, currentCount,1); + EmployeeInfoList = employeeInfoService.selectEmployeeInfoPage(currentPage, currentCount,role); } catch (Exception e) { return ResultVo.error(500, "参数异常,跳转页不能为0",map); } @@ -80,8 +79,10 @@ public class EmployeeInfoController { @GetMapping("/employeeInfo/{str}") public ResultVo selectNameOrNunberObtainEmployeeInfo(@PathVariable("str") String str){ - //最后 int 类型参数为权限信息,现为虚假数据 - List employeeInfoVoList = employeeInfoService.selectNameOrNunberObtainEmployeeInfo(str, 0); + // 授权 + Integer role = roleService.superOrCommon(); + + List employeeInfoVoList = employeeInfoService.selectNameOrNunberObtainEmployeeInfo(str, role); Map map = new HashMap<>(); @@ -95,31 +96,32 @@ public class EmployeeInfoController { /** * @param employeeInfo - * @param request 判断身份 * @return ResultVo 统一消息回复 * 用于普管和超管修改员工信息 */ @PutMapping("/employeeInfo") public ResultVo updateEmployeeInfo(@RequestBody EmployeeInfo employeeInfo){ -// Object role = request.getSession(); -// if (role != null){ -// judge = employeeInfoService.updateEmployeeInfo(employeeInfo,1); -// }else { -// judge = employeeInfoService.updateEmployeeInfo(employeeInfo,0); -// } - - //最后 int 类型参数为权限信息,现为虚假数据 - judge = employeeInfoService.updateEmployeeInfo(employeeInfo,1); + // 授权 + Integer role = roleService.superOrCommon(); Map map = new HashMap<>(); -// map.put("超管修改员工信息", judge); + + if(employeeInfoService.judgePhone(employeeInfo.getPhone()) != null){ + return ResultVo.error(500, "该电话号码已存在,请更换!",map); + }else if(employeeInfo.getRoleId().equals("3")){ + return ResultVo.error(500, "不许修改成超级管理员,请更换!",map); + } + + judge = employeeInfoService.updateEmployeeInfo(employeeInfo,role); + + //判断成功与否 if(judge != 1){ - return ResultVo.error(500,"超管修改员工信息失败",map); + return ResultVo.error(500,"管理员修改员工信息失败",map); } - return ResultVo.ok(200,"超管修改员工信息成功",map); + return ResultVo.ok(200,"管理员修改员工信息成功",map); } @@ -133,13 +135,12 @@ public class EmployeeInfoController { judge = employeeInfoService.deleteEmployeeInfo(id); Map map = new HashMap<>(); -// map.put("管理员删除员工信息", judge); //判断成功与否 if(judge != 1){ - return ResultVo.error(500,"超管删除员工信息失败",map); + return ResultVo.error(500,"管理员删除员工信息失败",map); } - return ResultVo.ok(200,"超管删除员工信息成功",map); + return ResultVo.ok(200,"管理员删除员工信息成功",map); } /** @@ -147,15 +148,23 @@ public class EmployeeInfoController { * @return * 用于普管和超管对员工信息的新增操作 */ -// @RequestMapping(value = "/insertEmployeeInfo",method = RequestMethod.POST) @PostMapping("/employeeInfo") public ResultVo insertEmployeeInfo(@RequestBody EmployeeInfo employeeInfo){ - //最后一个参数为权限,现为模拟 - judge = employeeInfoService.insertEmployeeInfo(employeeInfo,0); - Map map = new HashMap<>(); -// map.put("超管新增员工信息", judge); + + if(employeeInfoService.judgePhone(employeeInfo.getPhone()) != null){ + return ResultVo.error(500, "该电话号码已存在,请更换!",map); + }else if(employeeInfo.getRoleId().equals("3")){ + return ResultVo.error(500, "不许添加超级管理员,请更换!",map); + } + + // 授权 + Integer role = roleService.superOrCommon(); + judge = employeeInfoService.insertEmployeeInfo(employeeInfo,role); + + + //判断成功与否 if(judge != 1){ diff --git a/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java b/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java index 3aaca7e..0074b73 100644 --- a/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java +++ b/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java @@ -4,10 +4,12 @@ import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.entity.EmployeeRegister; import com.example.meetingroom.service.EmployeeInfoService; import com.example.meetingroom.service.EmployeeRegisterService; +import com.example.meetingroom.service.RoleService; import com.example.meetingroom.vo.EmployeeRegisterVo; import com.example.meetingroom.vo.PageVo_xuan; import com.example.meetingroom.vo.ResultVo; import io.lettuce.core.output.SocketAddressOutput; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -33,6 +35,9 @@ public class EmployeeRegisterController { @Autowired private EmployeeInfoService employeeInfoService; + @Autowired + private RoleService roleService; + //用于判断是否成功 private Integer judge; @@ -42,26 +47,18 @@ public class EmployeeRegisterController { * @return ResultVo 统一消息回复 * 用于分页和分页跳转 */ -// @RequestMapping(value = "/selectEmployeeRegisterPage/{currentPage}/{currentCount}",method = RequestMethod.GET) @GetMapping("/employeeRegister/{currentPage}/{currentCount}") public ResultVo selectEmployeeRegisterPage(@PathVariable("currentPage")Integer currentPage , @PathVariable("currentCount")Integer currentCount, HttpServletRequest request){ - // Object role = request.getSession().getAttribute("identity"); - - -// if (role == "???"){ -// PageVo_xuan EmployeeInfoList = employeeInfoService.selectEmployeeInfoPage(currentPage, currentCount,1); -// }else { -// PageVo_xuan EmployeeInfoList = employeeInfoService.selectEmployeeInfoPage(currentPage, currentCount,0); -// -// } + // 授权 + Integer role = roleService.superOrCommon(); Map map = new HashMap<>(); - //最后 int 类型参数为权限信息,现为虚假数据 + PageVo_xuan employeeRegisterVoPageVo = null; try { - employeeRegisterVoPageVo = employeeRegisterService.selectEmployeeRegisterPage(currentPage, currentCount, 1); + employeeRegisterVoPageVo = employeeRegisterService.selectEmployeeRegisterPage(currentPage, currentCount, role); } catch (Exception e) { return ResultVo.error(500, "参数异常,跳转页不能为0",map); } @@ -88,9 +85,9 @@ public class EmployeeRegisterController { //判断成功与否 if(judge != 1){ - return ResultVo.error(500,"超管删除注册表信息失败",map); + return ResultVo.error(500,"管理员删除注册表信息失败",map); } - return ResultVo.ok(200,"超管删除注册表信息成功",map); + return ResultVo.ok(200,"管理员删除注册表信息成功",map); } @@ -108,8 +105,8 @@ public class EmployeeRegisterController { @PutMapping("/employeeRegister") public ResultVo updateEmployeeRegister(@RequestBody EmployeeRegister employeeRegister){ - //模拟管理员id - String adminId = "1"; + //获取管理员id + Object adminId = SecurityUtils.getSubject().getSession().getAttribute("id"); judge = 0; @@ -122,29 +119,26 @@ public class EmployeeRegisterController { if (previousState.equals(afterState) || (previousState.equals("待审核") && afterState.equals("未通过"))){ System.out.println("(相同状态) || (审前待审核 && 审后未通过)这种情况不用新增和删除员工,只用更改注册表"); - judge = employeeRegisterService.updateEmployeeRegister(employeeRegister,adminId); + judge = employeeRegisterService.updateEmployeeRegister(employeeRegister, (String) adminId); } else if((previousState.equals("待审核") && afterState.equals("已通过")) || (previousState.equals("未通过") && afterState.equals("已通过"))){ //(审前待审核 && 审后已通过) || (审前未通过 && 审后已通过) 这种情况需要新增员工和用更改注册表 System.out.println("(审前待审核 && 审后已通过) || (审前未通过 && 审后已通过) 这种情况需要新增员工和用更改注册表"); - judge = employeeRegisterService.updateEmployeeRegister(employeeRegister,adminId); + judge = employeeRegisterService.updateEmployeeRegister(employeeRegister, (String) adminId); //查询注册密码 employeeRegister.setPassword(employeeRegisterService.selectEmployeeInfoPasswode(employeeRegister.getPhone())); employeeRegisterService.insertEmployeeInfo(employeeRegister); - } else if(previousState.equals("已通过") && afterState.equals("未通过")){ + } else if(previousState.equals("已通过") && afterState.equals("未通过")) { // 审前已通过 && 审后未通过 这种情况需要删除员工和用更改注册表 System.out.println("审前已通过 && 审后未通过 这种情况需要删除员工和用更改注册表"); - judge = employeeRegisterService.updateEmployeeRegister(employeeRegister,adminId); + judge = employeeRegisterService.updateEmployeeRegister(employeeRegister, (String) adminId); employeeRegisterService.deleteEmployeeRegisterPhone(employeeRegister.getPhone()); - - }else{ - System.out.println("error"); } @@ -153,9 +147,9 @@ public class EmployeeRegisterController { //判断成功与否 if(judge != 1){ - return ResultVo.error(500,"超管修改注册表审核结果和原因失败",map); + return ResultVo.error(500,"管理员修改注册表审核结果和原因失败",map); } - return ResultVo.ok(200,"超管修改注册表审核结果和原因成功",map); + return ResultVo.ok(200,"管理员修改注册表审核结果和原因成功",map); } /** diff --git a/src/main/java/com/example/meetingroom/controller/RoleController.java b/src/main/java/com/example/meetingroom/controller/RoleController.java index c2c13ff..a5409be 100644 --- a/src/main/java/com/example/meetingroom/controller/RoleController.java +++ b/src/main/java/com/example/meetingroom/controller/RoleController.java @@ -19,7 +19,7 @@ import java.util.Map; */ @RestController @CrossOrigin -@RequestMapping("/api") +@RequestMapping("") public class RoleController { @Autowired @@ -37,7 +37,7 @@ public class RoleController { * 查询所有权限,用于员工表权限修改 */ // @RequestMapping(value = "/seleteRoleList",method = RequestMethod.GET) - @GetMapping("/role") + @GetMapping("/api/role") public ResultVo seleteRoleList(){ List roleList = roleService.selectRoleList(); diff --git a/src/main/java/com/example/meetingroom/controller/RoomInfoController.java b/src/main/java/com/example/meetingroom/controller/RoomInfoController.java index f19d105..eedc463 100644 --- a/src/main/java/com/example/meetingroom/controller/RoomInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/RoomInfoController.java @@ -32,8 +32,7 @@ public class RoomInfoController { * @return ResultVo 统一消息回复 * 用于超管对会议室信息的修改操作, */ -// @RequestMapping(value = "/updateRoomInfo",method = RequestMethod.PUT) - @PutMapping("/roomInfo") + @PutMapping("/super/roomInfo") public ResultVo updateRoomInfo(@RequestBody RoomInfo roomInfo){ //用于判断是否成功 @@ -61,8 +60,7 @@ public class RoomInfoController { * @return ResultVo 统一消息回复 * 用于超管对会议室信息的删除操作 */ -// @RequestMapping(value = "/deleteRoomInfo",method = RequestMethod.DELETE) - @DeleteMapping("/roomInfo/{id}") + @DeleteMapping("/super/roomInfo/{id}") public ResultVo deleteRoomInfo(@PathVariable("id")String id){ judge = roomInfoService.deleteRoomInfo(id); @@ -82,8 +80,7 @@ public class RoomInfoController { * @return ResultVo 统一消息回复 * 用于超管新增会议室信息 */ -// @RequestMapping(value = "/insertRoomInfo",method = RequestMethod.POST) - @PostMapping("/roomInfo") + @PostMapping("/super/roomInfo") public ResultVo insertRoomInfo(@RequestBody RoomInfo roomInfo){ judge = roomInfoService.insertRoomInfo(roomInfo); @@ -105,8 +102,7 @@ public class RoomInfoController { * @return ResultVo 统一消息回复 * 用于分页和分页跳转 */ -// @RequestMapping(value = "/selectRoomInfoPage/{currentPage}/{currentCount}",method = RequestMethod.GET) - @GetMapping("/roomInfo/{currentPage}/{currentCount}") + @GetMapping("/super/roomInfo/{currentPage}/{currentCount}") public ResultVo selectRoomInfoPage(@PathVariable("currentPage")Integer currentPage ,@PathVariable("currentCount")Integer currentCount){ diff --git a/src/main/java/com/example/meetingroom/dao/DepartDao.java b/src/main/java/com/example/meetingroom/dao/DepartDao.java index 0abcb9d..3810232 100644 --- a/src/main/java/com/example/meetingroom/dao/DepartDao.java +++ b/src/main/java/com/example/meetingroom/dao/DepartDao.java @@ -36,7 +36,7 @@ public interface DepartDao { /** * @param id 会议室id,根据id进行删除操作 * @return int 0或1 - * 用于超管对会议室信息的删除操作 + * 用于超管对部门信息的删除操作 */ int deleteDepart(String id); diff --git a/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java b/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java index 7c1bfc2..4bbb176 100644 --- a/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java +++ b/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java @@ -75,6 +75,13 @@ public interface EmployeeInfoDao { */ int insertBatch(List lists); + /** + * @param phone + * @return + * 用于管理员新增员工时判断电话号码是否重复 + */ + String judgePhone(String phone); + List selectNameOrNunberObtainEmployeeInfo(@Param("str")String str, @Param("role")Integer role); EmployeeInfo getEmployeeInfoByPhoneAndPassword(String phone,String password); diff --git a/src/main/java/com/example/meetingroom/service/DepartService.java b/src/main/java/com/example/meetingroom/service/DepartService.java index 156b4f0..d04e9e2 100644 --- a/src/main/java/com/example/meetingroom/service/DepartService.java +++ b/src/main/java/com/example/meetingroom/service/DepartService.java @@ -30,7 +30,7 @@ public interface DepartService { /** * @param id 会议室id,根据id进行删除操作 * @return int 0或1 - * 用于超管对会议室信息的删除操作 + * 用于超管对部门信息的删除操作 */ int deleteDepart(String id); diff --git a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java index c1301f3..f9f5dd2 100644 --- a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java +++ b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java @@ -75,4 +75,6 @@ public interface EmployeeInfoService { String getRoleIdByPhone(String phone); int updatePassword(String phone, String newPassword); + + String judgePhone(String phone); } diff --git a/src/main/java/com/example/meetingroom/service/RoleService.java b/src/main/java/com/example/meetingroom/service/RoleService.java index e8c4b51..cddf2f3 100644 --- a/src/main/java/com/example/meetingroom/service/RoleService.java +++ b/src/main/java/com/example/meetingroom/service/RoleService.java @@ -19,6 +19,12 @@ public interface RoleService { */ List selectRoleList(); + /** + * @return + * 超,普管判断 + */ + Integer superOrCommon(); + String getRoleByPhone(String phone); String getRoleByEmployeeId(String id); diff --git a/src/main/java/com/example/meetingroom/service/impl/DepartServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/DepartServiceImpl.java index 2ef5104..f00974d 100644 --- a/src/main/java/com/example/meetingroom/service/impl/DepartServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/DepartServiceImpl.java @@ -47,7 +47,7 @@ public class DepartServiceImpl implements DepartService { /** * @param id 会议室id,根据id进行删除操作 * @return int 0或1 - * 用于超管对会议室信息的删除操作 + * 用于超管对部门信息的删除操作 */ @Override public int deleteDepart(String id){ diff --git a/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java index 1763da5..6a683fe 100644 --- a/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java @@ -198,4 +198,14 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService { public int updatePassword(String phone, String newPassword) { return employeeInfoDao.updatePassword(phone,newPassword); } + + /** + * @param phone + * @return + * 用于管理员新增员工时判断电话号码是否重复 + */ + @Override + public String judgePhone(String phone){ + return employeeInfoDao.judgePhone(phone); + } } diff --git a/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java index 60d2d1b..03e602d 100644 --- a/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java @@ -4,6 +4,7 @@ import com.example.meetingroom.dao.RoleDao; import com.example.meetingroom.dao.RoomInfoDao; import com.example.meetingroom.entity.Role; import com.example.meetingroom.service.RoleService; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -34,6 +35,21 @@ public class RoleServiceImpl implements RoleService { return roleDao.selectRoleList(); } + /** + * @return + * 超,普管判断 + */ + @Override + public Integer superOrCommon(){ + Integer role = 0; + if (SecurityUtils.getSubject().getSession().getAttribute("identity").equals("超级管理员")){ + role = 1; + }else if (SecurityUtils.getSubject().getSession().getAttribute("identity").equals("普通管理员")){ + role = 0; + } + return role; + } + @Override public String getRoleByPhone(String phone) { return roleDao.getRoleByPhone(phone); @@ -43,4 +59,7 @@ public class RoleServiceImpl implements RoleService { public String getRoleByEmployeeId(String id) { return roleDao.getRoleByEmployeeId(id); } + + + } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3fb9011..9326d35 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,13 +1,13 @@ server: - port: 8081 + port: 8080 spring: #mysql数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql:// chensiran.cn:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://localhost:3305/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root - password: root + password: mysql mybatis: mapper-locations: classpath*:mapper/*.xml diff --git a/src/main/resources/mapper/DepartMapper.xml b/src/main/resources/mapper/DepartMapper.xml index 342aebf..84f573a 100644 --- a/src/main/resources/mapper/DepartMapper.xml +++ b/src/main/resources/mapper/DepartMapper.xml @@ -19,7 +19,7 @@ where depart.id = #{id}; - + delete from meeting_room.depart where id = #{id}; diff --git a/src/main/resources/mapper/EmployeeInfoMapper.xml b/src/main/resources/mapper/EmployeeInfoMapper.xml index 0cb48ad..a569162 100644 --- a/src/main/resources/mapper/EmployeeInfoMapper.xml +++ b/src/main/resources/mapper/EmployeeInfoMapper.xml @@ -134,6 +134,13 @@ where phone = #{phone} + + + update employee_info set password = #{param2} where phone = #{param1} diff --git a/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java b/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java index 8c3f1a8..c9b75e5 100644 --- a/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java +++ b/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java @@ -46,15 +46,10 @@ class MeetingroomApplicationTests { } -// @Test -// public void test1(){ -// PageVo_xuan employeeInfoVoPageVo_xuan = new PageVo_xuan<>(); -// employeeInfoVoPageVo_xuan.getTotalRecord(); -// System.out.println(employeeInfoDao.selectEmployeeInfoVoPageCommon(employeeInfoVoPageVo_xuan,0)); -// -// -// } - + @Test + public void test1(){ + System.out.println(employeeInfoDao.judgePhone("11111")); + } -- Gitee From 2b3f3070c194f6a2f8184e51b541d46d88f29391 Mon Sep 17 00:00:00 2001 From: 277 <2286974448@qq.com> Date: Thu, 23 Sep 2021 01:06:28 +0000 Subject: [PATCH 04/13] update src/main/resources/application.yaml. --- src/main/resources/application.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 9326d35..c049b08 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,13 +1,13 @@ server: - port: 8080 + port: 8081 spring: #mysql数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3305/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://chensiran.cn:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root - password: mysql + password: root mybatis: mapper-locations: classpath*:mapper/*.xml -- Gitee From f55c7a255bbfa2475fde5d6d918ce71fdb8d75ea Mon Sep 17 00:00:00 2001 From: ljh Date: Thu, 23 Sep 2021 09:48:17 +0800 Subject: [PATCH 05/13] =?UTF-8?q?Jiahuan=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A6=82=E4=B8=8B=201=E3=80=81=E5=9C=A8RoomOrderMapper.xml?= =?UTF-8?q?=E7=9B=B8=E5=85=B3SQL=E8=AF=AD=E5=8F=A5=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B3=A8=E9=87=8A=E3=80=82=202=E3=80=81=E5=AF=B9?= =?UTF-8?q?=E2=80=9C=E4=BC=9A=E8=AE=AE=E5=AE=A4=E9=A2=84=E5=AE=9A=E2=80=9D?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8F=92=E5=85=A5=E5=A4=B1=E8=B4=A5=EF=BC=8C?= =?UTF-8?q?=E5=81=9A=E5=87=BA=E7=9B=B8=E5=BA=94=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meetingroom/controller/RoomOrderController.java | 3 +++ .../meetingroom/service/impl/RoomOrderServiceImpl.java | 5 +++++ src/main/resources/mapper/RoomOrderMapper.xml | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/src/main/java/com/example/meetingroom/controller/RoomOrderController.java b/src/main/java/com/example/meetingroom/controller/RoomOrderController.java index 6cdb49e..3985e85 100644 --- a/src/main/java/com/example/meetingroom/controller/RoomOrderController.java +++ b/src/main/java/com/example/meetingroom/controller/RoomOrderController.java @@ -112,6 +112,9 @@ public class RoomOrderController { map.put("ExecuteNumber",RoomOrderMessage); + if (RoomOrderMessage==null){ + return ResultVo.error(500,"插入失败,申请人错误",map); + } return ResultVo.ok(200,"成功",map); } diff --git a/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java index 009cfdd..1e3badd 100644 --- a/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java @@ -81,7 +81,12 @@ public class RoomOrderServiceImpl implements RoomOrderService { */ @Override public Object insertRoomOrderMessage(RoomOrderMessageVo roomOrderMessageVo) { + //根据applicant从employee_info表中查询申请人的id String employee_info_id = roomOrderDao.getEmployeeInfoId(roomOrderMessageVo.getApplicant()); + //若该申请人不在employee_info表中,则return null + if (employee_info_id==null){ + return null; + } return roomOrderDao.insertRoomOrderMessage(roomOrderMessageVo.getRoom_id(), employee_info_id, roomOrderMessageVo.getSubject(), diff --git a/src/main/resources/mapper/RoomOrderMapper.xml b/src/main/resources/mapper/RoomOrderMapper.xml index f5cd18f..49b2234 100644 --- a/src/main/resources/mapper/RoomOrderMapper.xml +++ b/src/main/resources/mapper/RoomOrderMapper.xml @@ -274,26 +274,32 @@ where id = #{orderId} + + + + + + select REPLACE(UUID(),'-','') @@ -304,6 +310,7 @@ (#{id},#{room_id},#{employee_info_id},#{subject},#{is_use},#{applicant},#{phone},#{employee_list},#{start_time},#{end_time},#{room_order_status},#{deleted}) + -- Gitee From 46ac55d27434567208a9eedb855c8ef8a72a6883 Mon Sep 17 00:00:00 2001 From: ljh Date: Thu, 23 Sep 2021 09:51:48 +0800 Subject: [PATCH 06/13] =?UTF-8?q?Jiahuan=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A6=82=E4=B8=8B=201=E3=80=81=E5=9C=A8RoomOrderMapper.xml?= =?UTF-8?q?=E7=9B=B8=E5=85=B3SQL=E8=AF=AD=E5=8F=A5=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B3=A8=E9=87=8A=E3=80=82=202=E3=80=81=E5=AF=B9?= =?UTF-8?q?=E2=80=9C=E4=BC=9A=E8=AE=AE=E5=AE=A4=E9=A2=84=E5=AE=9A=E2=80=9D?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8F=92=E5=85=A5=E5=A4=B1=E8=B4=A5=EF=BC=8C?= =?UTF-8?q?=E5=81=9A=E5=87=BA=E7=9B=B8=E5=BA=94=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/meetingroom/service/impl/RoomOrderServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java index 1e3badd..b389416 100644 --- a/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/RoomOrderServiceImpl.java @@ -77,7 +77,7 @@ public class RoomOrderServiceImpl implements RoomOrderService { /** * 分业务:“提交申请” - * 功能:实现接口,将前端返回的“会议室预订”信息,插入到room_order表中 + * 功能:实现接口,将前端返回的“会议室预订”信息,插入到room_order表中. */ @Override public Object insertRoomOrderMessage(RoomOrderMessageVo roomOrderMessageVo) { -- Gitee From 9182832c7da93358d770e2e0d9aff6896c1b100a Mon Sep 17 00:00:00 2001 From: Y1-zd Date: Thu, 23 Sep 2021 09:52:36 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E9=99=88=E6=A2=93=E5=BA=B7=EF=BC=9A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=BB=E9=A1=B5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86Shiro=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E6=96=B0=E5=A2=9E=E4=BA=86=E8=B7=A8=E5=9F=9F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E9=85=8D=E7=BD=AE=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++ .../meetingroom/config/EmployeeRealm.java | 29 +++++----- .../meetingroom/config/GlobalCorsConfig.java | 54 +++++++++++++++++++ .../meetingroom/config/ShiroConfig.java | 20 +++---- .../controller/DepartController.java | 2 +- .../controller/EmployeeInfoController.java | 29 +++++----- .../controller/RoleController.java | 23 +++++--- .../controller/RoomInfoController.java | 2 +- .../com/example/meetingroom/dao/RoleDao.java | 2 +- .../meetingroom/service/RoleService.java | 2 +- .../service/impl/RoleServiceImpl.java | 4 +- src/main/resources/application.yaml | 4 +- src/main/resources/mapper/RoleMapper.xml | 2 +- src/main/resources/templates/index.html | 2 +- src/main/resources/templates/user.html | 1 - .../MeetingroomApplicationTests.java | 8 +++ 16 files changed, 137 insertions(+), 53 deletions(-) create mode 100644 src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java diff --git a/pom.xml b/pom.xml index 55d0624..5118fd4 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,12 @@ aliyun-sdk-oss 3.10.2 + + + org.springframework.boot + spring-boot-starter-thymeleaf + + diff --git a/src/main/java/com/example/meetingroom/config/EmployeeRealm.java b/src/main/java/com/example/meetingroom/config/EmployeeRealm.java index 2239bf5..6681b4d 100644 --- a/src/main/java/com/example/meetingroom/config/EmployeeRealm.java +++ b/src/main/java/com/example/meetingroom/config/EmployeeRealm.java @@ -30,8 +30,10 @@ public class EmployeeRealm extends AuthorizingRealm { @Autowired private RoleService roleService; - /**+ + /** + * + * 对用户进行授权,同时传递该用户的身份信息。 + * @param principalCollection * @return */ @@ -39,14 +41,14 @@ public class EmployeeRealm extends AuthorizingRealm { protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { System.out.println("正在授权..."); EmployeeInfo primaryPrincipal = (EmployeeInfo) principalCollection.getPrimaryPrincipal(); - System.out.println("------------------"+primaryPrincipal); + System.out.println("------------------" + primaryPrincipal); String id = employeeInfoService.getRoleIdByPhone(primaryPrincipal.getPhone()); - String role = roleService.getRoleByEmployeeId(id); + String role = roleService.getRoleByRoleId(primaryPrincipal.getRoleId()); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); - SecurityUtils.getSubject().getSession().setAttribute("identity",role); - SecurityUtils.getSubject().getSession().setAttribute("id",primaryPrincipal.getId()); + SecurityUtils.getSubject().getSession().setAttribute("identity", role); + SecurityUtils.getSubject().getSession().setAttribute("id", primaryPrincipal.getId()); System.out.println(SecurityUtils.getSubject().getSession().getAttribute("identity")); - System.out.println("授权-----------"+role); + System.out.println("授权-----------" + role); info.addRole(role); return info; } @@ -54,6 +56,7 @@ public class EmployeeRealm extends AuthorizingRealm { /** * 进行用户的登录。登录之前会调用Session管理器,来找到活跃的Sessions,查看是否有相同的用户进行登录,有则进行下线处理。 * 然后再进行账号密码的比对进行登录。 + * * @param authenticationToken * @return * @throws AuthenticationException @@ -67,21 +70,21 @@ public class EmployeeRealm extends AuthorizingRealm { EmployeeInfo employee = employeeInfoService.getEmployeeInfoByPhone(username); //处理session DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager(); - DefaultWebSessionManager sessionManager = (DefaultWebSessionManager)securityManager.getSessionManager(); + DefaultWebSessionManager sessionManager = (DefaultWebSessionManager) securityManager.getSessionManager(); Collection sessions = sessionManager.getSessionDAO().getActiveSessions();//获取当前已登录的用户session列表 - System.out.println("principal:"+principal); - System.out.println("当前正活跃Session个数:"+sessions.size()); - for(Session session:sessions){ + System.out.println("principal:" + principal); + System.out.println("当前正活跃Session个数:" + sessions.size()); + for (Session session : sessions) { //通过比较当前用户的toString及Session中的用户toString,来判断是否是同一账号。是则进行剔除。 - System.out.println("已存在的活跃Session:"+session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)); - if(String.valueOf(employee).equals(String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)))) { + System.out.println("已存在的活跃Session:" + session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)); + if (String.valueOf(employee).equals(String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)))) { sessionManager.getSessionDAO().delete(session); System.out.println("成功剔除相同用户。"); } } System.out.println("正在认证..."); //根据是否查询到用户而进行对应处理:查无则抛异常,查到则进行认证。 - if (employee == null){ + if (employee == null) { throw new UnknownAccountException("请检查您的用户名及密码是否有误。"); } AuthenticationInfo info = new SimpleAuthenticationInfo(employee, employee.getPassword(), null, getName()); diff --git a/src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java b/src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java new file mode 100644 index 0000000..aa036f5 --- /dev/null +++ b/src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java @@ -0,0 +1,54 @@ +package com.example.meetingroom.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 前后端分离所产生的跨域问题所需配置,全局跨域 + */ +@Configuration +public class GlobalCorsConfig { + + /** + * 返回一个Cors过滤器,对相应的HTTP请求的放行及配置。 + * @return + */ + @Bean + public CorsFilter corsFilter() { + CorsConfiguration corsConfig = new CorsConfiguration(); + //设置Origin(原始域) + corsConfig.addAllowedOrigin("*"); + //设置是否发送cookie + corsConfig.setAllowCredentials(true); + //放行哪些原始域(头部信息) + corsConfig.addAllowedHeader("*"); + //暴露哪些头部信息 + corsConfig.addExposedHeader("*"); + //配置映射路径 + UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource(); + configurationSource.registerCorsConfiguration("/**", corsConfig); + return new CorsFilter(configurationSource); + } + + /** + * 对请求方式的放行。 + * @return + */ + @Bean + public WebMvcConfigurer webMvcConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedOrigins("*").allowCredentials(true). + allowedMethods("GET","POST","DELETE","PUT"). + allowedHeaders("*").exposedHeaders("Token","Channel"); + } + }; + } + +} diff --git a/src/main/java/com/example/meetingroom/config/ShiroConfig.java b/src/main/java/com/example/meetingroom/config/ShiroConfig.java index 18854a0..566b13d 100644 --- a/src/main/java/com/example/meetingroom/config/ShiroConfig.java +++ b/src/main/java/com/example/meetingroom/config/ShiroConfig.java @@ -23,6 +23,7 @@ public class ShiroConfig { /** * 配置过滤的相关信息。如过滤何种界面,设置登录返回界面等。 + * * @param webSecurityManager * @return ShiroFilterFactoryBean */ @@ -32,18 +33,16 @@ public class ShiroConfig { shiroFilterFactoryBean.setSecurityManager(webSecurityManager); Map filterChainDefinitionMap = new LinkedHashMap<>(); Map filterMap = new LinkedHashMap<>(); - filterMap.put("roleOf", new CustomRolesAuthorizationFilter()); + filterMap.put("roleOf", new CustomRolesAuthorizationFilter()); shiroFilterFactoryBean.setFilters(filterMap); //设置登录失败返回的页面 - shiroFilterFactoryBean.setLoginUrl("/"); + shiroFilterFactoryBean.setLoginUrl("/api/"); //静态资源的放行 //权限放行 - filterChainDefinitionMap.put("/toLogin","anon"); - filterChainDefinitionMap.put("/login","anon"); - filterChainDefinitionMap.put("/user/**","authc,roleOf[普通用户,普通管理员]"); - filterChainDefinitionMap.put("/oper/**","authc,roles[超级管理员]"); - filterChainDefinitionMap.put("/logout","logout"); + filterChainDefinitionMap.put("/login", "anon"); + filterChainDefinitionMap.put("/api/oper/**", "authc,roles[超级管理员]"); + filterChainDefinitionMap.put("/logout", "logout"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; @@ -51,6 +50,7 @@ public class ShiroConfig { /** * Session管理器,设置全局Session的配置。 + * * @return DefaultWebSessionManager */ @Bean @@ -58,13 +58,14 @@ public class ShiroConfig { DefaultWebSessionManager defaultSessionManager = new DefaultWebSessionManager(); //分别设置 session状态,全局会话时间,及删除失效session defaultSessionManager.setSessionValidationSchedulerEnabled(false); - defaultSessionManager.setGlobalSessionTimeout(60*30*1000); + defaultSessionManager.setGlobalSessionTimeout(60 * 30 * 1000); defaultSessionManager.setDeleteInvalidSessions(true); return defaultSessionManager; } /** * 安全管理器,设置自用Realm和其他管理器。 + * * @param realm * @param sessionManager * @return SecurityManager @@ -81,10 +82,11 @@ public class ShiroConfig { /** * 自用Realm,当前是EmployeeRealm。 + * * @return EmployeeRealm */ @Bean - public EmployeeRealm realm(){ + public EmployeeRealm realm() { return new EmployeeRealm(); } } \ No newline at end of file diff --git a/src/main/java/com/example/meetingroom/controller/DepartController.java b/src/main/java/com/example/meetingroom/controller/DepartController.java index 757fd1a..38a5f24 100644 --- a/src/main/java/com/example/meetingroom/controller/DepartController.java +++ b/src/main/java/com/example/meetingroom/controller/DepartController.java @@ -17,7 +17,7 @@ import java.util.Map; */ @RestController @CrossOrigin -@RequestMapping("/api") +@RequestMapping("/api/oper") public class DepartController { @Autowired diff --git a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java index 291cf14..426855c 100644 --- a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java @@ -95,7 +95,7 @@ public class EmployeeInfoController { /** * @param employeeInfo - * @param request 判断身份 + * @param request 判断身份 * @return ResultVo 统一消息回复 * 用于普管和超管修改员工信息 */ @@ -166,11 +166,12 @@ public class EmployeeInfoController { /** * 用户登录。若登录成功,会根据其所有的权限来进行相应界面的跳转。 + * * @param phone 账号 * @param password 前端加密后的MD5密码 * @return */ - @RequestMapping(value = "/login",method = RequestMethod.POST) + @RequestMapping(value = "/login", method = RequestMethod.POST) public ResultVo login(@RequestParam("phone") String phone, @RequestParam("password") String password) { Map data = new LinkedHashMap<>(); @@ -196,32 +197,34 @@ public class EmployeeInfoController { /** * 用户登出,登出之后会进行JSESSION的清空。 + * * @return 提示用户已经登出。 */ - @RequestMapping(value = "/logout",method = RequestMethod.GET) - public ResultVo logout(){ + @RequestMapping(value = "/logout", method = RequestMethod.GET) + public ResultVo logout() { SecurityUtils.getSubject().logout(); - return ResultVo.ok(200,"用户已登出系统。",null); + return ResultVo.ok(200, "用户已登出系统。", null); } /** * 用户修改密码,会先验证存在的账号和旧密码是否属实,若成功则进行密码的修改。 - * @param phone 账号 + * + * @param phone 账号 * @param oldPassword 旧密码 * @param newPassword 新密码 * @return 根据密码是否修改来返回是否修改成功的信息。 */ - @RequestMapping(value = "/changePassword",method = RequestMethod.POST) + @RequestMapping(value = "/changePassword", method = RequestMethod.POST) public ResultVo changePassword(@RequestParam("phone") String phone, @RequestParam("oldPassword") String oldPassword, - @RequestParam("newPassword") String newPassword){ - EmployeeInfo employee = employeeInfoService.getEmployeeInfoByPhoneAndPassword(phone,oldPassword); - if (employee!=null){ + @RequestParam("newPassword") String newPassword) { + EmployeeInfo employee = employeeInfoService.getEmployeeInfoByPhoneAndPassword(phone, oldPassword); + if (employee != null) { int isSuccess = employeeInfoService.updatePassword(phone, newPassword); - }else{ - return ResultVo.error(404,"请确认您的旧密码是否有误!",null); + } else { + return ResultVo.error(404, "请确认您的旧密码是否有误!", null); } - return ResultVo.ok(200,"您的密码已成功修改!",null); + return ResultVo.ok(200, "您的密码已成功修改!", null); } } diff --git a/src/main/java/com/example/meetingroom/controller/RoleController.java b/src/main/java/com/example/meetingroom/controller/RoleController.java index c2c13ff..4b3e018 100644 --- a/src/main/java/com/example/meetingroom/controller/RoleController.java +++ b/src/main/java/com/example/meetingroom/controller/RoleController.java @@ -1,6 +1,7 @@ package com.example.meetingroom.controller; import com.example.meetingroom.entity.Depart; +import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.entity.Role; import com.example.meetingroom.service.RoleService; import com.example.meetingroom.vo.ResultVo; @@ -54,17 +55,25 @@ public class RoleController { } /** - * 首页,同时解决同个浏览器一个session却有多个用户共用的问题。 + * 首页,登录界面,解决同个浏览器一个session却有多个用户共用的问题(即一个会话多用户登录) * 通过检查Subject中principal是否为空来判断是否已经有用户登录过。 - * @return 返回至index页面 + * @return 根据情况返回相应页面 */ @GetMapping({"/","/index"}) - public String index(){ - Object principal = SecurityUtils.getSubject().getPrincipal(); - System.out.println("登录首页,存在principal:"+principal); + public ResultVo index(){ + EmployeeInfo principal = (EmployeeInfo) SecurityUtils.getSubject().getPrincipal(); if (principal != null){ - return "redirect:/user/test"; + Map data = new HashMap<>(); + System.out.println("当前存在已登录用户:"+principal); + String principalRole = roleService.getRoleByRoleId(principal.getRoleId()); + System.out.println("当前用户权限为:"+SecurityUtils.getSubject().getSession().getAttribute("identity")); + data.put("role",principalRole); + if ("超级管理员".equals(principalRole)){ + return ResultVo.ok(200,"已存在用户登录,跳转至超级管理员界面。",data); + }else{ + return ResultVo.ok(200,"已存在用户登录,跳转至用户界面。",data); + } } - return "index"; + return ResultVo.ok(200,"当前会话无用户登录,则显示登录的界面。",null); } } diff --git a/src/main/java/com/example/meetingroom/controller/RoomInfoController.java b/src/main/java/com/example/meetingroom/controller/RoomInfoController.java index f19d105..fc8516e 100644 --- a/src/main/java/com/example/meetingroom/controller/RoomInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/RoomInfoController.java @@ -16,7 +16,7 @@ import java.util.*; */ @RestController @CrossOrigin -@RequestMapping("/api") +@RequestMapping("/api/oper") public class RoomInfoController { diff --git a/src/main/java/com/example/meetingroom/dao/RoleDao.java b/src/main/java/com/example/meetingroom/dao/RoleDao.java index 2d1f0bc..66eca9b 100644 --- a/src/main/java/com/example/meetingroom/dao/RoleDao.java +++ b/src/main/java/com/example/meetingroom/dao/RoleDao.java @@ -26,5 +26,5 @@ public interface RoleDao { String getRoleByPhone(String Phone); - String getRoleByEmployeeId(String id); + String getRoleByRoleId(String id); } diff --git a/src/main/java/com/example/meetingroom/service/RoleService.java b/src/main/java/com/example/meetingroom/service/RoleService.java index e8c4b51..dfe98da 100644 --- a/src/main/java/com/example/meetingroom/service/RoleService.java +++ b/src/main/java/com/example/meetingroom/service/RoleService.java @@ -21,5 +21,5 @@ public interface RoleService { String getRoleByPhone(String phone); - String getRoleByEmployeeId(String id); + String getRoleByRoleId(String id); } diff --git a/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java index 60d2d1b..73a0d18 100644 --- a/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java @@ -40,7 +40,7 @@ public class RoleServiceImpl implements RoleService { } @Override - public String getRoleByEmployeeId(String id) { - return roleDao.getRoleByEmployeeId(id); + public String getRoleByRoleId(String id) { + return roleDao.getRoleByRoleId(id); } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3fb9011..8f608af 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -5,9 +5,9 @@ spring: #mysql数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql:// chensiran.cn:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://localhost:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root - password: root + password: chenzikang mybatis: mapper-locations: classpath*:mapper/*.xml diff --git a/src/main/resources/mapper/RoleMapper.xml b/src/main/resources/mapper/RoleMapper.xml index defafcf..f28a7c4 100644 --- a/src/main/resources/mapper/RoleMapper.xml +++ b/src/main/resources/mapper/RoleMapper.xml @@ -21,7 +21,7 @@ where phone = #{phone} - select name from role where id = #{id} diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 1122c09..42bbcc5 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -6,7 +6,7 @@ -
+ 账号:
密码:
diff --git a/src/main/resources/templates/user.html b/src/main/resources/templates/user.html index 11f7446..f2787f3 100644 --- a/src/main/resources/templates/user.html +++ b/src/main/resources/templates/user.html @@ -7,7 +7,6 @@

你好!

-

你的名字:

你的ID:

你的身份:

diff --git a/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java b/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java index 8c3f1a8..ec097a9 100644 --- a/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java +++ b/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java @@ -3,6 +3,7 @@ package com.example.meetingroom; import com.example.meetingroom.dao.*; import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.entity.EmployeeRegister; +import com.example.meetingroom.service.RoleService; import com.example.meetingroom.service.impl.EmployeeRegisterServiceImpl; import com.example.meetingroom.vo.EmployeeInfoVo; import com.example.meetingroom.vo.PageVo_xuan; @@ -26,6 +27,9 @@ class MeetingroomApplicationTests { @Autowired private EmployeeRegisterServiceImpl employeeRegisterService; + @Autowired + private RoleService roleService; + @Test void contextLoads() { System.out.println(employeeInfoDao.deleteEmployeeInfo("001")); @@ -55,6 +59,10 @@ class MeetingroomApplicationTests { // // } + @Test + public void test01(){ + + } -- Gitee From 032531ce823ef10043f23ef5cf27b7813e5def88 Mon Sep 17 00:00:00 2001 From: 277 <2286974448@qq.com> Date: Thu, 23 Sep 2021 01:59:49 +0000 Subject: [PATCH 08/13] update src/main/resources/application.yaml. --- src/main/resources/application.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 8f608af..c049b08 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -5,9 +5,9 @@ spring: #mysql数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://chensiran.cn:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root - password: chenzikang + password: root mybatis: mapper-locations: classpath*:mapper/*.xml -- Gitee From 3050011e0c8f8ed19c65436ea7cc026be4be3db3 Mon Sep 17 00:00:00 2001 From: xuan <255124139@qq.com> Date: Thu, 23 Sep 2021 11:24:00 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E9=99=88=E7=82=AB=E5=8D=87=202021.9.23?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=80=A7=E5=88=AB0,1=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=88=90=E7=94=B7=E5=A5=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EmployeeInfoController.java | 5 +++++ .../example/meetingroom/dao/EmployeeInfoDao.java | 6 ++++++ .../meetingroom/service/EmployeeInfoService.java | 7 ++++++- .../service/impl/EmployeeInfoServiceImpl.java | 10 +++++++++- .../example/meetingroom/vo/EmployeeInfoVo.java | 16 ++++++++++++++-- src/main/resources/mapper/EmployeeInfoMapper.xml | 7 ++++--- 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java index e960299..a93da48 100644 --- a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java @@ -76,6 +76,11 @@ public class EmployeeInfoController { } + /** + * @param str + * @return + * 根据员工姓名和编号查询员工信息 + */ @GetMapping("/employeeInfo/{str}") public ResultVo selectNameOrNunberObtainEmployeeInfo(@PathVariable("str") String str){ diff --git a/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java b/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java index 4bbb176..bec0a9e 100644 --- a/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java +++ b/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java @@ -82,6 +82,12 @@ public interface EmployeeInfoDao { */ String judgePhone(String phone); + /** + * @param str + * @param role + * @return + * 根据员工姓名和编号查询员工信息 + */ List selectNameOrNunberObtainEmployeeInfo(@Param("str")String str, @Param("role")Integer role); EmployeeInfo getEmployeeInfoByPhoneAndPassword(String phone,String password); diff --git a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java index f9f5dd2..30fff0b 100644 --- a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java +++ b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java @@ -23,7 +23,12 @@ public interface EmployeeInfoService { */ PageVo_xuan selectEmployeeInfoPage(Integer currentPage, Integer currentCount, Integer role) throws Exception; - + /** + * @param str + * @param role + * @return + * 根据员工姓名和编号查询员工信息 + */ List selectNameOrNunberObtainEmployeeInfo(String str,Integer role); diff --git a/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java index 6a683fe..57efec6 100644 --- a/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java @@ -56,10 +56,18 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService { return employeeInfoVoPageVo; } - + /** + * @param str + * @param role + * @return + * 根据员工姓名和编号查询员工信息 + */ @Override public List selectNameOrNunberObtainEmployeeInfo(String str, Integer role){ + return employeeInfoDao.selectNameOrNunberObtainEmployeeInfo(str, role); + + } /** diff --git a/src/main/java/com/example/meetingroom/vo/EmployeeInfoVo.java b/src/main/java/com/example/meetingroom/vo/EmployeeInfoVo.java index ed5a249..f524514 100644 --- a/src/main/java/com/example/meetingroom/vo/EmployeeInfoVo.java +++ b/src/main/java/com/example/meetingroom/vo/EmployeeInfoVo.java @@ -35,6 +35,8 @@ public class EmployeeInfoVo { //性别(0为女,1为男) private int sex; + private String sexString; + // //创建时间 // private Date createTime; // @@ -47,7 +49,7 @@ public class EmployeeInfoVo { public EmployeeInfoVo() { } - public EmployeeInfoVo(String id, String roleName, String departName, String name, int number, String phone, String password, int sex) { + public EmployeeInfoVo(String id, String roleName, String departName, String name, int number, String phone, String password, int sex, String sexString) { this.id = id; this.roleName = roleName; this.departName = departName; @@ -56,6 +58,7 @@ public class EmployeeInfoVo { this.phone = phone; this.password = password; this.sex = sex; + this.sexString = sexString; } /** @@ -127,7 +130,15 @@ public class EmployeeInfoVo { this.sex = sex; } -// /** + public String getSexString() { + return sexString; + } + + public void setSexString(String sexString) { + this.sexString = sexString; + } + + // /** // * function: 获取创建时间并格式化 // * @return // */ @@ -154,6 +165,7 @@ public class EmployeeInfoVo { ", phone='" + phone + '\'' + ", password='" + password + '\'' + ", sex=" + sex + + ", sexString='" + sexString + '\'' + '}'; } } diff --git a/src/main/resources/mapper/EmployeeInfoMapper.xml b/src/main/resources/mapper/EmployeeInfoMapper.xml index a569162..264476e 100644 --- a/src/main/resources/mapper/EmployeeInfoMapper.xml +++ b/src/main/resources/mapper/EmployeeInfoMapper.xml @@ -60,10 +60,10 @@ + select * from meeting_room.role; -- Gitee From 4467bfdc2e03eca3f8b3841fde9fadb5449ce574 Mon Sep 17 00:00:00 2001 From: Y1-zd Date: Thu, 23 Sep 2021 14:03:55 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=B3=A8=E9=87=8A=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E8=B7=A8=E5=9F=9F=E9=85=8D=E7=BD=AE=E7=B1=BB=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++ .../meetingroom/config/EmployeeRealm.java | 94 +++++++++++++++++++ .../meetingroom/config/GlobalCorsConfig.java | 53 +++++++++++ .../meetingroom/config/ShiroConfig.java | 92 ++++++++++++++++++ .../controller/DepartController.java | 2 +- .../controller/EmployeeInfoController.java | 74 ++++++++++++++- .../EmployeeRegisterController.java | 42 +++++++-- .../controller/RoleController.java | 25 +++++ .../controller/RoomInfoController.java | 2 +- .../meetingroom/dao/EmployeeInfoDao.java | 28 ++++++ .../meetingroom/dao/EmployeeRegisterDao.java | 4 +- .../com/example/meetingroom/dao/RoleDao.java | 11 +++ .../CustomRolesAuthorizationFilter.java | 30 ++++++ .../service/EmployeeInfoService.java | 30 ++++++ .../service/EmployeeRegisterService.java | 7 ++ .../meetingroom/service/RoleService.java | 9 ++ .../service/impl/EmployeeInfoServiceImpl.java | 42 +++++++++ .../impl/EmployeeRegisterServiceImpl.java | 9 ++ .../service/impl/RoleServiceImpl.java | 15 +++ src/main/resources/application.yaml | 4 +- .../resources/mapper/EmployeeInfoMapper.xml | 22 +++++ .../mapper/EmployeeRegisterMapper.xml | 13 +++ src/main/resources/mapper/RoleMapper.xml | 18 +++- .../MeetingroomApplicationTests.java | 8 ++ 24 files changed, 623 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/example/meetingroom/config/EmployeeRealm.java create mode 100644 src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java create mode 100644 src/main/java/com/example/meetingroom/config/ShiroConfig.java create mode 100644 src/main/java/com/example/meetingroom/filter/CustomRolesAuthorizationFilter.java diff --git a/pom.xml b/pom.xml index 55d0624..5118fd4 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,12 @@ aliyun-sdk-oss 3.10.2 + + + org.springframework.boot + spring-boot-starter-thymeleaf + + diff --git a/src/main/java/com/example/meetingroom/config/EmployeeRealm.java b/src/main/java/com/example/meetingroom/config/EmployeeRealm.java new file mode 100644 index 0000000..2cfff9e --- /dev/null +++ b/src/main/java/com/example/meetingroom/config/EmployeeRealm.java @@ -0,0 +1,94 @@ +package com.example.meetingroom.config; + +import com.example.meetingroom.entity.EmployeeInfo; +import com.example.meetingroom.service.EmployeeInfoService; +import com.example.meetingroom.service.RoleService; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.*; +import org.apache.shiro.authz.AuthorizationInfo; +import org.apache.shiro.authz.SimpleAuthorizationInfo; +import org.apache.shiro.realm.AuthorizingRealm; +import org.apache.shiro.session.Session; +import org.apache.shiro.subject.PrincipalCollection; +import org.apache.shiro.subject.support.DefaultSubjectContext; +import org.apache.shiro.web.mgt.DefaultWebSecurityManager; +import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Collection; + +/** + * Shiro中自定义Realm,自定义认证和授权 + */ +@Component +public class EmployeeRealm extends AuthorizingRealm { + + @Autowired + private EmployeeInfoService employeeInfoService; + + @Autowired + private RoleService roleService; + + /** + * + + * 对用户进行授权,同时传递该用户的身份信息。 + * + * @param principalCollection + * @return + */ + @Override + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { + System.out.println("正在授权..."); + EmployeeInfo primaryPrincipal = (EmployeeInfo) principalCollection.getPrimaryPrincipal(); + System.out.println("------------------" + primaryPrincipal); + String id = employeeInfoService.getRoleIdByPhone(primaryPrincipal.getPhone()); + String role = roleService.getRoleByRoleId(primaryPrincipal.getRoleId()); + SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); + SecurityUtils.getSubject().getSession().setAttribute("identity", role); + SecurityUtils.getSubject().getSession().setAttribute("id", primaryPrincipal.getId()); + System.out.println(SecurityUtils.getSubject().getSession().getAttribute("identity")); + System.out.println("授权-----------" + role); + info.addRole(role); + return info; + } + + /** + * 进行用户的登录。登录之前会调用Session管理器,来找到活跃的Sessions,查看是否有相同的用户进行登录,有则进行下线处理。 + * 然后再进行账号密码的比对进行登录。 + * + * @param authenticationToken + * @return + * @throws AuthenticationException + */ + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { + //实现单用户登录,通过安全管理器,得到Session管理器,再去获得正在活跃的Sessions。 + UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; + Object principal = token.getPrincipal(); + String username = token.getUsername(); + EmployeeInfo employee = employeeInfoService.getEmployeeInfoByPhone(username); + //处理session + DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager(); + DefaultWebSessionManager sessionManager = (DefaultWebSessionManager) securityManager.getSessionManager(); + Collection sessions = sessionManager.getSessionDAO().getActiveSessions();//获取当前已登录的用户session列表 + System.out.println("principal:" + principal); + System.out.println("当前正活跃Session个数:" + sessions.size()); + for (Session session : sessions) { + //通过比较当前用户的toString及Session中的用户toString,来判断是否是同一账号。是则进行剔除。 + System.out.println("已存在的活跃Session:" + session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)); + if (String.valueOf(employee).equals(String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)))) { + sessionManager.getSessionDAO().delete(session); + System.out.println("成功剔除相同用户。"); + } + } + System.out.println("正在认证..."); + //根据是否查询到用户而进行对应处理:查无则抛异常,查到则进行认证。 + if (employee == null) { + throw new UnknownAccountException("请检查您的用户名及密码是否有误。"); + } + AuthenticationInfo info = new SimpleAuthenticationInfo(employee, employee.getPassword(), null, getName()); + return info; + } + +} diff --git a/src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java b/src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java new file mode 100644 index 0000000..ac0f8cb --- /dev/null +++ b/src/main/java/com/example/meetingroom/config/GlobalCorsConfig.java @@ -0,0 +1,53 @@ +package com.example.meetingroom.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 前后端分离所产生的跨域问题所需配置,全局跨域 + */ +@Configuration +public class GlobalCorsConfig { + + /** + * 返回一个Cors过滤器,对相应的HTTP请求的放行及配置。 + * @return + */ + @Bean + public CorsFilter corsFilter() { + CorsConfiguration corsConfig = new CorsConfiguration(); + //设置Origin(原始域) + corsConfig.addAllowedOrigin("*"); + //设置是否发送cookie + corsConfig.setAllowCredentials(true); + //放行哪些原始域(头部信息) + corsConfig.addAllowedHeader("*"); + //暴露哪些头部信息 + corsConfig.addExposedHeader("*"); + //配置映射路径 + UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource(); + configurationSource.registerCorsConfiguration("/**", corsConfig); + return new CorsFilter(configurationSource); + } + + /** + * 对请求方式的放行。 + * @return + */ + @Bean + public WebMvcConfigurer webMvcConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedOriginPatterns("*").allowCredentials(true). + allowedMethods("*").maxAge(3600); + } + }; + } + +} diff --git a/src/main/java/com/example/meetingroom/config/ShiroConfig.java b/src/main/java/com/example/meetingroom/config/ShiroConfig.java new file mode 100644 index 0000000..566b13d --- /dev/null +++ b/src/main/java/com/example/meetingroom/config/ShiroConfig.java @@ -0,0 +1,92 @@ +package com.example.meetingroom.config; + +import com.example.meetingroom.filter.CustomRolesAuthorizationFilter; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.spring.web.ShiroFilterFactoryBean; +import org.apache.shiro.web.mgt.DefaultWebSecurityManager; +import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.LinkedHashMap; +import java.util.Map; + +; + +/** + * Shiro的配置文件,在这里配置Shiro的三件套及登录拦截。 + */ +@Configuration +public class ShiroConfig { + + + /** + * 配置过滤的相关信息。如过滤何种界面,设置登录返回界面等。 + * + * @param webSecurityManager + * @return ShiroFilterFactoryBean + */ + @Bean + public ShiroFilterFactoryBean shiroFilter(@Qualifier("defaultWebSecurityManager") SecurityManager webSecurityManager) { + ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); + shiroFilterFactoryBean.setSecurityManager(webSecurityManager); + Map filterChainDefinitionMap = new LinkedHashMap<>(); + Map filterMap = new LinkedHashMap<>(); + filterMap.put("roleOf", new CustomRolesAuthorizationFilter()); + shiroFilterFactoryBean.setFilters(filterMap); + //设置登录失败返回的页面 + shiroFilterFactoryBean.setLoginUrl("/api/"); + //静态资源的放行 + + //权限放行 + filterChainDefinitionMap.put("/login", "anon"); + filterChainDefinitionMap.put("/api/oper/**", "authc,roles[超级管理员]"); + filterChainDefinitionMap.put("/logout", "logout"); + + shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); + return shiroFilterFactoryBean; + } + + /** + * Session管理器,设置全局Session的配置。 + * + * @return DefaultWebSessionManager + */ + @Bean + public DefaultWebSessionManager sessionManager() { + DefaultWebSessionManager defaultSessionManager = new DefaultWebSessionManager(); + //分别设置 session状态,全局会话时间,及删除失效session + defaultSessionManager.setSessionValidationSchedulerEnabled(false); + defaultSessionManager.setGlobalSessionTimeout(60 * 30 * 1000); + defaultSessionManager.setDeleteInvalidSessions(true); + return defaultSessionManager; + } + + /** + * 安全管理器,设置自用Realm和其他管理器。 + * + * @param realm + * @param sessionManager + * @return SecurityManager + */ + @Bean + public SecurityManager defaultWebSecurityManager(EmployeeRealm realm, + DefaultWebSessionManager sessionManager) { + //关于Shiro管理session的设置(启用session) + DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); + securityManager.setRealm(realm); + securityManager.setSessionManager(sessionManager); + return securityManager; + } + + /** + * 自用Realm,当前是EmployeeRealm。 + * + * @return EmployeeRealm + */ + @Bean + public EmployeeRealm realm() { + return new EmployeeRealm(); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/meetingroom/controller/DepartController.java b/src/main/java/com/example/meetingroom/controller/DepartController.java index 757fd1a..38a5f24 100644 --- a/src/main/java/com/example/meetingroom/controller/DepartController.java +++ b/src/main/java/com/example/meetingroom/controller/DepartController.java @@ -17,7 +17,7 @@ import java.util.Map; */ @RestController @CrossOrigin -@RequestMapping("/api") +@RequestMapping("/api/oper") public class DepartController { @Autowired diff --git a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java index 01faf0c..9bf2a6f 100644 --- a/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/EmployeeInfoController.java @@ -2,15 +2,21 @@ package com.example.meetingroom.controller; import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.service.EmployeeInfoService; +import com.example.meetingroom.service.RoleService; import com.example.meetingroom.vo.EmployeeInfoVo; import com.example.meetingroom.vo.PageVo_xuan; import com.example.meetingroom.vo.ResultVo; import org.apache.ibatis.annotations.Param; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -20,14 +26,13 @@ import java.util.Map; * @Date: 2021-9-8 08:10:07 */ @RestController -@CrossOrigin +@CrossOrigin() @RequestMapping("/api") public class EmployeeInfoController { @Autowired private EmployeeInfoService employeeInfoService; - //用于判断是否成功 private Integer judge; @@ -90,7 +95,6 @@ public class EmployeeInfoController { /** * @param employeeInfo - * @param request 判断身份 * @return ResultVo 统一消息回复 * 用于普管和超管修改员工信息 */ @@ -158,4 +162,68 @@ public class EmployeeInfoController { } return ResultVo.ok(200,"超管新增新增员工信息成功",map); } + + /** + * 用户登录。若登录成功,会根据其所有的权限来进行相应界面的跳转。 + * + * @param phone 账号 + * @param password 前端加密后的MD5密码 + * @return + */ + @RequestMapping(value = "/login", method = RequestMethod.POST) + public ResultVo login(@RequestParam("phone") String phone, + @RequestParam("password") String password) { + Map data = new LinkedHashMap<>(); + UsernamePasswordToken token = new UsernamePasswordToken(phone, password); + //Shiro框架中获取Subject对象,之后让Shiro进行用户名和密码的校验。 + Subject user = SecurityUtils.getSubject(); + if (!user.isAuthenticated()) { + try { + user.login(token); + } catch (AuthenticationException e) { + //认证失败则会返回失败的信息。 + data.put("登录状态", "失败"); + return ResultVo.error(404, "请检查您的用户密码是否有误。", data); + } + } + //登陆成功后 + data.put("登录状态", "成功"); + if (user.hasRole("超级管理员")) { + return ResultVo.ok(200, "登录成功,跳转到超级管理员界面。", data); + } + return ResultVo.ok(200, "登录成功。跳转到员工界面。", data); + } + + /** + * 用户登出,登出之后会进行JSESSION的清空。 + * + * @return 提示用户已经登出。 + */ + @RequestMapping(value = "/logout", method = RequestMethod.GET) + public ResultVo logout() { + SecurityUtils.getSubject().logout(); + return ResultVo.ok(200, "用户已登出系统。", null); + } + + /** + * 用户修改密码,会先验证存在的账号和旧密码是否属实,若成功则进行密码的修改。 + * + * @param phone 账号 + * @param oldPassword 旧密码 + * @param newPassword 新密码 + * @return 根据密码是否修改来返回是否修改成功的信息。 + */ + @RequestMapping(value = "/changePassword", method = RequestMethod.POST) + public ResultVo changePassword(@RequestParam("phone") String phone, + @RequestParam("oldPassword") String oldPassword, + @RequestParam("newPassword") String newPassword) { + EmployeeInfo employee = employeeInfoService.getEmployeeInfoByPhoneAndPassword(phone, oldPassword); + if (employee != null) { + int isSuccess = employeeInfoService.updatePassword(phone, newPassword); + } else { + return ResultVo.error(404, "请确认您的旧密码是否有误!", null); + } + return ResultVo.ok(200, "您的密码已成功修改!", null); + } + } diff --git a/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java b/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java index a951cfd..3aaca7e 100644 --- a/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java +++ b/src/main/java/com/example/meetingroom/controller/EmployeeRegisterController.java @@ -1,6 +1,8 @@ package com.example.meetingroom.controller; +import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.entity.EmployeeRegister; +import com.example.meetingroom.service.EmployeeInfoService; import com.example.meetingroom.service.EmployeeRegisterService; import com.example.meetingroom.vo.EmployeeRegisterVo; import com.example.meetingroom.vo.PageVo_xuan; @@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; /** @@ -27,6 +30,9 @@ public class EmployeeRegisterController { @Autowired private EmployeeRegisterService employeeRegisterService; + @Autowired + private EmployeeInfoService employeeInfoService; + //用于判断是否成功 private Integer judge; @@ -142,12 +148,6 @@ public class EmployeeRegisterController { } - - - - - - Map map = new HashMap<>(); // map.put("管理员修改注册表审核结果和原因", judge); @@ -158,4 +158,34 @@ public class EmployeeRegisterController { return ResultVo.ok(200,"超管修改注册表审核结果和原因成功",map); } + /** + * 传入的数据封装成EmployeeRegister,再通过EmployeeRegisterDao插入一名新用户。 + * 考虑到会有已注册账号进行注册的问题,同时需要管理员审核的问题,故会检测是否有该用户注册过,返回验证的信息、 + * @param register Post请求传入的注册信息 + * @return 返回是否能够注册,同时返回是否已经注册过。 + */ + @PostMapping("/register") + public ResultVo register(EmployeeRegister register) { + EmployeeRegister registerEmployee = register; + ResultVo resultVo; + Map data = new LinkedHashMap<>(); + //设置注册状态为”待审批“。 + registerEmployee.setEmployeeRegisterStatus("待审批"); + //查看是否有重复手机号码注册的情况,如若有则提示存在相同号码,但不影响待审批 + EmployeeInfo registeredUser = employeeInfoService.getEmployeeInfoByPhone(register.getPhone()); + if (registeredUser == null) { + data.put("用户注册状态", "该手机号未注册。"); + } else { + data.put("用户注册状态", "该手机号已注册。"); + } + //调用EmployeeRegisterDao来插入一条新用户,并根据成功与否来决定返回的结果 + int isInsert = employeeRegisterService.insertRegister(registerEmployee); + if (isInsert == 1) { + resultVo = ResultVo.ok(200, "成功将注册信息添加至审核表中。", data); + } else { + resultVo = ResultVo.error(500, "系统出错。", data); + } + return resultVo; + } + } diff --git a/src/main/java/com/example/meetingroom/controller/RoleController.java b/src/main/java/com/example/meetingroom/controller/RoleController.java index 78111f1..4b3e018 100644 --- a/src/main/java/com/example/meetingroom/controller/RoleController.java +++ b/src/main/java/com/example/meetingroom/controller/RoleController.java @@ -1,9 +1,11 @@ package com.example.meetingroom.controller; import com.example.meetingroom.entity.Depart; +import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.entity.Role; import com.example.meetingroom.service.RoleService; import com.example.meetingroom.vo.ResultVo; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -51,4 +53,27 @@ public class RoleController { // System.out.println(roleList); return ResultVo.ok(200,"展示权限信息成功",map); } + + /** + * 首页,登录界面,解决同个浏览器一个session却有多个用户共用的问题(即一个会话多用户登录) + * 通过检查Subject中principal是否为空来判断是否已经有用户登录过。 + * @return 根据情况返回相应页面 + */ + @GetMapping({"/","/index"}) + public ResultVo index(){ + EmployeeInfo principal = (EmployeeInfo) SecurityUtils.getSubject().getPrincipal(); + if (principal != null){ + Map data = new HashMap<>(); + System.out.println("当前存在已登录用户:"+principal); + String principalRole = roleService.getRoleByRoleId(principal.getRoleId()); + System.out.println("当前用户权限为:"+SecurityUtils.getSubject().getSession().getAttribute("identity")); + data.put("role",principalRole); + if ("超级管理员".equals(principalRole)){ + return ResultVo.ok(200,"已存在用户登录,跳转至超级管理员界面。",data); + }else{ + return ResultVo.ok(200,"已存在用户登录,跳转至用户界面。",data); + } + } + return ResultVo.ok(200,"当前会话无用户登录,则显示登录的界面。",null); + } } diff --git a/src/main/java/com/example/meetingroom/controller/RoomInfoController.java b/src/main/java/com/example/meetingroom/controller/RoomInfoController.java index f19d105..fc8516e 100644 --- a/src/main/java/com/example/meetingroom/controller/RoomInfoController.java +++ b/src/main/java/com/example/meetingroom/controller/RoomInfoController.java @@ -16,7 +16,7 @@ import java.util.*; */ @RestController @CrossOrigin -@RequestMapping("/api") +@RequestMapping("/api/oper") public class RoomInfoController { diff --git a/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java b/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java index 5434512..4b7e9e5 100644 --- a/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java +++ b/src/main/java/com/example/meetingroom/dao/EmployeeInfoDao.java @@ -77,5 +77,33 @@ public interface EmployeeInfoDao { List selectNameOrNunberObtainEmployeeInfo(@Param("str")String str, @Param("role")Integer role); + /** + * 根据账号和密码得到EmployeeInfo + * @param phone 账号 + * @param password 密码 + * @return EmployeeInfo + */ + EmployeeInfo getEmployeeInfoByPhoneAndPassword(String phone,String password); + + /** + * 根据账号得到EmployeeInfo + * @param phone 账号 + * @return EmployeeInfo + */ + EmployeeInfo getEmployeeInfoByPhone(String phone); + /** + * 根据账号获取权限ID + * @param phone 账号 + * @return 权限ID + */ + String getRoleIdByPhone(String phone); + + /** + * 根据账号来修改密码 + * @param phone 账号 + * @param newPassword 密码 + * @return + */ + int updatePassword(String phone, String newPassword); } \ No newline at end of file diff --git a/src/main/java/com/example/meetingroom/dao/EmployeeRegisterDao.java b/src/main/java/com/example/meetingroom/dao/EmployeeRegisterDao.java index ba9ae86..8d37a7f 100644 --- a/src/main/java/com/example/meetingroom/dao/EmployeeRegisterDao.java +++ b/src/main/java/com/example/meetingroom/dao/EmployeeRegisterDao.java @@ -75,8 +75,6 @@ public interface EmployeeRegisterDao { */ String selectEmployeeInfoPasswode(String phont); - - - + int insertRegister(EmployeeRegister register); } diff --git a/src/main/java/com/example/meetingroom/dao/RoleDao.java b/src/main/java/com/example/meetingroom/dao/RoleDao.java index cca4d6c..22736de 100644 --- a/src/main/java/com/example/meetingroom/dao/RoleDao.java +++ b/src/main/java/com/example/meetingroom/dao/RoleDao.java @@ -21,4 +21,15 @@ public interface RoleDao { * 查询所有权限,用于员工表权限修改 */ List selectRoleList(); + + String getRoleByEmployeeInfo(String roleId); + + String getRoleByPhone(String Phone); + + /** + * 根据权限ID来获取权限名 + * @param id 权限ID + * @return 权限名 + */ + String getRoleByRoleId(String id); } diff --git a/src/main/java/com/example/meetingroom/filter/CustomRolesAuthorizationFilter.java b/src/main/java/com/example/meetingroom/filter/CustomRolesAuthorizationFilter.java new file mode 100644 index 0000000..b46710a --- /dev/null +++ b/src/main/java/com/example/meetingroom/filter/CustomRolesAuthorizationFilter.java @@ -0,0 +1,30 @@ +package com.example.meetingroom.filter; + +import org.apache.shiro.subject.Subject; +import org.apache.shiro.web.filter.authz.AuthorizationFilter; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +/** + * 改写shiro判断身份权限的过滤器,使其满足其中一个身份便可以不拦截。 + */ +@Component +public class CustomRolesAuthorizationFilter extends AuthorizationFilter { + + @Override + protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception { + Subject subject = getSubject(servletRequest, servletResponse); + String[] identitys = (String[]) o; + if (identitys == null || identitys.length==0){ + return true; + } + for (int i = 0; i < identitys.length; i++) { + if (subject.hasRole(identitys[i])){ + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java index 6d803a5..6cb8eeb 100644 --- a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java +++ b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java @@ -65,4 +65,34 @@ public interface EmployeeInfoService { * @return 批量插入是否成功 */ Boolean insertBatch(List> excelDataList, int role); + + /** + * 根据账号得到EmployeeInfo + * @param phone 账号 + * @return EmployeeInfo + */ + EmployeeInfo getEmployeeInfoByPhone(String phone); + + /** + * 根据账号和密码获取EmployeeInfo + * @param phone 账号 + * @param password 密码 + * @return EmployeeInfo + */ + EmployeeInfo getEmployeeInfoByPhoneAndPassword(String phone,String password); + + /** + * 根据用户手机号码来获得权限ID + * @param phone 账号 + * @return 权限ID + */ + String getRoleIdByPhone(String phone); + + /** + * 用户更新密码 + * @param phone 账号 + * @param newPassword 密码 + * @return 成功更新条数 + */ + int updatePassword(String phone, String newPassword); } diff --git a/src/main/java/com/example/meetingroom/service/EmployeeRegisterService.java b/src/main/java/com/example/meetingroom/service/EmployeeRegisterService.java index 22a2961..254754d 100644 --- a/src/main/java/com/example/meetingroom/service/EmployeeRegisterService.java +++ b/src/main/java/com/example/meetingroom/service/EmployeeRegisterService.java @@ -64,4 +64,11 @@ public interface EmployeeRegisterService { * 根据联系方式获取注册表密码 */ String selectEmployeeInfoPasswode(String phone); + + /** + * 插入新的注册用户 + * @param register + * @return 成功条数 + */ + int insertRegister(EmployeeRegister register); } diff --git a/src/main/java/com/example/meetingroom/service/RoleService.java b/src/main/java/com/example/meetingroom/service/RoleService.java index 2065422..d0fc511 100644 --- a/src/main/java/com/example/meetingroom/service/RoleService.java +++ b/src/main/java/com/example/meetingroom/service/RoleService.java @@ -18,4 +18,13 @@ public interface RoleService { * 查询所有权限,用于员工表权限修改 */ List selectRoleList(); + + String getRoleByPhone(String phone); + + /** + * 根据权限ID来获取权限名 + * @param id 权限ID + * @return 权限名 + */ + String getRoleByRoleId(String id); } diff --git a/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java index f458685..c5d4ef0 100644 --- a/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/EmployeeInfoServiceImpl.java @@ -173,4 +173,46 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService { return false; } + + /** + * 根据账号得到EmployeeInfo + * @param phone 账号 + * @return EmployeeInfo + */ + @Override + public EmployeeInfo getEmployeeInfoByPhone(String phone) { + return employeeInfoDao.getEmployeeInfoByPhone(phone); + } + + /** + * 根据账号和密码得到EmployeeInfo + * @param phone 账号 + * @param password 密码 + * @return EmployeeInfo + */ + @Override + public EmployeeInfo getEmployeeInfoByPhoneAndPassword(String phone, String password) { + return employeeInfoDao.getEmployeeInfoByPhoneAndPassword(phone,password); + } + + /** + * 根据账号获取权限ID + * @param phone 账号 + * @return 权限ID + */ + @Override + public String getRoleIdByPhone(String phone) { + return employeeInfoDao.getRoleIdByPhone(phone); + } + + /** + * 根据账号来修改密码 + * @param phone 账号 + * @param newPassword 密码 + * @return + */ + @Override + public int updatePassword(String phone, String newPassword) { + return employeeInfoDao.updatePassword(phone,newPassword); + } } diff --git a/src/main/java/com/example/meetingroom/service/impl/EmployeeRegisterServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/EmployeeRegisterServiceImpl.java index 8224a60..adaf036 100644 --- a/src/main/java/com/example/meetingroom/service/impl/EmployeeRegisterServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/EmployeeRegisterServiceImpl.java @@ -156,6 +156,15 @@ public class EmployeeRegisterServiceImpl implements EmployeeRegisterService { return employeeRegisterDao.selectEmployeeInfoPasswode(phone); } + /** + * 插入新的注册用户 + * @param register + * @return 成功条数 + */ + @Override + public int insertRegister(EmployeeRegister register) { + return employeeRegisterDao.insertRegister(register); + } } diff --git a/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java b/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java index 10a52ed..fd57c78 100644 --- a/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/example/meetingroom/service/impl/RoleServiceImpl.java @@ -33,4 +33,19 @@ public class RoleServiceImpl implements RoleService { public List selectRoleList(){ return roleDao.selectRoleList(); } + + @Override + public String getRoleByPhone(String phone) { + return roleDao.getRoleByPhone(phone); + } + + /** + * 根据权限ID来获取权限名 + * @param id 权限ID + * @return 权限名 + */ + @Override + public String getRoleByRoleId(String id) { + return roleDao.getRoleByRoleId(id); + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3fb9011..8f608af 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -5,9 +5,9 @@ spring: #mysql数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql:// chensiran.cn:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://localhost:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root - password: root + password: chenzikang mybatis: mapper-locations: classpath*:mapper/*.xml diff --git a/src/main/resources/mapper/EmployeeInfoMapper.xml b/src/main/resources/mapper/EmployeeInfoMapper.xml index ff25bd4..de7a26a 100644 --- a/src/main/resources/mapper/EmployeeInfoMapper.xml +++ b/src/main/resources/mapper/EmployeeInfoMapper.xml @@ -112,7 +112,29 @@ and (e.name like concat(#{str}) or e.number like concat(#{str})) + + + + + + + + + + + + update employee_info set password = #{param2} + where phone = #{param1} + \ No newline at end of file diff --git a/src/main/resources/mapper/EmployeeRegisterMapper.xml b/src/main/resources/mapper/EmployeeRegisterMapper.xml index d668998..3bc87ad 100644 --- a/src/main/resources/mapper/EmployeeRegisterMapper.xml +++ b/src/main/resources/mapper/EmployeeRegisterMapper.xml @@ -80,5 +80,18 @@ where phone = #{phont}; + + + + select REPLACE(UUID(),'-','') + + insert into employee_register(id,name,sex,phone,password,depart_id,employee_register_status) + values(#{id},#{name},#{sex},#{phone},#{password},#{departId},#{employeeRegisterStatus}); + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/RoleMapper.xml b/src/main/resources/mapper/RoleMapper.xml index 75119a9..1b315fd 100644 --- a/src/main/resources/mapper/RoleMapper.xml +++ b/src/main/resources/mapper/RoleMapper.xml @@ -4,11 +4,27 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java b/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java index 8c3f1a8..ec097a9 100644 --- a/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java +++ b/src/test/java/com/example/meetingroom/MeetingroomApplicationTests.java @@ -3,6 +3,7 @@ package com.example.meetingroom; import com.example.meetingroom.dao.*; import com.example.meetingroom.entity.EmployeeInfo; import com.example.meetingroom.entity.EmployeeRegister; +import com.example.meetingroom.service.RoleService; import com.example.meetingroom.service.impl.EmployeeRegisterServiceImpl; import com.example.meetingroom.vo.EmployeeInfoVo; import com.example.meetingroom.vo.PageVo_xuan; @@ -26,6 +27,9 @@ class MeetingroomApplicationTests { @Autowired private EmployeeRegisterServiceImpl employeeRegisterService; + @Autowired + private RoleService roleService; + @Test void contextLoads() { System.out.println(employeeInfoDao.deleteEmployeeInfo("001")); @@ -55,6 +59,10 @@ class MeetingroomApplicationTests { // // } + @Test + public void test01(){ + + } -- Gitee From a9fb99e49b40c8b9df0251a2fb5b08cb466b8020 Mon Sep 17 00:00:00 2001 From: xuan <255124139@qq.com> Date: Thu, 23 Sep 2021 14:26:49 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/meetingroom/service/EmployeeInfoService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java index 30fff0b..a4f44c3 100644 --- a/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java +++ b/src/main/java/com/example/meetingroom/service/EmployeeInfoService.java @@ -81,5 +81,9 @@ public interface EmployeeInfoService { int updatePassword(String phone, String newPassword); + /** + * @param phone + * @return + */ String judgePhone(String phone); } -- Gitee From ea3c0537ad876e213028365836eb17e4cbcd9960 Mon Sep 17 00:00:00 2001 From: 277 <2286974448@qq.com> Date: Fri, 24 Sep 2021 08:44:20 +0000 Subject: [PATCH 13/13] update src/main/resources/application.yaml. --- src/main/resources/application.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 1c768ab..c049b08 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -7,7 +7,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://chensiran.cn:3306/meeting_room?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root - password: chenzikang + password: root mybatis: mapper-locations: classpath*:mapper/*.xml -- Gitee