Browse Source

申购、待采购、已采购页面数据隔离

yzc 1 năm trước cách đây
mục cha
commit
7a1b5490e6

+ 61 - 64
hx-purchase/src/main/java/com/fjhx/purchase/service/purchase/impl/PurchaseServiceImpl.java

@@ -217,11 +217,11 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
         Set<String> permissionList = sysRoleService.selectRolePermissionByUserId(SecurityUtils.getUserId());
         DynamicDataSourceContextHolder.poll();
         if (ObjectUtil.isNotEmpty(permissionList)) {
-            //if当前用户的角色 in [运营专员, 运营助理] 页面仅展示产品.管理部门 == 当前用户所在部门的相关数据
+            //if当前用户的角色 in [运营专员, 运营助理] 页面仅展示产品.管理部门 == 当前用户所在部门或下级部门的相关数据
             if (permissionList.contains("E-commerce operation") || permissionList.contains("Operation assistant")) {
-                Long userDeptId = SecurityUtils.getDeptId();
-                String userDeptIdStr = ObjectUtil.isNotEmpty(userDeptId) ? userDeptId.toString() : "";
-                wrapper.eq("json_unquote( pi.victoriatourist_json -> '$.deptId' )", userDeptIdStr);
+                wrapper.and(q -> q.eq("de.dept_id", SecurityUtils.getDeptId())
+                        .or()
+                        .like("de.ancestors", SecurityUtils.getDeptId()));
             }
         }
 
@@ -232,43 +232,68 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
             return page;
         }
 
