Commit 0c94316929590efc1376987a5f9a63bdba6f130b

Authored by YunaiV
1 parent 925806e6

fix: 适配商城、CRM 和 MES 布尔字段查询

yudao-module-crm/src/main/resources/mapper/statistics/CrmStatisticsPortraitMapper.xml
... ... @@ -4,7 +4,8 @@
4 4  
5 5 <select id="selectSummaryListGroupByAreaId"
6 6 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerAreaRespVO">
7   - SELECT area_id, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
  7 + <bind name="trueValue" value="true"/>
  8 + SELECT area_id, COUNT(*) AS customerCount, SUM(CASE WHEN deal_status = #{trueValue} THEN 1 WHEN deal_status IS NULL THEN NULL ELSE 0 END) AS dealCount
8 9 FROM crm_customer
9 10 WHERE deleted = 0 AND area_id IS NOT NULL
10 11 AND owner_user_id IN
... ... @@ -18,7 +19,8 @@
18 19  
19 20 <select id="selectCustomerIndustryListGroupByIndustryId"
20 21 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerIndustryRespVO">
21   - SELECT industry_id, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
  22 + <bind name="trueValue" value="true"/>
  23 + SELECT industry_id, COUNT(*) AS customerCount, SUM(CASE WHEN deal_status = #{trueValue} THEN 1 WHEN deal_status IS NULL THEN NULL ELSE 0 END) AS dealCount
22 24 FROM crm_customer
23 25 WHERE deleted = 0 AND industry_id IS NOT NULL
24 26 AND owner_user_id IN
... ... @@ -32,7 +34,8 @@
32 34  
33 35 <select id="selectCustomerSourceListGroupBySource"
34 36 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerSourceRespVO">
35   - SELECT source, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
  37 + <bind name="trueValue" value="true"/>
  38 + SELECT source, COUNT(*) AS customerCount, SUM(CASE WHEN deal_status = #{trueValue} THEN 1 WHEN deal_status IS NULL THEN NULL ELSE 0 END) AS dealCount
36 39 FROM crm_customer
37 40 WHERE deleted = 0 AND source IS NOT NULL
38 41 AND owner_user_id IN
... ... @@ -46,7 +49,8 @@
46 49  
47 50 <select id="selectCustomerLevelListGroupByLevel"
48 51 resultType="cn.iocoder.yudao.module.crm.controller.admin.statistics.vo.portrait.CrmStatisticCustomerLevelRespVO">
49   - SELECT level, COUNT(*) AS customerCount, SUM(deal_status) AS dealCount
  52 + <bind name="trueValue" value="true"/>
  53 + SELECT level, COUNT(*) AS customerCount, SUM(CASE WHEN deal_status = #{trueValue} THEN 1 WHEN deal_status IS NULL THEN NULL ELSE 0 END) AS dealCount
50 54 FROM crm_customer
51 55 WHERE deleted = 0 AND level IS NOT NULL
52 56 AND owner_user_id IN
... ...
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/product/ProductStatisticsMapper.xml
... ... @@ -4,6 +4,7 @@
4 4  
5 5 <select id="selectStatisticsResultPageByTimeBetween"
6 6 resultType="cn.iocoder.yudao.module.statistics.dal.dataobject.product.ProductStatisticsDO">
  7 + <bind name="trueValue" value="true"/>
7 8 SELECT spu.id AS spuId
8 9 -- 浏览量:一个用户可以有多次
9 10 , (SELECT COUNT(1)
... ... @@ -55,7 +56,7 @@
55 56 FROM trade_order_item item
56 57 JOIN trade_order o ON item.order_id = o.id
57 58 WHERE spu_id = spu.id
58   - AND o.pay_status = TRUE
  59 + AND o.pay_status = #{trueValue}
59 60 AND item.create_time BETWEEN #{beginTime} AND #{endTime}
60 61 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
61 62 AND item.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
... ... @@ -67,7 +68,7 @@
67 68 FROM trade_order_item item
68 69 JOIN trade_order o ON item.order_id = o.id
69 70 WHERE spu_id = spu.id
70   - AND o.pay_status = TRUE
  71 + AND o.pay_status = #{trueValue}
71 72 AND item.create_time BETWEEN #{beginTime} AND #{endTime}
72 73 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
73 74 AND item.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
... ...
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml
... ... @@ -4,6 +4,7 @@
4 4  
5 5 <select id="selectSummaryListByAreaId"
6 6 resultType="cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO">
  7 + <bind name="trueValue" value="true"/>
7 8 SELECT receiver_area_id AS areaId,
8 9 (SELECT COUNT(DISTINCT s.user_id)
9 10 FROM trade_order s
... ... @@ -15,7 +16,7 @@
15 16 (SELECT COUNT(DISTINCT s.user_id)
16 17 FROM trade_order s
17 18 WHERE s.receiver_area_id = m.receiver_area_id
18   - AND s.pay_status = TRUE
  19 + AND s.pay_status = #{trueValue}
19 20 AND s.deleted = 0
20 21 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
21 22 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
... ... @@ -24,7 +25,7 @@
24 25 (SELECT SUM(s.pay_price)
25 26 FROM trade_order s
26 27 WHERE s.receiver_area_id = m.receiver_area_id
27   - AND s.pay_status = TRUE
  28 + AND s.pay_status = #{trueValue}
28 29 AND s.deleted = 0
29 30 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
30 31 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
... ... @@ -49,10 +50,11 @@
49 50 </select>
50 51  
51 52 <select id="selectUserCountByPayTimeBetween" resultType="java.lang.Integer">
  53 + <bind name="trueValue" value="true"/>
52 54 SELECT COUNT(DISTINCT (user_id))
53 55 FROM trade_order
54 56 WHERE pay_time BETWEEN #{beginTime} AND #{endTime}
55   - AND pay_status = TRUE
  57 + AND pay_status = #{trueValue}
56 58 AND deleted = 0
57 59 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
58 60 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
... ... @@ -70,9 +72,10 @@
70 72 </select>
71 73  
72 74 <select id="selectCountByPayTimeBetween" resultType="java.lang.Integer">
  75 + <bind name="trueValue" value="true"/>
73 76 SELECT COUNT(1)
74 77 FROM trade_order
75   - WHERE pay_status = TRUE
  78 + WHERE pay_status = #{trueValue}
76 79 AND create_time BETWEEN #{beginTime} AND #{endTime}
77 80 AND deleted = 0
78 81 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
... ... @@ -81,9 +84,10 @@
81 84 </select>
82 85  
83 86 <select id="selectSummaryPriceByPayTimeBetween" resultType="java.lang.Integer">
  87 + <bind name="trueValue" value="true"/>
84 88 SELECT SUM(pay_price)
85 89 FROM trade_order s
86   - WHERE s.pay_status = TRUE
  90 + WHERE s.pay_status = #{trueValue}
87 91 AND deleted = 0
88 92 AND create_time BETWEEN #{beginTime} AND #{endTime}
89 93 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
... ... @@ -99,11 +103,12 @@
99 103 </resultMap>
100 104  
101 105 <select id="selectListByPayTimeBetweenAndGroupByDay" resultMap="TradeOrderTrendRespVOMap">
  106 + <bind name="trueValue" value="true"/>
102 107 SELECT ${@cn.iocoder.yudao.framework.mybatis.core.util.SqlDialectUtils@castDateText('pay_time')} AS statDate,
103 108 COUNT(1) AS order_pay_count,
104 109 SUM(pay_price) AS order_pay_price
105 110 FROM trade_order
106   - WHERE pay_status = TRUE
  111 + WHERE pay_status = #{trueValue}
107 112 AND create_time BETWEEN #{beginTime} AND #{endTime}
108 113 AND deleted = 0
109 114 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
... ... @@ -114,11 +119,12 @@
114 119 </select>
115 120  
116 121 <select id="selectListByPayTimeBetweenAndGroupByMonth" resultMap="TradeOrderTrendRespVOMap">
  122 + <bind name="trueValue" value="true"/>
117 123 SELECT ${@cn.iocoder.yudao.framework.mybatis.core.util.SqlDialectUtils@formatYearDashMonth('pay_time')} AS statDate,
118 124 COUNT(1) AS order_pay_count,
119 125 SUM(pay_price) AS order_pay_price
120 126 FROM trade_order
121   - WHERE pay_status = TRUE
  127 + WHERE pay_status = #{trueValue}
122 128 AND create_time BETWEEN #{beginTime} AND #{endTime}
123 129 AND deleted = 0
124 130 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
... ...
yudao-module-mes/src/main/resources/mapper/qc/pendinginspect/MesQcPendingInspectMapper.xml
... ... @@ -10,9 +10,11 @@
10 10 4. 销售出库单(OQC):单据状态=CONFIRMED(1),行的 oqc_check_flag=1 且 oqc_id 为空
11 11 5. 生产退料单(RQC):单据状态=CONFIRMED(1),行的 rqc_check_flag=1 且 rqc_id 为空 且 quality_status=0(待检)
12 12 6. 销售退货单(RQC):单据状态=CONFIRMED(1),行的 rqc_check_flag=1 且 rqc_id 为空 且 quality_status=0(待检)
  13 + IQC、RQC 的检验标记为 bit(1) 布尔列,使用绑定的 Boolean true 比较;OQC 的 oqc_check_flag 为 tinyint(1),保持数值 1 比较
13 14 注意:各分支无值的 ID 列使用 CASE WHEN 1 = 0 THEN 本分支 bigint 列 END 产生“带类型的 NULL”,避免 UNION 中裸 NULL 的类型推断差异
14 15 -->
15 16 <select id="selectQcPendingPage" resultType="cn.iocoder.yudao.module.mes.controller.admin.qc.pendinginspect.vo.MesQcPendingInspectRespVO">
  17 + <bind name="trueValue" value="true"/>
16 18 SELECT * FROM (
17 19 <!-- 1. IQC 来源:到货通知单 -->
18 20 SELECT
... ... @@ -32,7 +34,7 @@
32 34 FROM mes_wm_arrival_notice n
33 35 JOIN mes_wm_arrival_notice_line l ON n.id = l.notice_id
34 36 WHERE n.status = ${@cn.iocoder.yudao.module.mes.enums.wm.MesWmArrivalNoticeStatusEnum@PENDING_QC.status}
35   - AND l.iqc_check_flag = 1
  37 + AND l.iqc_check_flag = #{trueValue}
36 38 AND l.iqc_id IS NULL
37 39 AND n.deleted = 0
38 40 AND l.deleted = 0
... ... @@ -57,7 +59,7 @@
57 59 FROM mes_wm_outsource_receipt r
58 60 JOIN mes_wm_outsource_receipt_line rl ON r.id = rl.receipt_id
59 61 WHERE r.status = ${@cn.iocoder.yudao.module.mes.enums.wm.MesWmOutsourceReceiptStatusEnum@CONFIRMED.status}
60   - AND rl.iqc_check_flag = 1
  62 + AND rl.iqc_check_flag = #{trueValue}
61 63 AND rl.iqc_id IS NULL
62 64 AND r.deleted = 0
63 65 AND rl.deleted = 0
... ... @@ -132,7 +134,7 @@
132 134 FROM mes_wm_return_issue ri
133 135 JOIN mes_wm_return_issue_line ril ON ri.id = ril.issue_id
134 136 WHERE ri.status = ${@cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnIssueStatusEnum@CONFIRMED.status}
135   - AND ril.rqc_check_flag = 1
  137 + AND ril.rqc_check_flag = #{trueValue}
136 138 AND ril.rqc_id IS NULL
137 139 AND ril.quality_status = ${@cn.iocoder.yudao.module.mes.enums.wm.MesWmQualityStatusEnum@PENDING.status}
138 140 AND ri.deleted = 0
... ... @@ -158,7 +160,7 @@
158 160 FROM mes_wm_return_sales r
159 161 JOIN mes_wm_return_sales_line rl ON r.id = rl.return_id
160 162 WHERE r.status = ${@cn.iocoder.yudao.module.mes.enums.wm.MesWmReturnSalesStatusEnum@CONFIRMED.status}
161   - AND rl.rqc_check_flag = 1
  163 + AND rl.rqc_check_flag = #{trueValue}
162 164 AND rl.rqc_id IS NULL
163 165 AND rl.quality_status = ${@cn.iocoder.yudao.module.mes.enums.wm.MesWmQualityStatusEnum@PENDING.status}
164 166 AND r.deleted = 0
... ...