Blame view

OprMemDictMapper.xml 8.29 KB
涂亚平 committed
1 2 3 4 5 6
<?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.subsidy.mapper.OprMemDictMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.subsidy.model.OprMemDictDO">
涂亚平 committed
7 8 9 10 11 12
        <id column="id" property="id"/>
        <result column="create_date" property="createDate"/>
        <result column="update_date" property="updateDate"/>
        <result column="delete_date" property="deleteDate"/>
        <result column="user_id" property="userId"/>
        <result column="opr_type" property="oprType"/>
涂亚平 committed
13 14 15 16 17 18 19 20 21 22
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, user_id, opr_type
    </sql>

邓敏 committed
23

涂亚平 committed
24 25
    <select id="getHistory" resultType="com.subsidy.vo.opr.GetHistoryVO">
        SELECT
涂亚平 committed
26 27 28 29 30 31
        t.id,
        t2.user_name,
        t3.company_name,
        t.opr_type,
        t.create_date,
        t.result
涂亚平 committed
32
        FROM
涂亚平 committed
33 34
        opr_mem_dict t
        LEFT JOIN member t2 ON t.user_id = t2.id
35 36
        left join company_member_mapping t5 on t5.member_id = t2.id and t5.member_status = 1
        LEFT JOIN company_dict t3 ON t5.company_id = t3.id
涂亚平 committed
37
        WHERE
