Просмотр исходного кода

更新红点保存方法,增加兼容性。

hejq 7 лет назад
Родитель
Сommit
52cb2bb828

+ 7 - 29
src/main/java/com/uas/platform/b2b/dao/OrderRedDotAllDao.java

@@ -3,11 +3,9 @@ package com.uas.platform.b2b.dao;
 import com.uas.platform.b2b.model.OrderRedDotAll;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
-import java.util.Collection;
+import java.util.List;
 
 /**
  * 消息红点,全部
@@ -23,36 +21,16 @@ public interface OrderRedDotAllDao extends JpaRepository<OrderRedDotAll, Long>,
      *
      * @param orderType 单据类型
      * @param orderId 单据id
-     * @return OrderRedDotAll
+     * @return List<OrderRedDotAll>
      */
-    OrderRedDotAll findByOrderTypeAndOrderId(String orderType, Long orderId);
+    List<OrderRedDotAll> findByOrderTypeAndOrderId(String orderType, Long orderId);
 
     /**
-     * 通过供应商UU和单据类型查询所有消息数
+     *  通过企业UU,单据id,查询数量
      *
-     * @param vendUU 供应商UU
      * @param orderType 单据类型
-     * @return 消息总数
-     */
-    Integer countByVendUUAndOrderType(Long vendUU, String orderType);
-
-    /**
-     *  通过供应商UU和单据类型、客户分配查询所有消息数
-     *
-     * @param vendUU 供应商UU
-     * @param orderType 单据类型
-     * @param distribute 客户分配
-     * @return
-     */
-    @Query("select count(1) from OrderRedDotAll where vendUU = :vendUU and orderType = :orderType and enUU in :distribute")
-    Integer countByVendUUAndOrderTypeAndEnUU(@Param("vendUU") Long vendUU, @Param("orderType") String orderType, @Param("distribute") Collection<?> distribute);
-
-    /**
-     * 通过供应商UU和单据类型查询所有消息数
-     *
-     * @param enUU 客户UU
-     * @param orderType 单据类型
-     * @return 消息总数
+     * @param orderId 单据id
+     * @return 单据存在的数量
      */
-    Integer countByEnUUAndOrderType(Long enUU, String orderType);
+    Integer countByOrderTypeAndOrderId(String orderType, Long orderId);
 }

+ 8 - 7
src/main/java/com/uas/platform/b2b/service/impl/OrderRedDotServiceImpl.java

@@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -102,9 +103,9 @@ public class OrderRedDotServiceImpl implements OrderRedDotService {
      */
     @Override
     public void saveByOriginId(Long id, String orderType, Long enUU) {
-        OrderRedDotAll redDotAll = redDotAllDao.findByOrderTypeAndOrderId(orderType, id);
-        if (null == redDotAll) {
-            redDotAll = new OrderRedDotAll(orderType, enUU);
+        Integer count = redDotAllDao.countByOrderTypeAndOrderId(orderType, id);
+        if (0 == count) {
+            OrderRedDotAll redDotAll = new OrderRedDotAll(orderType, enUU);
             redDotAll.setOrderId(id);
             redDotAllDao.save(redDotAll);
         }
@@ -138,13 +139,13 @@ public class OrderRedDotServiceImpl implements OrderRedDotService {
      */
     @Override
     public void setReadByIds(String orderType, Long... sourceIds) {
-        List<OrderRedDotDone> redDotDoneList = new ArrayList<>();
+        Set<OrderRedDotDone> redDotDoneList = new HashSet<>();
         Arrays.stream(sourceIds).forEach(id -> {
             Integer count = countByOrderTypeAndOrderId(orderType, id);
             if (count == 0) {
-                OrderRedDotAll redDotAll = redDotAllDao.findByOrderTypeAndOrderId(orderType, id);
-                if (null != redDotAll) {
-                    OrderRedDotDone redDotDone = new OrderRedDotDone(redDotAll);
+                List<OrderRedDotAll> redDotAllList = redDotAllDao.findByOrderTypeAndOrderId(orderType, id);
+                if (!CollectionUtils.isEmpty(redDotAllList)) {
+                    OrderRedDotDone redDotDone = new OrderRedDotDone(redDotAllList.get(0));
                     redDotDoneList.add(redDotDone);
                 }
             }