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

fix: 消息红点设置已读空指针异常问题处理,增加判断逻辑;针对Set集合对象,重写hashCode和equals

hejq 7 лет назад
Родитель
Сommit
05f4c543f2

+ 44 - 0
src/main/java/com/uas/platform/b2b/model/OrderRedDotDone.java

@@ -151,4 +151,48 @@ public class OrderRedDotDone implements Serializable {
         this.orderId = redDotAll.getOrderId();
         this.orderType = redDotAll.getOrderType();
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        OrderRedDotDone that = (OrderRedDotDone) o;
+
+        if (id != null ? !id.equals(that.id) : that.id != null) {
+            return false;
+        }
+        if (redId != null ? !redId.equals(that.redId) : that.redId != null) {
+            return false;
+        }
+        if (enUU != null ? !enUU.equals(that.enUU) : that.enUU != null) {
+            return false;
+        }
+        if (userUU != null ? !userUU.equals(that.userUU) : that.userUU != null) {
+            return false;
+        }
+        if (orderId != null ? !orderId.equals(that.orderId) : that.orderId != null) {
+            return false;
+        }
+        if (orderType != null ? !orderType.equals(that.orderType) : that.orderType != null) {
+            return false;
+        }
+        return date != null ? date.equals(that.date) : that.date == null;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id != null ? id.hashCode() : 0;
+        result = 31 * result + (redId != null ? redId.hashCode() : 0);
+        result = 31 * result + (enUU != null ? enUU.hashCode() : 0);
+        result = 31 * result + (userUU != null ? userUU.hashCode() : 0);
+        result = 31 * result + (orderId != null ? orderId.hashCode() : 0);
+        result = 31 * result + (orderType != null ? orderType.hashCode() : 0);
+        result = 31 * result + (date != null ? date.hashCode() : 0);
+        return result;
+    }
 }

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

@@ -172,7 +172,7 @@ public class OrderRedDotServiceImpl implements OrderRedDotService {
      *
      * @param orderType 单据类型
      * @param roleName 角色
-     * @return
+     * @return 未读单据的id,原表id
      */
     @Override
     public List<Long> getUnreadIds(String orderType, String roleName) {
@@ -192,13 +192,15 @@ public class OrderRedDotServiceImpl implements OrderRedDotService {
      *
      * @param orderType 单据类型
      * @param roleName  角色
-     * @return 数量
+     * @return 设置已读的数量
      */
     @Override
     public Integer setReadByState(String orderType, String roleName) {
         List<Long> redAllIdList = getUnreadRedAllIdList(orderType, roleName);
-        List<List<Long>> idsList = SplitArray.splitAry(redAllIdList, SplitArray.QUERY_MAX_NUMBER);
-        idsList.forEach(ids -> setReadByIdList(ids));
+        if (!CollectionUtil.isEmpty(redAllIdList)) {
+            List<List<Long>> idsList = SplitArray.splitAry(redAllIdList, SplitArray.QUERY_MAX_NUMBER);
+            idsList.forEach(this::setReadByIdList);
+        }
         return redAllIdList.size();
     }
 
@@ -210,7 +212,7 @@ public class OrderRedDotServiceImpl implements OrderRedDotService {
      * @return List<Long>
      */
     private List<Long> getUnreadRedAllIdList(String orderType, String roleName) {
-        StringBuffer buffer = new StringBuffer("select red_id from reddot$all");
+        StringBuilder buffer = new StringBuilder("select red_id from reddot$all");
         Long enUU = SystemSession.getUser().getEnterprise().getUu();
         if (Role.SELLER.equals(roleName)) {
             buffer.append(" where red_venduu = ?");