-        if (CollectionUtils.isNotEmpty(list)) {
-            List<Long> supplyIds = list.stream().map(PurchaseVo::getSupplyId).collect(Collectors.toList());
-            List<SupplierInfo> supplierInfoList = supplierInfoService.list(Wrappers.<SupplierInfo>query().lambda().in(SupplierInfo::getId, supplyIds));
-            Map<Long, List<SupplierInfo>> supplyMap = supplierInfoList.stream().distinct().collect(Collectors.groupingBy(SupplierInfo::getId));
-            if (MapUtils.isNotEmpty(supplyMap)) {
-                for (PurchaseVo p : list) {
-                    List<SupplierInfo> supplys = supplyMap.getOrDefault(p.getSupplyId(), null);
-                    p.setSupplyName(supplys == null ? null : supplys.get(0).getName());
-                }
+        List<Long> supplyIds = list.stream().map(PurchaseVo::getSupplyId).collect(Collectors.toList());
+        List<SupplierInfo> supplierInfoList = supplierInfoService.list(Wrappers.<SupplierInfo>query().lambda().in(SupplierInfo::getId, supplyIds));
+        Map<Long, List<SupplierInfo>> supplyMap = supplierInfoList.stream().distinct().collect(Collectors.groupingBy(SupplierInfo::getId));
+        if (MapUtils.isNotEmpty(supplyMap)) {
+            for (PurchaseVo p : list) {
+                List<SupplierInfo> supplys = supplyMap.getOrDefault(p.getSupplyId(), null);
+                p.setSupplyName(supplys == null ? null : supplys.get(0).getName());
             }
         }
-        //-------------------------------------------------
-        if (CollectionUtils.isNotEmpty(list)) {
-            //维多利亚 赋值收货仓库名称
-            List<Long> wids = new ArrayList<>();
-            for (PurchaseVo purchaseVo : list) {
-                String victoriatouristJson = purchaseVo.getVictoriatouristJson();
-                if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
-                    JSONObject json = JSONObject.parseObject(victoriatouristJson);
-                    wids.add(json.getLong("receiptWarehouseId"));
-                }
+
+        //维多利亚 赋值收货仓库名称
+        List<Long> wids = new ArrayList<>();
+        for (PurchaseVo purchaseVo : list) {
+            String victoriatouristJson = purchaseVo.getVictoriatouristJson();
+            if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
+                JSONObject json = JSONObject.parseObject(victoriatouristJson);
+                wids.add(json.getLong("receiptWarehouseId"));
+            }
+        }
+        List<Warehouse> warehouses = new ArrayList<>();
+        if (ObjectUtil.isNotEmpty(wids)) {
+            warehouses = warehouseService.listByIds(wids);
+        }
+        Map<Long, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
+
+        //赋值已付款金额
+        List<Long> purchaseIds = list.stream().map(PurchaseVo::getId).collect(Collectors.toList());
+        Map<Long, List<PurchasePayRecordDetail>> PayRecordMap = purchasePayRecordDetailService.mapKGroup(PurchasePayRecordDetail::getPurchaseId,
+                q -> q.in(PurchasePayRecordDetail::getPurchaseId, purchaseIds));
+
+        //赋值退款金额
+        Map<Long, List<PurchaseRefundRecord>> refundRecordMap = purchaseRefundRecordService.mapKGroup(PurchaseRefundRecord::getPurchaseId,
+                q -> q.in(PurchaseRefundRecord::getPurchaseId, purchaseIds));
+
+        for (PurchaseVo purchaseVo : list) {
+            String victoriatouristJson = purchaseVo.getVictoriatouristJson();
+            if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
+                JSONObject json = JSONObject.parseObject(victoriatouristJson);
+                String warehouseName = warehousesMap.get(json.getLong("receiptWarehouseId"));
+                json.put("receiptWarehouseName", warehouseName);
+                purchaseVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
             }
-            if (ObjectUtils.isEmpty(wids)) {
-                return page;
+
+            //赋值已付款金额
+            List<PurchasePayRecordDetail> purchasePayRecords = PayRecordMap.get(purchaseVo.getId());
+            purchaseVo.setPaidAmount(BigDecimal.ZERO);
+            if (ObjectUtils.isNotEmpty(purchasePayRecords)) {
+                //求和已付款
+                BigDecimal paidAmount = purchasePayRecords.stream().map(PurchasePayRecordDetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+                purchaseVo.setPaidAmount(paidAmount);
             }
-            List<Warehouse> warehouses = warehouseService.listByIds(wids);
-            Map<Long, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
-            for (PurchaseVo purchaseVo : list) {
-                String victoriatouristJson = purchaseVo.getVictoriatouristJson();
-                if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
-                    JSONObject json = JSONObject.parseObject(victoriatouristJson);
-                    String warehouseName = warehousesMap.get(json.getLong("receiptWarehouseId"));
-                    json.put("receiptWarehouseName", warehouseName);
-                    purchaseVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
-                }
+
+            //赋值退款金额
+            List<PurchaseRefundRecord> purchaseRefundRecords = refundRecordMap.get(purchaseVo.getId());
+            purchaseVo.setRefundAmount(BigDecimal.ZERO);
+            if (ObjectUtils.isNotEmpty(purchaseRefundRecords)) {
+                //求和已退款
+                BigDecimal refundAmount = purchaseRefundRecords.stream().map(PurchaseRefundRecord::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+                purchaseVo.setRefundAmount(refundAmount);
             }
-            //赋值到货状态
+        }
+        //赋值到货状态
 //            List<Long> pids = list.stream().map(PurchaseVo::getId).collect(Collectors.toList());
 //            List<Arrival> arrivalList = arrivalService.list(q -> q.in(Arrival::getPurchaseId, pids));
 //            Map<Long, List<Arrival>> arrivalMap = arrivalList.stream().collect(Collectors.groupingBy(Arrival::getPurchaseId));
@@ -290,34 +315,6 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
 //                    purchaseVo.setArrivalStatus(2);
 //                }
 //            }
-        }
-        //赋值已付款金额
-        List<Long> purchaseIds = list.stream().map(PurchaseVo::getId).collect(Collectors.toList());
-        Map<Long, List<PurchasePayRecordDetail>> PayRecordMap = purchasePayRecordDetailService.mapKGroup(PurchasePayRecordDetail::getPurchaseId,
-                q -> q.in(PurchasePayRecordDetail::getPurchaseId, purchaseIds));
-        for (PurchaseVo purchaseVo : list) {
-            List<PurchasePayRecordDetail> purchasePayRecords = PayRecordMap.get(purchaseVo.getId());
-            if (ObjectUtils.isEmpty(purchasePayRecords)) {
-                purchaseVo.setPaidAmount(BigDecimal.ZERO);
-                continue;
-            }
-            //求和已付款
-            BigDecimal paidAmount = purchasePayRecords.stream().map(PurchasePayRecordDetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-            purchaseVo.setPaidAmount(paidAmount);
-        }
-        //赋值退款金额
-        Map<Long, List<PurchaseRefundRecord>> refundRecordMap = purchaseRefundRecordService.mapKGroup(PurchaseRefundRecord::getPurchaseId,
-                q -> q.in(PurchaseRefundRecord::getPurchaseId, purchaseIds));
-        for (PurchaseVo purchaseVo : list) {
-            List<PurchaseRefundRecord> purchaseRefundRecords = refundRecordMap.get(purchaseVo.getId());
-            if (ObjectUtils.isEmpty(purchaseRefundRecords)) {
-                purchaseVo.setRefundAmount(BigDecimal.ZERO);
-                continue;
-            }
-            //求和已退款
-            BigDecimal refundAmount = purchaseRefundRecords.stream().map(PurchaseRefundRecord::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-            purchaseVo.setRefundAmount(refundAmount);
-        }
 
         return page;
     }

+ 19 - 51
hx-purchase/src/main/java/com/fjhx/purchase/service/subscribe/impl/SubscribeDetailServiceImpl.java

@@ -39,7 +39,6 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.*;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 
@@ -88,17 +87,7 @@ public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMappe
             wrapper.in("t1", SubscribeDetail::getStatus, Arrays.asList(dto.getStatus().split(",")));
         }
 
-        // 如果类型存在带入类型查询
-        List<ProductInfoVo> productList = productInfoService.getListByProductType(dto.getProductType(),
-                dto.getDefinition(),
-                dto.getProductName(),
-                dto.getProductCode()
-        );
-        if (ObjectUtil.isEmpty(productList)) {
-            return new Page<>();
-        }
-        List<Long> productIds = productList.stream().map(ProductInfoVo::getId).collect(Collectors.toList());
-        wrapper.in("t1", SubscribeDetail::getBussinessId, productIds);
+        wrapper.eq("pi.definition", dto.getDefinition());
         wrapper.keyword(dto.getKeyword(),
                 new SqlField("t2", Subscribe::getCode),
                 new SqlField("pi", ProductInfo::getCustomCode),
@@ -157,11 +146,11 @@ public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMappe
         Set<String> permissionList = sysRoleService.selectRolePermissionByUserId(SecurityUtils.getUserId());
         DynamicDataSourceContextHolder.poll();
         if (ObjectUtil.isNotEmpty(permissionList)) {
-            //if当前用户的角色 in [运营专员, 运营助理] 页面仅展示产品.管理部门 == 当前用户所在部门的相关数据
+            //if当前用户的角色 in [运营专员, 运营助理] 页面仅展示产品.管理部门 == 当前用户所在部门或下级部门的相关数据
             if (permissionList.contains("E-commerce operation") || permissionList.contains("Operation assistant")) {
-                Long userDeptId = SecurityUtils.getDeptId();
-                String userDeptIdStr = ObjectUtil.isNotEmpty(userDeptId) ? userDeptId.toString() : "";
-                wrapper.eq("json_unquote( pi.victoriatourist_json -> '$.deptId' )", userDeptIdStr);
+                wrapper.and(q -> q.eq("de.dept_id", SecurityUtils.getDeptId())
+                        .or()
+                        .like("de.ancestors", SecurityUtils.getDeptId()));
             }
         }
 
@@ -172,23 +161,7 @@ public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMappe
             return page;
         }
 
-        for (SubscribeDetailVo s : list) {
-            Map<Long, ProductInfoVo> productMap = productList.stream().collect(Collectors.toMap(ProductInfoVo::getId, Function.identity()));
-            ProductInfoVo productInfo = productMap.get(s.getBussinessId());
-            s.setProductCode(productInfo.getCode());
-            s.setProductName(productInfo.getName());
-            s.setProductType(productInfo.getType());
-            s.setProductCategory(productInfo.getClassifyName());
-            s.setProductUnit(productInfo.getUnit());
-            s.setProductDefinition(productInfo.getDefinition());
-            s.setProductCustomCode(productInfo.getCustomCode());
-            s.setProductSpec(productInfo.getSpec());
-
-            String victoriatouristJson = productInfo.getVictoriatouristJson();
-            JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
-            s.setDeptId(json.getLong("deptId"));
-        }
-
+        //赋值已采购数量
         List<Long> subscribeDetailIds = list.stream().map(SubscribeDetail::getId).collect(Collectors.toList());
         if (ObjectUtil.isNotEmpty(subscribeDetailIds)) {
             List<PurchaseDetail> purchaseDetailsList = purchaseDetailService.list(q -> q.in(PurchaseDetail::getSubscribeDetailId, subscribeDetailIds));
@@ -226,26 +199,21 @@ public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMappe
                 wids.add(json.getLong("receiptWarehouseId"));
             }
         }
-        //赋值到货仓库名称
+        //获取到货仓库信息
+        List<Warehouse> warehouses = new ArrayList<>();
         if (ObjectUtil.isNotEmpty(wids)) {
-            List<Warehouse> warehouses = warehouseService.listByIds(wids);
-            Map<Long, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
-            for (SubscribeDetailVo subscribeDetailVo : records) {
-                String victoriatouristJson = subscribeDetailVo.getVictoriatouristJson();
-                if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
-                    JSONObject json = JSONObject.parseObject(victoriatouristJson);
-                    json.put("receiptWarehouseName", warehousesMap.get(json.getLong("receiptWarehouseId")));
-                    subscribeDetailVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
-                }
-            }
+            warehouses = warehouseService.listByIds(wids);
         }
-        //赋值采购数量
-        for (SubscribeDetailVo record : records) {
-            List<PurchaseDetail> list = purchaseDetailService.list(q -> q.eq(PurchaseDetail::getSubscribeDetailId, record.getId()));
-            BigDecimal count = list.stream()
-                    .map(PurchaseDetail::getCount)
-                    .reduce(BigDecimal.ZERO, BigDecimal::add);
-            record.setPurchaseCount(count);
+        Map<Long, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
+
+        for (SubscribeDetailVo subscribeDetailVo : records) {
+            //赋值到货仓库名称
+            String victoriatouristJson = subscribeDetailVo.getVictoriatouristJson();
+            if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
+                JSONObject json = JSONObject.parseObject(victoriatouristJson);
+                json.put("receiptWarehouseName", warehousesMap.get(json.getLong("receiptWarehouseId")));
+                subscribeDetailVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
+            }
         }
 
         return page;

+ 4 - 2
hx-purchase/src/main/resources/mapper/purchase/PurchaseMapper.xml

@@ -2,10 +2,12 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fjhx.purchase.mapper.purchase.PurchaseMapper">
     <select id="getPage" resultType="com.fjhx.purchase.entity.purchase.vo.PurchaseVo">
-        select p.*
-        from purchase p
+        SELECT p.*
+        FROM purchase p
                  LEFT JOIN purchase_detail pd ON pd.purchase_id = p.id
                  LEFT JOIN bytesailing_item.product_info pi ON pd.bussiness_id = pi.id
+                 LEFT JOIN bytesailing_base.sys_dept de
+                           ON json_unquote(pi.victoriatourist_json - > '$.deptId') = de.dept_id
             ${ew.customSqlSegment}
     </select>
     <select id="paymentBill" resultType="com.fjhx.purchase.entity.purchase.dto.PurchaseDto">

+ 25 - 15
hx-purchase/src/main/resources/mapper/subscribe/SubscribeDetailMapper.xml

@@ -2,21 +2,31 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fjhx.purchase.mapper.subscribe.SubscribeDetailMapper">
     <select id="getPage" resultType="com.fjhx.purchase.entity.subscribe.vo.SubscribeDetailVo">
-        SELECT
-            t1.*,
-            t2.`code` AS subscribeCode,
-            t2.subcribe_content AS subscribeContent,
-            t2.subcribe_time AS subcribeTime,
-            t2.subcribe_name AS subcribeName,
-            t2.id AS subcribeId,
-            t2.required_arrival_time AS requiredArrivalTime,
-            t2.put_warehouse_id AS putWarehouseId,
-            t2.victoriatourist_json,
-            t2.flow_id
-        FROM
-            subscribe_detail t1
-        LEFT JOIN subscribe t2 ON t1.subscribe_id = t2.id
-        left JOIN bytesailing_item.product_info pi on t1.bussiness_id = pi.id
+        SELECT t1.*,
+               t2.`code`                AS subscribeCode,
+               t2.subcribe_content      AS subscribeContent,
+               t2.subcribe_time         AS subcribeTime,
+               t2.subcribe_name         AS subcribeName,
+               t2.id                    AS subcribeId,
+               t2.required_arrival_time AS requiredArrivalTime,
+               t2.put_warehouse_id      AS putWarehouseId,
+               t2.victoriatourist_json,
+               t2.flow_id,
+               pi.code                     productCode,
+               pi.name                     productName,
+               pi.type                     productType,
+               pc.name                     productCategory,
+               pi.unit                     productUnit,
+               pi.definition               productDefinition,
+               pi.custom_code              productCustomCode,
+               pi.spec                     productSpec,
+               de.dept_id                  deptId
+        FROM subscribe_detail t1
+                 LEFT JOIN subscribe t2 ON t1.subscribe_id = t2.id
+                 left JOIN bytesailing_item.product_info pi on t1.bussiness_id = pi.id
+                 left join bytesailing_item.product_classify pc on pi.product_classify_id = pc.id
+                 LEFT JOIN bytesailing_base.sys_dept de
+                           ON json_unquote(pi.victoriatourist_json - > '$.deptId') = de.dept_id
             ${ew.customSqlSegment}
     </select>