yujian
2020-04-02 0ec22dcf4fd9c4496e6f681e7fab89f56c6e4e8a
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
<?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.OrderTeamRewardMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.OrderTeamReward">
        <id column="otr_id" property="id" jdbcType="BIGINT" />
        <result column="otr_uid" property="uid" jdbcType="BIGINT" />
        <result column="otr_money" property="money" jdbcType="DECIMAL" />
        <result column="otr_order_no" property="orderNo" jdbcType="VARCHAR" />
        <result column="otr_source_type" property="sourceType"
            jdbcType="INTEGER" />
        <result column="otr_state" property="state" jdbcType="INTEGER" />
        <result column="otr_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="otr_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
        <result column="otr_original_money" property="originalMoney"
            jdbcType="DECIMAL" />
        <result column="otr_pre_get_time" property="preGetTime"
            jdbcType="TIMESTAMP" />
        <result column="otr_get_time" property="getTime" jdbcType="TIMESTAMP" />
        <result column="otr_level" property="level" jdbcType="INTEGER" />
        <result column="otr_valid_time" property="validTime" jdbcType="TIMESTAMP" />
        <result column="otr_invalid_time" property="inValidTime"
            jdbcType="TIMESTAMP" />
        <association property="subsidy"
            javaType="com.yeshi.fanli.entity.order.InviteOrderSubsidy" column="otr_subsidy_id">
            <id column="otr_subsidy_id" property="id" />
        </association>
 
    </resultMap>
    <sql id="Base_Column_List">otr_id,otr_uid,otr_money,otr_order_no,otr_source_type,otr_state,otr_create_time,otr_update_time,otr_original_money,otr_subsidy_id,otr_pre_get_time,otr_get_time,otr_level,otr_valid_time,otr_invalid_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_order_team_reward where otr_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="listByOrderNoAndType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_order_team_reward where otr_order_no = #{orderNo} AND
        otr_source_type = #{type}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_order_team_reward where otr_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.order.OrderTeamReward"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_order_team_reward
        (otr_id,otr_uid,otr_money,otr_order_no,otr_source_type,otr_state,otr_create_time,otr_update_time,otr_original_money,otr_subsidy_id,otr_pre_get_time,otr_get_time,otr_level,otr_valid_time,otr_invalid_time)
        values
        (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{originalMoney,jdbcType=DECIMAL},#{subsidy.id,jdbcType=BIGINT},#{preGetTime,jdbcType=TIMESTAMP},#{getTime,jdbcType=TIMESTAMP},#{level,jdbcType=INTEGER},#{validTime,jdbcType=TIMESTAMP},#{inValidTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.OrderTeamReward"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_order_team_reward
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">otr_id,</if>
            <if test="uid != null">otr_uid,</if>
            <if test="money != null">otr_money,</if>
            <if test="orderNo != null">otr_order_no,</if>
            <if test="sourceType != null">otr_source_type,</if>
            <if test="state != null">otr_state,</if>
            <if test="createTime != null">otr_create_time,</if>
            <if test="updateTime != null">otr_update_time,</if>
            <if test="originalMoney != null">otr_original_money,</if>
            <if test="subsidy != null">otr_subsidy_id,</if>
            <if test="preGetTime != null">otr_pre_get_time,</if>
            <if test="getTime != null">otr_get_time,</if>
            <if test="level != null">otr_level,</if>
            <if test="validTime != null">otr_valid_time,</if>
            <if test="inValidTime != null">otr_invalid_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="originalMoney != null">#{originalMoney,jdbcType=DECIMAL},</if>
            <if test="subsidy != null">#{subsidy.id,jdbcType=BIGINT},</if>
            <if test="preGetTime != null">#{preGetTime,jdbcType=TIMESTAMP},</if>
            <if test="getTime != null">#{getTime,jdbcType=TIMESTAMP},</if>
            <if test="level != null">#{level,jdbcType=INTEGER},</if>
            <if test="validTime != null">#{validTime,jdbcType=TIMESTAMP},</if>
            <if test="inValidTime != null">#{inValidTime,jdbcType=TIMESTAMP}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.OrderTeamReward">update
        yeshi_ec_order_team_reward set otr_uid =
        #{uid,jdbcType=BIGINT},otr_money =
        #{money,jdbcType=DECIMAL},otr_order_no =
        #{orderNo,jdbcType=VARCHAR},otr_source_type =
        #{sourceType,jdbcType=INTEGER},otr_state =
        #{state,jdbcType=INTEGER},otr_create_time =
        #{createTime,jdbcType=TIMESTAMP},otr_update_time =
        #{updateTime,jdbcType=TIMESTAMP} ,otr_original_money
        =#{originalMoney,jdbcType=DECIMAL},otr_subsidy_id
        =#{subsidy.id,jdbcType=BIGINT} ,otr_pre_get_time
        =#{preGetTime,jdbcType=TIMESTAMP} ,otr_get_time
        =#{getTime,jdbcType=TIMESTAMP} ,otr_level =#{level,jdbcType=INTEGER}
        ,otr_valid_time =#{validTime,jdbcType=TIMESTAMP} ,otr_invalid_time
        =#{inValidTime,jdbcType=TIMESTAMP} where otr_id =
        #{id,jdbcType=BIGINT}</update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.OrderTeamReward">
        update yeshi_ec_order_team_reward
        <set>
            <if test="uid != null">otr_uid=#{uid,jdbcType=BIGINT},</if>
            <if test="money != null">otr_money=#{money,jdbcType=DECIMAL},</if>
            <if test="orderNo != null">otr_order_no=#{orderNo,jdbcType=VARCHAR},</if>
            <if test="sourceType != null">otr_source_type=#{sourceType,jdbcType=INTEGER},</if>
            <if test="state != null">otr_state=#{state,jdbcType=INTEGER},</if>
            <if test="createTime != null">otr_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">otr_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="originalMoney !=null">otr_original_money =#{originalMoney,jdbcType=DECIMAL},
            </if>
            <if test="subsidy !=null">otr_subsidy_id =#{subsidy.id,jdbcType=BIGINT},</if>
            <if test="preGetTime !=null">otr_pre_get_time =#{preGetTime,jdbcType=TIMESTAMP},</if>
            <if test="getTime !=null">otr_get_time =#{getTime,jdbcType=TIMESTAMP},</if>
            <if test="level !=null">otr_level =#{level,jdbcType=INTEGER},</if>
            <if test="validTime !=null">otr_valid_time =#{validTime,jdbcType=TIMESTAMP},</if>
            <if test="inValidTime !=null">otr_invalid_time =#{inValidTime,jdbcType=TIMESTAMP},</if>
        </set>
        where otr_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="getByOrderNoAndType" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_order_team_reward WHERE otr_uid = #{uid} AND otr_order_no =
        #{orderNo} AND otr_source_type = #{type} LIMIT 1</select>
    <select id="getByOrderNoAndTypeForUpdate" resultMap="BaseResultMap">SELECT *
        FROM yeshi_ec_order_team_reward WHERE otr_uid = #{uid} AND
        otr_order_no = #{orderNo} AND otr_source_type = #{type} for update
    </select>
    <select id="countByOrderNoAndType" resultType="java.lang.Long">SELECT count(*)
        FROM yeshi_ec_order_team_reward WHERE otr_order_no = #{orderNo} AND
        otr_source_type = #{type}</select>
    <select id="selectBySubsidyIdAndUidForUpdate" resultMap="BaseResultMap">SELECT *
        FROM yeshi_ec_order_team_reward WHERE otr_subsidy_id = #{subsidyId}
        AND otr_uid = #{uid} for update</select>
    <select id="listBySubsidyId" resultMap="BaseResultMap"
        parameterType="java.lang.Long">SELECT * FROM yeshi_ec_order_team_reward WHERE
        otr_subsidy_id = #{0}</select>
    <select id="listCanSettleByUid" resultMap="BaseResultMap">SELECT * FROM
        yeshi_ec_order_team_reward WHERE otr_uid =#{uid} AND otr_state=1 AND
        NOW()&gt;otr_pre_get_time limit #{start},#{count}</select>
    <select id="countCanSettle" resultType="java.lang.Long"
        parameterType="java.lang.Long">SELECT count(*) FROM yeshi_ec_order_team_reward WHERE
        otr_uid =#{uid} AND otr_state=1 AND NOW()&gt;otr_pre_get_time</select>
    <select id="listCanSettleUid" resultType="java.lang.Long">SELECT t.`otr_uid` FROM
        yeshi_ec_order_team_reward t WHERE t.`otr_state`=1 AND #{time} &gt;
        t.`otr_pre_get_time` GROUP BY t.`otr_uid` LIMIT #{start},#{count}
    </select>
    <select id="countCanSettleUid" resultType="java.lang.Long"
        parameterType="java.util.Date">SELECT COUNT(*) FROM ( SELECT t.otr_uid FROM
        yeshi_ec_order_team_reward t WHERE t.otr_state=1 AND
        #{0}&gt;t.otr_pre_get_time GROUP BY t.otr_uid) a
    </select>
        
    <select id="sumValidMoneyByUidAndDate" resultType="BigDecimal">
        SELECT SUM(d.`otr_money`) FROM yeshi_ec_order_team_reward d
        WHERE d.`otr_uid` = #{uid} AND (d.`otr_state` = 1 OR d.`otr_state` = 3)
        <if test="level != null">
            AND d.otr_level = #{level}
        </if>
        <if test="day == 1"> <!-- 今天 -->
            AND TO_DAYS(d.`otr_valid_time`) = TO_DAYS(NOW())
        </if>
        <if test="day == 2"> <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(d.`otr_valid_time`) = 1
        </if>
        <if test="day == 3"> <!-- 本月 -->
            AND DATE_FORMAT(d.`otr_valid_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day == 4"> <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(d.`otr_valid_time`, '%Y%m')) = 1
        </if>
    </select>    
        
        
    <select id="sumRecievedMoneyByUid" resultType="BigDecimal">
        SELECT SUM(d.`otr_money`) FROM yeshi_ec_order_team_reward d
        WHERE d.`otr_uid` = #{uid} AND d.`otr_state` = 3
        <if test="level != null">
            AND d.otr_level = #{level}
        </if>
    </select>    
        
        
</mapper>