Преглед на файлове

【BUG】#268 中心领导查询车间问题

zhaomn преди 3 години
родител
ревизия
117cda04f7
променени са 1 файла, в които са добавени 39 реда и са изтрити 7 реда
  1. 39 7
      railway-business/src/main/java/com/railway/business/baseinfo/service/impl/BaseStationServiceImpl.java

+ 39 - 7
railway-business/src/main/java/com/railway/business/baseinfo/service/impl/BaseStationServiceImpl.java

@@ -9,11 +9,16 @@ import com.railway.business.baseinfo.mapper.BaseStationMapper;
 import com.railway.business.baseinfo.service.IBaseStationService;
 import com.railway.business.catenary.domain.vo.JcebQueryVo;
 import com.railway.business.catenary.domain.vo.JcebStationVo;
+import com.railway.common.core.domain.entity.SysRole;
+import com.railway.common.core.domain.entity.SysUser;
 import com.railway.common.enums.DelFlagEnum;
 import com.railway.common.utils.SecurityUtils;
+import com.railway.common.utils.StringUtils;
 import com.railway.common.utils.bean.BeanUtils;
+import com.railway.framework.aspectj.DataScopeAspect;
 import java.util.Date;
 import java.util.List;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -24,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
  * @author author
  * @date 2021/10/16
  */
+@Slf4j
 @Service
 @Transactional(readOnly = true)
 public class BaseStationServiceImpl implements IBaseStationService {
@@ -83,9 +89,9 @@ public class BaseStationServiceImpl implements IBaseStationService {
     return rows;
   }
 
-  private void saveDeptStation(List<BaseDeptStation> deptStations, Long stationId){
-    if(CollectionUtils.isNotEmpty(deptStations)){
-      for(BaseDeptStation baseDeptStation : deptStations){
+  private void saveDeptStation(List<BaseDeptStation> deptStations, Long stationId) {
+    if (CollectionUtils.isNotEmpty(deptStations)) {
+      for (BaseDeptStation baseDeptStation : deptStations) {
         baseDeptStation.setDelFlag(DelFlagEnum.NOT_DELETE.getCode());
         baseDeptStation.setStationId(stationId);
         baseDeptStation.setCreateTime(new Date());
@@ -101,7 +107,7 @@ public class BaseStationServiceImpl implements IBaseStationService {
   @Override
   public BaseStationVo getInfo(Long stationId) {
     BaseStationVo station = baseStationMapper.getInfo(stationId);
-    if(null == station){
+    if (null == station) {
       return null;
     }
     setBaseStation(station);
@@ -118,7 +124,7 @@ public class BaseStationServiceImpl implements IBaseStationService {
    */
   @Override
   public BaseDeptStation getInfo(Long deptId, Long lineId, Long stationId) {
-    if(null == deptId){
+    if (null == deptId) {
       deptId = SecurityUtils.getDeptId();
     }
     BaseStationQuery query = new BaseStationQuery();
@@ -134,13 +140,13 @@ public class BaseStationServiceImpl implements IBaseStationService {
   @Override
   public List<BaseStationVo> getDetailList(BaseStationQuery query) {
     List<BaseStationVo> stations = baseStationMapper.getList(query);
-    for(BaseStationVo station : stations){
+    for (BaseStationVo station : stations) {
       setBaseStation(station);
     }
     return stations;
   }
 
-  private void setBaseStation(BaseStationVo station){
+  private void setBaseStation(BaseStationVo station) {
     List<BaseDeptStation> deptStations = deptStationMapper.getList(station.getStationId());
     station.setDeptStations(deptStations);
   }
@@ -150,6 +156,32 @@ public class BaseStationServiceImpl implements IBaseStationService {
    */
   @Override
   public List<BaseStation> getListByDeptId(BaseStationQuery query) {
+    SysUser user = SecurityUtils.getLoginUser().getUser();
+    if (user.isAdmin()) {
+      query.setDeptId(null);
+    } else {
+      String dataScope = DataScopeAspect.DATA_SCOPE_SELF;
+      List<SysRole> roles = user.getRoles();
+      if (null != roles) {
+        for (SysRole role : roles) {
+          if (StringUtils.isNotEmpty(role.getDataScope())) {
+            // 数据范围,取最小的。(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限)
+            if (dataScope.compareTo(role.getDataScope()) > 0) {
+              dataScope = role.getDataScope();
+            }
+          }
+        }
+      }
+      // 车间职工、未提交的,都只能查看自己创建的
+      if (null == dataScope || dataScope.equals(DataScopeAspect.DATA_SCOPE_SELF)
+          || dataScope.equals(DataScopeAspect.DATA_SCOPE_DEPT)) {
+        log.debug("^_^ 车间职工、车间领导只能查看自己车间的 ^_^");
+        query.setDeptId(user.getDeptId());
+      } else if (dataScope.equals(DataScopeAspect.DATA_SCOPE_ALL)) {
+        log.debug("^_^ 中心领导查询所有车间 ^_^");
+        query.setDeptId(null);
+      }
+    }
     return baseStationMapper.getStationList(query);
   }