xuekang
2024-05-13 15a0280ae9e7db96fdf0744c722d214d2cb5a0e5
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
<?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="com.nuvole.four.mapper.ActivityShopRecordMapper" >
  <select id="selectList" parameterType="com.nuvole.four.domain.query.ActivityShopRecordQuery" resultType="com.nuvole.four.domain.ActivityShopRecord">
    select <include refid="Base_Column_List"></include>
    from activity_shop_record
    <where>
        deleted = 0
      <if test="activityId!=null">
        and activity_id =#{activityId}
      </if>
      <if test="merchantShopId!=null">
        and merchant_shop_id =#{merchantShopId}
      </if>
      <if test="channelId!=null">
        and channel_id =#{channelId}
      </if>
      <if test="channelName!=null and channelName!=''">
        and channel_name like concat('%',#{channelName},'%')
      </if>
      <if test="totalFee!=null">
        and total_fee =#{totalFee}
      </if>
      <if test="thirdShopNo!=null and thirdShopNo!=''">
        and third_shop_no like concat('%',#{thirdShopNo},'%')
      </if>
      <if test="useFee!=null">
        and use_fee =#{useFee}
      </if>
      <if test="surplusFee!=null">
        and surplus_fee =#{surplusFee}
      </if>
      <if test="status!=null">
        and status =#{status}
      </if>
      <if test="deleted!=null">
        and deleted =#{deleted}
      </if>
      <if test="createBy!=null">
        and create_by =#{createBy}
      </if>
      <if test="createTime!=null">
        and create_time =#{createTime}
      </if>
      <if test="updateBy!=null">
        and update_by =#{updateBy}
      </if>
      <if test="updateTime!=null">
        and update_time =#{updateTime}
      </if>
    </where>
  </select>
 
    <select id="getActRateByShopId" resultType="map">
        SELECT
            feeAct.online_mer_wx_rate onlineMerWxRate,
            feeAct.online_mer_zfb_rate onlineMerZfbRate,
            feeAct.online_mer_unionpay_rate onlineMerUnionpayRate ,
            feeAct.offline_mer_wx_rate offlineMerWxRate,
            feeAct.offline_mer_zfb_rate offlineMerZfbRate,
            feeAct.offline_mer_unionpay_rate offlineMerUnionpayRate,
            shopRec.surplus_fee surplusFee,
            shopRec.activity_id activityId,
            shopRec.merchant_shop_id merchantShopId,
            shopRec.channel_id channelId
        FROM
            activity_shop_record shopRec
            LEFT JOIN activity_fee feeAct ON feeAct.id = shopRec.activity_id
        <where>
            NOW() BETWEEN feeAct.begin_time
            AND feeAct.end_time
            AND feeAct.`status` = 1
            AND feeAct.deleted = 0
            AND shopRec.deleted = 0
            AND shopRec.`status` = 1
            <if test="shopId != null">
                AND shopRec.merchant_shop_id = #{shopId}
            </if>
            <if test="channelId != null">
                AND shopRec.channel_id = #{channelId}
            </if>
        </where>
    </select>
    <select id="getAlreadyMerchantList" resultType="com.nuvole.four.domain.dto.ActivityShopRecordDto">
        select * from activity_shop_record
        <where>
            deleted = 0 and activity_id = #{activityId}
            <if test="merchantId != null">
                and merchant_shop_id =#{merchantId}
            </if>
            <if test="channelId != null">
                and channel_id = #{channelId}
            </if>
        </where>
    </select>
    <select id="selectByCondition" resultType="com.nuvole.four.domain.ActivityShopRecord">
        select * from activity_shop_record
        <where>
            and deleted = 0 and activity_id = #{activityId}
            <if test="ids != null">
                and merchant_shop_id in
                <foreach collection="ids" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
 
    <update id="updShopSurplusFee">
        UPDATE activity_shop_record
        SET use_fee = IFNULL(use_fee,0) + #{useFee},
        surplus_fee = IFNULL(surplus_fee,total_fee) - #{useFee}
        WHERE
            activity_id = #{activityId}
            AND merchant_shop_id = #{merchantShopId}
            AND channel_id =#{channelId}
    </update>
 
    <insert id="batchInsert" parameterType="list">
        insert into activity_shop_record
        (id,
        activity_id,
        merchant_shop_id,
        channel_id,
        channel_name,
        total_fee,
        third_shop_no,
        use_fee,
        surplus_fee,
        status,
        deleted,
        create_by,
        create_time)
        values
        <foreach collection="list" item="i" separator=",">
            (
            #{i.id},
            #{i.activityId},
            #{i.merchantShopId},
            #{i.channelId},
            #{i.channelName},
            #{i.totalFee},
            #{i.thirdShopNo},
            #{i.useFee},
            #{i.surplusFee},
            #{i.status},
            #{i.deleted},
            #{i.createBy},
            #{i.createTime}
            )
        </foreach>
        ON duplicate KEY UPDATE
        update_by = values(update_by),
        update_time = values(update_time)
    </insert>
 
    <insert id="batchUpdate" parameterType="list">
        insert into activity_shop_record
            (id,
            total_fee,
            use_fee,
            surplus_fee,
            update_by,
            update_time)
        values
        <foreach collection="list" item="i" separator=",">
            (
            #{i.id},
            #{i.totalFee},
            #{i.useFee},
            #{i.surplusFee},
            #{i.updateBy},
            #{i.updateTime}
            )
        </foreach>
        ON duplicate KEY UPDATE
            total_fee = values(total_fee),
            use_fee = values(use_fee),
            surplus_fee = values(surplus_fee),
            update_by = values(update_by),
            update_time = values(update_time)
    </insert>
</mapper>