Browse Source

只显示未关联服务端

Zhaops 6 years ago
parent
commit
c4403b4154

+ 0 - 13
diagbotman-service/src/main/java/com/diagbot/entity/wrapper/LantoneProductWrapper.java

@@ -46,11 +46,6 @@ public class LantoneProductWrapper extends LantoneProduct {
      */
     private String organizationName;
 
-    /**
-     * 关联的service
-     */
-    private String serviceIds;
-
     /**
      * 关联的service
      */
@@ -64,14 +59,6 @@ public class LantoneProductWrapper extends LantoneProduct {
         this.serviceInfos = serviceInfos;
     }
 
-    public String getServiceIds() {
-        return serviceIds;
-    }
-
-    public void setServiceIds(String serviceIds) {
-        this.serviceIds = serviceIds;
-    }
-
     public String getOrganizationName() {
         return organizationName;
     }

+ 23 - 0
diagbotman-service/src/main/java/com/diagbot/entity/wrapper/ServiceInfoWrapper.java

@@ -0,0 +1,23 @@
+package com.diagbot.entity.wrapper;
+
+import com.diagbot.entity.ServiceInfo;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2018/10/15 9:57
+ */
+public class ServiceInfoWrapper extends ServiceInfo {
+    /**
+     * 产品Id
+     */
+    private Long productId;
+
+    public Long getProductId() {
+        return productId;
+    }
+
+    public void setProductId(Long productId) {
+        this.productId = productId;
+    }
+}

+ 27 - 7
diagbotman-service/src/main/java/com/diagbot/facade/LantoneProductFacade.java

@@ -1,5 +1,6 @@
 package com.diagbot.facade;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.client.UserServiceClient;
@@ -13,20 +14,24 @@ import com.diagbot.entity.OpenedProductsIndex;
 import com.diagbot.entity.ServiceInfo;
 import com.diagbot.entity.wrapper.LantoneProductWrapper;
 import com.diagbot.entity.wrapper.OpendProductWrapper;
+import com.diagbot.entity.wrapper.ServiceInfoWrapper;
 import com.diagbot.enums.AccessTypeEnum;
 import com.diagbot.enums.IsDeleteEnum;
 import com.diagbot.enums.ProductAuditEnum;
+import com.diagbot.enums.ServiceTypeEnum;
 import com.diagbot.enums.StatusEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.LantoneProductServiceImpl;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.DateUtil;
+import com.diagbot.util.EntityUtil;
 import com.diagbot.util.UserUtils;
 import com.diagbot.vo.AddProductsVO;
 import com.diagbot.vo.LantoneProductSelectVO;
 import com.diagbot.vo.OppendedProductVO;
 import com.diagbot.vo.UpdateProductVO;
+import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -127,6 +132,16 @@ public class LantoneProductFacade extends LantoneProductServiceImpl {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
                     "获取用户机构信息失败");
         }
