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

线边库监控数据权限过滤处理

oyq28 преди 3 години
родител
ревизия
c2a4cc720b

+ 2 - 2
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/edgeLibrary/dao/StockInfoMapper.java

@@ -32,7 +32,7 @@ public interface StockInfoMapper extends SuperMapper<StockInfo> {
      * 根据货架(层)查询库存数量
      * @return
      */
-    List<Map> getStockCountByShelves();
+    List<Map> getStockCountByShelves(Map paramsMap);
     List<Map>getStockCountByStorgeId();
     List<Map> getGoodsList();
 
@@ -41,7 +41,7 @@ public interface StockInfoMapper extends SuperMapper<StockInfo> {
      */
     IPage<StockInfo> selectPageList(IPage page,@Param("brandName")String brandName,@Param("brandNo")String brandNo,@Param("specification")String specification, @Param(Constants.WRAPPER) Wrapper<StockInfo> queryWrapper);
 
-    Map getCount();
+    Map getCount(Map map);
 
     List<StockInfo>getListBySpecId(Map map);
 

+ 18 - 3
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/edgeLibrary/service/impl/StockInfoServiceImpl.java

@@ -3,6 +3,8 @@ package com.github.zuihou.business.edgeLibrary.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.zuihou.authority.entity.auth.User;
 import com.github.zuihou.base.R;
 import com.github.zuihou.base.service.SuperServiceImpl;
 import com.github.zuihou.business.DemoLine.DemoLineConstant;
@@ -23,6 +25,7 @@ import com.github.zuihou.business.productionReadyCenter.service.MToolMeterialSer
 import com.github.zuihou.business.productionReadyCenter.service.MToolMeterialSpecsService;
 import com.github.zuihou.business.productionReadyCenter.service.TrayService;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
+import com.github.zuihou.business.util.CommonUtil;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.CodeRuleModule;
 import com.github.zuihou.common.util.StringUtil;
@@ -32,7 +35,9 @@ import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.injection.annonation.InjectionResult;
 import com.github.zuihou.tenant.service.CodeRuleService;
 import com.github.zuihou.utils.BeanPlusUtil;
+import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -126,8 +131,13 @@ public class StockInfoServiceImpl extends SuperServiceImpl<StockInfoMapper, Stoc
     public Map iconList(Map map) {
         Map returnMap = new HashMap();
 
+        String orgIdsStr = CommonUtil.getOrgIdsStr();
+        Map paramsMap = Maps.newHashMap();
+        if(StringUtil.isNotEmpty(orgIdsStr)) {
+            paramsMap.put("orgIds", orgIdsStr);
+        }
         //根据货架查询里面数量
-        List<Map> shelvesStockCountlist = baseMapper.getStockCountByShelves();
+        List<Map> shelvesStockCountlist = baseMapper.getStockCountByShelves(paramsMap);
         Map<Long,Map>shelvesStockCountMap = new HashMap<Long,Map>();
         //获取库位的库存数量,判断是否为空库存
         List<Map> storgeStockCountlist= baseMapper.getStockCountByStorgeId();
@@ -142,7 +152,12 @@ public class StockInfoServiceImpl extends SuperServiceImpl<StockInfoMapper, Stoc
         }
 
         //查询出所有货架
-        List<Storge> storgeList= storgeService.list(Wraps.<Storge>lbQ().orderByAsc(Storge::getWeight));
+        /*
+        LbqWrapper<Storge> query = Wraps.<Storge>lbQ()
+                .in(User::getId, idList)
+                .eq(User::getStatus, true); */
+        IPage<Storge> pages = storgeService.pageList(new Page<Storge>(1L, 50), Wraps.<Storge>lbQ().orderByAsc(Storge::getWeight));
+        List<Storge> storgeList= pages!=null? pages.getRecords(): Lists.newArrayList();
         //查询所有的库位
         Map<Long,List<Map>>storgeMap = new HashMap<Long,List<Map>>();
         for(Storge storge:storgeList){
@@ -191,7 +206,7 @@ public class StockInfoServiceImpl extends SuperServiceImpl<StockInfoMapper, Stoc
         }
         returnMap.put("shelvesTreeList",shelvesMapTreeList);
 
-        Map countMap = baseMapper.getCount();
+        Map countMap = baseMapper.getCount(paramsMap);
         Integer shelvesCount = 0;
         Integer storgeCount = 0;
         Integer instockCount = 0;

+ 31 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/util/CommonUtil.java

@@ -1,6 +1,11 @@
 package com.github.zuihou.business.util;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
+import com.github.zuihou.authority.service.auth.UserService;
+import com.github.zuihou.business.edgeLibrary.service.StockInfoService;
+import com.github.zuihou.context.BaseContextHandler;
+import org.apache.commons.compress.utils.Lists;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -30,4 +35,30 @@ public class CommonUtil {
         }
         return titleList;
     }
+
+    /**
+     * 获取当前用户部门ID范围(数组格式)
+     * @param
+     * @return
+     */
+    public static List<Long> getOrgIdsArr(){
+        //机构部门数据权限判断验证
+        BaseContextHandler.setTenant("0000");
+        Long userId = BaseContextHandler.getUserId();
+        UserService userService = (UserService)MsgUtil.getBean(UserService.class);
+        //获取用户权限访问机构
+        Map<String, Object> orgMap = userService.getDataScopeById(userId);
+        List<Long> orgIds = orgMap.containsKey("orgIds")? (List)orgMap.get("orgIds") : Lists.newArrayList();
+        return orgIds;
+    }
+
+    /**
+     * 获取当前用户部门ID范围(字符串格式)
+     * @param
+     * @return
+     */
+    public static String getOrgIdsStr(){
+        List<Long> orgIds = getOrgIdsArr();
+        return CollectionUtil.isNotEmpty(orgIds)? CollectionUtil.join(orgIds, ",") : "";
+    }
 }

