ProgressPrizeMapper.xml 4.5 KB
Newer Older
licc's avatar
licc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?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="cn.wisenergy.mapper.ProgressPrizeMapper">
    <resultMap id="monthMap" type="cn.wisenergy.model.app.ProgressPrize">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="year_month" property="yearMonth"/>
        <result column="growth_rate" property="growthRate"/>
        <result column="award_money" property="awardMoney"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
licc's avatar
licc committed
15
        progress_prize
licc's avatar
licc committed
16 17 18 19 20 21 22 23
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
licc's avatar
licc committed
24
        user_id,`year_month`,`growth_rate`,award_money,create_time,update_time
licc's avatar
licc committed
25 26 27 28 29 30 31 32
    </sql>

    <sql id="vals">
        #{userId},#{yearMonth},#{growthRate},#{awardMoney},now(),now()
    </sql>

    <sql id="updateCondition">
        <if test="userId != null">user_id = #{userId},</if>
licc's avatar
licc committed
33 34
        <if test="yearMonth != null">`year_month` = #{yearMonth},</if>
        <if test="growthRate != null">`growth_rate` =#{growthRate},</if>
licc's avatar
licc committed
35 36 37 38 39 40 41
        <if test="awardMoney != null">award_money =#{awardMoney},</if>
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="userId != null">and user_id = #{userId}</if>
licc's avatar
licc committed
42 43
        <if test="yearMonth != null">and `year_month` = #{yearMonth}</if>
        <if test="growthRate != null">and `growth_rate` =#{growthRate}</if>
licc's avatar
licc committed
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
        <if test="awardMoney != null">and award_money =#{awardMoney}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

    <insert id="add" parameterType="cn.wisenergy.model.app.ProgressPrize" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

    <update id="edit" parameterType="cn.wisenergy.model.app.ProgressPrize">
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
        <where>
            id = #{id}
        </where>
    </update>

    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

licc's avatar
licc committed
75 76 77 78 79 80 81
    <select id="getByYearMonth" resultType="cn.wisenergy.model.app.ProgressPrize">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="yearMonth != null">
licc's avatar
licc committed
82
                `year_month` = #{yearMonth}
licc's avatar
licc committed
83 84 85 86
            </if>
        </where>
    </select>

licc's avatar
licc committed
87
    <select id="getByTime" resultType="cn.wisenergy.model.vo.ProgressPrizeVo">
licc's avatar
licc committed
88
        select p.user_id as userId,u.head_image as headImage,p.`growth_rate` as growthRate, p.award_money as awardMoney
licc's avatar
licc committed
89 90 91 92 93
        from
        progress_prize p ,user_info u
        where
        p.user_id=u.user_id
        and p.`year_month` = #{yearMonth}
licc's avatar
licc committed
94
        and p.award_money>0
licc's avatar
licc committed
95
        order by p.`growth_rate` desc,p.award_money desc,u.create_time desc
licc's avatar
licc committed
96 97
    </select>

licc's avatar
licc committed
98 99 100 101 102 103 104 105 106 107
    <select id="getByUserIdYearMonth" resultType="cn.wisenergy.model.app.ProgressPrize">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="userId != null and userId != ''">
                user_id=#{userId}
            </if>
            <if test="yearMonth != null">
licc's avatar
licc committed
108
                and `year_month`= #{yearMonth}
licc's avatar
licc committed
109 110 111 112
            </if>
        </where>
    </select>

licc's avatar
licc committed
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
    <select id="count" resultType="java.lang.Integer">
        select count(1)
        from
        <include refid="table"/>
        <where>
            <if test="queryTime != null and queryTime != ''">
                `year_month` = #{queryTime}
            </if>
        </where>
    </select>

    <select id="getList" resultType="cn.wisenergy.model.app.ProgressPrize">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="queryTime != null and queryTime != ''">
                `year_month` = #{queryTime}
            </if>
        </where>
        order by create_time desc
        limit #{startNum},#{endNum}
    </select>

licc's avatar
licc committed
138
</mapper>