Bladeren bron

大屏每小时更新全部数据

qin 1 jaar geleden
bovenliggende
commit
ec64a9534d

+ 9 - 0
src/main/java/com/poteviohealth/cgp/statistics/mapper/OrderMapper.java

@@ -114,6 +114,15 @@ public interface OrderMapper extends BaseMapper<Order>{
     @SqlParser(filter = true)
     List<OrderIntegrationData> queryOrderIntegrationData(@Param("operatorId")Integer operatorId, @Param("dbName")String dbName);
 
+    /**
+     * 获取订单数据
+     * @param operatorId
+     * @param dbName
+     * @return
+     */
+    @SqlParser(filter = true)
+    List<OrderIntegrationData> queryOrderVisitData(@Param("operatorId")Integer operatorId, @Param("dbName")String dbName);
+
     /**
      * 获取服务分类
      * @param dbName

+ 61 - 16
src/main/java/com/poteviohealth/cgp/statistics/service/impl/OrderServiceImpl.java

@@ -141,6 +141,7 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
                 log.info("---更新工单数据开始---");
                 List<ListParams> categoryList = baseMapper.getAllCategory(dbName);
                 changeOrder(maps,operatorIds,categoryList);
+                changeOrderVisit(maps,operatorIds);
                 log.info("---更新工单数据结束---");
                 //更新积分相关数据
                 log.info("---更新商户积分数据开始---");
@@ -1512,28 +1513,60 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
         return returnList;
     }
 
-    private void integrationData(List<OrderStatisticsData> returnList,List<OrderIntegrationData> orderList,
-                                 Integer areaId,Map<Integer,List<ListParams>> categoryMap){
+    private List<OrderStatisticsData> getOrderVisitStatisticsDataList(List<Integer> ids){
+        List<OrderStatisticsData> returnList = Lists.newArrayList();
+        List<OrderIntegrationData> list = Lists.newArrayList();
+
+        for (Integer id : ids) {
+            //获取已完成的服务工单
+            list.addAll(baseMapper.queryOrderVisitData(id,dbName));
+        }
+
+        //按照市统计
+        Map<Integer,List<OrderIntegrationData>> cityMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCityId));
+        //按照区统计
+        Map<Integer,List<OrderIntegrationData>> countryMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCountryId));
+        //按照街道统计
+        Map<Integer,List<OrderIntegrationData>> streetMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getStreetId));
+        for (Integer integer : cityMaps.keySet()) {
+            visitData(returnList,cityMaps.get(integer),integer);
+        }
+        for (Integer integer : countryMaps.keySet()) {
+            visitData(returnList,countryMaps.get(integer),integer);
+        }
+        for (Integer integer : streetMaps.keySet()) {
+            visitData(returnList,streetMaps.get(integer),integer);
+        }
+
+        return returnList;
+    }
+    private void visitData(List<OrderStatisticsData> returnList,List<OrderIntegrationData> orderList,Integer areaId){
+
+
         OrderStatisticsData data = new OrderStatisticsData();
         data.setAreaId(areaId);
         List<Long> visitNumList = orderList.stream().map(o->o.getCustomerId()).distinct().collect(Collectors.toList());
         data.setVisitNum(visitNumList.size());
-       /* List<OrderIntegrationData> visitOrderList = orderList.stream().filter(o->o.getVisitStatus().equals(1)).collect(Collectors.toList());
-        BigDecimal visitRate = new BigDecimal(visitOrderList.size()).divide(new BigDecimal(orderList.size()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)).setScale(2,BigDecimal.ROUND_HALF_UP);*/
         data.setVisitRate(new BigDecimal(100));
         if(data.getVisitNum()>0){
             List<Long> satisfactionList = orderList.stream().filter(v->v.getResult().equals(1)).map(o->o.getOrderId()).collect(Collectors.toList());
             data.setSatisfactionNum(satisfactionList.size());
             List<Long> qualifiedList = orderList.stream().filter(v->v.getQualified().equals(1)).map(o->o.getOrderId()).collect(Collectors.toList());
-            //BigDecimal qualifiedRate = new BigDecimal(qualifiedList.size()).divide(new BigDecimal(orderList.size()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)).setScale(2,BigDecimal.ROUND_HALF_UP);
             data.setQualifiedNum(qualifiedList.size());
         }else{
             data.setSatisfactionNum(0);
             data.setQualifiedNum(0);
         }
 
-        data.setOrderNum(orderList.size());
+        returnList.add(data);
+    }
+
 
+    private void integrationData(List<OrderStatisticsData> returnList,List<OrderIntegrationData> orderList,
+                                 Integer areaId,Map<Integer,List<ListParams>> categoryMap){
+        OrderStatisticsData data = new OrderStatisticsData();
+        data.setAreaId(areaId);
+        data.setOrderNum(orderList.size());
         List<OrderIntegrationData> monthOrderList = orderList.stream()
                 .filter(o-> DateUtil.isIn(o.getFinishTime(), com.poteviohealth.cgp.common.utils.DateUtils.getFirstDayOfMonth(new Date()), com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(new Date())))
                 .collect(Collectors.toList());
@@ -1548,7 +1581,6 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
             e.printStackTrace();
         }
 