+ 32 - 9
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/edgeLibrary/StockInfoMapper.xml

@@ -87,9 +87,9 @@
     </select>
 
     <!-- 统计货架里数量 -->
-    <select id="getStockCountByShelves"  resultType="map">
+    <select id="getStockCountByShelves" parameterType="map" resultType="map">
         SELECT
-            s1.parent_id id,
+            b.parent_id id,
             ifnull(count( s.id),0) allCount,
             ifnull(sum( case when LENGTH(i.id) >0 then 1 else 0 end ),0)stockCount,
             ifnull(count( s.id),0) - ifnull(sum( case when LENGTH(i.id) >0 then 1 else 0 end ),0)freeCount,
@@ -97,8 +97,16 @@
         FROM
             imcs_s_storge s
         LEFT JOIN imcs_s_stock_info i ON s.id = i.storge_id
-        LEFT JOIN imcs_s_shelves s1 ON s.shelves_id = s1.id
-        GROUP BY s1.parent_id
+        LEFT JOIN (
+            SELECT  h.id, h.parent_id, h.name as bname, h1.name as aname, h1.status
+            FROM imcs_s_shelves h LEFT JOIN imcs_s_shelves h1 ON h.parent_id = h1.id
+        ) b ON s.shelves_id = b.id
+        LEFT JOIN imcs_z_zone z ON Locate(z.abbreviate, b.aname)
+        where b.status = 1
+        <if test="orgIds != null and orgIds != ''">
+            and z.org_id in (${orgIds})
+        </if>
+        GROUP BY b.parent_id
     </select>
 
     <!-- 获取库位的库存数量,判断是否为空库存 -->
