java110
2020-07-07 70862b9228ccb2156971a22085ac31b6c8b6d2cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="centerServiceDAOImpl">
 
 
    <!-- 查询订单信息 -->
    <select id="getOrder" resultType="Map" parameterType="Map">
        SELECT `o_id` oId, `app_id` appId, `ext_transaction_id` extTransactionId, `user_id` userId, `request_time`
        requestTime,
        `create_time` createTime,`order_type_cd` orderTypeCd, `finish_time` finishTime, `remark`
        from c_orders t
        where 1=1
        <if test="oId != null and oId != ''">
            and t.o_id = #{oId}
        </if>
        <if test="extTransactionId != null and extTransactionId != ''">
            and t.ext_transaction_id = #{extTransactionId}
        </if>
        <if test="appId != null and appId != ''">
            and t.app_id = #{appId}
        </if>
    </select>
 
    <!-- 查询订单项信息 -->
    <select id="getOrderItems" resultType="Map" parameterType="Map">
        select t.b_id bId,t.o_id oId,t.create_time createTime,t.action,t.action_obj actionObj,
        t.finish_time finishTime,t.remark,ul.service_name serviceName,ul.log_text logText
        from c_order_item t
        LEFT JOIN unitem_log ul on t.b_id = ul.b_id and t.o_id = ul.o_id and ul.status_cd = '0'
        where 1=1
        <if test="oId != null and oId != ''">
            and t.o_id = #{oId}
        </if>
        <if test="bId != null and bId != ''">
            and t.b_id = #{bId}
        </if>
    </select>
 
 
    <!--保存订单信息 c_orders 中 -->
    <insert id="saveOrder" parameterType="Map">
        <![CDATA[
 
                    insert into c_orders(o_id,app_id,ext_transaction_id,user_id,request_time,order_type_cd,remark,status_cd)
                    values(#{oId},#{appId},#{extTransactionId},#{userId},#{requestTime},#{orderTypeCd},#{remark},'S')
 
        ]]>
    </insert>
    <!-- 保存属性信息c_orders_attrs 中-->
    <insert id="saveOrderAttrs" parameterType="Map">
        <![CDATA[
            insert into c_orders_attrs(o_id,attr_id,spec_cd,value)
            values(#{oId},#{attrId},#{specCd},#{value})
        ]]>
    </insert>
 
    <!--保存订单信息 c_order_item 中 -->
    <insert id="saveOrderItem" parameterType="Map">
        INSERT INTO `c_order_item` (`b_id`, `o_id`, `action`, `action_obj`, `finish_time`, `remark`,status_cd)
        VALUES (#{bId}, #{oId}, #{action}, #{actionObj}, #{finishTime}, #{remark},'S')
    </insert>
 
    <!--保存订单信息 unitem_log 中 -->
    <insert id="saveUnItemLog" parameterType="Map">
        INSERT INTO `unitem_log` (`b_id`, `o_id`, `service_name`, `log_text`,status_cd)
        VALUES (#{bId}, #{oId}, #{serviceName}, #{logText},'0')
    </insert>
    <!-- 修改订单项信息 -->
    <update id="updateOrderItem" parameterType="Map">
        update c_order_item t
        set t.finish_time = #{finishTime},
             t.status_cd = #{statusCd}
        where t.o_id = #{oId}
    </update>
 
    <!-- 删除事务日志 -->
    <update id="deleteUnItemLog" parameterType="Map">
        delete from unitem_log where o_id = #{oId}
    </update>
 
 
 
    <!-- 保存订单项信息 c_business -->
    <insert id="saveBusiness" parameterType="Map">
        <![CDATA[
 
                    insert into c_business(b_id,o_id,business_type_cd,remark,status_cd)
                    values(#{bId},#{oId},#{businessTypeCd},#{remark},#{statusCd})
 
        ]]>
    </insert>
    <!-- 保存属性信息 c_business_attrs -->
    <insert id="saveBusinessAttrs" parameterType="Map">
        <![CDATA[
 
                    insert into c_business_attrs(b_id,attr_id,spec_cd,value)
                    values(#{bId},#{attrId},#{specCd},#{value})
 
        ]]>
    </insert>
    <!-- 更新订单信息(一般就更新订单状态) -->
    <update id="updateOrder" parameterType="Map">
        <![CDATA[
 
                    update c_orders co set
                    co.status_cd=#{statusCd},
                    co.finish_time=#{finishTime}
                    where co.o_id=#{oId}
 
        ]]>
    </update>
    <!-- 更新订单项信息(一般就更新订单项状态)-->
    <update id="updateBusiness" parameterType="Map">
        <![CDATA[
 
                    update c_business cb set
                    cb.status_cd=#{statusCd},
                    cb.finish_time=#{finishTime}
                    where cb.o_id=#{oId}
 
        ]]>
    </update>
    <!--根据bId 修改业务项信息-->
    <update id="updateBusinessByBId" parameterType="Map">
        <![CDATA[
 
                    update c_business cb set
                    cb.status_cd=#{statusCd},
                    cb.finish_time=#{finishTime}
                    where cb.b_id in (#{bId})
                    and cb.status_cd not in ('E')
 
        ]]>
    </update>
    <!-- 当所有业务动作是否都是C,将订单信息改为 C-->
    <update id="completeOrderByBId" parameterType="String">
        <![CDATA[
 
                    update c_orders co set co.status_cd = 'C' where co.status_cd='S'
                        and not exists(
                                select 1 from c_business cb where cb.status_cd <> 'C'
                                and cb.o_id = co.o_id
                                and cb.b_id in (#{bId})
                        )
 
        ]]>
    </update>
 
    <!-- 当所有业务动作是否都是C,将订单信息改为 C-->
    <update id="completeOrderByOId" parameterType="String">
        <![CDATA[
 
                    update c_orders co set co.status_cd = 'C' where co.status_cd='S'
                        and co.o_id = #{oId}
                        and not exists(
                                select 1 from c_business cb where cb.status_cd <> 'C'
                                and cb.o_id = co.o_id
                        )
 
        ]]>
    </update>
 
    <select id="getOrderInfoByBId" parameterType="String" resultType="Map">
        <![CDATA[
 
                select co.* from c_orders co where 1 = 1 and exists
                (
                    select 1 from c_business cb where cb.o_id = co.o_id
                    and cb.b_id = #{bId}
                )
 
        ]]>
    </select>
    <!-- 根据 OID 查询 business -->
    <select id="getBusinessByOId" parameterType="map" resultType="map">
        SELECT co.`o_id`,co.`app_id`,co.`order_type_cd`,co.`user_id`,cb.`business_type_cd`,cb.`b_id`,cb.`status_cd`
        FROM c_orders co,c_business cb
        WHERE co.`o_id` = cb.`o_id`
        AND cb.`business_type_cd` NOT IN ('DO')
        <if test="statusCd != null and statusCd != ''">
            AND cb.`status_cd` = #{statusCd}
        </if>
        <if test="oId != null and oId != ''">
            AND co.`o_id` = #{oId}
        </if>
    </select>
 
    <select id="getDeleteOrderBusinessByOId" parameterType="String" resultType="Map">
        <![CDATA[
 
                   select cb.b_id,cb.o_id,cb.business_type_cd,cb.status_cd from c_orders co,c_business cb where co.o_id = cb.o_id and cb.business_type_cd = 'DO' and cb.status_cd = 'DO'
                   and co.o_id = #{oId}
 
        ]]>
    </select>
 
    <!-- 获取同个订单中已经完成的订单项-->
    <select id="getCommonOrderCompledBusinessByBId" parameterType="String" resultType="Map">
        <![CDATA[
 
                    select * from c_business cb where cb.finish_time is not null
                    and cb.o_id in (
                        select cb1.o_id from c_business cb1 where cb1.b_id = #{bId}
                    )
 
        ]]>
    </select>
    <!--查询 所有有效 app信息-->
    <select id="getAppRouteAndServiceInfoAll" resultType="Map">
        <![CDATA[
 
                     SELECT ca.app_id,ca.name,ca.security_code,ca.while_list_ip,ca.black_list_ip,cr.invoke_limit_times,
                    cr.order_type_cd,cs.service_id,cs.business_type_cd,cr.invoke_model,cs.is_instance,
                    cs.messageQueueName,cs.method,cs.name,cs.provide_app_id,cs.retry_count,cs.seq,cs.service_code,
                    cs.timeout,cs.url FROM c_app ca,c_route cr,c_service cs
                    WHERE ca.status_cd = '0'
                    AND ca.app_id = cr.app_id
                    AND cr.status_cd = '0'
                    AND cr.service_id = cs.service_id
                    AND cs.status_cd = '0'
 
        ]]>
 
    </select>
 
    <select id="getMappingInfoAll" resultType="com.java110.entity.mapping.Mapping">
        <![CDATA[
 
                     SELECT cm.domain,cm.name,cm.key,cm.value,cm.remark from c_mapping cm where cm.status_cd = '0'
 
        ]]>
    </select>
 
    <select id="judgeAllBusinessCompleted" parameterType="map" resultType="map">
        SELECT co.* FROM c_orders co WHERE co.`o_id` = #{oId} and not exists (
        SELECT 1 FROM c_business cb WHERE cb.`o_id` = co.`o_id`
        AND cb.`status_cd` NOT IN (#{statusCd})
        )
        AND NOT EXISTS (
        SELECT 1 FROM c_business cbs WHERE cbs.`o_id` =co.`o_id`
        AND cbs.`business_type_cd` = 'DO'
        )
        AND co.`status_cd` NOT IN ('D','C','E')
    </select>
 
    <select id="judgeAllBusinessDeleteOrder" parameterType="map" resultType="map">
        SELECT co.* FROM c_orders co WHERE co.`o_id` = #{oId} and not exists (
        SELECT 1 FROM c_business cb WHERE cb.`o_id` = co.`o_id`
        AND cb.`status_cd` NOT IN (#{statusCd})
        )
        AND EXISTS (
        SELECT 1 FROM c_business cbs WHERE cbs.`o_id` =co.`o_id`
        AND cbs.`business_type_cd` = 'DO'
        )
        AND co.`status_cd` NOT IN ('C')
    </select>
 
    <!---->
    <select id="queryOwenrOrders" parameterType="map" resultType="map">
        <![CDATA[
 
                    select cb.b_id bId,co.o_id oId,cb.business_type_cd businessTypeCd  from c_orders co,c_business cb where co.o_id = cb.o_id
                    and cb.business_type_cd in ('110100030001','110100040001','110100050001','111100030001','111100050001')
                    and cb.status_cd = 'C'
 
        ]]>
    </select>
 
    <select id="queryManchineOrders" parameterType="map" resultType="map">
        <![CDATA[
 
                select cb.b_id bId,co.o_id oId,cb.business_type_cd businessTypeCd  from c_orders co,c_business cb where co.o_id = cb.o_id
                and cb.business_type_cd in ('200200030001','200200040001','200200050001')
                and cb.status_cd = 'C'
 
        ]]>
    </select>
 
    <!-- 240200030001', -->
    <select id="queryApplicationKeyOrders" parameterType="map" resultType="map">
        <![CDATA[
 
                select cb.b_id bId,co.o_id oId,cb.business_type_cd businessTypeCd  from c_orders co,c_business cb where co.o_id = cb.o_id
                and cb.business_type_cd in ('240200040001','240200050001')
                and cb.status_cd = 'C'
 
        ]]>
    </select>
 
    <select id="queryOrderByBusinessType" parameterType="map" resultType="map">
        select cb.b_id bId,co.o_id oId,cb.business_type_cd businessTypeCd
        from c_orders co,c_business cb
        where co.o_id = cb.o_id
        and cb.status_cd = 'C'
        <if test="businessTypeCds !=null">
            and cb.business_type_cd in
            <foreach collection="businessTypeCds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
 
    <update id="updateBusinessStatusCd" parameterType="Map">
        update c_business cb set cb.status_cd = 'C1'
        where cb.b_id = #{bId}
    </update>
 
 
    <!-- querySameOrderBusiness 查询同订单 订单项 -->
    <select id="querySameOrderBusiness" parameterType="map" resultType="map">
 
        SELECT
        cb1.b_id bId,
        cb1.o_id oId,
        cb1.create_time createTime,
        cb1.business_type_cd businessTypeCd,
        cb1.finish_time finishTime,
        cb1.status_cd statusCd
        FROM
        c_business cb1
        <if test="bId != null and bId != ''">
            ,c_business cb2
        </if>
        WHERE
        1=1
        <if test="bId != null and bId != ''">
            and cb1.o_id = cb2.o_id
            AND cb2.b_id = #{bId}
        </if>
        <if test="oId != null and oId != ''">
            and cb1.o_id = #{oId}
        </if>
        <if test="businessTypeCd != null and businessTypeCd != ''">
            and cb1.business_type_cd = #{businessTypeCd}
        </if>
 
 
    </select>
 
</mapper>