admin
2020-06-10 271ae63c20fcbe28d29c47f1881138ff6551a2a1
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
<?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.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceOrderUserMapMapper">
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">
        <id column="sou_id" property="id" jdbcType="BIGINT" />
        <result column="sou_source_uid" property="sourceUid" jdbcType="BIGINT" />
        <result column="sou_target_uid" property="targetUid" jdbcType="BIGINT" />
        <result column="sou_state" property="state" jdbcType="INTEGER" />
        <result column="sou_type" property="type" jdbcType="INTEGER" />
        <result column="sou_rate" property="rate" jdbcType="DECIMAL" />
        <result column="sou_money" property="money" jdbcType="DECIMAL" />
        <result column="sou_pre_send_time" property="preSendTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <result column="sou_send_time" property="sendTime" jdbcType="TIMESTAMP" />
        <association property="sourceOrder" column="sou_source_order_id"
            javaType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder">
            <id column="sou_source_order_id" property="id" jdbcType="BIGINT" />
        </association>
 
    </resultMap>
    
    <resultMap id="TeamDividentsVOMap" type="com.yeshi.fanli.vo.order.TeamDividentsVO">
        <result column="tdo_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="tdo_source_type" property="sourceType"    jdbcType="INTEGER" />
        <result column="dividents" property="dividents" jdbcType="DECIMAL" />
        <result column="subsidy" property="subsidy" jdbcType="DECIMAL" />
    </resultMap>
    
    
    <resultMap id="TeamOrderVOMap" type="com.yeshi.fanli.vo.order.TeamOrderVO">
        <result column="sou_state" property="divState" jdbcType="INTEGER" />
        <result column="totalMoney" property="divMoney" jdbcType="DECIMAL" />
        <result column="tdo_source_type" property="sourceType" jdbcType="INTEGER" />
        <result column="tdo_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="sou_send_time" property="sendTime" jdbcType="TIMESTAMP" />
        <result column="sou_source_uid" property="uid" jdbcType="BIGINT" />
    </resultMap>
    
    
    <sql id="Base_Column_List">sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu,sou_send_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where sou_id =
        #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_team_dividents_source_order_user where sou_id =
        #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_dividents_source_order_user
        (sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu,sou_send_time)
        values
        (#{id,jdbcType=BIGINT},#{sourceOrder.id,jdbcType=BIGINT},#{sourceUid,jdbcType=BIGINT},#{targetUid,jdbcType=BIGINT},#{state,jdbcType=INTEGER},#{type,jdbcType=INTEGER},#{rate,jdbcType=DECIMAL},#{money,jdbcType=DECIMAL},#{preSendTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{beiZhu,jdbcType=VARCHAR},#{sendTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_team_dividents_source_order_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">sou_id,</if>
            <if test="sourceOrder != null">sou_source_order_id,</if>
            <if test="sourceUid != null">sou_source_uid,</if>
            <if test="targetUid != null">sou_target_uid,</if>
            <if test="state != null">sou_state,</if>
            <if test="type != null">sou_type,</if>
            <if test="rate != null">sou_rate,</if>
            <if test="money != null">sou_money,</if>
            <if test="preSendTime != null">sou_pre_send_time,</if>
            <if test="createTime != null">sou_create_time,</if>
            <if test="updateTime != null">sou_update_time,</if>
            <if test="beiZhu != null">sou_beizhu,</if>
            <if test="sendTime != null">sou_send_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="sourceOrder != null">#{sourceOrder.id,jdbcType=BIGINT},</if>
            <if test="sourceUid != null">#{sourceUid,jdbcType=BIGINT},</if>
            <if test="targetUid != null">#{targetUid,jdbcType=BIGINT},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="type != null">#{type,jdbcType=INTEGER},</if>
            <if test="rate != null">#{rate,jdbcType=DECIMAL},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="preSendTime != null">#{preSendTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="sendTime != null">#{sendTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">update yeshi_ec_team_dividents_source_order_user set
        sou_source_order_id = #{sourceOrder.id,jdbcType=BIGINT},sou_source_uid
        = #{sourceUid,jdbcType=BIGINT},sou_target_uid =
        #{targetUid,jdbcType=BIGINT},sou_state =
        #{state,jdbcType=INTEGER},sou_type = #{type,jdbcType=INTEGER},sou_rate
        = #{rate,jdbcType=DECIMAL},sou_money =
        #{money,jdbcType=DECIMAL},sou_pre_send_time =
        #{preSendTime,jdbcType=TIMESTAMP},sou_create_time =
        #{createTime,jdbcType=TIMESTAMP},sou_update_time =
        #{updateTime,jdbcType=TIMESTAMP},sou_beizhu =
        #{beiZhu,jdbcType=VARCHAR} ,sou_send_time
        =#{sendTime,jdbcType=TIMESTAMP} where sou_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">
        update yeshi_ec_team_dividents_source_order_user
        <set>
            <if test="sourceOrder != null">sou_source_order_id=#{sourceOrder.id,jdbcType=BIGINT},
            </if>
            <if test="sourceUid != null">sou_source_uid=#{sourceUid,jdbcType=BIGINT},</if>
            <if test="targetUid != null">sou_target_uid=#{targetUid,jdbcType=BIGINT},</if>
            <if test="state != null">sou_state=#{state,jdbcType=INTEGER},</if>
            <if test="type != null">sou_type=#{type,jdbcType=INTEGER},</if>
            <if test="rate != null">sou_rate=#{rate,jdbcType=DECIMAL},</if>
            <if test="money != null">sou_money=#{money,jdbcType=DECIMAL},</if>
            <if test="preSendTime != null">sou_pre_send_time=#{preSendTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">sou_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">sou_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="beiZhu != null">sou_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="sendTime !=null">sou_send_time =#{sendTime,jdbcType=TIMESTAMP},</if>
        </set>
        where sou_id = #{id,jdbcType=BIGINT}
    </update>
 
 
 
    <update id="invalidOrderBySourceUid">
        update yeshi_ec_team_dividents_source_order_user
        <set>
            sou_state=4,
            sou_update_time=now(),
            sou_beizhu=#{beiZhu},
        </set>
        where sou_source_uid=#{sourceUid}
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state">sou_state=#{state}</foreach>
        </if>
 
    </update>
 
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where sou_id = #{0} for
        update
    </select>
    <select id="list" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where 1=1
        <if test="sourceOrderId!=null">and sou_source_order_id=#{sourceOrderId}</if>
        <if test="sourceUid!=null">and sou_source_uid=#{sourceUid}</if>
        <if test="targetUid!=null">and sou_target_uid=#{targetUid}</if>
        <if test="preSendTime!=null">and sou_pre_send_time=#{preSendTime}</if>
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state">sou_state=#{state}</foreach>
        </if>
        <if test="typeList!=null">
            <foreach collection="typeList" open=" and (" separator=" or "
                close=")" item="type">sou_type=#{type}</foreach>
        </if>
        limit #{start},#{count}
    </select>
    <select id="count" resultType="java.lang.Long">
        select count(*) from yeshi_ec_team_dividents_source_order_user where
        1=1
        <if test="sourceOrderId!=null">and sou_source_order_id=#{sourceOrderId}</if>
        <if test="sourceUid!=null">and sou_source_uid=#{sourceUid}</if>
        <if test="targetUid!=null">and sou_target_uid=#{targetUid}</if>
        <if test="preSendTime!=null">and sou_pre_send_time=#{preSendTime}</if>
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state">sou_state=#{state}</foreach>
        </if>
        <if test="typeList!=null">
            <foreach collection="typeList" open=" and (" separator=" or "
                close=")" item="type">sou_type=#{type}</foreach>
        </if>
    </select>
    <select id="listCanSendSourceUidByPreSendTime" resultType="java.lang.Long">SELECT
        DISTINCT(o.`sou_source_uid`) FROM
        `yeshi_ec_team_dividents_source_order_user` o WHERE o.`sou_state`=2
        AND o.`sou_pre_send_time`=#{preSendTime} limit #{start},#{count}
    </select>
    <select id="countCanSendSourceUidByPreSendTime" resultType="java.lang.Long">SELECT
        count(DISTINCT(o.`sou_source_uid`)) FROM
        `yeshi_ec_team_dividents_source_order_user` o WHERE o.`sou_state`=2
        AND o.`sou_pre_send_time`=#{preSendTime}
    </select>
    
    
    <select id="listByDateAndTargetUid" resultMap="TeamDividentsVOMap">
        SELECT  t.`tdo_order_no`,t.`tdo_source_type`, SUM(IF(d.`sou_type` = 1, d.`sou_money`,0)) AS subsidy,
             SUM(IF(d.`sou_type` = 2, d.`sou_money`,0)) AS dividents  FROM  yeshi_ec_team_dividents_source_order_user d
        LEFT JOIN yeshi_ec_team_dividents_source_order t ON d.`sou_source_order_id` = t.`tdo_id`
        WHERE d.`sou_target_uid` = #{targetUid}  AND d.`sou_state` <![CDATA[<>]]>4 
            AND t.`tdo_create_time` >= #{minTime} AND t.`tdo_create_time` <![CDATA[<=]]>#{maxTime}
          <if test = "key != null and key != ''">
              AND (t.`tdo_order_no` = #{key} OR d.`sou_source_uid` = #{key})
          </if>
        GROUP BY t.`tdo_order_no`,t.`tdo_source_type`
        ORDER BY t.`tdo_create_time` DESC
        LIMIT #{start},#{count}
    </select>
    
    
    <select id="countByDateAndTargetUid" resultType="Long">
        SELECT COUNT(A.sou_id) FROM (SELECT d.`sou_id` FROM  yeshi_ec_team_dividents_source_order_user d
        LEFT JOIN yeshi_ec_team_dividents_source_order t ON d.`sou_source_order_id` = t.`tdo_id`
        WHERE d.`sou_target_uid` = #{targetUid} AND d.`sou_state` <![CDATA[<>]]>4 
             AND t.`tdo_create_time` >= #{minTime} AND t.`tdo_create_time` <![CDATA[<=]]>#{maxTime} 
          <if test = "key != null and key != ''">
              AND (t.`tdo_order_no` = #{key} OR d.`sou_source_uid` = #{key})
          </if>
        GROUP BY t.`tdo_order_no`,t.`tdo_source_type`)A
    </select>
    
    <select id="sumByDateAndTargetUid" resultMap="TeamDividentsVOMap">
        SELECT SUM(IF(d.`sou_type` = 1,TRUNCATE( d.`sou_money`,2),0)) AS subsidy, SUM(IF(d.`sou_type` = 2,TRUNCATE( d.`sou_money`,2),0)) AS dividents  FROM  yeshi_ec_team_dividents_source_order_user d
        LEFT JOIN yeshi_ec_team_dividents_source_order t ON d.`sou_source_order_id` = t.`tdo_id`
        WHERE d.`sou_target_uid` = #{targetUid} AND d.`sou_state` <![CDATA[<>]]>4 
            AND t.`tdo_create_time` >= #{minTime} AND t.`tdo_create_time` <![CDATA[<=]]>#{maxTime}
          <if test = "key != null and key != ''">
              AND (t.`tdo_order_no` = #{key} OR d.`sou_source_uid` = #{key})
          </if>
    </select>
    
    
    <select id="searchByOrderNoOrSourceUid" resultMap="TeamOrderVOMap">
        SELECT  d.*,t.*, SUM(d.`sou_money`) AS totalMoney  FROM  yeshi_ec_team_dividents_source_order_user d
        LEFT JOIN yeshi_ec_team_dividents_source_order t ON d.`sou_source_order_id` = t.`tdo_id`
        WHERE d.`sou_target_uid` =  #{targetUid} AND (t.`tdo_order_no` = #{key} OR d.`sou_source_uid` = #{key})
        GROUP BY t.`tdo_order_no`,t.`tdo_source_type`
        ORDER BY t.`tdo_create_time` DESC
        LIMIT #{start},#{count}
    </select>
    
    <select id="countSearchByOrderNoOrSourceUid" resultType="Long">
        SELECT COUNT(A.sou_id) FROM (SELECT d.`sou_id` FROM  yeshi_ec_team_dividents_source_order_user d
        LEFT JOIN yeshi_ec_team_dividents_source_order t ON d.`sou_source_order_id` = t.`tdo_id`
        WHERE d.`sou_target_uid` =  #{targetUid} AND (t.`tdo_order_no` = #{key} OR d.`sou_source_uid` = #{key})
        GROUP BY t.`tdo_order_no`,t.`tdo_source_type`)A
    </select>
</mapper>