@@ -146,17 +154,32 @@
         select sum(shelvesCount) as shelvesCount,sum(storgeCount) as storgeCount,sum(instockCount) as instockCount,
         (sum(storgeCount)-sum(instockCount)) as freestockCount,sum(lockstockCount) as lockstockCount from (
             -- 货架
-            select count(1) as shelvesCount,0 as storgeCount,0 as instockCount,0 as lockstockCount from imcs_s_shelves where type= '1'
+            select count(1) as shelvesCount,0 as storgeCount,0 as instockCount,0 as lockstockCount from (select s.name, z.org_id from imcs_s_shelves s left join imcs_z_zone z on locate(z.abbreviate, s.name) where s.type= '1' and s.status= '1'
+            <if test="orgIds != null and orgIds != ''">
+                and z.org_id in (${orgIds})
+            </if>
+            group by s.id  ) v
             union all
             -- 库位
-            select 0 as shelvesCount,count(1) as storgeCount,0 as instockCount,0 as lockstockCount from imcs_s_storge
+            select 0 as shelvesCount,count(1) as storgeCount,0 as instockCount,0 as lockstockCount from imcs_s_storge s  LEFT JOIN ( SELECT  h.id, h.parent_id, h.name as bname, h1.name as aname, h1.status as storgeStatus FROM imcs_s_shelves h LEFT JOIN imcs_s_shelves h1 ON h.parent_id = h1.id
+            ) b ON s.shelves_id = b.id LEFT JOIN imcs_z_zone z ON Locate(z.abbreviate, b.aname) where b.storgeStatus = 1
+            <if test="orgIds != null and orgIds != ''">
+                and z.org_id in (${orgIds})
+            </if>
             union all
             -- 已存库位
-            select 0 as shelvesCount,0 as storgeCount,count(1) as instockCount,0 as lockstockCount from imcs_s_storge where id in(select storge_id from imcs_s_stock_info)
+            select 0 as shelvesCount,0 as storgeCount,count(1) as instockCount,0 as lockstockCount from imcs_s_storge s LEFT JOIN ( SELECT  h.id, h.parent_id, h.name as bname, h1.name as aname, h1.status as instockStatus FROM imcs_s_shelves h LEFT JOIN imcs_s_shelves h1 ON h.parent_id = h1.id
+            ) b ON s.shelves_id = b.id LEFT JOIN imcs_z_zone z ON Locate(z.abbreviate, b.aname) where s.id in (select storge_id from imcs_s_stock_info) and b.instockStatus = 1
+            <if test="orgIds != null and orgIds != ''">
+                and z.org_id in (${orgIds})
+            </if>
             union all
             -- 锁定库位
-            select 0 as shelvesCount,0 as storgeCount,0 as instockCount,count(1) as lockstockCount
-            from imcs_s_storge where lock_status = '0'
+            select 0 as shelvesCount,0 as storgeCount,0 as instockCount,count(1) as lockstockCount from imcs_s_storge s LEFT JOIN ( SELECT  h.id, h.parent_id, h.name as bname, h1.name as aname, h1.status as lockStaus FROM imcs_s_shelves h LEFT JOIN imcs_s_shelves h1 ON h.parent_id = h1.id
+            ) b ON s.shelves_id = b.id LEFT JOIN imcs_z_zone z ON Locate(z.abbreviate, b.aname) where s.lock_status = '0' and b.lockStaus
+            <if test="orgIds != null and orgIds != ''">
+                and z.org_id in (${orgIds})
+            </if>
         )r
     </select>
 

+ 8 - 3
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/edgeLibrary/StorgeMapper.xml

@@ -21,7 +21,7 @@
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
         id,create_time,update_user,create_user,update_time,
-        shelves_id, storge_type_id, no, name, status,weight,storgeTypeDesc,storgeNum,lock_status
+        shelves_id, storge_type_id, no, name, status,weight,storgeTypeDesc,storgeNum,lock_status,org_id
     </sql>
 
     <select id="storgeCount" parameterType="com.github.zuihou.business.edgeLibrary.entity.Storge" resultType="Integer">
@@ -38,10 +38,15 @@
         select
         <include refid="Base_Column_List"/>
         from (
-            select a.*,b.name as storgeTypeDesc,ifnull(c.storgeNum,0) as storgeNum from imcs_s_storge a
+            select a.*,b.name as storgeTypeDesc,ifnull(c.storgeNum,0) as storgeNum, z.org_id from imcs_s_storge a
             left join imcs_s_storge_type b on a.storge_type_id = b.id
             left join (select storge_id,count(1) as storgeNum from imcs_s_stock_info group by storge_id) c on a.id=c.storge_id
-        ) s ${ew.customSqlSegment}
+            LEFT JOIN (
+                SELECT  h.id, h.parent_id, h1.name as aname, h1.status
+                FROM imcs_s_shelves h LEFT JOIN imcs_s_shelves h1 ON h.parent_id = h1.id
+            ) d ON a.shelves_id = d.id
+            LEFT JOIN imcs_z_zone z ON Locate(z.abbreviate, d.aname)
+            ) s ${ew.customSqlSegment}
     </select>