-
         List<OrderIntegrationData> dayOrderList = orderList.stream()
                 .filter(o->DateUtil.isIn(o.getFinishTime(), com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(new Date()), com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(new Date())))
                 .collect(Collectors.toList());
@@ -1605,19 +1637,36 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
                 continue;
             }
             for (Order order : orders) {
-                if(order.getVisitNum() == null){
-                    order.setVisitNum(0);
-                }
                 if(order.getOrderNum() == null){
                     order.setOrderNum(0);
                 }
+                order.setOrderNum(orderStatisticsData.getOrderNum());
+                order.setOrderNumMonth(orderStatisticsData.getOrderNumMonth());
+                order.setOrderNumWeek(orderStatisticsData.getOrderNumWeek());
+                order.setOrderNumDay(orderStatisticsData.getOrderNumDay());
+                order.setServiceTypeList(orderStatisticsData.getServiceTypeList());
+            }
+        }
+    }
+
+    private void changeOrderVisit(Map<Integer, List<Order>> maps,List<Integer> operatorIds) {
+        //更新工单相关数据
+        List<OrderStatisticsData> orderList = this.getOrderVisitStatisticsDataList(operatorIds);
+        for (OrderStatisticsData orderStatisticsData : orderList) {
+            List<Order> orders = maps.get(orderStatisticsData.getAreaId());
+            if(orders == null || orders.isEmpty()){
+                continue;
+            }
+            for (Order order : orders) {
+                if(order.getVisitNum() == null){
+                    order.setVisitNum(0);
+                }
                 if(order.getSatisfactionRate() == null){
                     order.setSatisfactionRate(new BigDecimal("0.00"));
                 }
                 if(order.getQualifiedRate() == null){
                     order.setQualifiedRate(new BigDecimal("0.00"));
                 }
-                order.setOrderNum(orderStatisticsData.getOrderNum());
                 order.setVisitNum(orderStatisticsData.getVisitNum());
                 order.setVisitRate(orderStatisticsData.getVisitRate());
                 if(order.getOrderNum().equals(0)){
@@ -1639,11 +1688,7 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
                             order.setQualifiedRate(new BigDecimal(100));
                         }
                     }
-                 }
-                order.setOrderNumMonth(orderStatisticsData.getOrderNumMonth());
-                order.setOrderNumWeek(orderStatisticsData.getOrderNumWeek());
-                order.setOrderNumDay(orderStatisticsData.getOrderNumDay());
-                order.setServiceTypeList(orderStatisticsData.getServiceTypeList());
+                }
             }
         }
     }

+ 37 - 4
src/main/resources/mapper/statistics/OrderMapper.xml

@@ -159,11 +159,10 @@
     <select id="queryOrderIntegrationData"
             resultType="com.poteviohealth.cgp.statistics.model.outdto.OrderIntegrationData">
         SELECT o.order_id as orderId,o.city_id as cityId,o.country_id as countryId,o.street_id as streetId,o.visit_status as visitStatus
-                ,o.customer_id as  customerId,o.finish_time as  finishTime,od.product_category_id as productCategoryId,v.qualified as qualified,
-               v.result as result FROM ${dbName}_order.o_order_${operatorId} o,${dbName}_order.o_order_detail_${operatorId} od,${dbName}_order.o_visit_${operatorId} v
+                ,o.customer_id as  customerId,o.finish_time as  finishTime,od.product_category_id as productCategoryId,
+                FROM ${dbName}_order.o_order_${operatorId} o,${dbName}_order.o_order_detail_${operatorId} od
         where o.order_id = od.order_id
-          and v.order_id = o.order_id
-          and o.yn= 0 and v.yn = 0
+          and o.yn= 0
           and o.order_status = 6
           and o.order_type = 2
           and o.city_id is not null
@@ -174,6 +173,40 @@
         group by o.order_id
     </select>
 
+    <select id="queryOrderVisitData"
+            resultType="com.poteviohealth.cgp.statistics.model.outdto.OrderIntegrationData">
+        SELECT
+            o.order_id AS orderId,
+            o.city_id AS cityId,
+            o.country_id AS countryId,
+            o.street_id AS streetId,
+            o.customer_id AS customerId,
+            v.qualified AS qualified,
+            v.result AS result
+        FROM
+            ${dbName}_order.o_order_${operatorId} o,
+            ${dbName}_order.o_visit_${operatorId} v
+                JOIN (
+                SELECT
+                    MAX( t2.id ) AS maxv
+                FROM
+                    ${dbName}_order.o_visit_${operatorId} t2
+                WHERE
+                    t2.yn = 0
+                GROUP BY
+                    t2.order_id
+            ) t ON t.maxv = v.id
+        WHERE
+            v.order_id = o.order_id
+          AND o.yn = 0
+          AND v.yn = 0
+          AND o.order_type = 2
+          AND o.city_id IS NOT NULL
+          AND o.country_id IS NOT NULL
+          AND o.street_id IS NOT NULL
+        GROUP BY o.order_id
+    </select>
+
     <select id="getAllCategory" resultType="com.poteviohealth.cgp.common.integrated.ListParams">
         select id,name,parent_id as `key` from ${dbName}_common.f_category where yn = 0
     </select>