+
+        List<ServiceInfoWrapper> serviceInfoWrapperList = serviceInfoFacade.selectWrapperListByUserId(userId);
+        Map<Long, List<ServiceInfoWrapper>> serviceListMap = EntityUtil.makeEntityListMap(serviceInfoWrapperList, "productId");
+
+        QueryWrapper<ServiceInfo> qwServiceInfo = new QueryWrapper();
+        qwServiceInfo.eq("user_id", userId).
+                eq("type", ServiceTypeEnum.User_Create.getKey()).
+                eq("is_deleted", IsDeleteEnum.N.getKey());
+        List<ServiceInfo> serviceInfoList = serviceInfoFacade.list(qwServiceInfo);
+
         for (LantoneProductWrapper product : list) {
             product.setOrganizationName(mapRespDTO.data.get(userId).getOrgName());
             String[] accessType = product.getAccessType().split(",|,");
@@ -144,14 +159,19 @@ public class LantoneProductFacade extends LantoneProductServiceImpl {
             product.setAccessTypeArray(accessTypeArray);
             product.setChargeTypeArray(chargeTypeArray);
 
-            String[] serviceIds = product.getServiceIds().split(",|,");
-            Long[] lserviceIds = new Long[serviceIds.length];
-            for (int i = 0; i < serviceIds.length; i++) {
-                lserviceIds[i] = Long.parseLong(serviceIds[i]);
+            List<ServiceInfoWrapper> serviceWrappers = serviceListMap.get(product.getId());
+            Map<Long, ServiceInfoWrapper> serviceRelationMap = EntityUtil.makeEntityMap(serviceWrappers, "id");
+            if (serviceWrappers != null) {
+                List<ServiceInfo> serviceNoRelations = Lists.newArrayList();
+                for (ServiceInfo serviceInfo : serviceInfoList) {
+                    if (!serviceRelationMap.containsKey(serviceInfo.getId())) {
+                        serviceNoRelations.add(serviceInfo);
+                    }
+                }
+                product.setServiceInfos(serviceNoRelations);
+            } else {
+                product.setServiceInfos(serviceInfoList);
             }
-
-            List<ServiceInfo> services = serviceInfoFacade.getServiceListNoRelation(lserviceIds);
-            product.setServiceInfos(services);
         }
         return list;
     }

+ 9 - 0
diagbotman-service/src/main/java/com/diagbot/mapper/ServiceInfoMapper.java

@@ -2,7 +2,9 @@ package com.diagbot.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.diagbot.entity.ServiceInfo;
+import com.diagbot.entity.wrapper.ServiceInfoWrapper;
 
+import java.util.List;
 /**
  * <p>
  * 用户服务表 Mapper 接口
@@ -12,4 +14,11 @@ import com.diagbot.entity.ServiceInfo;
  * @since 2018-09-17
  */
 public interface ServiceInfoMapper extends BaseMapper<ServiceInfo> {
+
+    /**
+     * 根据用户id取服务端列表
+     * @param userId
+     * @return
+     */
+    List<ServiceInfoWrapper> selectWrapperListByUserId(Long userId);
 }

+ 9 - 0
diagbotman-service/src/main/java/com/diagbot/service/ServiceInfoService.java

@@ -2,6 +2,9 @@ package com.diagbot.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.diagbot.entity.ServiceInfo;
+import com.diagbot.entity.wrapper.ServiceInfoWrapper;
+
+import java.util.List;
 
 /**
  * <p>
@@ -12,4 +15,10 @@ import com.diagbot.entity.ServiceInfo;
  * @since 2018-09-17
  */
 public interface ServiceInfoService extends IService<ServiceInfo> {
+    /**
+     * 根据用户id取服务端列表
+     * @param userId
+     * @return
+     */
+    List<ServiceInfoWrapper> selectWrapperListByUserId(Long userId);
 }

+ 11 - 0
diagbotman-service/src/main/java/com/diagbot/service/impl/ServiceInfoServiceImpl.java

@@ -2,10 +2,13 @@ package com.diagbot.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.diagbot.entity.ServiceInfo;
+import com.diagbot.entity.wrapper.ServiceInfoWrapper;
 import com.diagbot.mapper.ServiceInfoMapper;
 import com.diagbot.service.ServiceInfoService;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 用户服务表 服务实现类
@@ -16,4 +19,12 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class ServiceInfoServiceImpl extends ServiceImpl<ServiceInfoMapper, ServiceInfo> implements ServiceInfoService {
+    /**
+     * 根据用户id取服务端列表
+     * @param userId
+     * @return
+     */
+    public List<ServiceInfoWrapper> selectWrapperListByUserId(Long userId){
+        return baseMapper.selectWrapperListByUserId(userId);
+    }
 }

+ 3 - 11
diagbotman-service/src/main/resources/mapper/LantoneProductMapper.xml

@@ -90,17 +90,9 @@
 
     <!--根据用户查询已开通产品-->
     <select id="opendedProductByUserId" resultMap="BaseResultWrapperMap" parameterType="java.lang.Long">
-        select a.*,b.start_time,b.end_time,b.service_status as opened_service_status,c.time,t.service_ids
-        from diag_lantone_product a,diag_opened_products b,diag_product_order c,diag_order_details d,
-        (SELECT product_id,GROUP_CONCAT(service_id) as service_ids
-            FROM diag_product_service t1,diag_service_info t2
-            WHERE t1.service_id = t2.id
-            AND t1.is_deleted = 'N'
-            AND t2.is_deleted = 'N'
-            AND t2.user_id = #{userId}
-            AND t2.type = 1
-            GROUP BY t1.product_id) t
-        where a.id=b.product_id and a.id=d.product_id and a.id=t.product_id
+        select a.*,b.start_time,b.end_time,b.service_status as opened_service_status,c.time
+        from diag_lantone_product a,diag_opened_products b,diag_product_order c,diag_order_details d
+        where a.id=b.product_id and a.id=d.product_id
 			  and c.num=d.order_num
               and d.audit_status=1
               and a.is_deleted='N' and b.is_deleted='N' and c.is_deleted='N' and d.is_deleted='N'

+ 25 - 0
diagbotman-service/src/main/resources/mapper/ServiceInfoMapper.xml

@@ -16,4 +16,29 @@
         <result column="user_id" property="userId"/>
         <result column="type" property="type"/>
     </resultMap>
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultWrapperMap" type="com.diagbot.entity.wrapper.ServiceInfoWrapper">
+        <id column="id" property="id"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="gmt_create" property="gmtCreate"/>
+        <result column="gmt_modified" property="gmtModified"/>
+        <result column="creator" property="creator"/>
+        <result column="modifier" property="modifier"/>
+        <result column="name" property="name"/>
+        <result column="description" property="description"/>
+        <result column="user_id" property="userId"/>
+        <result column="type" property="type"/>
+        <result column="product_id" property="productId"/>
+    </resultMap>
+
+    <!--根据用户查询已开通产品-->
+    <select id="selectWrapperListByUserId" resultMap="BaseResultWrapperMap" parameterType="java.lang.Long">
+        select a.*,b.product_id
+        from diag_service_info a,diag_product_service b
+        where a.id=b.service_id
+        and a.type=1
+        and a.user_id= #{userId}
+        and a.is_deleted='N' and b.is_deleted='N'
+    </select>
 </mapper>