yangdamao 1 жил өмнө
parent
commit
c03fadd8d5

+ 2 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/goods/mapper/TopOldOrderMapper.java

@@ -9,6 +9,7 @@ import com.zhongzheng.modules.top.goods.domain.TopOldOrder;
 import com.zhongzheng.modules.top.goods.vo.TopOldOrderInvoiceVo;
 import com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo;
 import com.zhongzheng.modules.top.goods.vo.TopOldOrderVo;
+import com.zhongzheng.modules.top.order.bo.TopDetailStatisticsTotal;
 import com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo;
 import com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo;
 import com.zhongzheng.modules.top.order.vo.*;
@@ -93,7 +94,7 @@ public interface TopOldOrderMapper extends BaseMapper<TopOldOrder> {
 
     List<TopOrderStatisticsDetailVo> getDetailStatistics(TopOrderStatisticsBo bo);
 
-    TopOrderStatisticsDetailTotalVo getDetailStatisticsTotal(@Param("startTime")Long startTime,@Param("endTime")Long endTime);
+    TopOrderStatisticsDetailTotalVo getDetailStatisticsTotal(TopDetailStatisticsTotal total);
 
     Long getOrderTenant(Long customerId);
 

+ 42 - 8
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/goods/service/impl/TopOldOrderServiceImpl.java

@@ -59,6 +59,7 @@ import com.zhongzheng.modules.top.goods.mapper.TopOldOrderMapper;
 import com.zhongzheng.modules.top.goods.service.*;
 import com.zhongzheng.modules.top.goods.vo.*;
 import com.zhongzheng.modules.top.order.bo.PayOrderCallBackBo;
+import com.zhongzheng.modules.top.order.bo.TopDetailStatisticsTotal;
 import com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo;
 import com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo;
 import com.zhongzheng.modules.top.order.domain.TopOrderBankPay;
@@ -2828,10 +2829,10 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                 twoVo.setCustomerName(customerName);
                 twoVo.setTime(time);
                 twoVo.setTimeStr(DateUtils.timestampToDateFormat(time,"yyyy-MM"));
-                if (voList2.stream().anyMatch(x ->
+                if (voList3.stream().anyMatch(x ->
                         DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
                                 && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= monthTime.get(time))){
-                    TopOrderStatisticsTwoVo statisticsTwoVo = voList2.stream()
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList3.stream()
                             .filter(x ->
                                     DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
                                             && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= monthTime.get(time)).findFirst().get();
@@ -2876,13 +2877,22 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                     break;
             }
         }
-
+        if (StringUtils.isNotBlank(bo.getBusinessName())){
+            String collect = Arrays.stream(bo.getBusinessName().split("-")).collect(Collectors.joining());
+            bo.setBusinessName(collect);
+        }
         List<TopOrderStatisticsDetailVo> detailVos = baseMapper.getDetailStatistics(bo);
         if (CollectionUtils.isEmpty(detailVos)){
             return new ArrayList<>();
         }
-
-        TopOrderStatisticsDetailTotalVo totalVo = baseMapper.getDetailStatisticsTotal(bo.getStartTime(),bo.getEndTime());
+        TopDetailStatisticsTotal total = new TopDetailStatisticsTotal();
+        total.setStartTime(bo.getStartTime());
+        total.setEndTime(bo.getEndTime());
+        total.setCustomerId(bo.getCustomerId());
+        total.setBusinessName(bo.getBusinessName());
+        total.setCustomerName(bo.getCustomerName());
+        total.setTenantId(bo.getTenantId());
+        TopOrderStatisticsDetailTotalVo totalVo = baseMapper.getDetailStatisticsTotal(total);
         detailVos.forEach(item -> {
             //订单客户机构ID
             if (item.getOrderType() == 1){
@@ -2903,6 +2913,9 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
             topOrderStatisticsBo.setStartTime(startTime - time);
             topOrderStatisticsBo.setEndTime(startTime);
             topOrderStatisticsBo.setCustomerId(item.getCustomerId());
+            topOrderStatisticsBo.setBusinessName(bo.getBusinessName());
+            topOrderStatisticsBo.setCustomerName(bo.getCustomerName());
+            topOrderStatisticsBo.setTenantId(bo.getTenantId());
             List<TopOrderStatisticsMoneyVo> moneyStatistics = baseMapper.getMoneyStatistics(topOrderStatisticsBo);
             if (CollectionUtils.isNotEmpty(moneyStatistics)){
                 BigDecimal money = moneyStatistics.stream().findFirst().get().getMoney();
@@ -3238,7 +3251,14 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                     break;
             }
         }
-        TopOrderStatisticsDetailTotalVo totalVo = baseMapper.getDetailStatisticsTotal(bo.getStartTime(),bo.getEndTime());
+        TopDetailStatisticsTotal total = new TopDetailStatisticsTotal();
+        total.setStartTime(bo.getStartTime());
+        total.setEndTime(bo.getEndTime());
+        total.setCustomerId(bo.getCustomerId());
+        total.setBusinessName(bo.getBusinessName());
+        total.setCustomerName(bo.getCustomerName());
+        total.setTenantId(bo.getTenantId());
+        TopOrderStatisticsDetailTotalVo totalVo = baseMapper.getDetailStatisticsTotal(total);
         resultVo.setOrderNum(totalVo.getOrderNumTotal());
         resultVo.setMoney(totalVo.getMoneyTotal());
         BigDecimal moneyTotal = totalVo.getMoneyTotal();
@@ -3248,7 +3268,14 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
         Long endTime = bo.getEndTime();
         Long time = endTime - startTime;
         Long timeTwo =startTime - time;
-        TopOrderStatisticsDetailTotalVo totalVoTwo = baseMapper.getDetailStatisticsTotal(timeTwo,startTime);
+        TopDetailStatisticsTotal total1 = new TopDetailStatisticsTotal();
+        total1.setStartTime(timeTwo);
+        total1.setEndTime(startTime);
+        total1.setCustomerId(bo.getCustomerId());
+        total1.setBusinessName(bo.getBusinessName());
+        total1.setCustomerName(bo.getCustomerName());
+        total1.setTenantId(bo.getTenantId());
+        TopOrderStatisticsDetailTotalVo totalVoTwo = baseMapper.getDetailStatisticsTotal(total1);
         if (ObjectUtils.isNotNull(totalVoTwo)){
             BigDecimal money = totalVoTwo.getMoneyTotal();
             if (ObjectUtils.isNull(money)){
@@ -3271,7 +3298,14 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
         //同比
         Long startBefore = DateUtils.getDayBefore(bo.getStartTime(), 365);
         Long endBefore = DateUtils.getDayBefore(bo.getEndTime(), 365);
-        TopOrderStatisticsDetailTotalVo totalVo3 = baseMapper.getDetailStatisticsTotal(startBefore,endBefore);
+        TopDetailStatisticsTotal total2 = new TopDetailStatisticsTotal();
+        total2.setStartTime(startBefore);
+        total2.setEndTime(endBefore);
+        total2.setCustomerId(bo.getCustomerId());
+        total2.setBusinessName(bo.getBusinessName());
+        total2.setCustomerName(bo.getCustomerName());
+        total2.setTenantId(bo.getTenantId());
+        TopOrderStatisticsDetailTotalVo totalVo3 = baseMapper.getDetailStatisticsTotal(total2);
         if (ObjectUtils.isNotNull(totalVo3)){
             BigDecimal money = totalVo3.getMoneyTotal();
             if (ObjectUtils.isNull(money)){

+ 34 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/order/bo/TopDetailStatisticsTotal.java

@@ -0,0 +1,34 @@
+package com.zhongzheng.modules.top.order.bo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author yangdamao
+ * @date 2023年11月21日 16:29
+ */
+@Data
+public class TopDetailStatisticsTotal implements Serializable {
+
+    @ApiModelProperty("开始时间")
+    private Long startTime;
+
+    @ApiModelProperty("结束时间")
+    private Long endTime;
+
+    private Long customerId;
+
+    private String customerName;
+
+    @ApiModelProperty("业务号")
+    private String createNo;
+
+    @ApiModelProperty("企业ID")
+    private String tenantId;
+
+    @ApiModelProperty("业务层次")
+    private String businessName;
+
+}

+ 123 - 3
zhongzheng-system/src/main/resources/mapper/modules/top/TopOldOrderMapper.xml

@@ -670,6 +670,15 @@
                 <if test="customerId != null and customerId != ''">
                     AND too.old_customer_id = #{customerId}
                 </if>
+                <if test="tenantId != null and tenantId != ''">
+                    AND too.tenant_id = #{tenantId}
+                </if>
+                <if test="businessName != null and businessName != ''">
+                    AND (SELECT COUNT(DISTINCT oog.order_sn) FROM top_old_order_goods oog WHERE too.order_sn = oog.order_sn AND INSTR(oog.business_full_name,#{businessName}) ) > 0
+                </if>
+                <if test="customerName != null and customerName != ''">
+                    AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
+                </if>
             GROUP BY
             too.old_customer_id UNION ALL
             SELECT
@@ -693,6 +702,24 @@
                 <if test="customerId != null and customerId != ''">
                     AND o.tenant_id  = #{customerId}
                 </if>
+                <if test="businessName != null and businessName != ''">
+                    AND (
+                    SELECT
+                    COUNT(DISTINCT og.order_sn)
+                    FROM order_goods og
+                    LEFT JOIN goods g ON og.goods_id = g.goods_id
+                    LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
+                    LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
+                    LEFT JOIN course_business cb ON g.business_id = cb.id
+                    WHERE o.order_sn = og.order_sn
+                    AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
+                </if>
+                <if test="tenantId != null and tenantId != ''">
+                    AND o.tenant_id = #{tenantId}
+                </if>
+                <if test="customerName != null and customerName != ''">
+                    AND (SELECT COUNT(s.tenant_id) FROM sys_tenant s WHERE o.tenant_id = s.tenant_id AND s.tenant_name LIKE CONCAT('%',#{customerName},'%')) > 0
+                </if>
             GROUP BY
             o.tenant_id
         ) a
@@ -775,6 +802,15 @@
         <if test="customerId != null and customerId != ''">
             AND too.old_customer_id = #{customerId}
         </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND too.tenant_id = #{tenantId}
+        </if>
+        <if test="businessName != null and businessName != ''">
+            AND (SELECT COUNT(DISTINCT oog.order_sn) FROM top_old_order_goods oog WHERE too.order_sn = oog.order_sn AND INSTR(oog.business_full_name,#{businessName}) ) > 0
+        </if>
+        <if test="customerName != null and customerName != ''">
+            AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
+        </if>
         GROUP BY
         too.old_customer_id UNION ALL
         SELECT
@@ -798,6 +834,24 @@
         <if test="customerId != null and customerId != ''">
             AND o.tenant_id  = #{customerId}
         </if>
+        <if test="businessName != null and businessName != ''">
+            AND (
+            SELECT
+            COUNT(DISTINCT og.order_sn)
+            FROM order_goods og
+            LEFT JOIN goods g ON og.goods_id = g.goods_id
+            LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
+            LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
+            LEFT JOIN course_business cb ON g.business_id = cb.id
+            WHERE o.order_sn = og.order_sn
+            AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND o.tenant_id = #{tenantId}
+        </if>
+        <if test="customerName != null and customerName != ''">
+            AND (SELECT COUNT(s.tenant_id) FROM sys_tenant s WHERE o.tenant_id = s.tenant_id AND s.tenant_name LIKE CONCAT('%',#{customerName},'%')) > 0
+        </if>
         GROUP BY
         o.tenant_id
         ) a
@@ -845,12 +899,12 @@
         ) num_total
     </select>
 
-    <select id="getDetailStatisticsTotal" parameterType="java.lang.Long"
+    <select id="getDetailStatisticsTotal" parameterType="com.zhongzheng.modules.top.order.bo.TopDetailStatisticsTotal"
             resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailTotalVo">
         SELECT
         ((
         SELECT
-        SUM( too.order_received - too.order_refunded ) AS money
+        IFNULL(SUM( too.order_received - too.order_refunded ),0) AS money
         FROM
         top_old_order too
         WHERE
@@ -863,9 +917,21 @@
         <if test="endTime != null and endTime != ''">
             AND too.check_time &lt;= #{endTime}
         </if>
+        <if test="customerId != null and customerId != ''">
+            AND too.old_customer_id = #{customerId}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND too.tenant_id = #{tenantId}
+        </if>
+        <if test="businessName != null and businessName != ''">
+            AND (SELECT COUNT(DISTINCT oog.order_sn) FROM top_old_order_goods oog WHERE too.order_sn = oog.order_sn AND INSTR(oog.business_full_name,#{businessName}) ) > 0
+        </if>
+        <if test="customerName != null and customerName != ''">
+            AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
+        </if>
         ) + (
         SELECT
-        SUM( o.pay_price ) AS money
+        IFNULL(SUM( o.pay_price ),0) AS money
         FROM
         `order` o
         WHERE
@@ -880,6 +946,27 @@
         <if test="endTime != null and endTime != ''">
             AND o.create_time &lt;= #{endTime}
         </if>
+        <if test="customerId != null and customerId != ''">
+            AND o.tenant_id  = #{customerId}
+        </if>
+        <if test="businessName != null and businessName != ''">
+            AND (
+            SELECT
+            COUNT(DISTINCT og.order_sn)
+            FROM order_goods og
+            LEFT JOIN goods g ON og.goods_id = g.goods_id
+            LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
+            LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
+            LEFT JOIN course_business cb ON g.business_id = cb.id
+            WHERE o.order_sn = og.order_sn
+            AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND o.tenant_id = #{tenantId}
+        </if>
+        <if test="customerName != null and customerName != ''">
+            AND (SELECT COUNT(s.tenant_id) FROM sys_tenant s WHERE o.tenant_id = s.tenant_id AND s.tenant_name LIKE CONCAT('%',#{customerName},'%')) > 0
+        </if>
         )) moneyTotal,
         ((
         SELECT
@@ -896,6 +983,18 @@
         <if test="endTime != null and endTime != ''">
             AND too.check_time &lt;= #{endTime}
         </if>
+        <if test="customerId != null and customerId != ''">
+            AND too.old_customer_id = #{customerId}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND too.tenant_id = #{tenantId}
+        </if>
+        <if test="businessName != null and businessName != ''">
+            AND (SELECT COUNT(DISTINCT oog.order_sn) FROM top_old_order_goods oog WHERE too.order_sn = oog.order_sn AND INSTR(oog.business_full_name,#{businessName}) ) > 0
+        </if>
+        <if test="customerName != null and customerName != ''">
+            AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
+        </if>
         ) + (
         SELECT
         COUNT(o.order_id) AS orderNum
@@ -913,6 +1012,27 @@
         <if test="endTime != null and endTime != ''">
             AND o.create_time &lt;= #{endTime}
         </if>
+        <if test="customerId != null and customerId != ''">
+            AND o.tenant_id  = #{customerId}
+        </if>
+        <if test="businessName != null and businessName != ''">
+            AND (
+            SELECT
+            COUNT(DISTINCT og.order_sn)
+            FROM order_goods og
+            LEFT JOIN goods g ON og.goods_id = g.goods_id
+            LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
+            LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
+            LEFT JOIN course_business cb ON g.business_id = cb.id
+            WHERE o.order_sn = og.order_sn
+            AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND o.tenant_id = #{tenantId}
+        </if>
+        <if test="customerName != null and customerName != ''">
+            AND (SELECT COUNT(s.tenant_id) FROM sys_tenant s WHERE o.tenant_id = s.tenant_id AND s.tenant_name LIKE CONCAT('%',#{customerName},'%')) > 0
+        </if>
         )) orderNumTotal
     </select>