涂亚平 committed
38 39 40 41 42 43 44 45
        t.delete_date IS NULL
        AND t2.delete_date IS NULL
        AND t3.delete_date IS NULL
        <if test="userName != null and userName !=''">
            and t2.user_name like concat('%',#{userName} ,'%')
        </if>
        AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) BETWEEN DATE_FORMAT( #{startDate}, '%Y-%m-%d' )
        AND DATE_FORMAT( #{endDate}, '%Y-%m-%d' )
涂亚平 committed
46
        ORDER BY
涂亚平 committed
47
        t.create_date DESC
涂亚平 committed
48
    </select>
邓敏 committed
49 50 51 52 53 54 55

    <select id="getRecordByDate" resultType="com.subsidy.model.OprMemDictDO">
        SELECT
            *
        FROM
            opr_mem_dict
        WHERE
56
            create_date &lt; (NOW() -interval 1 day)
邓敏 committed
57
    </select>
涂亚平 committed
58 59

    <select id="getLatestLoginInfo" parameterType="long" resultType="com.subsidy.model.OprMemDictDO">
涂亚平 committed
60 61
        SELECT t.id,
            t.ip_address,
涂亚平 committed
62 63 64
            t.opr_type,
            t.result,
            t.user_id,
涂亚平 committed
65
            t.create_date
涂亚平 committed
66 67 68 69
        FROM
            opr_mem_dict t
        WHERE
            t.delete_date IS NULL
涂亚平 committed
70
            AND t.result = 1
涂亚平 committed
71
            AND t.user_id = #{userId}
涂亚平 committed
72 73
            and DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
            order by t.id desc
涂亚平 committed
74
            limit 1
涂亚平 committed
75
    </select>
涂亚平 committed
76

涂亚平 committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    <select id="getLatestLogoutInfo" parameterType="long" resultType="com.subsidy.model.OprMemDictDO">
        SELECT t.id,
            t.ip_address,
            t.opr_type,
            t.result,
            t.user_id,
            t.create_date
        FROM
            opr_mem_dict t
        WHERE
            t.delete_date IS NULL
            AND t.result = 1
            AND t.user_id =#{userId}
            and t.opr_type = '登出'
            and DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
            order by t.id desc
            limit 1
    </select>
涂亚平 committed
95 96


涂亚平 committed
97 98 99 100 101 102 103 104
    <!--    <update id="deleteData" parameterType="com.subsidy.model.OprMemDictDO">-->
    <!--        DELETE-->
    <!--        FROM-->
    <!--            opr_mem_dict-->
    <!--        WHERE-->
    <!--            delete_date IS NULL-->
    <!--            AND id = #{id}-->
    <!--    </update>-->
涂亚平 committed
105 106 107

    <select id="onlineUsers" resultType="long">
        SELECT
涂亚平 committed
108
        distinct t1.user_id
涂亚平 committed
109
        FROM
涂亚平 committed
110 111 112 113 114 115 116
        (
        SELECT
        user_id,
        opr_type,
        max( create_date ) AS time1
        FROM
        opr_mem_dict
涂亚平 committed
117
        WHERE
涂亚平 committed
118 119 120
        DATE_FORMAT( create_date, '%Y-%m-%d ' ) = DATE_FORMAT( now(), '%Y-%m-%d ' )
        AND result = 1
        AND opr_type = "登录"
涂亚平 committed
121
        and delete_date IS NULL
涂亚平 committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        GROUP BY
        user_id
        ORDER BY
        create_date DESC
        ) t1
        LEFT JOIN (
        SELECT
        user_id,
        opr_type,
        max( create_date ) AS time2
        FROM
        opr_mem_dict
        WHERE
        DATE_FORMAT( create_date, '%Y-%m-%d ' ) = DATE_FORMAT( now(), '%Y-%m-%d ' )
        AND result = 1
        AND opr_type = "登出"
涂亚平 committed
138
        and delete_date is null
涂亚平 committed
139 140 141 142 143 144
        GROUP BY
        user_id
        ORDER BY
        create_date DESC
        ) t2 ON t1.user_id = t2.user_id
        WHERE
145
         t2.time2 &lt; t1.time1
涂亚平 committed
146 147
    </select>

涂亚平 committed
148
    <select id="insertLastStudyRecord" resultType="com.subsidy.vo.opr.InsertLastStudyRecordVO">
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
      SELECT
     t1.member_id,
     t1.sign_in_date,
     t1.ip_address,
     DATE_ADD(t2.mt,INTERVAL FLOOR(RAND()*100) SECOND) as mt
 FROM
     (
     SELECT DISTINCT
         t.sign_in_date,
         t.member_id,
         t.ip_address
     FROM
         sign_in_record t
     WHERE
         t.delete_date IS NULL
     AND DATE_FORMAT( t.sign_in_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )) t1
     LEFT JOIN (
     SELECT
         t1.member_id,
         max( t1.maxtime ) AS mt
     FROM
         (
         SELECT
             member_id,
             max( create_date ) AS maxtime
         FROM
             vod_play_history
         WHERE
             delete_date IS NULL
             AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
         GROUP BY
             member_id UNION ALL
         SELECT
             member_id,
             max( create_date ) AS maxtime
         FROM
             exercise_done_result
         WHERE
             delete_date IS NULL
             AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
         GROUP BY
             member_id UNION ALL
         SELECT
             ask_id,
             max( create_date ) AS maxtime
         FROM
             answering_question
         WHERE
             delete_date IS NULL
             AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
         GROUP BY
             ask_id UNION ALL
      SELECT member_id,
            max( create_date ) AS maxtime
     from
         activity_detection
     where delete_date is null
     and DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
     GROUP BY member_id
         ) t1
     GROUP BY
     t1.member_id
     ) t2 ON t1.member_id = t2.member_id
涂亚平 committed
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
    </select>

    <select id="shutdownUser" resultType="long">
        SELECT
        t1.user_id
        FROM
        (
        SELECT
        t.user_id,
        max( t.create_date ) AS log_out
        FROM
        opr_mem_dict t
        WHERE
        t.delete_date IS NULL
        AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
        AND t.opr_type = '登出'
        GROUP BY
        t.user_id
        ) t1
        LEFT JOIN (
        SELECT
        t.member_id,
        max( t.create_date ) AS play_time
        FROM
        vod_play_history t
        WHERE
        t.delete_date IS NULL
        AND DATE_FORMAT( t.create_date, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' )
        GROUP BY
        t.member_id
        ) t2 ON t1.user_id = t2.member_id
        WHERE
        t2.member_id IS NOT NULL
        AND t1.log_out &lt; t2.play_time
    </select>

    <insert id="insertOrUpdate">
        insert into opr_mem_dict(user_id,opr_type,result,ip_address,create_date)
        values (#{userId},#{oprType},#{result},#{ipAddress},#{createDate})
        on duplicate key update
        user_id=values(user_id),
        opr_type=values(opr_type),
        result=values(result),
        ip_address=values(ip_address),
        create_date=values(create_date)
    </insert>

涂亚平 committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
    <select id="getLoginInfo" parameterType="long" resultType="com.subsidy.model.OprMemDictDO">
        SELECT
           *
        FROM
            (
            SELECT
                *
            FROM
                opr_mem_dict t
                where t.delete_date is null
                and t.user_id  = #{userId}
                and DATE_FORMAT(t.create_date,'%Y-%m-%d') =DATE_FORMAT(now(), '%Y-%m-%d')
                and TIMESTAMPDIFF(SECOND,t.create_date,now()) &lt;= 300
            ORDER BY
            t.create_date DESC
            LIMIT 5)t2
    </select>

    <select id="clearTodayLoginData" parameterType="long">
        DELETE
        FROM
            opr_mem_dict
        WHERE
            delete_date IS NULL
            AND user_id = #{userId}
            AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = CURRENT_DATE
    </select>

涂亚平 committed
287
</mapper>