Browse Source

产品库权限问题处理

yzc 1 year ago
parent
commit
bb03fd0a13

+ 4 - 4
hx-common/src/main/java/com/fjhx/common/service/documentary/impl/DocumentaryRecordServiceImpl.java

@@ -80,7 +80,7 @@ public class DocumentaryRecordServiceImpl extends ServiceImpl<DocumentaryRecordM
                     // 设置子线程共享
                     RequestContextHolder.setRequestAttributes(servletRequestAttributes, true);
                     SecurityContextHolder.setContext(context);
-//                    DynamicDataSourceContextHolder.push(SourceConstant.COMMON);
+                    DynamicDataSourceContextHolder.push(SourceConstant.BASE);
 
                     List<Long> excludeBusinessId = null;
                     Long noRecordDocumentaryId = dto.getNoRecordDocumentaryId();
@@ -96,7 +96,7 @@ public class DocumentaryRecordServiceImpl extends ServiceImpl<DocumentaryRecordM
                     Page<? extends DocumentaryData> page = bean.getDocumentaryPage(dto.getCondition(), dto, excludeBusinessId);
                     setDocumentaryRecord(page);
 
-//                    DynamicDataSourceContextHolder.poll();
+                    DynamicDataSourceContextHolder.poll();
                     return page;
                 }, threadPoolExecutor).exceptionally(e -> {
                     if (e instanceof ServiceException) {
@@ -110,14 +110,14 @@ public class DocumentaryRecordServiceImpl extends ServiceImpl<DocumentaryRecordM
                     // 设置子线程共享
                     RequestContextHolder.setRequestAttributes(servletRequestAttributes, true);
                     SecurityContextHolder.setContext(context);
-//                    DynamicDataSourceContextHolder.push(SourceConstant.COMMON);
+                    DynamicDataSourceContextHolder.push(SourceConstant.BASE);
 
                     List<DocumentaryVo> documentaryList = getDocumentaryList(typeEnum.getKey());
                     if (documentaryList.size() > 0) {
                         setDocumentaryRecordCount(documentaryList);
                     }
 
-//                    DynamicDataSourceContextHolder.poll();
+                    DynamicDataSourceContextHolder.poll();
                     return documentaryList;
                 }, threadPoolExecutor).exceptionally(e -> {
                     if (e instanceof ServiceException) {

+ 7 - 7
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -131,14 +131,14 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         }
 
         //权限过滤:产品-子公司看自己的产品,总公司看全部,物料没有限制
-        if (Objects.equals(dto.getDefinition(), 1)) {
-            Long companyId = SecurityUtils.getCompanyId();
-            if (!Objects.equals(companyId, 100L)) {
-                wrapper.eq(ProductInfo::getCompanyId, companyId);
-            } else {
-                wrapper.eq(ProductInfo::getCompanyId, dto.getCompanyId());
-            }
+        Long companyId = SecurityUtils.getCompanyId();
+        if (!Objects.equals(companyId, 100L)) {
+            dto.setCompanyId(companyId);
         }
+        wrapper.and(q1 -> q1.
+                and(q -> q.eq(ProductInfo::getDefinition, 1).eq(ProductInfo::getCompanyId, dto.getCompanyId()))
+                .or().eq(ProductInfo::getDefinition, 2)
+        );
 
         wrapper.orderByDesc("pi", ProductInfo::getId);
         Page<ProductInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);