From 56968f6f02f691397eac17d8fb8f8b34f440ab90 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 20 Jul 2021 17:45:09 +0800
Subject: [PATCH] add orderStatusCnt

---
 gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java            |    3 +
 gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml                   |   14 +++++++
 gc-order/src/main/java/com/xzx/gc/order/controller/ApiJhyOrderController.java |    7 +++
 gc-order/src/main/java/com/xzx/gc/order/vo/JhyStatusCountVo.java              |   13 ++++++
 gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java          |   32 ++++++++++++++-
 5 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/gc-order/src/main/java/com/xzx/gc/order/controller/ApiJhyOrderController.java b/gc-order/src/main/java/com/xzx/gc/order/controller/ApiJhyOrderController.java
index 91f6e7a..e45e802 100644
--- a/gc-order/src/main/java/com/xzx/gc/order/controller/ApiJhyOrderController.java
+++ b/gc-order/src/main/java/com/xzx/gc/order/controller/ApiJhyOrderController.java
@@ -23,6 +23,7 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
 
 @Slf4j
 @RestController
@@ -82,4 +83,10 @@
         return Result.success();
     }
 
+    @ApiOperation("订单状态数量")
+    @PostMapping(value = "/orderStatusCnt")
+    public JsonResult<Map<Integer, Integer>> orderStatusCnt(HttpServletRequest request) {
+        return JsonResult.success(jhyOrderService.orderStatusCount(getUserId(request)));
+    }
+
 }
diff --git a/gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java b/gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java
index 01156c0..c60b730 100644
--- a/gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java
+++ b/gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java
@@ -3,6 +3,7 @@
 import com.xzx.gc.entity.JhyOrder;
 import com.xzx.gc.order.dto.JhyOrderListDto;
 import com.xzx.gc.order.vo.JhyOrderListVo;
+import com.xzx.gc.order.vo.JhyStatusCountVo;
 import com.xzx.gc.util.GcMapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
@@ -13,4 +14,6 @@
 public interface JhyOrderMapper extends GcMapper<JhyOrder> {
 
     List<JhyOrderListVo> selectJhyOrderList(@Param("record") JhyOrderListDto jhyOrderListDto);
+
+    List<JhyStatusCountVo> selectOrderStatusCount(@Param("userId") String userId);
 }
diff --git a/gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java b/gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java
index 6c8c7df..ee3c7f3 100644
--- a/gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java
+++ b/gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java
@@ -18,6 +18,7 @@
 import com.xzx.gc.order.mapper.*;
 import com.xzx.gc.order.vo.JhyOrderDetailsVo;
 import com.xzx.gc.order.vo.JhyOrderListVo;
+import com.xzx.gc.order.vo.JhyStatusCountVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -25,9 +26,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Slf4j
 @Service
@@ -172,6 +171,7 @@
             order.setStatus(JhyOrder.ORDER_STATUS_CANCEL);
         }
 
+        order.setJhyId(null);
         jhyOrderMapper.updateByPrimaryKey(order);
     }
 
@@ -236,4 +236,30 @@
 
         distribService.distribRecord(order.getId(), order.getUserId());
     }
+
+    public Map<Integer, Integer> orderStatusCount(String userId) {
+        List<JhyStatusCountVo> count = jhyOrderMapper.selectOrderStatusCount(userId);
+
+        Map<Integer, Integer> map = new HashMap<>();
+        for (int i = 1; i < 6; i++) {
+            if (CollUtil.isNotEmpty(count)) {
+                boolean flag = false;
+                for (JhyStatusCountVo jhyStatusCountVo : count) {
+                    if (i == jhyStatusCountVo.getStatus()) {
+                        map.put(i, jhyStatusCountVo.getCnt());
+                        flag = true;
+                        break;
+                    }
+                }
+
+                if (flag) {
+                    continue;
+                }
+            }
+
+            map.put(i, 0);
+        }
+
+        return map;
+    }
 }
diff --git a/gc-order/src/main/java/com/xzx/gc/order/vo/JhyStatusCountVo.java b/gc-order/src/main/java/com/xzx/gc/order/vo/JhyStatusCountVo.java
new file mode 100644
index 0000000..e698e3b
--- /dev/null
+++ b/gc-order/src/main/java/com/xzx/gc/order/vo/JhyStatusCountVo.java
@@ -0,0 +1,13 @@
+package com.xzx.gc.order.vo;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "JhyStatucCountVo", description = "")
+public class JhyStatusCountVo {
+
+    private Integer status;
+
+    private Integer cnt;
+}
diff --git a/gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml b/gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml
index e796b6d..01997c5 100644
--- a/gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml
+++ b/gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml
@@ -43,4 +43,18 @@
         group by a.id
         order by a.receiving_time desc, a.id desc
     </select>
+
+    <select id="selectOrderStatusCount" resultType="com.xzx.gc.order.vo.JhyStatusCountVo">
+        select
+           status,
+           count(1) cnt
+        from xzx_jhy_order where status=1
+        union  all
+        select
+           status,
+           count(1) cnt
+        from xzx_jhy_order
+        where user_id=#{userId}
+        group by status
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.1