TeamPerformanceMapper.xml 6.57 KB
Newer Older
licc's avatar
licc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?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.TeamPerformanceMapper">
    <resultMap id="monthMap" type="cn.wisenergy.model.app.TeamPerformance">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="user_level" property="userLevel"/>
        <result column="year_month" property="yearMonth"/>
        <result column="month_team_performance" property="monthTeamPerformance"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
        team_performance
    </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,user_level,`year_month`,month_team_performance,create_time,update_time
licc's avatar
licc committed
25 26 27 28 29 30 31
    </sql>

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

    <sql id="updateCondition">
licc's avatar
licc committed
32
        <if test="userId != null">user_id = #{userId},</if>
licc's avatar
licc committed
33
        <if test="userLevel != null">user_level = #{userLevel},</if>
licc's avatar
licc committed
34
        <if test="yearMonth != null">`year_month` =#{yearMonth},</if>
licc's avatar
licc committed
35 36 37 38 39 40
        <if test="monthTeamPerformance != null">month_team_performance =#{monthTeamPerformance},</if>
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
licc's avatar
licc committed
41
        <if test="userId != null">and user_id = #{userId}</if>
licc's avatar
licc committed
42
        <if test="userLevel != null">and user_level = #{userLevel}</if>
licc's avatar
licc committed
43
        <if test="yearMonth != null">and `year_month` =#{yearMonth}</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 75 76 77 78 79 80 81 82 83 84
        <if test="monthTeamPerformance != null">and month_team_performance =#{monthTeamPerformance}</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.TeamPerformance" 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.TeamPerformance">
        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>

    <select id="getByUserIdAndTime" resultType="cn.wisenergy.model.app.TeamPerformance">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="userId != null">
                user_id = #{userId}
            </if>
            <if test="yearMonth != null">
licc's avatar
licc committed
85
                and `year_month`=#{yearMonth}
licc's avatar
licc committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99
            </if>
        </where>
    </select>

    <select id="countTeamMoney" resultType="java.lang.Double">
        select
        sum(month_team_performance)
        from
        <include refid="table"/>
        <where>
            <if test="userLevel != null">
                user_level = #{userLevel}
            </if>
            <if test="yearMonth != null">
licc's avatar
licc committed
100
                and `year_month` = #{yearMonth}
licc's avatar
licc committed
101 102 103 104
            </if>
        </where>
    </select>

licc's avatar
licc committed
105 106 107 108 109 110 111
    <select id="getByBeforeTime" resultType="cn.wisenergy.model.app.TeamPerformance">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="yearMonth != null">
licc's avatar
licc committed
112
                `year_month` &lt; #{yearMonth}
licc's avatar
licc committed
113 114 115 116 117 118 119 120 121 122 123
            </if>
        </where>
    </select>

    <select id="countByTime" resultType="java.lang.Double">
        select
        sum(month_team_performance)
        from
        <include refid="table"/>
        <where>
            <if test="yearMonth != null">
licc's avatar
licc committed
124
                `year_month` = #{yearMonth}
licc's avatar
licc committed
125 126 127 128 129 130 131 132 133 134 135
            </if>
        </where>
    </select>

    <select id="countTwenty" resultType="java.lang.Double">
        select
        sum(month_team_performance)
        from
        <include refid="table"/>
        <where>
            <if test="yearMonth != null">
licc's avatar
licc committed
136
                `year_month` = #{yearMonth}
licc's avatar
licc committed
137 138 139 140 141 142 143 144 145 146 147 148
            </if>
            order by month_team_performance desc
            limit 20
        </where>
    </select>

    <select id="userTwenty" resultType="cn.wisenergy.model.app.TeamPerformance">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
149
            user_level != 0
licc's avatar
licc committed
150
            <if test="yearMonth != null">
licc's avatar
licc committed
151
                and `year_month` = #{yearMonth}
licc's avatar
licc committed
152 153 154 155 156 157
            </if>
            order by month_team_performance desc
            limit 20
        </where>
    </select>

codezwjava's avatar
codezwjava committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    <select id="countUserTeamByUserId" resultType="double">
        select sum(month_team_performance)
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>

    <select id="monthUserTeamByuserId" resultType="double">
        select month_team_performance
        from
        <include refid="table"/>
        <where>
            user_id=#{userid}
            and `year_month` = #{yearMonth}
        </where>
    </select>
licc's avatar
licc committed
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

    <select id="count" resultType="java.lang.Integer">
        select count(1)
        from
        <include refid="table"/>
        <where>
            <if test="userId != null and userId != ''">
                user_id=#{userId}
            </if>
            <if test="queryTime != null and queryTime != ''">
                and `year_month` = #{queryTime}
            </if>
        </where>
    </select>

    <select id="getList" resultType="cn.wisenergy.model.app.TeamPerformance">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="userId != null and userId != ''">
                user_id=#{userId}
            </if>
            <if test="queryTime != null and queryTime != ''">
                and `year_month` = #{queryTime}
            </if>
        </where>
        order by create_time desc
        limit #{startNum},#{endNum}
    </select>
207 208 209 210 211 212 213 214 215

    <select id="getByUserId" resultType="cn.wisenergy.model.app.TeamPerformance">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where
        user_id = #{userId}
    </select>
licc's avatar
licc committed
216
</mapper>