From 15f005e0a7a1b5f349a3b1b3198078775f32bc42 Mon Sep 17 00:00:00 2001 From: zxc <954985705@qq.com> Date: Fri, 24 Apr 2020 19:35:50 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E4=BA=BA=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/dto/CustomerIdDTO.java | 27 ++++++ .../epmet/dto/form/AddDepartmentFormDTO.java | 20 ----- .../dto/form/AddDepartmentStaffFormDTO.java | 31 +++++++ .../controller/DepartmentController.java | 10 ++- .../epmet/dao/CustomerStaffDepartmentDao.java | 7 ++ .../com/epmet/feign/EpmetUserFeignClient.java | 22 +++++ .../EpmetUserFeignClientFallBack.java | 9 ++ .../com/epmet/service/DepartmentService.java | 9 ++ .../service/impl/CustomerGridServiceImpl.java | 1 + .../service/impl/DepartmentServiceImpl.java | 29 +++++++ .../mapper/CustomerStaffDepartmentDao.xml | 10 +++ .../controller/CustomerStaffController.java | 86 ++++--------------- .../java/com/epmet/dao/CustomerStaffDao.java | 12 ++- .../epmet/service/CustomerStaffService.java | 14 +-- .../impl/CustomerStaffServiceImpl.java | 21 +++++ .../resources/mapper/CustomerStaffDao.xml | 16 ++++ 16 files changed, 223 insertions(+), 101 deletions(-) create mode 100644 epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerIdDTO.java create mode 100644 epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentStaffFormDTO.java diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerIdDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerIdDTO.java new file mode 100644 index 0000000000..d18a182d1e --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerIdDTO.java @@ -0,0 +1,27 @@ +package com.epmet.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 根据userId查询customerId 的DTO + * @Auther zxc + * @Create 2020-04-24 15:57 + */ +@Data +public class CustomerIdDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * userId 用户id + */ + private String userId; + + /** + * customerId 客户id + */ + private String customerId; + +} diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java index 1188979f4a..57680d2ecd 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java @@ -16,20 +16,10 @@ package com.epmet.dto.form; * along with this program. If not, see . */ - import lombok.Data; import javax.validation.constraints.NotBlank; import java.io.Serializable; -import java.util.List; - -/** - * 添加部门人员DTO - * @Auther zxc - * @Create 2020-04-24 14:51 -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - /** * 添加部门-接口入参 @@ -41,16 +31,6 @@ public class AddDepartmentFormDTO implements Serializable { private static final long serialVersionUID = 1L; - /** - *部门id - */ - private String departmentId; - - /** - * 选中人员id - */ - private List selectedList; - /** * 所属组织机构ID(customer_agency.id) */ diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentStaffFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentStaffFormDTO.java new file mode 100644 index 0000000000..96503be98e --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentStaffFormDTO.java @@ -0,0 +1,31 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + +/** + * 添加部门人员DTO + * @Auther zxc + * @Create 2020-04-24 14:51 + */ +@Data +public class AddDepartmentStaffFormDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + *部门id + */ + @NotBlank(message = "部门id不能为空") + private String departmentId; + + /** + * 选中人员id + */ + @NotBlank(message = "选中人员不能为空") + private List selectedList; + +} \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java index 33a1d7fe87..eba65e1372 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java @@ -29,9 +29,15 @@ public class DepartmentController { @Autowired private DepartmentService departmentService; + /** + * 添加部门人员 + * @param tokenDto + * @param addDepartmentStaffFormDTO + * @return + */ @PostMapping(value = "adddepartmentstaff") - public Result addDepartmentStaff(@LoginUser TokenDto tokenDto, @RequestBody AddDepartmentFormDTO addDepartmentFormDTO){ - return null; + public Result addDepartmentStaff(@LoginUser TokenDto tokenDto, @RequestBody AddDepartmentStaffFormDTO addDepartmentStaffFormDTO){ + return departmentService.addDepartmentStaff(tokenDto,addDepartmentStaffFormDTO); } /** diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java index dfdba500d7..548684b5e0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java @@ -34,4 +34,11 @@ import java.util.List; public interface CustomerStaffDepartmentDao extends BaseDao { List selectUserIdByDepartmentId(@Param("departmentId") String departmentId); + + /** + * 修改部门人数 + * @param + * @auther zxc + */ + void updateDepartmentStaffCount(@Param("addCount")Integer addCount,@Param("departmentId")String departmentId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 96f51e83ec..8eb86517de 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -3,6 +3,10 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.*; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.CustomerStaffGridDTO; +import com.epmet.dto.StaffGridListDTO; +import com.epmet.dto.form.AddDepartmentStaffFormDTO; import com.epmet.dto.form.DepartmentInStaffFormDTO; import com.epmet.dto.form.StaffInfoFromDTO; import com.epmet.dto.form.StaffSubmitFromDTO; @@ -36,6 +40,11 @@ public interface EpmetUserFeignClient { @PostMapping(value = "/epmetuser/customerstaff/getstaffinfobyuserid") Result getCustomerStaffInfoByUserId(@RequestBody CustomerStaffDTO formDTO); + /** + * 获取网格下人员具体信息(头像、名字...) + * @param customerStaffGridDTOS + * @return + */ @PostMapping("/epmetuser/customerstaff/selectstaffgridlistbyuserid") Result> getStaffGridList(@RequestBody List customerStaffGridDTOS); @@ -47,6 +56,11 @@ public interface EpmetUserFeignClient { @PostMapping("/epmetuser/customerstaff/staffsinagency") Result> getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO); + /** + * 获取网格下未禁用的人员数量 + * @param userIdDTO + * @return + */ @PostMapping(value = "/epmetuser/customerstaff/selectgridstaffcountbyuserid") Result selectGridStaffCountByUserId(@RequestBody UserIdDTO userIdDTO); @@ -120,4 +134,12 @@ public interface EpmetUserFeignClient { @PostMapping("/epmetuser/customerstaff/getdepartmentstafflist") Result> getDepartmentStaffList(DepartmentInStaffFormDTO departmentInStaffFormDTO); + /** + * 根据userId查询customerId + * @param addDepartmentStaffFormDTO + * @auther zxc + */ + @PostMapping("/epmetuser/customerstaff/selectcustomeridbyuserid") + Result> selectCustomerIdByUserId(AddDepartmentStaffFormDTO addDepartmentStaffFormDTO); + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java index 273b6172d1..1284fb622b 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java @@ -4,6 +4,10 @@ import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.*; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.CustomerStaffGridDTO; +import com.epmet.dto.StaffGridListDTO; +import com.epmet.dto.form.AddDepartmentStaffFormDTO; import com.epmet.dto.form.DepartmentInStaffFormDTO; import com.epmet.dto.form.StaffInfoFromDTO; import com.epmet.dto.form.StaffSubmitFromDTO; @@ -82,4 +86,9 @@ public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient { public Result disabledStaff(StaffInfoFromDTO fromDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "disabledStaff", fromDTO); } + @Override + public Result> selectCustomerIdByUserId(AddDepartmentStaffFormDTO addDepartmentStaffFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "selectCustomerIdByUserId", addDepartmentStaffFormDTO); + } + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/DepartmentService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/DepartmentService.java index 48fe029fb0..2d49860de2 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/DepartmentService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/DepartmentService.java @@ -17,7 +17,9 @@ package com.epmet.service; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerIdDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; @@ -77,4 +79,11 @@ public interface DepartmentService { * @Description 获取机构下部门列表 */ Result> departmentList(DepartmentListFormDTO formDTO); + + /** + * 添加部门人员 + * @param addDepartmentStaffFormDTO + * @return + */ + Result addDepartmentStaff(TokenDto tokenDto,AddDepartmentStaffFormDTO addDepartmentStaffFormDTO); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java index a53a6bac1c..075799dfb8 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java @@ -177,6 +177,7 @@ public class CustomerGridServiceImpl extends BaseServiceImpl griddetail(CustomerGridFormDTO customerGridFormDTO) { GridDetailResultDTO griddetail = baseDao.griddetail(customerGridFormDTO); List customerStaffGridDTOS = baseDao.selectUserIdByGridId(customerGridFormDTO); + //获取人员具体信息(头像、名字...) Result> staffGridList = epmetUserFeignClient.getStaffGridList(customerStaffGridDTOS); griddetail.setStaffGridList(staffGridList.getData()); return new Result().ok(griddetail); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/DepartmentServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/DepartmentServiceImpl.java index 263daff4ac..dda0d02ae7 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/DepartmentServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/DepartmentServiceImpl.java @@ -20,17 +20,20 @@ package com.epmet.service.impl; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.CustomerDepartmentConstant; import com.epmet.dao.CustomerAgencyDao; import com.epmet.dao.CustomerDepartmentDao; import com.epmet.dao.CustomerStaffDepartmentDao; +import com.epmet.dto.CustomerIdDTO; import com.epmet.dto.StaffRoleDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.entity.CustomerAgencyEntity; import com.epmet.entity.CustomerDepartmentEntity; +import com.epmet.entity.CustomerStaffDepartmentEntity; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.service.DepartmentService; import com.epmet.util.ModuleConstant; @@ -197,4 +200,30 @@ public class DepartmentServiceImpl implements DepartmentService { List departmentList = customerDepartmentDao.selectDepartmentList(formDTO.getAgencyId()); return new Result>().ok(departmentList); } + + /** + * 添加部门人员 + * @param tokenDto + * @param addDepartmentStaffFormDTO + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Result addDepartmentStaff(TokenDto tokenDto,AddDepartmentStaffFormDTO addDepartmentStaffFormDTO) { + CustomerStaffDepartmentEntity customerStaffDepartmentEntity = new CustomerStaffDepartmentEntity(); + Result> listResult = epmetUserFeignClient.selectCustomerIdByUserId(addDepartmentStaffFormDTO); + List data = listResult.getData(); + customerStaffDepartmentEntity.setDepartmentId(addDepartmentStaffFormDTO.getDepartmentId()); + customerStaffDepartmentEntity.setCreatedBy(tokenDto.getUserId()); + customerStaffDepartmentEntity.setUpdatedBy(tokenDto.getUserId()); + customerStaffDepartmentEntity.setDelFlag("0"); + customerStaffDepartmentEntity.setRevision(0); + for (CustomerIdDTO customerIdDTO : data) { + customerStaffDepartmentEntity.setUserId(customerIdDTO.getUserId()); + customerStaffDepartmentEntity.setCustomerId(customerIdDTO.getCustomerId()); + customerStaffDepartmentDao.insert(customerStaffDepartmentEntity); + } + customerStaffDepartmentDao.updateDepartmentStaffCount(data.size(),addDepartmentStaffFormDTO.getDepartmentId()); + return new Result(); + } } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml index 86c597d402..d0d80492b6 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml @@ -26,5 +26,15 @@ + + + UPDATE + customer_department + SET + total_user = total_user + #{addCount} + WHERE + id = #{departmentId} + + \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index f1ed7bd6ba..748252137b 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -27,6 +27,10 @@ import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.dto.*; import com.epmet.dto.form.*; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.CustomerStaffGridDTO; +import com.epmet.dto.StaffGridListDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.DepartInStaffListResultDTO; import com.epmet.dto.result.StaffDetailResultDTO; import com.epmet.dto.result.StaffInfoResultDTO; @@ -145,18 +149,13 @@ public class CustomerStaffController { return customerStaffService.getCustomerStaffInfoByUserId(formDTO); } - @PostMapping(value = "selectgridstaffcountbyuserid") - public Result selectGridStaffCountByUserId(@RequestBody UserIdDTO userIdDTO){ - return customerStaffService.selectGridStaffCountByUserId(userIdDTO); - } - /** * 组织首页-工作人员列表 * @param fromDTO * @return */ @PostMapping("staffsinagency") - public Result> getStaffInfoForHome(@RequestBody StaffsInAgencyFromDTO fromDTO) { + public Result> getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { return customerStaffService.getStaffInfoForHome(fromDTO); } @@ -166,74 +165,18 @@ public class CustomerStaffController { * @return */ @PostMapping("stafflist") - public Result> getStaffList(@RequestBody StaffsInAgencyFromDTO fromDTO) { + public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { return customerStaffService.getStaffList(fromDTO); } /** - * 人员添加页面初始化 - * - * @param fromDTO 参数 - * @return Result + * 查询网格下未被禁用人员 + * @param userIdDTO + * @auther zxc */ - @PostMapping("rolelist") - public Result addStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ - return customerStaffService.addStaffInit(fromDTO); - } - - /** - * 人员编辑页面初始化 - * - * @param fromDTO 参数 - * @return Result - */ - @PostMapping("editstaffinit") - public Result editStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ - return customerStaffService.editStaffInit(fromDTO); - } - - /** - * 人员添加 - * - * @param fromDTO 参数 - * @return Result - */ - @PostMapping("addstaff") - public Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO){ - return customerStaffService.addStaff(fromDTO); - } - - /** - * 人员编辑 - * - * @param fromDTO 参数 - * @return Result - */ - @PostMapping("editstaff") - public Result editStaff(@RequestBody StaffSubmitFromDTO fromDTO){ - return customerStaffService.editStaff(fromDTO); - } - - /** - * 人员详情 - * - * @param fromDTO 参数 - * @return Result - */ - @PostMapping("staffdetail") - public Result getStaffDetail(@RequestBody StaffInfoFromDTO fromDTO){ - return customerStaffService.getStaffDetail(fromDTO); - } - - /** - * 人员禁用 - * - * @param fromDTO 参数 - * @return Result - */ - @PostMapping("disabledstaff") - public Result disabledStaff(@RequestBody StaffInfoFromDTO fromDTO){ - return customerStaffService.disabledStaff(fromDTO); + @PostMapping(value = "selectgridstaffcountbyuserid") + public Result selectGridStaffCountByUserId(@RequestBody UserIdDTO userIdDTO){ + return customerStaffService.selectGridStaffCountByUserId(userIdDTO); } /** @@ -246,4 +189,9 @@ public class CustomerStaffController { public Result> getDepartmentStaffList(DepartmentInStaffFormDTO fromDTO) { return customerStaffService.getDepartmentStaffList(fromDTO); } + + @PostMapping(value = "selectcustomeridbyuserid") + public Result> selectCustomerIdByUserId(@RequestBody AddDepartmentStaffFormDTO addDepartmentStaffFormDTO){ + return customerStaffService.selectCustomerIdByUserId(addDepartmentStaffFormDTO); + } } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java index e74e4b6ce5..6c4cab6dc7 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java @@ -20,10 +20,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.*; -import com.epmet.dto.form.CustomerStaffFormDTO; -import com.epmet.dto.form.StaffInfoFromDTO; -import com.epmet.dto.form.DepartmentInStaffFormDTO; -import com.epmet.dto.form.StaffsInAgencyFromDTO; +import com.epmet.dto.form.*; import com.epmet.dto.result.DepartInStaffListResultDTO; import com.epmet.dto.result.StaffInfoResultDTO; import com.epmet.entity.CustomerStaffEntity; @@ -115,4 +112,11 @@ public interface CustomerStaffDao extends BaseDao { * @Description 根据客户Id及userId集合查询用户基本信息 */ List selectDepartmentStaffList(DepartmentInStaffFormDTO fromDTO); + + /** + * + * @param departmentStaffFormDTO + * @auther zxc + */ + List selectCustomerIdByUserId(AddDepartmentStaffFormDTO departmentStaffFormDTO); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index a79bafba8b..abd130c21c 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -21,15 +21,10 @@ import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.*; -import com.epmet.dto.form.CustomerGridFormDTO; +import com.epmet.dto.form.*; import com.epmet.dto.CustomerStaffDTO; import com.epmet.dto.CustomerStaffGridDTO; import com.epmet.dto.StaffGridListDTO; -import com.epmet.dto.form.CustomerStaffFormDTO; -import com.epmet.dto.form.StaffInfoFromDTO; -import com.epmet.dto.form.StaffSubmitFromDTO; -import com.epmet.dto.form.DepartmentInStaffFormDTO; -import com.epmet.dto.form.StaffsInAgencyFromDTO; import com.epmet.dto.result.StaffDetailResultDTO; import com.epmet.dto.result.DepartInStaffListResultDTO; import com.epmet.dto.result.StaffInfoResultDTO; @@ -218,4 +213,11 @@ public interface CustomerStaffService extends BaseService { * @Description 根据客户Id及userId集合查询用户基本信息 */ Result> getDepartmentStaffList(DepartmentInStaffFormDTO fromDTO); + + /** + * 根据userId查询customerId + * @param: addDepartmentStaffFormDTO + * @auther: zxc + */ + Result> selectCustomerIdByUserId(AddDepartmentStaffFormDTO addDepartmentStaffFormDTO); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index fdd47f560d..d3a98772bd 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -32,6 +32,17 @@ import com.epmet.dao.CustomerStaffDao; import com.epmet.dto.*; import com.epmet.dto.form.*; import com.epmet.dto.result.*; +import com.epmet.dto.form.*; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.CustomerStaffGridDTO; +import com.epmet.dto.GovStaffRoleDTO; +import com.epmet.dto.StaffGridListDTO; +import com.epmet.dto.StaffRoleDTO; +import com.epmet.dto.result.StaffDetailResultDTO; +import com.epmet.dto.result.DepartInStaffListResultDTO; +import com.epmet.dto.result.StaffInfoResultDTO; +import com.epmet.dto.result.StaffInitResultDTO; +import com.epmet.dto.result.StaffRoleResultDTO; import com.epmet.entity.CustomerStaffEntity; import com.epmet.entity.GovStaffRoleEntity; import com.epmet.entity.StaffRoleEntity; @@ -352,4 +363,14 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl>().ok(staffList); } + /** + * + * @param: addDepartmentStaffFormDTO + * @auther: zxc + */ + @Override + public Result> selectCustomerIdByUserId(AddDepartmentStaffFormDTO addDepartmentStaffFormDTO) { + return new Result>().ok(baseDao.selectCustomerIdByUserId(addDepartmentStaffFormDTO)); + } + } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml index b2bd97dbd4..d1cfdd797d 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml @@ -145,4 +145,20 @@ ORDER BY CONVERT (real_name USING gbk) ASC + + + \ No newline at end of file From 9f1d40240fb1b59ee03c00fd6bee3e5acb7054bb Mon Sep 17 00:00:00 2001 From: wxz Date: Sat, 25 Apr 2020 14:28:26 +0800 Subject: [PATCH 02/14] =?UTF-8?q?1.=E6=9D=83=E9=99=90=E8=BF=87=E6=BB=A4-?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=E4=B8=8B=E7=BA=A7=E7=B3=BB?= =?UTF-8?q?=E5=88=97=EF=BC=8C=E9=98=B6=E6=AE=B5=E6=80=A7=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/aspect/DataFilterAspect.java | 232 +++++++++++++++--- .../mybatis/constant/OpeScopeConstant.java | 17 ++ .../mybatis/dto/form/OperationScopeDTO.java | 87 +++++++ .../dto/form/OperationScopeFormDTO.java | 18 ++ .../dto/form/StaffPermCacheResultDTO.java | 25 ++ .../mybatis/feign/GovAccessFeignClient.java | 17 +- .../GovAccessFeignClientFallback.java | 12 +- .../commons/tools/aspect/AccessOpeAspect.java | 2 - .../tools/security/dto/GovTokenDto.java | 23 +- .../java/com/epmet/dto/OperationScopeDTO.java | 81 ++++++ .../main/java/com/epmet/dto/RoleScopeDTO.java | 86 +++++++ .../epmet/dto/form/OperationScopeFormDTO.java | 18 ++ .../epmet/dto/form/StaffPermCacheFormDTO.java | 10 + .../dto/result/StaffPermCacheResultDTO.java | 26 ++ .../epmet/controller/AccessController.java | 49 +++- .../java/com/epmet/dao/OperationScopeDao.java | 45 ++++ .../main/java/com/epmet/dao/RoleScopeDao.java | 33 +++ .../epmet/entity/OperationScopeEntity.java | 51 ++++ .../com/epmet/entity/RoleScopeEntity.java | 56 +++++ .../com/epmet/redis/OperationScopeRedis.java | 47 ++++ .../java/com/epmet/redis/RoleScopeRedis.java | 47 ++++ .../java/com/epmet/service/AccessService.java | 16 +- .../epmet/service/OperationScopeService.java | 95 +++++++ .../com/epmet/service/RoleScopeService.java | 95 +++++++ .../epmet/service/impl/AccessServiceImpl.java | 29 ++- .../impl/OperationScopeServiceImpl.java | 104 ++++++++ .../service/impl/RoleScopeServiceImpl.java | 104 ++++++++ .../db.migration/epmet_gov_access.sql | 3 +- .../resources/mapper/OperationScopeDao.xml | 29 +++ .../main/resources/mapper/RoleScopeDao.xml | 20 ++ .../epmet/controller/AccessController.java | 2 +- .../com/epmet/feign/GovOrgFeignClient.java | 8 + .../fallback/GovOrgFeignClientFallBack.java | 6 + .../epmet/service/impl/AccessServiceImpl.java | 47 +++- .../epmet/controller/AgencyController.java | 25 +- .../java/com/epmet/service/AgencyService.java | 8 + .../epmet/service/impl/AgencyServiceImpl.java | 5 + .../mapper/CustomerStaffDepartmentDao.xml | 2 +- .../java/com/epmet/dto/GovStaffRoleDTO.java | 2 +- .../epmet/controller/StaffRoleController.java | 4 +- .../com/epmet/service/StaffRoleService.java | 3 +- .../service/impl/StaffRoleServiceImpl.java | 4 +- 42 files changed, 1512 insertions(+), 81 deletions(-) create mode 100644 epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java create mode 100644 epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java create mode 100644 epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeFormDTO.java create mode 100644 epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java create mode 100644 epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java create mode 100644 epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/RoleScopeDTO.java create mode 100644 epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/OperationScopeFormDTO.java create mode 100644 epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/RoleScopeDao.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationScopeEntity.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/RoleScopeEntity.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationScopeService.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/RoleScopeService.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml create mode 100644 epmet-module/gov-access/gov-access-server/src/main/resources/mapper/RoleScopeDao.xml diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java index 14ce3af0a1..b9431a6c48 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java @@ -1,19 +1,21 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *

* https://www.renren.io - * + *

* 版权所有,侵权必究! */ package com.epmet.commons.mybatis.aspect; +import com.epmet.commons.mybatis.constant.OpeScopeConstant; +import com.epmet.commons.mybatis.dto.form.OperationScopeDTO; +import com.epmet.commons.mybatis.dto.form.StaffPermCacheResultDTO; import com.epmet.commons.mybatis.dto.form.StaffPermissionFormDTO; import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.mybatis.feign.GovAccessFeignClient; import com.epmet.commons.tools.aspect.AccessOpeAspect; import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.Result; @@ -27,9 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; /** * 数据过滤,切面处理类 @@ -49,6 +49,8 @@ public class DataFilterAspect { @Autowired private GovAccessFeignClient govAccessFeignClient; + public static final String orgIdPathSpliter = ":"; + @Before("@annotation(com.epmet.commons.mybatis.annotation.DataFilter)") public void dataFilter(JoinPoint point) { // 反射的方式 @@ -60,20 +62,39 @@ public class DataFilterAspect { // } //} - String reqiurePermission = AccessOpeAspect.requirePermissionTl.get(); + String requirePermission = AccessOpeAspect.requirePermissionTl.get(); // 没有配置所需权限,不做操作,打印提示日志 - if (StringUtils.isBlank(reqiurePermission)) { + if (StringUtils.isBlank(requirePermission)) { log.warn("Api编码需要指定所需权限,请在Api上使用@RequirePermission注解完成所需权限配置"); return; } + StaffPermissionFormDTO staffPermissionFormDTO = new StaffPermissionFormDTO(); + staffPermissionFormDTO.setApp(loginUserUtil.getLoginUserApp()); + staffPermissionFormDTO.setClient(loginUserUtil.getLoginUserClient()); + staffPermissionFormDTO.setStaffId(loginUserUtil.getLoginUserId()); + Result result = govAccessFeignClient.getStaffCurrPermissions(staffPermissionFormDTO); + + if (result.getCode() != 0) { + // 查询不到权限,记录日志,抛出8000异常 + log.error("调用Access查询权限失败:{}", result.getMsg()); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + + StaffPermCacheResultDTO permCacheResultDTO = result.getData(); + + if (permCacheResultDTO == null || CollectionUtils.isEmpty(permCacheResultDTO.getPermissions())) { + log.error("操作权限不足,查询不到权限"); + throw new RenException(EpmetErrorCode.REQUIRE_PERMISSION.getCode()); + } + // 校验操作权限 - validateOpePermission(reqiurePermission); + validateOpePermission(permCacheResultDTO.getPermissions(), requirePermission); Object[] methodArgs = point.getArgs(); for (Object methodArg : methodArgs) { if (methodArg instanceof DataScope) { - ((DataScope) methodArg).setSqlFilter(getSqlFilterSegment()); + ((DataScope) methodArg).setSqlFilter(getSqlFilterSegment(permCacheResultDTO.getRoleIdList(), requirePermission, permCacheResultDTO.getOrgIdPath())); return; } } @@ -84,38 +105,187 @@ public class DataFilterAspect { /** * 校验操作权限 */ - private void validateOpePermission(String requirePermission) { - StaffPermissionFormDTO staffPermissionFormDTO = new StaffPermissionFormDTO(); - staffPermissionFormDTO.setApp(loginUserUtil.getLoginUserApp()); - staffPermissionFormDTO.setClient(loginUserUtil.getLoginUserClient()); - staffPermissionFormDTO.setStaffId(loginUserUtil.getLoginUserId()); - Result> permissions = govAccessFeignClient.getStaffCurrPermissions(staffPermissionFormDTO); - if (permissions.getCode() != 0) { - // 查询不到权限,记录日志,抛出8000异常 - log.error("调用Access查询权限失败:{}", permissions.getMsg()); - throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + private void validateOpePermission(Set permissions, String reqiurePermission) { + if (!permissions.contains(reqiurePermission)) { + // 权限不足 + log.error("操作权限不足"); + throw new RenException(EpmetErrorCode.REQUIRE_PERMISSION.getCode()); } - - if (!CollectionUtils.isEmpty(permissions.getData()) && StringUtils.isNotBlank(requirePermission) - && permissions.getData().contains(requirePermission)) { - // 权限允许,正常结束 - return; - } - // 权限不足抛出异常 - throw new RenException(EpmetErrorCode.REQUIRE_PERMISSION.getCode()); } /** * 生成过滤sql片段 + * * @return */ - private String getSqlFilterSegment() { + private String getSqlFilterSegment(Set roleIds, String reqiurePermission, String orgIdPath) { // 根据角色列表查询操作范围列表 + // todo 暂停,先模拟数据 + //roleIds.forEach(roleId -> { + // OperationScopeFormDTO osformDto = new OperationScopeFormDTO(); + // osformDto.setRoleId(roleId); + // osformDto.setOperationKey(reqiurePermission); + // Result> result = govAccessFeignClient.getOperationScopesByRoleId(osformDto); + // List scopeDTOS = result.getData(); + //}); + Set scopeDTOS = genScopeDtos(); - // 拼接sql语句 + // 过滤有效范围 + HashSet scopes = filteScopes(scopeDTOS); + + // 取出父组织ID path 和当前组织ID + String pOrgPath = orgIdPath.substring(0, orgIdPath.lastIndexOf(orgIdPathSpliter)); + String currOrgPath = orgIdPath.substring(orgIdPath.lastIndexOf(orgIdPathSpliter) + 1); + StringBuilder sb = new StringBuilder(" AND ("); + getOrgScopeSql(sb, scopes, currOrgPath, pOrgPath); + sb.replace(sb.lastIndexOf("OR"), sb.lastIndexOf("OR") + 3, ""); + sb.append(") "); + // 拼接sql语句 + sb.replace(141,142,""); // TODO - return "dept_id in (1,2,3)"; + return ""; + } + + /** + * 计算范围过滤sql + * @param scopes + * @param currOrg + * @param pOrgPath + * @return + */ + private void getOrgScopeSql(StringBuilder sb,HashSet scopes, String currOrg, String pOrgPath) { + for (String scope : scopes) { + switch (scope) { + case OpeScopeConstant.ORG_CURR: + getAgencyCurrScopedSql(sb, currOrg); + sb.append(" OR "); + break; + case OpeScopeConstant.ORG_CURR_AND_SUB: + getAgencyCurrAndSubScopedSql(sb, pOrgPath); + sb.append(" OR "); + break; + case OpeScopeConstant.ORG_CURR_SUB: + getAgencyCurrSubScopedSql(sb, pOrgPath, currOrg); + sb.append(" OR "); + break; + case OpeScopeConstant.ORG_EQUAL: + // todo 同级 + //sb.append(" OR "); + break; + case OpeScopeConstant.ORG_EQUAL_AND_SUB: + // todo 同级及其子级 + //sb.append(" OR "); + break; + case OpeScopeConstant.ORG_EQUAL_SUB: + // todo 同级的子级 + //sb.append(" OR "); + break; + } + } + } + + /** + * 本身 + * @param sb + * @param orgId + */ + public void getAgencyCurrScopedSql(StringBuilder sb,String orgId) { + sb.append(" ORG_ID = ").append(orgId); + } + + /** + * 本身及子级 + * @param sb + * @param pOrgIdPath + */ + public void getAgencyCurrAndSubScopedSql(StringBuilder sb,String pOrgIdPath) { + sb.append(" ORG_ID_PATH like '").append(pOrgIdPath).append("%'"); + } + + /** + * 子级组织(不含本身) + * @param sb + */ + public void getAgencyCurrSubScopedSql(StringBuilder sb,String pOrgIdPath, String currOrgIdPath) { + sb.append("ORG_ID_PATH like '").append(pOrgIdPath).append(orgIdPathSpliter).append(currOrgIdPath).append("%'"); + } + + /** + * 过滤有效范围 + * + * @param scopeDTOS + * @return + */ + private HashSet filteScopes(Set scopeDTOS) { + HashMap filtedScopes = new HashMap<>(); + + for (OperationScopeDTO scope : scopeDTOS) { + String scopeIndex = scope.getScopeIndex(); + String[] currArr = scopeIndex.split("_"); + if ("0".equals(currArr[1])) { + // 为0,说明没有包含关系,直接放入 + filtedScopes.put(scopeIndex, scope); + continue; + } + + OperationScopeDTO tempScope = filtedScopes.get(currArr[0]); + if (tempScope != null) { + // 已经有ac开头的了 + String tempScopeIndex = tempScope.getScopeIndex(); + if (Integer.valueOf(currArr[1]) < Integer.valueOf(tempScopeIndex.split("_")[1])) { + filtedScopes.put(currArr[0], scope); + } + } else { + filtedScopes.put(currArr[0], scope); + } + } + HashSet scopeStrs = new HashSet<>(); + Set> entries = filtedScopes.entrySet(); + for (Map.Entry entry : entries) { + scopeStrs.add(entry.getValue().getScopeKey()); + } + return scopeStrs; + } + + /** + * 模拟范围数据 + * + * @return + */ + private Set genScopeDtos() { + OperationScopeDTO scopeDTO1 = new OperationScopeDTO(); + scopeDTO1.setScopeKey("org_curr"); + scopeDTO1.setScopeName("本机关"); + scopeDTO1.setScopeIndex("ac_0"); + + OperationScopeDTO scopeDTO2 = new OperationScopeDTO(); + scopeDTO2.setScopeKey("org_curr_and_sub"); + scopeDTO2.setScopeName("本机关及下级"); + scopeDTO2.setScopeIndex("ac_501"); + + OperationScopeDTO scopeDTO3 = new OperationScopeDTO(); + scopeDTO3.setScopeKey("org_curr_sub"); + scopeDTO3.setScopeName("本机关的下级"); + scopeDTO3.setScopeIndex("ac_502"); + + OperationScopeDTO scopeDTO4 = new OperationScopeDTO(); + scopeDTO4.setScopeKey("org_equal_and_sub"); + scopeDTO4.setScopeName("同级机关及下级"); + scopeDTO4.setScopeIndex("ae_601"); + + OperationScopeDTO scopeDTO5 = new OperationScopeDTO(); + scopeDTO5.setScopeKey("org_equal_sub"); + scopeDTO5.setScopeName("同级机关的下级"); + scopeDTO5.setScopeIndex("ae_602"); + + Set scopeDTOS = new HashSet<>(); + scopeDTOS.add(scopeDTO1); + scopeDTOS.add(scopeDTO2); + scopeDTOS.add(scopeDTO3); + scopeDTOS.add(scopeDTO4); + scopeDTOS.add(scopeDTO5); + return scopeDTOS; } ///** diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java new file mode 100644 index 0000000000..3d415ffb30 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/constant/OpeScopeConstant.java @@ -0,0 +1,17 @@ +package com.epmet.commons.mybatis.constant; + +public class OpeScopeConstant { + //"同级组织的下级" + public static final String ORG_EQUAL_SUB = "org_equal_sub"; + //"同级组织及下级" + public static final String ORG_EQUAL_AND_SUB = "org_equal_and_sub"; + //"同级组织" + public static final String ORG_EQUAL = "org_equal"; + //"本组织的下级" + public static final String ORG_CURR_SUB = "org_curr_sub"; + //"本组织及下级" + public static final String ORG_CURR_AND_SUB = "org_curr_and_sub"; + //"本组织" + public static final String ORG_CURR = "org_curr"; + +} diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java new file mode 100644 index 0000000000..494cff66b9 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java @@ -0,0 +1,87 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.commons.mybatis.dto.form; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Data +public class OperationScopeDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private String id; + + /** + * 范围key + */ + private String scopeKey; + + /** + * 范围名称 + */ + private String scopeName; + + /** + * 范围序号 + */ + private String scopeIndex; + + /** + * 是否删除,0:未删除,1:已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建者id + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新者id + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeFormDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeFormDTO.java new file mode 100644 index 0000000000..fe5aca825b --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeFormDTO.java @@ -0,0 +1,18 @@ +package com.epmet.commons.mybatis.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class OperationScopeFormDTO { + + public interface ListOperationScopeGroup {} + + @NotBlank(message = "角色ID不能为空", groups = {ListOperationScopeGroup.class}) + private String roleId; + + @NotBlank(message = "操作的key不能为空", groups = {ListOperationScopeGroup.class}) + private String operationKey; + +} diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java new file mode 100644 index 0000000000..6f37ef7033 --- /dev/null +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java @@ -0,0 +1,25 @@ +package com.epmet.commons.mybatis.dto.form; + +import lombok.Data; + +import java.util.Set; + +@Data +public class StaffPermCacheResultDTO { + + /** + * 权限列表 + */ + private Set permissions; + + /** + * 角色列表 + */ + private Set roleIdList; + + /** + * 机构Id + */ + private String orgIdPath; + +} diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java index 198d996bc9..4d04adc835 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java @@ -1,12 +1,17 @@ package com.epmet.commons.mybatis.feign; +import com.epmet.commons.mybatis.dto.form.OperationScopeDTO; +import com.epmet.commons.mybatis.dto.form.OperationScopeFormDTO; +import com.epmet.commons.mybatis.dto.form.StaffPermCacheResultDTO; import com.epmet.commons.mybatis.dto.form.StaffPermissionFormDTO; import com.epmet.commons.mybatis.feign.fallback.GovAccessFeignClientFallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import java.util.List; import java.util.Set; /** @@ -17,10 +22,18 @@ import java.util.Set; public interface GovAccessFeignClient { /** - * 查询用户当前权限列表(DataFilterAspect中用到) + * 查询用户当前权限列表 * @return */ @PostMapping("/gov/access/access/getcurrpermissions") - Result> getStaffCurrPermissions(StaffPermissionFormDTO dto); + Result getStaffCurrPermissions(StaffPermissionFormDTO dto); + + /** + * 查询角色的操作key对应操作范围列表 + * @param operationScopeFormDTO + * @return + */ + @PostMapping("/gov/access/access/operationscopes") + Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO); } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java index 3c5ccd599b..2f5b9287a1 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java @@ -1,5 +1,8 @@ package com.epmet.commons.mybatis.feign.fallback; +import com.epmet.commons.mybatis.dto.form.OperationScopeDTO; +import com.epmet.commons.mybatis.dto.form.OperationScopeFormDTO; +import com.epmet.commons.mybatis.dto.form.StaffPermCacheResultDTO; import com.epmet.commons.mybatis.dto.form.StaffPermissionFormDTO; import com.epmet.commons.mybatis.feign.GovAccessFeignClient; import com.epmet.commons.tools.constant.ServiceConstant; @@ -7,7 +10,7 @@ import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import org.springframework.stereotype.Component; -import java.util.Set; +import java.util.List; /** * 调用政府端权限 @@ -19,7 +22,12 @@ import java.util.Set; public class GovAccessFeignClientFallback implements GovAccessFeignClient { @Override - public Result> getStaffCurrPermissions(StaffPermissionFormDTO dto) { + public Result getStaffCurrPermissions(StaffPermissionFormDTO dto) { return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getStaffCurrPermissions", dto); } + + @Override + public Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getOperationScopesByRoleId", operationScopeFormDTO); + } } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/AccessOpeAspect.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/AccessOpeAspect.java index eeeedc6508..72070ee6e1 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/AccessOpeAspect.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/AccessOpeAspect.java @@ -37,8 +37,6 @@ public class AccessOpeAspect { RequirePermission requirePermissionAnno = methodSignature.getMethod().getAnnotation(RequirePermission.class); String key = requirePermissionAnno.key(); String desc = requirePermissionAnno.desc(); - System.out.println(key); - System.out.println(desc); // 放入ThreadLocal,供DataFilterAspect中使用 requirePermissionTl.set(key); diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java index 7088bb10a3..49d6cb15a3 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/dto/GovTokenDto.java @@ -34,6 +34,16 @@ public class GovTokenDto extends BaseTokenDto implements Serializable { */ private String customerId; + /** + * 过期时间戳 + */ + private Long expireTime; + + /** + * 最后一次更新时间 + */ + private long updateTime; + /** * 当前登录的组织id(顶级) */ @@ -55,18 +65,13 @@ public class GovTokenDto extends BaseTokenDto implements Serializable { private List deptIdList; /** - * 过期时间戳 - */ - private Long expireTime; - - /** - * 最后一次更新时间 + * 功能权限列表,实际上是gov_staff => staff_role => role_operation查询到的operationKey */ - private long updateTime; + private Set permissions; /** - * 功能权限列表,实际上是gov_staff => staff_role => role_operation查询到的operationKey + * 角色ID列表 */ - private Set permissions; + private Set roleIdList; } diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java new file mode 100644 index 0000000000..19e1111e96 --- /dev/null +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/OperationScopeDTO.java @@ -0,0 +1,81 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Data +public class OperationScopeDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private String id; + + /** + * 范围key + */ + private String scopeKey; + + /** + * 范围名称 + */ + private String scopeName; + + /** + * 是否删除,0:未删除,1:已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建者id + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新者id + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/RoleScopeDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/RoleScopeDTO.java new file mode 100644 index 0000000000..17f8866215 --- /dev/null +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/RoleScopeDTO.java @@ -0,0 +1,86 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 角色能操作哪些范围 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Data +public class RoleScopeDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * + */ + private String id; + + /** + * 角色ID + */ + private String roleId; + + /** + * 操作key + */ + private String operationKey; + + /** + * 范围Key + */ + private String scopeKey; + + /** + * 是否删除,0:未删除,1:已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建者id + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新者id + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/OperationScopeFormDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/OperationScopeFormDTO.java new file mode 100644 index 0000000000..af992b7d51 --- /dev/null +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/OperationScopeFormDTO.java @@ -0,0 +1,18 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class OperationScopeFormDTO { + + public interface ListOperationScopeGroup {} + + @NotBlank(message = "角色ID不能为空", groups = {ListOperationScopeGroup.class}) + private String roleId; + + @NotBlank(message = "操作的key不能为空", groups = {ListOperationScopeGroup.class}) + private String operationKey; + +} diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java index 56907e52af..191314af0a 100644 --- a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java @@ -36,9 +36,19 @@ public class StaffPermCacheFormDTO { @NotBlank(message = "登录头信息client不能为空", groups = {UpdatePermissionCache.class, GetStaffCurrPermissions.class}) private String client; + /** + * 组织ID路径 + */ + private String orgIdPath; + /** * 权限列表 */ private Set permissions; + /** + * 角色列表 + */ + private Set roleIdList; + } diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java new file mode 100644 index 0000000000..0f6be83e72 --- /dev/null +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java @@ -0,0 +1,26 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.util.Set; + +@Data +public class StaffPermCacheResultDTO { + + /** + * 权限列表 + */ + private Set permissions; + + /** + * 角色列表 + */ + private Set roleIdList; + + /** + * 组织ID + */ + private String orgIdPath; + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java index aa954dc584..d60f7cb528 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java @@ -1,15 +1,20 @@ package com.epmet.controller; +import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.OperationScopeDTO; +import com.epmet.dto.form.OperationScopeFormDTO; import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.dto.result.StaffPermCacheResultDTO; +import com.epmet.entity.OperationScopeEntity; import com.epmet.service.AccessService; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; import java.util.Set; /** @@ -37,7 +42,9 @@ public class AccessController { String app = staffPermCacheFormDTO.getApp(); String client = staffPermCacheFormDTO.getClient(); Set permissions = staffPermCacheFormDTO.getPermissions(); - accessService.updatePermissionCache(staffId, app, client, permissions); + Set roleIdList = staffPermCacheFormDTO.getRoleIdList(); + String orgId = staffPermCacheFormDTO.getOrgIdPath(); + accessService.updatePermissionCache(staffId, app, client, permissions, roleIdList, orgId); return new Result(); } @@ -46,9 +53,35 @@ public class AccessController { * @return */ @PostMapping("getcurrpermissions") - public Result> getStaffCurrPermissions(@RequestBody StaffPermCacheFormDTO dto) { + public Result getStaffCurrPermissions(@RequestBody StaffPermCacheFormDTO dto) { ValidatorUtils.validateEntity(dto, StaffPermCacheFormDTO.GetStaffCurrPermissions.class); - Set permissions = accessService.listStaffCurrPermissions(dto.getApp(), dto.getClient(), dto.getStaffId()); - return new Result>().ok(permissions); + GovTokenDto govTokenDto = accessService.listStaffCurrPermissions(dto.getApp(), dto.getClient(), dto.getStaffId()); + StaffPermCacheResultDTO resultDTO = null; + if (govTokenDto != null) { + resultDTO = new StaffPermCacheResultDTO(); + resultDTO.setPermissions(govTokenDto.getPermissions()); + resultDTO.setRoleIdList(govTokenDto.getRoleIdList()); + resultDTO.setOrgIdPath(govTokenDto.getOrgIdPath()); + } + return new Result().ok(resultDTO); + } + + /** + * 查询角色的操作key对应操作范围列表(需要入缓存) + * @return + */ + // todo 需要加缓存 + @PostMapping("operationscopes") + public Result> getOperationScopesByRoleId(@RequestBody OperationScopeFormDTO operationScopeFormDTO) { + ValidatorUtils.validateEntity(operationScopeFormDTO, OperationScopeFormDTO.ListOperationScopeGroup.class); + List scopes = accessService.listOperationScopesByRoleId(operationScopeFormDTO.getRoleId(), operationScopeFormDTO.getOperationKey()); + ArrayList scopeDtos = new ArrayList<>(); + scopes.forEach(scope -> { + OperationScopeDTO scopeDTO = new OperationScopeDTO(); + BeanUtils.copyProperties(scope, scopeDTO); + scopeDtos.add(scopeDTO); + }); + + return new Result>().ok(scopeDtos); } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java new file mode 100644 index 0000000000..a944cdd628 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java @@ -0,0 +1,45 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.OperationScopeEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.context.annotation.Scope; + +import java.util.List; + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Mapper +public interface OperationScopeDao extends BaseDao { + + /** + * 查询角色的操作key对应操作范围列表 + * @param roleId 角色id + * @param operationKey 操作key + * @return + */ + List listOperationScopesByRoleId(@Param("roleId") String roleId, + @Param("operationKey") String operationKey); +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/RoleScopeDao.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/RoleScopeDao.java new file mode 100644 index 0000000000..60982f5528 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/RoleScopeDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.RoleScopeEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 角色能操作哪些范围 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Mapper +public interface RoleScopeDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationScopeEntity.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationScopeEntity.java new file mode 100644 index 0000000000..2fd6b18361 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationScopeEntity.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("operation_scope") +public class OperationScopeEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 范围key + */ + private String scopeKey; + + /** + * 范围名称 + */ + private String scopeName; + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/RoleScopeEntity.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/RoleScopeEntity.java new file mode 100644 index 0000000000..2c3c6f21dc --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/RoleScopeEntity.java @@ -0,0 +1,56 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 角色能操作哪些范围 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("role_scope") +public class RoleScopeEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 角色ID + */ + private String roleId; + + /** + * 操作key + */ + private String operationKey; + + /** + * 范围Key + */ + private String scopeKey; + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java new file mode 100644 index 0000000000..3f5a7c6562 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.redis; + +import com.epmet.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Component +public class OperationScopeRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java new file mode 100644 index 0000000000..1198f8651a --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.redis; + +import com.epmet.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 角色能操作哪些范围 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Component +public class RoleScopeRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java index a9e5150db8..4355b2714b 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java @@ -1,5 +1,9 @@ package com.epmet.service; +import com.epmet.commons.tools.security.dto.GovTokenDto; +import com.epmet.entity.OperationScopeEntity; + +import java.util.List; import java.util.Set; public interface AccessService { @@ -8,11 +12,19 @@ public interface AccessService { * @param staffId * @param permissions */ - void updatePermissionCache(String staffId, String app, String client, Set permissions); + void updatePermissionCache(String staffId, String app, String client, Set permissions, Set roleIdList, String orgIdPath); /** * 查询用户当前权限列表 * @return */ - Set listStaffCurrPermissions(String app, String client, String staffId); + GovTokenDto listStaffCurrPermissions(String app, String client, String staffId); + + /** + * 查询角色的操作key对应操作范围列表 + * @param roleId + * @param operationKey + * @return + */ + List listOperationScopesByRoleId(String roleId, String operationKey); } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationScopeService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationScopeService.java new file mode 100644 index 0000000000..cb24b913c0 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationScopeService.java @@ -0,0 +1,95 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.OperationScopeDTO; +import com.epmet.entity.OperationScopeEntity; + +import java.util.List; +import java.util.Map; + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +public interface OperationScopeService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-04-24 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-04-24 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return OperationScopeDTO + * @author generator + * @date 2020-04-24 + */ + OperationScopeDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-24 + */ + void save(OperationScopeDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-24 + */ + void update(OperationScopeDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-04-24 + */ + void delete(String[] ids); +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/RoleScopeService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/RoleScopeService.java new file mode 100644 index 0000000000..34cdd6e07f --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/RoleScopeService.java @@ -0,0 +1,95 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.RoleScopeDTO; +import com.epmet.entity.RoleScopeEntity; + +import java.util.List; +import java.util.Map; + +/** + * 角色能操作哪些范围 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +public interface RoleScopeService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-04-24 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-04-24 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return RoleScopeDTO + * @author generator + * @date 2020-04-24 + */ + RoleScopeDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-24 + */ + void save(RoleScopeDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-24 + */ + void update(RoleScopeDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-04-24 + */ + void delete(String[] ids); +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java index cd846aa3b8..95b01a1f0c 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java @@ -2,6 +2,8 @@ package com.epmet.service.impl; import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.utils.CpUserDetailRedis; +import com.epmet.dao.OperationScopeDao; +import com.epmet.entity.OperationScopeEntity; import com.epmet.service.AccessService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,6 +12,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.HashSet; +import java.util.List; import java.util.Set; @Service @@ -20,19 +23,25 @@ public class AccessServiceImpl implements AccessService { @Autowired private CpUserDetailRedis cpUserDetailRedis; + @Autowired + private OperationScopeDao operationScopeDao; + /** * 更新权限缓存 * @param staffId * @param permissions */ @Override - public void updatePermissionCache(String staffId, String app, String client, Set permissions) { + public void updatePermissionCache(String staffId, String app, String client, Set permissions, Set roleIdList, String orgIdPath) { GovTokenDto govTokenDto = cpUserDetailRedis.get(app, client, staffId, GovTokenDto.class); if (govTokenDto == null) { logger.warn("更新[{}]用户缓存:Redis中不存在该用户TokenDto缓存信息", staffId); return ; } + // 将权限,角色列表,和当前组织ID存入TokenDto govTokenDto.setPermissions(permissions); + govTokenDto.setRoleIdList(roleIdList); + govTokenDto.setOrgIdPath(orgIdPath); // 将新的TokenDto更新到redis中 long expire = cpUserDetailRedis.getExpire(app, client, staffId); @@ -41,11 +50,17 @@ public class AccessServiceImpl implements AccessService { } @Override - public Set listStaffCurrPermissions(String app, String client, String staffId) { - GovTokenDto govTokenDto = cpUserDetailRedis.get(app, client, staffId, GovTokenDto.class); - if (govTokenDto == null || CollectionUtils.isEmpty(govTokenDto.getPermissions())) { - return new HashSet<>(); - } - return new HashSet<>(govTokenDto.getPermissions()); + public GovTokenDto listStaffCurrPermissions(String app, String client, String staffId) { + return cpUserDetailRedis.get(app, client, staffId, GovTokenDto.class); + } + + /** + * 查询角色的操作key对应操作范围列表 + * @param roleId + * @param operationKey + * @return + */ + public List listOperationScopesByRoleId(String roleId, String operationKey) { + return operationScopeDao.listOperationScopesByRoleId(roleId, operationKey); } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java new file mode 100644 index 0000000000..fe8f8b4079 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java @@ -0,0 +1,104 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.dao.OperationScopeDao; +import com.epmet.dto.OperationScopeDTO; +import com.epmet.entity.OperationScopeEntity; +import com.epmet.redis.OperationScopeRedis; +import com.epmet.service.OperationScopeService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 权限范围表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Service +public class OperationScopeServiceImpl extends BaseServiceImpl implements OperationScopeService { + + @Autowired + private OperationScopeRedis operationScopeRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, OperationScopeDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, OperationScopeDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public OperationScopeDTO get(String id) { + OperationScopeEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, OperationScopeDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(OperationScopeDTO dto) { + OperationScopeEntity entity = ConvertUtils.sourceToTarget(dto, OperationScopeEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(OperationScopeDTO dto) { + OperationScopeEntity entity = ConvertUtils.sourceToTarget(dto, OperationScopeEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java new file mode 100644 index 0000000000..4417549965 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java @@ -0,0 +1,104 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.dao.RoleScopeDao; +import com.epmet.dto.RoleScopeDTO; +import com.epmet.entity.RoleScopeEntity; +import com.epmet.redis.RoleScopeRedis; +import com.epmet.service.RoleScopeService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 角色能操作哪些范围 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-24 + */ +@Service +public class RoleScopeServiceImpl extends BaseServiceImpl implements RoleScopeService { + + @Autowired + private RoleScopeRedis roleScopeRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, RoleScopeDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, RoleScopeDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public RoleScopeDTO get(String id) { + RoleScopeEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, RoleScopeDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(RoleScopeDTO dto) { + RoleScopeEntity entity = ConvertUtils.sourceToTarget(dto, RoleScopeEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(RoleScopeDTO dto) { + RoleScopeEntity entity = ConvertUtils.sourceToTarget(dto, RoleScopeEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql b/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql index bcc1d74a5d..6bcbc33e76 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql @@ -61,7 +61,8 @@ CREATE TABLE `role_operation` ( CREATE TABLE `role_scope` ( `ID` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `ROLE_ID` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色ID', - `SCOPE_KEY` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '范围Key', + `OPERATION_KEY` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '操作Key', + `SCOPE_KEY` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '范围Key', `DEL_FLAG` tinyint(1) NULL DEFAULT NULL COMMENT '是否删除,0:未删除,1:已删除', `REVISION` int(10) NULL DEFAULT NULL COMMENT '乐观锁', `CREATED_BY` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建者id', diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml new file mode 100644 index 0000000000..dd4554f5d8 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/RoleScopeDao.xml b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/RoleScopeDao.xml new file mode 100644 index 0000000000..fdca928212 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/RoleScopeDao.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/AccessController.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/AccessController.java index 173e19243a..61944d3939 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/AccessController.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/controller/AccessController.java @@ -30,7 +30,7 @@ public class AccessController { private AccessService accessService; /** - * 查询用户可操作功能列表(包含缓存) + * 查询用户可操作功能列表(同时更新缓存) * @param tokenDto * @param staffOperationDTO * @return diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java index 737988fd0b..8c03d28764 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java @@ -2,6 +2,7 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.LatestGridFormDTO; import com.epmet.dto.result.CustomerGridByUserIdResultDTO; import com.epmet.dto.result.LatestCustomerResultDTO; @@ -49,4 +50,11 @@ public interface GovOrgFeignClient { @PostMapping(value = "/gov/org/customerstaffgrid/getstaffgrid") Result getStaffGrid(@RequestBody LatestGridFormDTO latestGridFormDTO); + /** + * 根据Id查询agency + * @param agencyId + * @return + */ + @PostMapping("/gov/org/agency/{agencyId}") + Result getAgencyById(@PathVariable("agencyId") String agencyId); } diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java index 818a325666..128f81bd50 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java @@ -3,6 +3,7 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.LatestGridFormDTO; import com.epmet.dto.result.CustomerGridByUserIdResultDTO; import com.epmet.dto.result.LatestCustomerResultDTO; @@ -28,6 +29,11 @@ public class GovOrgFeignClientFallBack implements GovOrgFeignClient { return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getStaffGrid",latestGridFormDTO); } + @Override + public Result getAgencyById(String agencyId) { + return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getAgencyById", agencyId); + } + @Override public Result getLatestCustomer(String userId) { return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getLatestCustomer", userId); diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java index 1da258978a..d76e2e2f34 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java @@ -1,14 +1,20 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.GovStaffRoleDTO; import com.epmet.dto.form.StaffPermCacheFormDTO; import com.epmet.dto.form.StaffRoleFormDTO; import com.epmet.dto.result.RoleOperationResultDTO; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.GovAccessFeignClient; +import com.epmet.feign.GovOrgFeignClient; import com.epmet.service.AccessService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -21,12 +27,17 @@ import java.util.Set; @Service public class AccessServiceImpl implements AccessService { + private static Logger logger = LoggerFactory.getLogger(AccessServiceImpl.class); + @Autowired private EpmetUserFeignClient userFeignClient; @Autowired private GovAccessFeignClient govAccessFeignClient; + @Autowired + private GovOrgFeignClient govOrgFeignClient; + @Autowired private CpUserDetailRedis cpUserDetailRedis; @@ -49,24 +60,46 @@ public class AccessServiceImpl implements AccessService { roleDTOS.addAll(gridResult.getData()); } - // 拼装 + // 拼装操作key列表 Set opeKeys = new HashSet<>(); + // 角色ID列表 + Set roleIds = new HashSet<>(); roleDTOS.forEach(roleDto -> { String roleId = roleDto.getId(); - List roleOperations = govAccessFeignClient.listOperationsByRoleId(roleId).getData(); - roleOperations.forEach(roleOpe -> { - if (roleOpe != null) { - opeKeys.add(roleOpe.getOperationKey()); - } - }); + Result> result = govAccessFeignClient.listOperationsByRoleId(roleId); + if (result.getCode() != 0) { + // 获取operation异常 + logger.error("调用GovAccess,根据RoleId查询Operation列表失败:{}", result.getMsg()); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + List roleOperations = result.getData(); + // 角色id + roleIds.add(roleDto.getId()); + if (!CollectionUtils.isEmpty(roleOperations)) { + roleOperations.forEach(roleOpe -> { + if (roleOpe != null) { + opeKeys.add(roleOpe.getOperationKey()); + } + }); + } }); + // 查询该直属机关的orgIdPath + Result agencyById = govOrgFeignClient.getAgencyById(agencyId); + if (agencyById.getCode() != 0 || agencyById.getData() == null) { + logger.error("根据当前机构id[{}]查询pids失败:{}", agencyId, agencyById.getMsg()); + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + // 将最新权限缓存到redis,为了尽量统一操作入口,调用gov-access接口实现 StaffPermCacheFormDTO staffPermCacheFormDTO = new StaffPermCacheFormDTO(); staffPermCacheFormDTO.setApp(app); staffPermCacheFormDTO.setClient(client); staffPermCacheFormDTO.setStaffId(staffId); staffPermCacheFormDTO.setPermissions(opeKeys); + staffPermCacheFormDTO.setRoleIdList(roleIds); + // 拼接orgIdPath + staffPermCacheFormDTO.setOrgIdPath(String.format("%s:%s", agencyById.getData().getPids(), agencyId)); govAccessFeignClient.updatePermissionCache(staffPermCacheFormDTO); return opeKeys; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index b8b8300489..728e6e03a8 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -18,17 +18,17 @@ package com.epmet.controller; import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.AddAgencyResultDTO; import com.epmet.dto.result.AgencyListResultDTO; import com.epmet.dto.result.AgencysResultDTO; import com.epmet.dto.result.SubAgencyResultDTO; +import com.epmet.entity.CustomerAgencyEntity; import com.epmet.service.AgencyService; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -110,4 +110,21 @@ public class AgencyController { public Result> agencyList(@RequestBody AgencyListFormDTO formDTO) { return agencyService.agencyList(formDTO); } + + /** + * 根据Id查询agency + * @param agencyId + * @return + */ + @PostMapping("{agencyId}") + public Result getAgencyById(@PathVariable("agencyId") String agencyId) { + CustomerAgencyEntity agency = agencyService.getAgencyById(agencyId); + CustomerAgencyDTO customerAgencyDTO = new CustomerAgencyDTO(); + if (agency != null) { + BeanUtils.copyProperties(agency, customerAgencyDTO); + return new Result().ok(customerAgencyDTO); + } + return new Result(); + } + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java index f2edc0c462..d09e56ba05 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java @@ -23,6 +23,7 @@ import com.epmet.dto.result.AddAgencyResultDTO; import com.epmet.dto.result.AgencyListResultDTO; import com.epmet.dto.result.AgencysResultDTO; import com.epmet.dto.result.SubAgencyResultDTO; +import com.epmet.entity.CustomerAgencyEntity; import java.util.List; @@ -80,4 +81,11 @@ public interface AgencyService { * @Description 获取组织列表 */ Result> agencyList(AgencyListFormDTO formDTO); + + /** + * 根据Id查询 + * @param agencyId + * @return + */ + CustomerAgencyEntity getAgencyById(String agencyId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index a71c53e80a..7177d64d7e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -184,4 +184,9 @@ public class AgencyServiceImpl implements AgencyService { List agencyList = customerAgencyDao.selectAgencyList(formDTO.getAgencyId()); return new Result>().ok(agencyList); } + + @Override + public CustomerAgencyEntity getAgencyById(String agencyId) { + return customerAgencyDao.selectById(agencyId); + } } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml index d0d80492b6..eaedaef1a6 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml @@ -22,7 +22,7 @@ customer_staff_department WHERE del_flag = '0' - AND department_id = #{} + AND department_id = #{departmentId} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/GovStaffRoleDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/GovStaffRoleDTO.java index 78905406ba..9bc2f4c4de 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/GovStaffRoleDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/GovStaffRoleDTO.java @@ -23,7 +23,7 @@ import lombok.Data; /** - * 政府端角色表 + * 政府端角色字典表 * * @author generator generator@elink-cn.com * @since v1.0.0 2020-04-22 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java index 795b0a34d9..c3fc1b9f24 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java @@ -1,5 +1,7 @@ package com.epmet.controller; +import com.epmet.commons.mybatis.entity.DataScope; +import com.epmet.commons.tools.annotation.RequirePermission; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.GovStaffRoleDTO; @@ -65,7 +67,7 @@ public class StaffRoleController { ValidatorUtils.validateEntity(staffRoleFormDTO, StaffRoleFormDTO.GetStaffsInRole.class); String roleKey = staffRoleFormDTO.getRoleKey(); String orgId = staffRoleFormDTO.getOrgId(); - List staffRoleDTOS = staffRoleService.listStaffsInRole(roleKey, orgId); + List staffRoleDTOS = staffRoleService.listStaffsInRole(roleKey, orgId , DataScope.getDefault()); return new Result>().ok(staffRoleDTOS); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java index 88742d7400..9c6af5321e 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java @@ -17,6 +17,7 @@ package com.epmet.service; +import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; import com.epmet.dto.StaffRoleDTO; @@ -100,7 +101,7 @@ public interface StaffRoleService extends BaseService { * @param orgId * @return */ - List listStaffsInRole(String roleKey, String orgId); + List listStaffsInRole(String roleKey, String orgId, DataScope dataScope); /** * 清空工作人员权限 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java index 0a9d7ce90d..180521ebe3 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java @@ -19,6 +19,8 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.annotation.DataFilter; +import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ConvertUtils; @@ -110,7 +112,7 @@ public class StaffRoleServiceImpl extends BaseServiceImpl listStaffsInRole(String roleKey, String orgId) { + public List listStaffsInRole(String roleKey, String orgId, DataScope dataScope) { return baseDao.listStaffIdsByRoleKeyAndOrgId(roleKey, orgId); } From 4cd81531f8a89ef2d9222f44cd74b77bd4bebe42 Mon Sep 17 00:00:00 2001 From: wxz Date: Sat, 25 Apr 2020 22:30:40 +0800 Subject: [PATCH 03/14] =?UTF-8?q?1.=E5=AE=8C=E6=88=90=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E8=8C=83=E5=9B=B4sql=E8=BF=87=E6=BB=A4=EF=BC=8C=E6=9C=AC?= =?UTF-8?q?=E7=BD=91=E6=A0=BCsql=E8=BF=87=E6=BB=A4=EF=BC=8C=E6=88=91?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=9A=84sql=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/aspect/DataFilterAspect.java | 171 +++++++++++------- .../mybatis/dto/form/OperationScopeDTO.java | 5 + .../dto/form/StaffPermCacheResultDTO.java | 5 + .../mybatis/feign/GovAccessFeignClient.java | 2 +- .../GovAccessFeignClientFallback.java | 4 +- .../interceptor/DataFilterInterceptor.java | 22 ++- .../epmet/commons/tools/redis/RedisKeys.java | 10 + .../dto/result/RoleOpeScopeResultDTO.java | 28 +++ .../dto/result/StaffPermCacheResultDTO.java | 5 + .../epmet/controller/AccessController.java | 18 +- .../java/com/epmet/dao/OperationScopeDao.java | 6 +- .../com/epmet/redis/OperationScopeRedis.java | 47 ----- .../com/epmet/redis/RoleOpeScopeRedis.java | 43 +++++ .../com/epmet/redis/RoleOperationRedis.java | 47 ----- .../java/com/epmet/redis/RoleScopeRedis.java | 47 ----- .../java/com/epmet/service/AccessService.java | 3 +- .../epmet/service/impl/AccessServiceImpl.java | 24 ++- .../impl/OperationScopeServiceImpl.java | 3 - .../impl/RoleOperationServiceImpl.java | 4 - .../service/impl/RoleScopeServiceImpl.java | 4 - .../db.migration/epmet_gov_access.sql | 1 + .../resources/mapper/OperationScopeDao.xml | 10 +- .../com/epmet/feign/GovAccessFeignClient.java | 2 +- 23 files changed, 256 insertions(+), 255 deletions(-) create mode 100644 epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java delete mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java delete mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOperationRedis.java delete mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java index b9431a6c48..13910a6f3a 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/aspect/DataFilterAspect.java @@ -8,8 +8,10 @@ package com.epmet.commons.mybatis.aspect; +import com.epmet.commons.mybatis.annotation.DataFilter; import com.epmet.commons.mybatis.constant.OpeScopeConstant; import com.epmet.commons.mybatis.dto.form.OperationScopeDTO; +import com.epmet.commons.mybatis.dto.form.OperationScopeFormDTO; import com.epmet.commons.mybatis.dto.form.StaffPermCacheResultDTO; import com.epmet.commons.mybatis.dto.form.StaffPermissionFormDTO; import com.epmet.commons.mybatis.entity.DataScope; @@ -23,6 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.reflect.MethodSignature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -53,15 +56,11 @@ public class DataFilterAspect { @Before("@annotation(com.epmet.commons.mybatis.annotation.DataFilter)") public void dataFilter(JoinPoint point) { - // 反射的方式 - //MethodSignature signature = (MethodSignature) point.getSignature(); - //Class[] parameterTypes = signature.getParameterTypes(); - //for (Class parameterType : parameterTypes) { - // if (parameterType == DataScope.class) { - // - // } - //} + // 通过反射,取到注解属性 + DataFilter dataFilterAnno = ((MethodSignature) point.getSignature()).getMethod().getAnnotation(DataFilter.class); + String tableAlias = dataFilterAnno.tableAlias(); + // 从ThreadLocal中取所需权限 String requirePermission = AccessOpeAspect.requirePermissionTl.get(); // 没有配置所需权限,不做操作,打印提示日志 if (StringUtils.isBlank(requirePermission)) { @@ -69,10 +68,14 @@ public class DataFilterAspect { return; } + String app = loginUserUtil.getLoginUserApp(); + String client = loginUserUtil.getLoginUserClient(); + String userId = loginUserUtil.getLoginUserId(); + StaffPermissionFormDTO staffPermissionFormDTO = new StaffPermissionFormDTO(); - staffPermissionFormDTO.setApp(loginUserUtil.getLoginUserApp()); - staffPermissionFormDTO.setClient(loginUserUtil.getLoginUserClient()); - staffPermissionFormDTO.setStaffId(loginUserUtil.getLoginUserId()); + staffPermissionFormDTO.setApp(app); + staffPermissionFormDTO.setClient(client); + staffPermissionFormDTO.setStaffId(userId); Result result = govAccessFeignClient.getStaffCurrPermissions(staffPermissionFormDTO); if (result.getCode() != 0) { @@ -91,10 +94,17 @@ public class DataFilterAspect { // 校验操作权限 validateOpePermission(permCacheResultDTO.getPermissions(), requirePermission); + // 生成过滤sql Object[] methodArgs = point.getArgs(); for (Object methodArg : methodArgs) { if (methodArg instanceof DataScope) { - ((DataScope) methodArg).setSqlFilter(getSqlFilterSegment(permCacheResultDTO.getRoleIdList(), requirePermission, permCacheResultDTO.getOrgIdPath())); + ((DataScope) methodArg).setSqlFilter(getSqlFilterSegment( + userId, + permCacheResultDTO.getRoleIdList(), + requirePermission, + permCacheResultDTO.getOrgIdPath(), + permCacheResultDTO.getGridId(), + tableAlias)); return; } } @@ -118,56 +128,111 @@ public class DataFilterAspect { * * @return */ - private String getSqlFilterSegment(Set roleIds, String reqiurePermission, String orgIdPath) { + private String getSqlFilterSegment(String userId,Set roleIds, String reqiurePermission, String orgIdPath, String gridId, String tableAlias) { // 根据角色列表查询操作范围列表 - // todo 暂停,先模拟数据 - //roleIds.forEach(roleId -> { - // OperationScopeFormDTO osformDto = new OperationScopeFormDTO(); - // osformDto.setRoleId(roleId); - // osformDto.setOperationKey(reqiurePermission); - // Result> result = govAccessFeignClient.getOperationScopesByRoleId(osformDto); - // List scopeDTOS = result.getData(); - //}); - Set scopeDTOS = genScopeDtos(); - - // 过滤有效范围 + Set scopeDTOS = new HashSet<>(); + roleIds.forEach(roleId -> { + OperationScopeFormDTO osformDto = new OperationScopeFormDTO(); + osformDto.setRoleId(roleId); + osformDto.setOperationKey(reqiurePermission); + Result> result = govAccessFeignClient.getOperationScopesByRoleId(osformDto); + if (result.success()) { + scopeDTOS.addAll(result.getData()); + } + }); + + // 过滤范围 HashSet scopes = filteScopes(scopeDTOS); + if (CollectionUtils.isEmpty(scopes)) { + // 没有范围限制 + return ""; + } + StringBuilder sb = new StringBuilder(); + + // 1.生成sql:组织范围过滤 + genOrgScopeSql(sb, orgIdPath, scopes, tableAlias); + + // 2.生成sql:我发起的 + genIStartedSql(sb, userId, tableAlias); + + // 3.生成sql:本网格的 + genInGrid(sb, gridId, tableAlias); + + //sb.append(")"); + System.out.println("生成的过滤sql:" + sb.toString()); + return sb.toString(); + } + + /** + * 网格sql + * @param sb + * @param gridId + * @param tableAlias + */ + private void genInGrid(StringBuilder sb, String gridId, String tableAlias) { + if (StringUtils.isBlank(tableAlias)) { + sb.append(" OR GRID_ID ='").append(gridId).append("'"); + } else { + sb.append(" OR ").append(tableAlias).append(".GRID_ID ='").append(gridId).append("'"); + } + } + + /** + * sql:我发起的 + * @param userId + */ + private void genIStartedSql(StringBuilder sb, String userId, String tableAlias) { + if (StringUtils.isBlank(tableAlias)) { + sb.append(" OR CREATED_BY ='").append(userId).append("'"); + } else { + sb.append(" OR ").append(tableAlias).append(".CREATED_BY ='").append(userId).append("'"); + } + } + /** + * 计算组织范围过滤sql,整体入口 + * @param sb + * @param orgIdPath + * @param scopes + */ + public void genOrgScopeSql(StringBuilder sb, String orgIdPath, HashSet scopes, String tableAlias) { // 取出父组织ID path 和当前组织ID String pOrgPath = orgIdPath.substring(0, orgIdPath.lastIndexOf(orgIdPathSpliter)); String currOrgPath = orgIdPath.substring(orgIdPath.lastIndexOf(orgIdPathSpliter) + 1); - - StringBuilder sb = new StringBuilder(" AND ("); - getOrgScopeSql(sb, scopes, currOrgPath, pOrgPath); + genOrgScopeSql(sb, scopes, currOrgPath, pOrgPath, tableAlias); sb.replace(sb.lastIndexOf("OR"), sb.lastIndexOf("OR") + 3, ""); - sb.append(") "); - // 拼接sql语句 - sb.replace(141,142,""); - // TODO - return ""; } /** - * 计算范围过滤sql + * 计算组织范围过滤sql * @param scopes * @param currOrg * @param pOrgPath * @return */ - private void getOrgScopeSql(StringBuilder sb,HashSet scopes, String currOrg, String pOrgPath) { + private void genOrgScopeSql(StringBuilder sb,HashSet scopes, String currOrg, String pOrgPath, String tableAlias) { for (String scope : scopes) { switch (scope) { case OpeScopeConstant.ORG_CURR: - getAgencyCurrScopedSql(sb, currOrg); - sb.append(" OR "); + if (StringUtils.isBlank(tableAlias)) { + sb.append(" ORG_ID = '").append(currOrg).append("' OR "); + } else { + sb.append(" ").append(tableAlias).append(".ORG_ID = '").append(currOrg).append("' OR "); + } break; case OpeScopeConstant.ORG_CURR_AND_SUB: - getAgencyCurrAndSubScopedSql(sb, pOrgPath); - sb.append(" OR "); + if (StringUtils.isBlank(tableAlias)) { + sb.append(" ORG_ID_PATH like '").append(pOrgPath).append("%' ").append(" OR "); + } else { + sb.append(" ").append(tableAlias).append(".ORG_ID_PATH like '").append(pOrgPath).append("%' ").append(" OR "); + } break; case OpeScopeConstant.ORG_CURR_SUB: - getAgencyCurrSubScopedSql(sb, pOrgPath, currOrg); - sb.append(" OR "); + if (StringUtils.isBlank(tableAlias)) { + sb.append(" ORG_ID_PATH like '").append(pOrgPath).append(orgIdPathSpliter).append(currOrg).append("%' ").append(" OR "); + } else { + sb.append(" ").append(tableAlias).append(".ORG_ID_PATH like '").append(pOrgPath).append(orgIdPathSpliter).append(currOrg).append("%' ").append(" OR "); + } break; case OpeScopeConstant.ORG_EQUAL: // todo 同级 @@ -185,32 +250,6 @@ public class DataFilterAspect { } } - /** - * 本身 - * @param sb - * @param orgId - */ - public void getAgencyCurrScopedSql(StringBuilder sb,String orgId) { - sb.append(" ORG_ID = ").append(orgId); - } - - /** - * 本身及子级 - * @param sb - * @param pOrgIdPath - */ - public void getAgencyCurrAndSubScopedSql(StringBuilder sb,String pOrgIdPath) { - sb.append(" ORG_ID_PATH like '").append(pOrgIdPath).append("%'"); - } - - /** - * 子级组织(不含本身) - * @param sb - */ - public void getAgencyCurrSubScopedSql(StringBuilder sb,String pOrgIdPath, String currOrgIdPath) { - sb.append("ORG_ID_PATH like '").append(pOrgIdPath).append(orgIdPathSpliter).append(currOrgIdPath).append("%'"); - } - /** * 过滤有效范围 * diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java index 494cff66b9..3e65b753d7 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/OperationScopeDTO.java @@ -39,6 +39,11 @@ public class OperationScopeDTO implements Serializable { */ private String id; + /** + * 角色id + */ + private String roleId; + /** * 范围key */ diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java index 6f37ef7033..7775756b38 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/dto/form/StaffPermCacheResultDTO.java @@ -22,4 +22,9 @@ public class StaffPermCacheResultDTO { */ private String orgIdPath; + /** + * 网格ID + */ + private String gridId; + } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java index 4d04adc835..50b20890e7 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/GovAccessFeignClient.java @@ -34,6 +34,6 @@ public interface GovAccessFeignClient { * @return */ @PostMapping("/gov/access/access/operationscopes") - Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO); + Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO); } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java index 2f5b9287a1..6dfa1b89cc 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/feign/fallback/GovAccessFeignClientFallback.java @@ -10,7 +10,7 @@ import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import org.springframework.stereotype.Component; -import java.util.List; +import java.util.Set; /** * 调用政府端权限 @@ -27,7 +27,7 @@ public class GovAccessFeignClientFallback implements GovAccessFeignClient { } @Override - public Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO) { + public Result> getOperationScopesByRoleId(OperationScopeFormDTO operationScopeFormDTO) { return ModuleUtils.feignConError(ServiceConstant.GOV_ACCESS_SERVER, "getOperationScopesByRoleId", operationScopeFormDTO); } } diff --git a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/interceptor/DataFilterInterceptor.java b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/interceptor/DataFilterInterceptor.java index 046c012da4..d26f7525a1 100644 --- a/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/interceptor/DataFilterInterceptor.java +++ b/epmet-commons/epmet-commons-mybatis/src/main/java/com/epmet/commons/mybatis/interceptor/DataFilterInterceptor.java @@ -10,9 +10,9 @@ package com.epmet.commons.mybatis.interceptor; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.PluginUtils; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler; import com.epmet.commons.mybatis.entity.DataScope; +import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.executor.statement.StatementHandler; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; @@ -43,10 +43,10 @@ public class DataFilterInterceptor extends AbstractSqlParserHandler implements I this.sqlParser(metaObject); // 先判断是不是SELECT操作 - MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); - if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) { - return invocation.proceed(); - } + //MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement"); + //if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) { + // return invocation.proceed(); + //} // 针对定义了rowBounds,做为mapper接口方法的参数 BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql"); @@ -79,12 +79,18 @@ public class DataFilterInterceptor extends AbstractSqlParserHandler implements I // 拼接新SQL String orderBy = "ORDER BY"; String groupBy = "GROUP BY"; + String sqlFilter = scope.getSqlFilter(); + if (originalSql.indexOf("WHERE") == 0) { + // 不包含where,需要手动拼接上 + sqlFilter = " WHERE ".concat(sqlFilter); + } + if (originalSql.indexOf(groupBy) > -1) { - originalSql = originalSql.replace(groupBy, scope.getSqlFilter() + groupBy); + originalSql = originalSql.replace(groupBy, sqlFilter + groupBy); } else if (originalSql.indexOf(orderBy) > -1) { - originalSql = originalSql.replace(orderBy, scope.getSqlFilter() + orderBy); + originalSql = originalSql.replace(orderBy, sqlFilter + orderBy); } else { - originalSql = originalSql + scope.getSqlFilter(); + originalSql = originalSql.concat(" AND (").concat(scope.getSqlFilter()).concat(")"); } // 重写SQL diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 199e38e235..6598010561 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -207,4 +207,14 @@ public class RedisKeys { public static String getLoginSmsCodeKey(String app, String client, String phone) { return String.format(rootPrefix+"smsCode:login:%s:%s:%s",app,client,phone); } + + /** + * 角色的操作权限对应的可操作范围 + * @param roleId 角色ID + * @param opeKey 操作Key + * @return + */ + public static String getRoleOpeScopesKey(String roleId, String opeKey) { + return rootPrefix.concat("gov:access:role:opescopes:").concat(roleId).concat(opeKey); + } } diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java new file mode 100644 index 0000000000..fbafb374e7 --- /dev/null +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/RoleOpeScopeResultDTO.java @@ -0,0 +1,28 @@ +package com.epmet.dto.result; + +import lombok.Data; + +@Data +public class RoleOpeScopeResultDTO { + + /** + * 角色ID + */ + private String roleId; + + /** + * 范围key + */ + private String scopeKey; + + /** + * 范围名称 + */ + private String scopeName; + + /** + * 范围序号 + */ + private String scopeIndex; + +} diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java index 0f6be83e72..ce24cf9501 100644 --- a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/result/StaffPermCacheResultDTO.java @@ -23,4 +23,9 @@ public class StaffPermCacheResultDTO { */ private String orgIdPath; + /** + * 网格ID + */ + private String gridId; + } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java index d60f7cb528..e34df14a06 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java @@ -6,6 +6,7 @@ import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.OperationScopeDTO; import com.epmet.dto.form.OperationScopeFormDTO; import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.dto.result.StaffPermCacheResultDTO; import com.epmet.entity.OperationScopeEntity; import com.epmet.service.AccessService; @@ -62,26 +63,19 @@ public class AccessController { resultDTO.setPermissions(govTokenDto.getPermissions()); resultDTO.setRoleIdList(govTokenDto.getRoleIdList()); resultDTO.setOrgIdPath(govTokenDto.getOrgIdPath()); + resultDTO.setGridId(govTokenDto.getGridId()); } return new Result().ok(resultDTO); } /** - * 查询角色的操作key对应操作范围列表(需要入缓存) + * 查询角色的操作key对应操作范围列表(缓存) * @return */ - // todo 需要加缓存 @PostMapping("operationscopes") - public Result> getOperationScopesByRoleId(@RequestBody OperationScopeFormDTO operationScopeFormDTO) { + public Result> getOperationScopesByRoleId(@RequestBody OperationScopeFormDTO operationScopeFormDTO) { ValidatorUtils.validateEntity(operationScopeFormDTO, OperationScopeFormDTO.ListOperationScopeGroup.class); - List scopes = accessService.listOperationScopesByRoleId(operationScopeFormDTO.getRoleId(), operationScopeFormDTO.getOperationKey()); - ArrayList scopeDtos = new ArrayList<>(); - scopes.forEach(scope -> { - OperationScopeDTO scopeDTO = new OperationScopeDTO(); - BeanUtils.copyProperties(scope, scopeDTO); - scopeDtos.add(scopeDTO); - }); - - return new Result>().ok(scopeDtos); + Set scopes = accessService.listOperationScopesByRoleId(operationScopeFormDTO.getRoleId(), operationScopeFormDTO.getOperationKey()); + return new Result>().ok(scopes); } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java index a944cdd628..4ac02b7f91 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationScopeDao.java @@ -18,12 +18,14 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.entity.OperationScopeEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.context.annotation.Scope; import java.util.List; +import java.util.Set; /** * 权限范围表 @@ -40,6 +42,6 @@ public interface OperationScopeDao extends BaseDao { * @param operationKey 操作key * @return */ - List listOperationScopesByRoleId(@Param("roleId") String roleId, - @Param("operationKey") String operationKey); + Set listOperationScopesByRoleId(@Param("roleId") String roleId, + @Param("operationKey") String operationKey); } \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java deleted file mode 100644 index 3f5a7c6562..0000000000 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/OperationScopeRedis.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.redis; - -import com.epmet.commons.tools.redis.RedisUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * 权限范围表 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-04-24 - */ -@Component -public class OperationScopeRedis { - @Autowired - private RedisUtils redisUtils; - - public void delete(Object[] ids) { - - } - - public void set(){ - - } - - public String get(String id){ - return null; - } - -} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java new file mode 100644 index 0000000000..cd929c692d --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOpeScopeRedis.java @@ -0,0 +1,43 @@ +package com.epmet.redis; + +import cn.hutool.core.bean.BeanUtil; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.dto.result.RoleOpeScopeResultDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Set; + +/** + * 角色的操作权限对应的操作范围Redis + */ +@Component +public class RoleOpeScopeRedis { + + @Autowired + private RedisUtils redisUtils; + + /** + * 缓存角色操作范围 + * @param roleId + * @param opeKey + * @param scopes + */ + public void setRoleOpeScopes(String roleId, String opeKey, Set scopes) { + String roleOpeScopesKey = RedisKeys.getRoleOpeScopesKey(roleId, opeKey); + redisUtils.set(roleOpeScopesKey, scopes); + } + + /** + * 查询角色操作范围 + * @param roleId + * @param opeKey + * @return + */ + public Set getRoleOpeScopes(String roleId, String opeKey) { + String roleOpeScopesKey = RedisKeys.getRoleOpeScopesKey(roleId, opeKey); + return (Set)redisUtils.get(roleOpeScopesKey); + } + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOperationRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOperationRedis.java deleted file mode 100644 index d57c02ebde..0000000000 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleOperationRedis.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.redis; - -import com.epmet.commons.tools.redis.RedisUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * 角色能进行那些操作 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-04-22 - */ -@Component -public class RoleOperationRedis { - @Autowired - private RedisUtils redisUtils; - - public void delete(Object[] ids) { - - } - - public void set(){ - - } - - public String get(String id){ - return null; - } - -} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java deleted file mode 100644 index 1198f8651a..0000000000 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/redis/RoleScopeRedis.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.redis; - -import com.epmet.commons.tools.redis.RedisUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * 角色能操作哪些范围 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-04-24 - */ -@Component -public class RoleScopeRedis { - @Autowired - private RedisUtils redisUtils; - - public void delete(Object[] ids) { - - } - - public void set(){ - - } - - public String get(String id){ - return null; - } - -} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java index 4355b2714b..df16e1e9df 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java @@ -1,6 +1,7 @@ package com.epmet.service; import com.epmet.commons.tools.security.dto.GovTokenDto; +import com.epmet.dto.result.RoleOpeScopeResultDTO; import com.epmet.entity.OperationScopeEntity; import java.util.List; @@ -26,5 +27,5 @@ public interface AccessService { * @param operationKey * @return */ - List listOperationScopesByRoleId(String roleId, String operationKey); + Set listOperationScopesByRoleId(String roleId, String operationKey); } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java index 95b01a1f0c..34e458ec6a 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java @@ -1,9 +1,11 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.dao.OperationScopeDao; -import com.epmet.entity.OperationScopeEntity; +import com.epmet.dto.result.RoleOpeScopeResultDTO; +import com.epmet.redis.RoleOpeScopeRedis; import com.epmet.service.AccessService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,8 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; -import java.util.HashSet; -import java.util.List; import java.util.Set; @Service @@ -26,6 +26,9 @@ public class AccessServiceImpl implements AccessService { @Autowired private OperationScopeDao operationScopeDao; + @Autowired + private RoleOpeScopeRedis roleOpeScopeRedis; + /** * 更新权限缓存 * @param staffId @@ -60,7 +63,18 @@ public class AccessServiceImpl implements AccessService { * @param operationKey * @return */ - public List listOperationScopesByRoleId(String roleId, String operationKey) { - return operationScopeDao.listOperationScopesByRoleId(roleId, operationKey); + public Set listOperationScopesByRoleId(String roleId, String operationKey) { + Set roleOpeScopes = roleOpeScopeRedis.getRoleOpeScopes(roleId, operationKey); + if (roleOpeScopes != null) { + return roleOpeScopes; + } + Set scopes = operationScopeDao.listOperationScopesByRoleId(roleId, operationKey); + try { + roleOpeScopeRedis.setRoleOpeScopes(roleId, operationKey, scopes); + } catch (Exception e) { + String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); + logger.error("GovAccess:查询角色的操作范围:缓存范围出错:{}", errorStackTrace); + } + return scopes; } } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java index fe8f8b4079..e582395fe2 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationScopeServiceImpl.java @@ -26,7 +26,6 @@ import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.dao.OperationScopeDao; import com.epmet.dto.OperationScopeDTO; import com.epmet.entity.OperationScopeEntity; -import com.epmet.redis.OperationScopeRedis; import com.epmet.service.OperationScopeService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -46,8 +45,6 @@ import java.util.Map; @Service public class OperationScopeServiceImpl extends BaseServiceImpl implements OperationScopeService { - @Autowired - private OperationScopeRedis operationScopeRedis; @Override public PageData page(Map params) { diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleOperationServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleOperationServiceImpl.java index bb6d914d2e..a690363b33 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleOperationServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleOperationServiceImpl.java @@ -27,7 +27,6 @@ import com.epmet.dao.RoleOperationDao; import com.epmet.dto.RoleOperationDTO; import com.epmet.dto.result.RoleOperationResultDTO; import com.epmet.entity.RoleOperationEntity; -import com.epmet.redis.RoleOperationRedis; import com.epmet.service.RoleOperationService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -47,9 +46,6 @@ import java.util.Map; @Service public class RoleOperationServiceImpl extends BaseServiceImpl implements RoleOperationService { - @Autowired - private RoleOperationRedis roleOperationRedis; - @Override public PageData page(Map params) { IPage page = baseDao.selectPage( diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java index 4417549965..bff52f8d64 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/RoleScopeServiceImpl.java @@ -26,7 +26,6 @@ import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.dao.RoleScopeDao; import com.epmet.dto.RoleScopeDTO; import com.epmet.entity.RoleScopeEntity; -import com.epmet.redis.RoleScopeRedis; import com.epmet.service.RoleScopeService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -46,9 +45,6 @@ import java.util.Map; @Service public class RoleScopeServiceImpl extends BaseServiceImpl implements RoleScopeService { - @Autowired - private RoleScopeRedis roleScopeRedis; - @Override public PageData page(Map params) { IPage page = baseDao.selectPage( diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql b/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql index 6bcbc33e76..93d8c2a148 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/db.migration/epmet_gov_access.sql @@ -10,6 +10,7 @@ CREATE TABLE `operation_scope` ( `ID` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'id', `SCOPE_KEY` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '范围key', `SCOPE_NAME` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '范围名称', + `SCOPE_INDEX` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '范围序号', `DEL_FLAG` tinyint(1) NULL DEFAULT NULL COMMENT '是否删除,0:未删除,1:已删除', `REVISION` int(10) NULL DEFAULT NULL COMMENT '乐观锁', `CREATED_BY` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建者id', diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml index dd4554f5d8..ab6839e941 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationScopeDao.xml @@ -16,13 +16,13 @@ - + select os.SCOPE_KEY, os.SCOPE_NAME, rs.ROLE_ID, os.SCOPE_INDEX from role_scope rs - inner join operation_scope os - on (rs.SCOPE_KEY = os.SCOPE_KEY) + inner join operation_scope os + on (rs.SCOPE_KEY = os.SCOPE_KEY) where rs.ROLE_ID = #{roleId} - and rs.OPERATION_KEY = #{operationKey} + and rs.OPERATION_KEY = #{operationKey} diff --git a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java index 8cb514ad3f..b41a5e59ca 100644 --- a/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java +++ b/epmet-module/gov-mine/gov-mine-server/src/main/java/com/epmet/feign/GovAccessFeignClient.java @@ -16,7 +16,7 @@ import java.util.List; * @Description * @Author sun */ -@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallback.class) +@FeignClient(name = ServiceConstant.GOV_ACCESS_SERVER, fallback = GovAccessFeignClientFallback.class, url = "localhost:8099") public interface GovAccessFeignClient { /** From 54294a9ed1fb421a45cd21a976914c61992f74f9 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Sun, 26 Apr 2020 09:00:30 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=94=BF=E5=BA=9C=E7=AB=AF-=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E6=A8=A1=E5=9D=97=E4=BB=A3=E7=A0=81=E8=A1=A5=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dao/CustomerStaffDepartmentDao.java | 7 +++++++ .../mapper/CustomerStaffDepartmentDao.xml | 14 +------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java index dfdba500d7..22ab90c4ba 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerStaffDepartmentDao.java @@ -33,5 +33,12 @@ import java.util.List; @Mapper public interface CustomerStaffDepartmentDao extends BaseDao { + /** + * + * @param departmentId + * @return + * * @Author sun + * @Description 查询部门下工作人员的用户Id集合 + */ List selectUserIdByDepartmentId(@Param("departmentId") String departmentId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml index 86c597d402..8df91287f1 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerStaffDepartmentDao.xml @@ -3,18 +3,6 @@ - - - - - - - - - - - - From c3ced082931fd17ba98cfad0d1ab425310acf295 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Sun, 26 Apr 2020 09:14:47 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=94=BF=E5=BA=9C=E7=AB=AF-=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0token=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/AgencyController.java | 14 ++++++++------ .../com/epmet/controller/DepartmentController.java | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index 728e6e03a8..2ddc8f3c98 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -17,6 +17,8 @@ package com.epmet.controller; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.*; @@ -52,7 +54,7 @@ public class AgencyController { * @Description 添加组织 */ @PostMapping("addagency") - public Result addAgency(@RequestBody AddAgencyFormDTO formDTO) { + public Result addAgency(@LoginUser TokenDto tokenDTO, @RequestBody AddAgencyFormDTO formDTO) { return agencyService.addAgency(formDTO); } @@ -63,7 +65,7 @@ public class AgencyController { * @Description 组织名称编辑 */ @PostMapping("editagency") - public Result editAgency(@RequestBody EditAgencyFormDTO formDTO) { + public Result editAgency(@LoginUser TokenDto tokenDTO, @RequestBody EditAgencyFormDTO formDTO) { return agencyService.editAgency(formDTO); } @@ -74,7 +76,7 @@ public class AgencyController { * @Description 删除组织机关 */ @PostMapping("removeagency") - public Result removeAgency(@RequestBody RemoveAgencyFormDTO formDTO) { + public Result removeAgency(@LoginUser TokenDto tokenDTO, @RequestBody RemoveAgencyFormDTO formDTO) { return agencyService.removeAgency(formDTO); } @@ -85,7 +87,7 @@ public class AgencyController { * @Description 组织首页-获取组织机构信息 */ @PostMapping("agencydetail") - public Result agencyDetail(@RequestBody AgencydetailFormDTO formDTO) { + public Result agencyDetail(@LoginUser TokenDto tokenDTO, @RequestBody AgencydetailFormDTO formDTO) { return agencyService.agencyDetail(formDTO); } @@ -96,7 +98,7 @@ public class AgencyController { * @Description 组织首页-下级机关列表 */ @PostMapping("subagencylist") - public Result subAgencyList(@RequestBody SubAgencyFormDTO formDTO) { + public Result subAgencyList(@LoginUser TokenDto tokenDTO, @RequestBody SubAgencyFormDTO formDTO) { return agencyService.subAgencyList(formDTO); } @@ -107,7 +109,7 @@ public class AgencyController { * @Description 获取组织列表 */ @PostMapping("agencylist") - public Result> agencyList(@RequestBody AgencyListFormDTO formDTO) { + public Result> agencyList(@LoginUser TokenDto tokenDTO, @RequestBody AgencyListFormDTO formDTO) { return agencyService.agencyList(formDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java index eba65e1372..4d627ebaac 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java @@ -47,7 +47,7 @@ public class DepartmentController { * @Description 添加部门 */ @PostMapping("adddepartment") - public Result addDepartment(@RequestBody AddDepartmentFormDTO formDTO) { + public Result addDepartment(@LoginUser TokenDto tokenDTO, @RequestBody AddDepartmentFormDTO formDTO) { return departmentService.addDepartment(formDTO); } @@ -58,7 +58,7 @@ public class DepartmentController { * @Description 部门信息修改 */ @PostMapping("editdepartment") - public Result editDepartment(@RequestBody EditDepartmentFormDTO formDTO) { + public Result editDepartment(@LoginUser TokenDto tokenDTO, @RequestBody EditDepartmentFormDTO formDTO) { return departmentService.editDepartment(formDTO); } @@ -69,7 +69,7 @@ public class DepartmentController { * @Description 删除部门 */ @PostMapping("removedepartment") - public Result removeDepartment(@RequestBody RemoveDepartmentFormDTO formDTO) { + public Result removeDepartment(@LoginUser TokenDto tokenDTO, @RequestBody RemoveDepartmentFormDTO formDTO) { return departmentService.removeDepartment(formDTO); } @@ -80,7 +80,7 @@ public class DepartmentController { * @Description 获取部门详情 */ @PostMapping("departmentdetail") - public Result departmentDetail(@RequestBody DepartmentdetailFormDTO formDTO) { + public Result departmentDetail(@LoginUser TokenDto tokenDTO, @RequestBody DepartmentdetailFormDTO formDTO) { return departmentService.departmentDetail(formDTO); } @@ -91,7 +91,7 @@ public class DepartmentController { * @Description 组织首页-获取机关下部门列表 */ @PostMapping("departmentinagencylist") - public Result departmentInAgencyList(@RequestBody DepartmentInAgencyFormDTO formDTO) { + public Result departmentInAgencyList(@LoginUser TokenDto tokenDTO, @RequestBody DepartmentInAgencyFormDTO formDTO) { return departmentService.departmentInAgencyList(formDTO); } @@ -102,7 +102,7 @@ public class DepartmentController { * @Description 获取机构下部门列表 */ @PostMapping("departmentlist") - public Result> departmentList(@RequestBody DepartmentListFormDTO formDTO) { + public Result> departmentList(@LoginUser TokenDto tokenDTO, @RequestBody DepartmentListFormDTO formDTO) { return departmentService.departmentList(formDTO); } } \ No newline at end of file From 4582b9f3647dc60220422b28c449a320e6aaae4f Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Sun, 26 Apr 2020 09:26:29 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E6=96=B9=E6=B3=95=E6=B7=BB=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/service/impl/CustomerStaffServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index d3a98772bd..f5a2d154b1 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -19,6 +19,7 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.entity.DataScope; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; @@ -354,7 +355,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl staffRoleDTOS = staffRoleService.listStaffsInRole(UserRoleConstant.DEPT_LEADER, formDTO.getDepartmentId()); + List staffRoleDTOS = staffRoleService.listStaffsInRole(UserRoleConstant.DEPT_LEADER, formDTO.getDepartmentId(), DataScope.getDefault()); staffRoleDTOS.forEach(roleDto -> { staffList.stream().filter(staffDto -> roleDto.getStaffId().equals(staffDto.getStaffId())).findAny().ifPresent(result -> From 46d7f7ff76413653eb4133073f09164cc969a76a Mon Sep 17 00:00:00 2001 From: zxc <954985705@qq.com> Date: Sun, 26 Apr 2020 10:20:24 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/dao/CustomerGridDao.java | 9 +++++++++ .../java/com/epmet/feign/EpmetUserFeignClient.java | 2 +- .../feign/fallback/EpmetUserFeignClientFallBack.java | 2 +- .../epmet/service/impl/CustomerGridServiceImpl.java | 5 ++--- .../src/main/resources/mapper/CustomerGridDao.xml | 11 +++++++++++ .../com/epmet/controller/CustomerStaffController.java | 2 +- .../src/main/java/com/epmet/dao/CustomerStaffDao.java | 2 +- .../java/com/epmet/service/CustomerStaffService.java | 2 +- .../epmet/service/impl/CustomerStaffServiceImpl.java | 2 +- .../src/main/resources/mapper/CustomerStaffDao.xml | 7 +++++-- 10 files changed, 33 insertions(+), 11 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java index d15a7c7032..a43d3e56ae 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java @@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerGridDTO; import com.epmet.dto.CustomerStaffGridDTO; +import com.epmet.dto.UserIdDTO; import com.epmet.dto.form.CustomerGridFormDTO; import com.epmet.dto.form.DeleteGridFormDTO; import com.epmet.dto.form.ListCustomerGridFormDTO; @@ -123,5 +124,13 @@ public interface CustomerGridDao extends BaseDao { */ void deleteGrid(DeleteGridFormDTO deleteGridFormDTO); + /** + * + * @Description 根据gridId查询userId + * @Author zxc + * @CreatedTime 2020/4/26 10:08 + */ + List selectUserIdByGrid(@Param("gridId")String gridId); + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 8eb86517de..aa12f45ab9 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -62,7 +62,7 @@ public interface EpmetUserFeignClient { * @return */ @PostMapping(value = "/epmetuser/customerstaff/selectgridstaffcountbyuserid") - Result selectGridStaffCountByUserId(@RequestBody UserIdDTO userIdDTO); + Result selectGridStaffCountByUserId(@RequestBody List userIdDTO); /** * 工作人员列表 diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java index 1284fb622b..29986d388f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java @@ -42,7 +42,7 @@ public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient { } @Override - public Result selectGridStaffCountByUserId(UserIdDTO userIdDTO) { + public Result selectGridStaffCountByUserId(List userIdDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "selectGridStaffCountByUserId", userIdDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java index 075799dfb8..00db15a6bd 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java @@ -223,10 +223,9 @@ public class CustomerGridServiceImpl extends BaseServiceImpl userIdDTOS = baseDao.selectUserIdByGrid(deleteGridFormDTO.getGridId()); deleteGridFormDTO.setUserId(tokenDto.getUserId()); - Result gridStaffCountDTOResult = epmetUserFeignClient.selectGridStaffCountByUserId(userIdDTO); + Result gridStaffCountDTOResult = epmetUserFeignClient.selectGridStaffCountByUserId(userIdDTOS); if (gridStaffCountDTOResult.getData().getEnableCount()==0){ baseDao.deleteGrid(deleteGridFormDTO); }else { diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml index c7a54db7b9..4ab272a119 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml @@ -194,4 +194,15 @@ id = #{gridId} + + + \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index 748252137b..c499eb62e7 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -175,7 +175,7 @@ public class CustomerStaffController { * @auther zxc */ @PostMapping(value = "selectgridstaffcountbyuserid") - public Result selectGridStaffCountByUserId(@RequestBody UserIdDTO userIdDTO){ + public Result selectGridStaffCountByUserId(@RequestBody List userIdDTO){ return customerStaffService.selectGridStaffCountByUserId(userIdDTO); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java index 6c4cab6dc7..2b5fe0cb46 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java @@ -62,7 +62,7 @@ public interface CustomerStaffDao extends BaseDao { * @param userIdDTO * @return */ - GridStaffCountDTO selectGridStaffCountByUserId(UserIdDTO userIdDTO); + GridStaffCountDTO selectGridStaffCountByUserId(List userIdDTO); /** * 根据userId查询查询网格下的用户信息 * diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index abd130c21c..92f6779396 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -204,7 +204,7 @@ public interface CustomerStaffService extends BaseService { * @param userIdDTO * @return */ - Result selectGridStaffCountByUserId(UserIdDTO userIdDTO); + Result selectGridStaffCountByUserId(List userIdDTO); /** * @param fromDTO diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index f5a2d154b1..d6a76ac6f9 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -340,7 +340,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl selectGridStaffCountByUserId(UserIdDTO userIdDTO) { + public Result selectGridStaffCountByUserId(List userIdDTO) { Result gridStaffCountDTOResult = new Result(); GridStaffCountDTO gridStaffCountDTO = baseDao.selectGridStaffCountByUserId(userIdDTO); gridStaffCountDTOResult.setData(gridStaffCountDTO); diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml index d1cfdd797d..9335d663bd 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml @@ -44,13 +44,16 @@ - SELECT count(*) AS enableCount FROM customer_staff WHERE - user_id = #{userId} + user_id in + + #{staff.userId} + AND del_flag = 0 AND enable_flag = 'enable' From b85a33b2294e66c0cf87846f24d7d52417eac7ef Mon Sep 17 00:00:00 2001 From: zxc <954985705@qq.com> Date: Sun, 26 Apr 2020 13:17:21 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/exception/EpmetErrorCode.java | 4 +++- .../main/java/com/epmet/dto/form/EditGridFormDTO.java | 5 +++++ .../src/main/java/com/epmet/dao/CustomerGridDao.java | 2 +- .../epmet/service/impl/CustomerGridServiceImpl.java | 10 +++++++++- .../src/main/resources/mapper/CustomerGridDao.xml | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 161c9cd9ef..f84dfde45f 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -32,7 +32,9 @@ public enum EpmetErrorCode { NOT_DEL_AGENCY_PER(8205, "该机关存在工作人员,不允许删除"), NOT_DEL_DEPARTMENT(8206, "该部门存在工作人员,不允许删除"), - REQUIRE_PERMISSION(8301, "没有足够的操作权限"); + REQUIRE_PERMISSION(8301, "没有足够的操作权限"), + + NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"); private int code; diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java index 2c5556f7a3..b22e5048f9 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java @@ -18,6 +18,11 @@ public class EditGridFormDTO implements Serializable { */ private String gridId; + /** + * pid 当前机关id + */ + private String agencyId; + /** * 网格名称 */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java index a43d3e56ae..11fb36a5fc 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java @@ -110,7 +110,7 @@ public interface CustomerGridDao extends BaseDao { * @param gridName * @return */ - String selectGridIdByGridName(@Param("gridName")String gridName); + String selectGridIdByGridName(@Param("gridName")String gridName,@Param("agencyId")String pid); /** * 编辑网格信息 diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java index 00db15a6bd..f783b6c336 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java @@ -186,6 +186,10 @@ public class CustomerGridServiceImpl extends BaseServiceImpl addGrid(TokenDto tokenDto, AddGridFormDTO addGridFormDTO) { + String checkGridName = baseDao.selectGridIdByGridName(addGridFormDTO.getGridName(),addGridFormDTO.getAgencyId()); + if (checkGridName!=null){ + return new Result().error(EpmetErrorCode.NOT_ADD_GRID.getCode()); + } CustomerGridEntity customerGridEntity = new CustomerGridEntity(); customerGridEntity.setCustomerId(baseDao.selectCustomerIdByUserId(tokenDto.getUserId())); customerGridEntity.setGridName(addGridFormDTO.getGridName()); @@ -197,7 +201,7 @@ public class CustomerGridServiceImpl extends BaseServiceImpl().ok(addGridResultDTO); @@ -211,6 +215,10 @@ public class CustomerGridServiceImpl extends BaseServiceImpl From 1a7d7691393766a7a9ce57dfb72883c32c733242 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Sun, 26 Apr 2020 13:27:15 +0800 Subject: [PATCH 09/14] =?UTF-8?q?getMyOrg=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/mapper/CustomerAgencyDao.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml index 90b926b729..ace0e18f8e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml @@ -24,8 +24,8 @@ SELECT - ca.pid AS rootAgencyId, + ca.id AS rootAgencyId, ca.ORGANIZATION_NAME AS rootAgencyName, ca.CUSTOMER_ID AS customerId FROM From add02f02100d44560b2977d05b315df8e014a922 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Sun, 26 Apr 2020 15:10:46 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=B1=BB=E5=9E=8B=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/dto/CustomerAgencyDTO.java | 2 +- .../src/main/java/com/epmet/entity/CustomerAgencyEntity.java | 2 +- .../src/main/java/com/epmet/excel/CustomerAgencyExcel.java | 2 +- .../src/main/resources/db/migration/epmet_gov_org.sql | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerAgencyDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerAgencyDTO.java index 7b9abc9de6..f7380580b4 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerAgencyDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerAgencyDTO.java @@ -75,7 +75,7 @@ public class CustomerAgencyDTO implements Serializable { /** * 地区编码 */ - private Integer areaCode; + private String areaCode; /** * 删除标识 diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java index 5549845d66..6a669609eb 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java @@ -75,7 +75,7 @@ public class CustomerAgencyEntity extends BaseEpmetEntity { /** * 地区编码 */ - private Integer areaCode; + private String areaCode; /** * 总人数 diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/CustomerAgencyExcel.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/CustomerAgencyExcel.java index 346963be94..7edffbcc60 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/CustomerAgencyExcel.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/CustomerAgencyExcel.java @@ -53,7 +53,7 @@ public class CustomerAgencyExcel { private String level; @Excel(name = "地区编码") - private Integer areaCode; + private String areaCode; @Excel(name = "删除标识") private String delFlag; diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/epmet_gov_org.sql b/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/epmet_gov_org.sql index f4d0e47dc7..aa68f1c8fa 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/epmet_gov_org.sql +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/epmet_gov_org.sql @@ -110,4 +110,6 @@ ALTER TABLE customer_agency ADD ( PROVINCE VARCHAR (32) DEFAULT NULL COMMENT '省份', CITY VARCHAR (32) DEFAULT NULL COMMENT '城市', DISTRICT VARCHAR (32) DEFAULT NULL COMMENT '区县' -); \ No newline at end of file +); + +ALTER TABLE customer_agency MODIFY AREA_CODE VARCHAR(10) NOT NULL; \ No newline at end of file From f9c6972ea5d94fc44f2237d131b682c00301915b Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Sun, 26 Apr 2020 15:36:09 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E6=94=BF=E5=BA=9C=E7=AB=AF-=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=87=AA=E6=B5=8B=E7=A8=8B=E5=BA=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dto/form/AddAgencyFormDTO.java | 19 ++++++---- .../epmet/dto/form/AddDepartmentFormDTO.java | 2 ++ .../epmet/controller/AgencyController.java | 7 ++++ .../controller/DepartmentController.java | 7 ++++ .../com/epmet/feign/EpmetUserFeignClient.java | 2 +- .../epmet/service/impl/AgencyServiceImpl.java | 23 +++++++++--- .../mapper/CustomerDepartmentDao.xml | 35 +++++++++++-------- .../controller/CustomerStaffController.java | 2 +- 8 files changed, 69 insertions(+), 28 deletions(-) diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java index 7cb0a69b27..1e7cd65f80 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java @@ -20,6 +20,7 @@ package com.epmet.dto.form; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.io.Serializable; @@ -37,7 +38,7 @@ public class AddAgencyFormDTO implements Serializable { * 上级机关组织Id(当前机关组织添加下级组织) */ @NotBlank(message = "上级机关组织ID不能为空") - private String pid; + private String parentAgencyId; /** * 机构组织名称 @@ -52,27 +53,31 @@ public class AddAgencyFormDTO implements Serializable { * 市级: city * 省级:province) 机关级别(社区级:community,乡(镇、街道)级:street,区县级: district,市级: city省级:province) */ + @NotBlank(message = "机关级别不能为空") private String level; /** * 地区编码 */ - private Integer areaCode; - - /** - * 国家 - */ - private String district; + @NotBlank(message = "地区编码不能为空") + private String areaCode; /** * 省份 */ + @NotBlank(message = "省级名称不能为空") private String province; /** * 城市 */ + @NotBlank(message = "市级名称不能为空") private String city; + /** + * 区县 + */ + @NotBlank(message = "区县名称不能为空") + private String district; } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java index 57680d2ecd..e03ad75034 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddDepartmentFormDTO.java @@ -40,11 +40,13 @@ public class AddDepartmentFormDTO implements Serializable { /** * 部门名称 */ + @NotBlank(message = "部门名称不能为空") private String departmentName; /** * 部门职责 */ + @NotBlank(message = "部门职责不能为空") private String departmentDuty; diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index 2ddc8f3c98..7f192ee942 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -20,6 +20,7 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.AddAgencyResultDTO; @@ -55,6 +56,7 @@ public class AgencyController { */ @PostMapping("addagency") public Result addAgency(@LoginUser TokenDto tokenDTO, @RequestBody AddAgencyFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return agencyService.addAgency(formDTO); } @@ -66,6 +68,7 @@ public class AgencyController { */ @PostMapping("editagency") public Result editAgency(@LoginUser TokenDto tokenDTO, @RequestBody EditAgencyFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return agencyService.editAgency(formDTO); } @@ -77,6 +80,7 @@ public class AgencyController { */ @PostMapping("removeagency") public Result removeAgency(@LoginUser TokenDto tokenDTO, @RequestBody RemoveAgencyFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return agencyService.removeAgency(formDTO); } @@ -88,6 +92,7 @@ public class AgencyController { */ @PostMapping("agencydetail") public Result agencyDetail(@LoginUser TokenDto tokenDTO, @RequestBody AgencydetailFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return agencyService.agencyDetail(formDTO); } @@ -99,6 +104,7 @@ public class AgencyController { */ @PostMapping("subagencylist") public Result subAgencyList(@LoginUser TokenDto tokenDTO, @RequestBody SubAgencyFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return agencyService.subAgencyList(formDTO); } @@ -110,6 +116,7 @@ public class AgencyController { */ @PostMapping("agencylist") public Result> agencyList(@LoginUser TokenDto tokenDTO, @RequestBody AgencyListFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return agencyService.agencyList(formDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java index 4d627ebaac..b55e48a3e0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/DepartmentController.java @@ -3,6 +3,7 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.*; import com.epmet.dto.result.AddDepartmentResultDTO; import com.epmet.dto.result.DepartmentDetailResultDTO; @@ -48,6 +49,7 @@ public class DepartmentController { */ @PostMapping("adddepartment") public Result addDepartment(@LoginUser TokenDto tokenDTO, @RequestBody AddDepartmentFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return departmentService.addDepartment(formDTO); } @@ -59,6 +61,7 @@ public class DepartmentController { */ @PostMapping("editdepartment") public Result editDepartment(@LoginUser TokenDto tokenDTO, @RequestBody EditDepartmentFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return departmentService.editDepartment(formDTO); } @@ -70,6 +73,7 @@ public class DepartmentController { */ @PostMapping("removedepartment") public Result removeDepartment(@LoginUser TokenDto tokenDTO, @RequestBody RemoveDepartmentFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return departmentService.removeDepartment(formDTO); } @@ -81,6 +85,7 @@ public class DepartmentController { */ @PostMapping("departmentdetail") public Result departmentDetail(@LoginUser TokenDto tokenDTO, @RequestBody DepartmentdetailFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return departmentService.departmentDetail(formDTO); } @@ -92,6 +97,7 @@ public class DepartmentController { */ @PostMapping("departmentinagencylist") public Result departmentInAgencyList(@LoginUser TokenDto tokenDTO, @RequestBody DepartmentInAgencyFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return departmentService.departmentInAgencyList(formDTO); } @@ -103,6 +109,7 @@ public class DepartmentController { */ @PostMapping("departmentlist") public Result> departmentList(@LoginUser TokenDto tokenDTO, @RequestBody DepartmentListFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); return departmentService.departmentList(formDTO); } } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index aa12f45ab9..1d52e9072d 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -132,7 +132,7 @@ public interface EpmetUserFeignClient { * @Description 根据客户Id及userId集合查询用户基本信息 */ @PostMapping("/epmetuser/customerstaff/getdepartmentstafflist") - Result> getDepartmentStaffList(DepartmentInStaffFormDTO departmentInStaffFormDTO); + Result> getDepartmentStaffList(@RequestBody DepartmentInStaffFormDTO departmentInStaffFormDTO); /** * 根据userId查询customerId diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index 7177d64d7e..f1901d64cf 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -28,6 +28,7 @@ import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.entity.CustomerAgencyEntity; import com.epmet.service.AgencyService; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -65,14 +66,19 @@ public class AgencyServiceImpl implements AgencyService { entity.setOrganizationName(formDTO.getAgencyName()); entity.setTotalUser(NumConstant.ZERO); //1:查询上级机关信息 - CustomerAgencyEntity parentEntity = customerAgencyDao.selectById(formDTO.getPid()); + CustomerAgencyEntity parentEntity = customerAgencyDao.selectById(formDTO.getParentAgencyId()); + if (null == parentEntity) { + log.error(CustomerAgencyConstant.SAVE_EXCEPTION); + throw new RenException(CustomerAgencyConstant.SAVE_EXCEPTION); + } + entity.setPid(parentEntity.getId()); entity.setCustomerId(parentEntity.getCustomerId()); - if (null == parentEntity.getPid()) { + if (StringUtils.isBlank(parentEntity.getPid())) { entity.setPids(parentEntity.getId()); entity.setAllParentName(parentEntity.getOrganizationName()); } else { - entity.setPids(":" + parentEntity.getId()); - entity.setAllParentName("-" + parentEntity.getOrganizationName()); + entity.setPids(parentEntity.getPids()+":" + parentEntity.getId()); + entity.setAllParentName(parentEntity.getAllParentName()+"-" + parentEntity.getOrganizationName()); } //2:保存组织信息 if (customerAgencyDao.insert(entity) < NumConstant.ONE) { @@ -121,7 +127,14 @@ public class AgencyServiceImpl implements AgencyService { result.setMsg(EpmetErrorCode.NOT_DEL_AGENCY.getMsg()); return result; } - //2:删除当前机关组织(逻辑删) + //2:不存在下级机关,本级存在工作人员的不能删除 + CustomerAgencyEntity entity = customerAgencyDao.selectById(formDTO.getAgencyId()); + if (null != entity && entity.getTotalUser() > NumConstant.ZERO) { + result.setCode(EpmetErrorCode.NOT_DEL_AGENCY_PER.getCode()); + result.setMsg(EpmetErrorCode.NOT_DEL_AGENCY_PER.getMsg()); + return result; + } + //3:删除当前机关组织(逻辑删) if (customerAgencyDao.deleteById(formDTO.getAgencyId()) < NumConstant.ONE) { log.error(CustomerAgencyConstant.DEL_EXCEPTION); throw new RenException(CustomerAgencyConstant.DEL_EXCEPTION); diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerDepartmentDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerDepartmentDao.xml index 7543fe31f6..932f7f66d3 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerDepartmentDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerDepartmentDao.xml @@ -3,20 +3,27 @@ - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index c499eb62e7..1ae28a3d14 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -186,7 +186,7 @@ public class CustomerStaffController { * @Description 根据客户Id及userId集合查询用户基本信息 */ @PostMapping("getdepartmentstafflist") - public Result> getDepartmentStaffList(DepartmentInStaffFormDTO fromDTO) { + public Result> getDepartmentStaffList(@RequestBody DepartmentInStaffFormDTO fromDTO) { return customerStaffService.getDepartmentStaffList(fromDTO); } From 63e16b80d9fa0e958d1c85b929b855bafcc45c52 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Sun, 26 Apr 2020 16:46:46 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E7=BB=84=E7=BB=87-=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=20bug?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/exception/EpmetErrorCode.java | 6 +- .../epmet/dto/form/StaffSubmitFromDTO.java | 4 ++ .../com/epmet/feign/EpmetUserFeignClient.java | 2 +- .../EpmetUserFeignClientFallBack.java | 2 +- .../epmet/service/impl/StaffServiceImpl.java | 56 ++++++++++++--- .../controller/CustomerStaffController.java | 70 ++++++++++++++++++- .../epmet/service/CustomerStaffService.java | 2 +- .../impl/CustomerStaffServiceImpl.java | 64 +++++++++++------ .../resources/mapper/CustomerStaffDao.xml | 38 ++++++---- 9 files changed, 193 insertions(+), 51 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index f84dfde45f..5dbc9f0cf2 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -34,8 +34,10 @@ public enum EpmetErrorCode { REQUIRE_PERMISSION(8301, "没有足够的操作权限"), - NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"); - + NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"), + MOBILE_USED(8402,"该手机号已注册"), + STAFF_ADD_FAILED(8403,"人员添加失败"), + STAFF_EDIT_FAILED(8404,"人员编辑失败"); private int code; private String msg; diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java index 87ffa6f26b..0f368af813 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java @@ -16,6 +16,10 @@ import java.util.List; @Data public class StaffSubmitFromDTO implements Serializable { private static final long serialVersionUID = 1L; + /** + * 客户ID + */ + private String customerId; /** * 机关ID */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 1d52e9072d..d8a404d782 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -96,7 +96,7 @@ public interface EpmetUserFeignClient { * @return Result */ @PostMapping("/epmetuser/customerstaff/addstaff") - Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO); + Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO); /** * 人员编辑 diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java index 29986d388f..20255d3962 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java @@ -68,7 +68,7 @@ public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient { } @Override - public Result addStaff(StaffSubmitFromDTO fromDTO) { + public Result addStaff(StaffSubmitFromDTO fromDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "addStaff", fromDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java index db4e263508..dcdb8087f7 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java @@ -1,8 +1,10 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.CustomerStaffAgencyDTO; +import com.epmet.dto.CustomerStaffDTO; import com.epmet.dto.form.StaffInfoFromDTO; import com.epmet.dto.form.StaffSubmitFromDTO; import com.epmet.dto.form.StaffsInAgencyFromDTO; @@ -11,6 +13,7 @@ import com.epmet.dto.result.StaffInfoResultDTO; import com.epmet.dto.result.StaffInitResultDTO; import com.epmet.dto.result.StaffsInAgencyResultDTO; import com.epmet.entity.CustomerAgencyEntity; +import com.epmet.entity.CustomerStaffAgencyEntity; import com.epmet.feign.EpmetUserFeignClient; import com.epmet.feign.OperCrmFeignClient; import com.epmet.service.CustomerAgencyService; @@ -18,7 +21,9 @@ import com.epmet.service.CustomerStaffAgencyService; import com.epmet.service.StaffService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -43,11 +48,17 @@ public class StaffServiceImpl implements StaffService { StaffsInAgencyResultDTO resultDTO = new StaffsInAgencyResultDTO(); //获取机关所在客户ID和人员总数 CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + if (null == customerAgencyEntity) { + resultDTO.setStaffList(new ArrayList<>()); + resultDTO.setStaffCount(0); + return new Result().ok(resultDTO); + } resultDTO.setStaffCount(customerAgencyEntity.getTotalUser()); fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); List customerStaffAgencyList = customerStaffAgencyService.getCustomerStaffAgencyList(fromDTO).getData(); if (null == customerStaffAgencyList || customerStaffAgencyList.size() == 0) { - return new Result().ok(null); + resultDTO.setStaffList(new ArrayList<>()); + return new Result().ok(resultDTO); } //提取所有userID List staffIds = customerStaffAgencyList.stream().map(CustomerStaffAgencyDTO::getUserId).collect(Collectors.toList()); @@ -62,6 +73,9 @@ public class StaffServiceImpl implements StaffService { public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { //获取机关所在客户ID CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + if (null == customerAgencyEntity) { + return new Result>().ok(new ArrayList<>()); + } fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); List customerStaffAgencyList = customerStaffAgencyService.getCustomerStaffAgencyList(fromDTO).getData(); if (null == customerStaffAgencyList || customerStaffAgencyList.size() == 0) { @@ -71,8 +85,7 @@ public class StaffServiceImpl implements StaffService { List staffIds = customerStaffAgencyList.stream().map(CustomerStaffAgencyDTO::getUserId).collect(Collectors.toList()); fromDTO.setStaffList(staffIds); //获取用户列表 - Result> staffInfoListResult = epmetUserFeignClient.getStaffInfoForHome(fromDTO); - return null; + return epmetUserFeignClient.getStaffList(fromDTO); } @Override @@ -90,24 +103,47 @@ public class StaffServiceImpl implements StaffService { } @Override + @Transactional(rollbackFor = Exception.class) public Result addStaff(TokenDto tokenDto, StaffSubmitFromDTO fromDTO) { + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); fromDTO.setApp(tokenDto.getApp()); fromDTO.setClient(tokenDto.getClient()); - Result result = epmetUserFeignClient.addStaff(fromDTO); - //机关总人数加一 - if (result.success()) { - CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); - customerAgencyEntity.setTotalUser(customerAgencyEntity.getTotalUser() + 1); - customerAgencyService.updateById(customerAgencyEntity); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + Result result = epmetUserFeignClient.addStaff(fromDTO); + + if (!result.success()) { + if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { + return new Result().error(result.getCode(), result.getMsg()); + } + return new Result().error(EpmetErrorCode.STAFF_ADD_FAILED.getCode(), EpmetErrorCode.STAFF_ADD_FAILED.getMsg()); } + //人员机关关系表 + CustomerStaffAgencyEntity customerStaffAgencyEntity = new CustomerStaffAgencyEntity(); + customerStaffAgencyEntity.setCustomerId(customerAgencyEntity.getCustomerId()); + customerStaffAgencyEntity.setUserId(result.getData().getUserId()); + customerStaffAgencyEntity.setAgencyId(customerAgencyEntity.getId()); + customerStaffAgencyService.insert(customerStaffAgencyEntity); + //机关总人数加一 + customerAgencyEntity.setTotalUser(customerAgencyEntity.getTotalUser() + 1); + customerAgencyService.updateById(customerAgencyEntity); return new Result(); } @Override public Result editStaff(TokenDto tokenDto, StaffSubmitFromDTO fromDTO) { + CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); + fromDTO.setApp(tokenDto.getApp()); fromDTO.setClient(tokenDto.getClient()); - return epmetUserFeignClient.editStaff(fromDTO); + Result result = epmetUserFeignClient.editStaff(fromDTO); + if (!result.success()) { + if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { + return new Result().error(result.getCode(), result.getMsg()); + } + return new Result().error(EpmetErrorCode.STAFF_EDIT_FAILED.getCode(), EpmetErrorCode.STAFF_EDIT_FAILED.getMsg()); + } + return result; } @Override diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index 1ae28a3d14..cdc627dcc8 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -155,7 +155,7 @@ public class CustomerStaffController { * @return */ @PostMapping("staffsinagency") - public Result> getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { + public Result> getStaffInfoForHome(@RequestBody StaffsInAgencyFromDTO fromDTO) { return customerStaffService.getStaffInfoForHome(fromDTO); } @@ -165,7 +165,7 @@ public class CustomerStaffController { * @return */ @PostMapping("stafflist") - public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { + public Result> getStaffList(@RequestBody StaffsInAgencyFromDTO fromDTO) { return customerStaffService.getStaffList(fromDTO); } @@ -194,4 +194,70 @@ public class CustomerStaffController { public Result> selectCustomerIdByUserId(@RequestBody AddDepartmentStaffFormDTO addDepartmentStaffFormDTO){ return customerStaffService.selectCustomerIdByUserId(addDepartmentStaffFormDTO); } + + /** + * 人员添加页面初始化 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("rolelist") + public Result addStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.addStaffInit(fromDTO); + } + + /** + * 人员编辑页面初始化 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("editstaffinit") + public Result editStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.editStaffInit(fromDTO); + } + + /** + * 人员添加 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("addstaff") + public Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO){ + return customerStaffService.addStaff(fromDTO); + } + + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("editstaff") + public Result editStaff(@RequestBody StaffSubmitFromDTO fromDTO){ + return customerStaffService.editStaff(fromDTO); + } + + /** + * 人员详情 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("staffdetail") + public Result getStaffDetail(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.getStaffDetail(fromDTO); + } + + /** + * 人员禁用 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("disabledstaff") + public Result disabledStaff(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.disabledStaff(fromDTO); + } } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index 92f6779396..924c85d2f2 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -173,7 +173,7 @@ public interface CustomerStaffService extends BaseService { * @param fromDTO 参数 * @return Result */ - Result addStaff(StaffSubmitFromDTO fromDTO); + Result addStaff(StaffSubmitFromDTO fromDTO); /** * 人员编辑 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index d6a76ac6f9..799ab62d71 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -61,6 +61,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -84,6 +85,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl page(Map params) { IPage page = baseDao.selectPage( @@ -178,12 +180,18 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl> getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { List list = baseDao.selectCustomerStaffList(fromDTO); + if (null == list) { + list = new ArrayList<>(); + } return new Result>().ok(list); } @Override public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { List list = baseDao.selectStaffList(fromDTO); + if (null == list) { + list = new ArrayList<>(); + } return new Result>().ok(list); } @@ -194,7 +202,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl roleList = govStaffRoleService.getGovStaffRoleList(govStaffRoleDTO); if (null == roleList || roleList.size() == 0) { - return new Result().ok(null); + return new Result().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); } List staffRoleList = roleList.stream().map(p -> { StaffRoleResultDTO staffRoleResultDTO = new StaffRoleResultDTO(); @@ -245,7 +253,14 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl addStaff(StaffSubmitFromDTO fromDTO) { + CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); + customerStaffFormDTO.setCustomerId(fromDTO.getCustomerId()); + customerStaffFormDTO.setMobile(fromDTO.getMobile()); + CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(customerStaffFormDTO); + if (null != customerStaffDTO) { + return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + } //USER表插入数据 UserEntity userEntity = new UserEntity(); userEntity.setFromApp(fromDTO.getApp()); @@ -253,6 +268,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().ok(ConvertUtils.sourceToTarget(staffEntity, CustomerStaffDTO.class)); } @Override @Transactional(rollbackFor = Exception.class) public Result editStaff(StaffSubmitFromDTO fromDTO) { + CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); + customerStaffFormDTO.setCustomerId(fromDTO.getCustomerId()); + customerStaffFormDTO.setMobile(fromDTO.getMobile()); + CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(customerStaffFormDTO); + if (!fromDTO.getStaffId().equals(customerStaffDTO.getUserId())) { + return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + } + CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); //Customer_Staff表插入数据 CustomerStaffEntity staffEntity = new CustomerStaffEntity(); @@ -334,18 +358,19 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl selectGridStaffCountByUserId(List userIdDTO) { - Result gridStaffCountDTOResult = new Result(); - GridStaffCountDTO gridStaffCountDTO = baseDao.selectGridStaffCountByUserId(userIdDTO); - gridStaffCountDTOResult.setData(gridStaffCountDTO); - return gridStaffCountDTOResult; - } + /** + * 根据userId查询网格下未被禁用的人员数量 + * + * @param userIdDTO + * @return + */ + @Override + public Result selectGridStaffCountByUserId(List userIdDTO) { + Result gridStaffCountDTOResult = new Result(); + GridStaffCountDTO gridStaffCountDTO = baseDao.selectGridStaffCountByUserId(userIdDTO); + gridStaffCountDTOResult.setData(gridStaffCountDTO); + return gridStaffCountDTOResult; + } @Override public Result> getDepartmentStaffList(DepartmentInStaffFormDTO formDTO) { @@ -364,11 +389,10 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl>().ok(staffList); } - /** - * - * @param: addDepartmentStaffFormDTO - * @auther: zxc - */ + /** + * @param: addDepartmentStaffFormDTO + * @auther: zxc + */ @Override public Result> selectCustomerIdByUserId(AddDepartmentStaffFormDTO addDepartmentStaffFormDTO) { return new Result>().ok(baseDao.selectCustomerIdByUserId(addDepartmentStaffFormDTO)); diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml index 9335d663bd..828aa05c1d 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml @@ -59,29 +59,39 @@ @@ -111,7 +121,7 @@ #{userId} - ORDER BY convert(cs.REAL_NAME using gbk) asc ASC + ORDER BY convert(cs.REAL_NAME using gbk) ASC