Procházet zdrojové kódy

数据隔离权限处理

oyq28 před 3 roky
rodič
revize
784d8b9738

+ 2 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/classSchedule/dao/ScheduleUserChangeMapper.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.github.zuihou.base.mapper.SuperMapper;
 import com.github.zuihou.business.classSchedule.entity.ScheduleUserChange;
 
+import com.github.zuihou.database.mybatis.auth.DataScope;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -24,5 +25,5 @@ public interface ScheduleUserChangeMapper extends SuperMapper<ScheduleUserChange
     /**
      * 分页
      */
-    IPage<ScheduleUserChange> pageList(IPage page, @Param(Constants.WRAPPER) Wrapper<ScheduleUserChange> queryWrapper);
+    IPage<ScheduleUserChange> pageList(IPage page, @Param(Constants.WRAPPER) Wrapper<ScheduleUserChange> queryWrapper, DataScope dataScope);
 }

+ 2 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/classSchedule/service/impl/ScheduleUserChangeServiceImpl.java

@@ -17,6 +17,7 @@ import com.github.zuihou.business.classSchedule.service.ScheduleUserChangeServic
 import com.github.zuihou.base.service.SuperServiceImpl;
 
 import com.github.zuihou.business.classSchedule.service.ScheduleUserDateService;
+import com.github.zuihou.database.mybatis.auth.DataScope;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.injection.annonation.InjectionResult;
@@ -61,7 +62,7 @@ public class ScheduleUserChangeServiceImpl extends SuperServiceImpl<ScheduleUser
     // 启用属性自动注入
     @InjectionResult
     public IPage<ScheduleUserChange> pageList(IPage page, LbqWrapper<ScheduleUserChange> wrapper) {
-        return baseMapper.pageList(page, wrapper);
+        return baseMapper.pageList(page, wrapper, new DataScope());
     }
 
     @Override

+ 30 - 0
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/classSchedule/ScheduleMonthController.java

@@ -1,5 +1,12 @@
 package com.github.zuihou.business.controller.classSchedule;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.zuihou.authority.dto.auth.UserPageDTO;
+import com.github.zuihou.authority.entity.auth.User;
+import com.github.zuihou.authority.service.auth.UserService;
+import com.github.zuihou.base.request.PageParams;
 import com.github.zuihou.business.classSchedule.entity.ScheduleMonth;
 import com.github.zuihou.business.classSchedule.dto.ScheduleMonthSaveDTO;
 import com.github.zuihou.business.classSchedule.dto.ScheduleMonthUpdateDTO;
@@ -10,9 +17,13 @@ import java.util.Map;
 import java.util.stream.Collectors;
 import com.github.zuihou.base.controller.SuperController;
 import com.github.zuihou.base.R;
+import com.github.zuihou.context.BaseContextHandler;
+import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.compress.utils.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -38,6 +49,9 @@ import org.springframework.web.bind.annotation.RestController;
 //@PreAuth(replace = "scheduleMonth:")
 public class ScheduleMonthController extends SuperController<ScheduleMonthService, Long, ScheduleMonth, ScheduleMonthPageDTO, ScheduleMonthSaveDTO, ScheduleMonthUpdateDTO> {
 
+    @Autowired
+    private UserService userService;
+
     /**
      * 添加
      * @param scheduleMonthSaveDTO
@@ -49,6 +63,22 @@ public class ScheduleMonthController extends SuperController<ScheduleMonthServic
         return success(scheduleMonth);
     }
 
+    @Override
+    public void query(PageParams<ScheduleMonthPageDTO> params, IPage<ScheduleMonth> page, Long defSize) {
+        ScheduleMonth model = BeanUtil.toBean(params.getModel(),ScheduleMonth.class);
+        QueryWrap<ScheduleMonth> wrapper = this.handlerWrapper(model, params);
+        BaseContextHandler.setTenant("0000");
+        Long userId = BaseContextHandler.getUserId();
+        Map<String, Object> orgMap = userService.getDataScopeById(userId);
+        List<Long> orgIds = orgMap.containsKey("orgIds")? (List)orgMap.get("orgIds") : Lists.newArrayList();
+        if(CollectionUtil.isNotEmpty(orgIds)){
+            wrapper.in("org_id", orgIds);
+        }
+        baseService.page(page, wrapper);
+    }
+
+
+
     @ApiOperation(value = "修改排班月份", notes = "修改排班月份")
     @PostMapping("/update")
     public R<ScheduleMonth> update(ScheduleMonthUpdateDTO model) {