叶君翔 3 anni fa
parent
commit
c66904a906

+ 14 - 9
lb-module/src/main/java/com/ydd/module/service/impl/ProfitsActivityServiceImpl.java

@@ -17,6 +17,7 @@ import com.ydd.module.service.IProfitsActivityService;
 import com.ydd.module.service.IShopService;
 import com.ydd.module.utils.CommonUtils;
 import lombok.SneakyThrows;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.compress.utils.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
@@ -24,10 +25,7 @@ import org.apache.commons.lang3.time.DateUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -61,8 +59,11 @@ public class ProfitsActivityServiceImpl extends ServiceImpl<ProfitsActivityMappe
         // 查询昨天有取消订单或者完成订单的商户
         List<Merchant> merchantList = baseMapper.selectMerchantByDate(startTime, endTime);
         List<Long> merchantIds = merchantList.stream().map(Merchant::getId).collect(Collectors.toList());
-        List<Shop> shops = iShopService.getShopByMerchantIds(merchantIds);
-        Map<Long, List<Shop>> shopMap = shops.stream().collect(Collectors.groupingBy(Shop::getMerchantId));
+        Map<Long, List<Shop>> shopMap = new HashMap<>();
+        if (CollectionUtils.isNotEmpty(merchantIds)) {
+            List<Shop> shops = iShopService.getShopByMerchantIds(merchantIds);
+            shopMap = shops.stream().collect(Collectors.groupingBy(Shop::getMerchantId));
+        }
         for (Merchant merchant : merchantList) {
             Long merchantId = merchant.getId();
             ProfitsActivity profitsActivity = new ProfitsActivity();
@@ -73,11 +74,15 @@ public class ProfitsActivityServiceImpl extends ServiceImpl<ProfitsActivityMappe
             profitsActivity.setMerchantId(merchantId);
             // 查询商户昨天下单量(type: 4-> 完成,-1-> 取消)
             List<Shop> shopList = shopMap.get(merchantId);
-            List<Long> shopIds = shopList.stream().map(Shop::getId).collect(Collectors.toList());
-            Integer completeNum = baseMapper.getOrderNumByShopIdsAndTime(shopIds, 4, startTime, endTime);
-            Integer cancelNum = baseMapper.getOrderNumByShopIdsAndTime(shopIds, -1, startTime, endTime);
+            Integer completeNum = 0;
+            Integer cancelNum = 0;
+            if (CollectionUtils.isNotEmpty(shopList)) {
+                List<Long> shopIds = shopList.stream().map(Shop::getId).collect(Collectors.toList());
+                completeNum = baseMapper.getOrderNumByShopIdsAndTime(shopIds, 4, startTime, endTime);
+                cancelNum = baseMapper.getOrderNumByShopIdsAndTime(shopIds, -1, startTime, endTime);
 //                Integer completeNum = baseMapper.selectOrderNumByDate(merchantId, date, 4);
 //                Integer cancelNum = baseMapper.selectOrderNumByDate(merchantId, date, -1);
+            }
             // 完成订单数
             profitsActivity.setCompleteNum(completeNum);
             // 取消订单数

+ 12 - 8
lb-module/src/main/resources/mapper/module/shopMapper.xml

@@ -285,20 +285,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="findShopIdByMerchantId" resultType="java.lang.Long">
         SELECT id FROM lb_shop WHERE 1 = 1
         AND deleted = 0
-        AND merchant_id IN
-        <foreach collection="merchantIds" index="index" item="merchantId" open="(" separator="," close=")">
-            #{merchantId}
-        </foreach>
+        <if test="merchantIds != null and merchantIds.size > 0">
+            AND merchant_id IN
+            <foreach collection="merchantIds" index="index" item="merchantId" open="(" separator="," close=")">
+                #{merchantId}
+            </foreach>
+        </if>
     </select>
 
     <select id="getShopByMerchantIds" resultType="com.ydd.module.domain.Shop">
         SELECT id, merchant_id
         FROM lb_shop
         WHERE deleted = 0
-        AND merchant_id IN
-        <foreach collection="merchantIds" index="index" item="merchantId" open="(" separator="," close=")">
-            #{merchantId}
-        </foreach>
+        <if test="merchantIds != null and merchantIds.size > 0">
+            AND merchant_id IN
+            <foreach collection="merchantIds" index="index" item="merchantId" open="(" separator="," close=")">
+                #{merchantId}
+            </foreach>
+        </if>
     </select>
 
     <select id="findShopSelectList" resultType="com.ydd.module.dto.ShopSelectDto">