Эх сурвалжийг харах

init: init project step4: biz code support

shc 1 жил өмнө
parent
commit
98f035fea3

+ 44 - 25
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmDaAgentController.java

@@ -2,7 +2,6 @@ package com.qunzhixinxi.hnqz.admin.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -31,6 +30,7 @@ import com.qunzhixinxi.hnqz.admin.service.SysCsmUserRelationService;
 import com.qunzhixinxi.hnqz.admin.service.SysDeptRelationService;
 import com.qunzhixinxi.hnqz.admin.service.SysDeptService;
 import com.qunzhixinxi.hnqz.admin.service.SysEnterpriseAreaService;
+import com.qunzhixinxi.hnqz.admin.service.SysUserAreaService;
 import com.qunzhixinxi.hnqz.admin.service.WmDaAgentService;
 import com.qunzhixinxi.hnqz.admin.service.WmDaDrugEntService;
 import com.qunzhixinxi.hnqz.admin.service.WmRelationService;
@@ -56,6 +56,7 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -89,6 +90,7 @@ public class WmDaAgentController {
     private final SysDeptRelationService sysDeptRelationService;
     private final SysCsmUserRelationService sysCsmUserRelationService;
     private final SysDeptCsmMapper sysDeptCsmMapper;
+    private final SysUserAreaService userAreaService;
     private final SysEnterpriseAreaService enterpriseAreaService;
 
     /**
@@ -101,36 +103,53 @@ public class WmDaAgentController {
     @GetMapping("/page")
     public R<?> getWmDaAgentPage(Page page, WmDaAgent wmDaAgent) {
 
+        Integer myselfId = SecurityUtils.getUser().getDeptId();
 
+        Set<Integer> ids = new HashSet<>(myselfId);
+
+        // 查询我的下游
         WmRelation wmRelation = new WmRelation();
-        wmRelation.setUpId(SecurityUtils.getUser().getDeptId());
+        wmRelation.setUpId(myselfId);
         List<WmRelation> wmRelationList = wmRelationMapper.selectUpIdList(wmRelation);
-        List<WmDaAgent> wmDaAgentList = new ArrayList<>();
-        wmDaAgent.setDeptId(SecurityUtils.getUser().getDeptId());
-        WmDaAgent wmDaAgent3 = wmDaAgentMapper.selectDeptId(wmDaAgent);
-        if (wmDaAgent3 != null) {
-            wmDaAgentList.add(wmDaAgent3);
-        }
         if (CollUtil.isNotEmpty(wmRelationList)) {
-            List<Integer> ids = wmRelationList.stream().map(WmRelation::getDownId).collect(Collectors.toList());
-
-            for (Integer id : ids) {
-                WmDaAgent wmDaAgent1 = new WmDaAgent();
-                wmDaAgent1.setDeptId(id);
-                WmDaAgent wmDaAgent2 = wmDaAgentMapper.selectDeptId(wmDaAgent1);
-                if (wmDaAgent2 != null) {
-                    wmDaAgentList.add(wmDaAgent2);
-                }
+            // 下游ID
+            List<Integer> downIds = wmRelationList.stream().map(WmRelation::getDownId).collect(Collectors.toList());
+            if (CollUtil.isNotEmpty(downIds)) {
+                ids.addAll(downIds);
             }
+
+        }
+
+
+        // 区域限制
+        List<Long> areaId;
+        if (CollUtil.isNotEmpty(wmDaAgent.getAreaCodes())){
+
+            areaId = wmDaAgent.getAreaCodes();
+
+        } else {
+            areaId = userAreaService.listUserAreas(Long.valueOf(SecurityUtils.getUser().getId()));
+
         }
 
-        // 公司名称条件筛选
-        if (StrUtil.isNotBlank(wmDaAgent.getGsmc())) {
-            wmDaAgentList = wmDaAgentList.stream()
-                    .filter(agent -> StrUtil.contains(agent.getGsmc(), wmDaAgent.getGsmc()))
-                    .collect(Collectors.toList());
+        List<Long> entIds = enterpriseAreaService.listAreaEnts(areaId);
+
+        // 交集
+        Set<Integer> resSet = new HashSet<>(ids);
+        resSet.retainAll(entIds.stream().map(Long::intValue).collect(Collectors.toSet()));
+
+
+        if (CollUtil.isEmpty(resSet)){
+            return R.ok(page);
         }
 
+        List<WmDaAgent> wmDaAgentList = wmDaAgentMapper.selectDeptByIds(resSet, wmDaAgent.getGsmc());
+
+        if (CollUtil.isEmpty(wmDaAgentList)) {
+            return R.ok(page);
+        }
+
+
         //每页数据条数
         Page<WmDaAgent> page1 = new Page<>();
         int current = Long.valueOf(page.getCurrent()).intValue();
@@ -789,14 +808,14 @@ public class WmDaAgentController {
     public R<?> listByDept() {
         List<WmDept> dept = wmDaAgentService.listByDept();
 
-        if (CollUtil.isNotEmpty(dept)){
+        if (CollUtil.isNotEmpty(dept)) {
 
             Set<Long> collect = dept.stream().map(d -> Long.valueOf(d.getDeptId())).collect(Collectors.toSet());
             Map<Long, List<Long>> longListMap = enterpriseAreaService.listEntAreas1(collect);
 
             dept.forEach(d -> {
-               d.setAreaCodes(longListMap.get(Long.valueOf(d.getDeptId())));
-           });
+                d.setAreaCodes(longListMap.get(Long.valueOf(d.getDeptId())));
+            });
         }
 
         return R.ok(dept);

+ 3 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/WmDaAgentMapper.java

@@ -8,6 +8,7 @@ import com.qunzhixinxi.hnqz.common.data.datascope.DataScopeMapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -44,6 +45,8 @@ public interface WmDaAgentMapper extends DataScopeMapper<WmDaAgent> {
     List<WmDaAgent> selectExtDrugEntList(@Param("query") WmDaAgent wmDaAgent);
 
     WmDaAgent selectDeptId(WmDaAgent wmDaAgent);
+    List<WmDaAgent> selectDeptByIds(@Param("deptIds") Collection<Integer> deptIds,
+                                    @Param("entName") String entName);
 
     List<Map<String, Object>> selectDeptId1(@Param("deptId") Integer deptId);
 

+ 0 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/WmRelationMapper.java

@@ -22,6 +22,5 @@ public interface WmRelationMapper extends BaseMapper<WmRelation> {
 
 	List<WmRelation> selectByUpId(Integer deptId);
 
-//	List<WmRelation> selectByUpId(String id);
 
 }

+ 17 - 0
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmDaAgentMapper.xml

@@ -197,6 +197,23 @@
         a.dept_id = #{deptId}
     </select>
 
+    <select id="selectDeptByIds" resultMap="wmDaAgentMap">
+        select
+        a.*,
+        d.dept_permissions
+        from wm_da_agent a
+        left join sys_dept d on a.dept_id = d.dept_id
+        <where>
+            a.dept_id in
+            <foreach collection="deptIds" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+            <if test="entName != null">
+                and a.dept_name like concat('%', #{entName} ,'%')
+            </if>
+        </where>
+    </select>
+
     <select id="selectDeptId1" resultType="map">
         select
         id,