<?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.sooka.system.mapper.TULogMapper">

    <resultMap type="TULog" id="TULogResult">
        <result property="id"    column="id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="loginUser"    column="login_user"    />
        <result property="loginName"    column="login_name"    />
        <result property="interfaceinfoId"    column="interfaceinfo_id"    />
        <result property="interfaceinfoName"    column="interfaceinfo_name"    />
        <result property="ipaddress"    column="ipaddress"    />
        <result property="os"    column="os"    />
        <result property="platformInterfacetype"    column="platform_interfacetype"    />
        <result property="browser"    column="browser"    />
        <result property="param"    column="param"    />
        <result property="results"    column="results"    />
        <result property="operationQuantity"    column="operation_quantity"    />
        <result property="operationStatus"    column="operation_status"    />
        <result property="exceptionLog"    column="exception_log"    />
    </resultMap>

    <sql id="selectTULogVo">
        select id, status, remark, del_flag, create_by, create_time, update_by, update_time, login_user, login_name, interfaceinfo_id, interfaceinfo_name, ipaddress, os, platform_interfacetype, browser, param, results, operation_quantity, operation_status, exception_log from t_u_log
    </sql>

    <select id="selectTULogList" parameterType="TULog" resultMap="TULogResult">
        <include refid="selectTULogVo"/>
        <where>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="loginUser != null "> and login_user = #{loginUser}</if>
            <if test="loginName != null  and loginName != ''"> and login_name like concat('%', #{loginName}, '%')</if>
            <if test="interfaceinfoId != null  and interfaceinfoId != ''"> and interfaceinfo_id = #{interfaceinfoId}</if>
            <if test="interfaceinfoName != null  and interfaceinfoName != ''"> and interfaceinfo_name like concat('%', #{interfaceinfoName}, '%')</if>
            <if test="ipaddress != null  and ipaddress != ''"> and ipaddress = #{ipaddress}</if>
            <if test="os != null  and os != ''"> and os = #{os}</if>
            <if test="platformInterfacetype != null  and platformInterfacetype != ''"> and platform_interfacetype = #{platformInterfacetype}</if>
            <if test="browser != null  and browser != ''"> and browser = #{browser}</if>
            <if test="param != null  and param != ''"> and param = #{param}</if>
            <if test="results != null  and results != ''"> and results = #{results}</if>
            <if test="operationQuantity != null "> and operation_quantity = #{operationQuantity}</if>
            <if test="operationStatus != null "> and operation_status = #{operationStatus}</if>
            <if test="exceptionLog != null  and exceptionLog != ''"> and exception_log = #{exceptionLog}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectTULogById" parameterType="String" resultMap="TULogResult">
        <include refid="selectTULogVo"/>
        where id = #{id}
    </select>

    <insert id="insertTULog" parameterType="TULog">
        insert into t_u_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="loginUser != null">login_user,</if>
            <if test="loginName != null">login_name,</if>
            <if test="interfaceinfoId != null">interfaceinfo_id,</if>
            <if test="interfaceinfoName != null">interfaceinfo_name,</if>
            <if test="ipaddress != null">ipaddress,</if>
            <if test="os != null">os,</if>
            <if test="platformInterfacetype != null">platform_interfacetype,</if>
            <if test="browser != null">browser,</if>
            <if test="param != null">param,</if>
            <if test="results != null">results,</if>
            <if test="operationQuantity != null">operation_quantity,</if>
            <if test="operationStatus != null">operation_status,</if>
            <if test="exceptionLog != null">exception_log,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="loginUser != null">#{loginUser},</if>
            <if test="loginName != null">#{loginName},</if>
            <if test="interfaceinfoId != null">#{interfaceinfoId},</if>
            <if test="interfaceinfoName != null">#{interfaceinfoName},</if>
            <if test="ipaddress != null">#{ipaddress},</if>
            <if test="os != null">#{os},</if>
            <if test="platformInterfacetype != null">#{platformInterfacetype},</if>
            <if test="browser != null">#{browser},</if>
            <if test="param != null">#{param},</if>
            <if test="results != null">#{results},</if>
            <if test="operationQuantity != null">#{operationQuantity},</if>
            <if test="operationStatus != null">#{operationStatus},</if>
            <if test="exceptionLog != null">#{exceptionLog},</if>
         </trim>
    </insert>

    <update id="updateTULog" parameterType="TULog">
        update t_u_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="loginUser != null">login_user = #{loginUser},</if>
            <if test="loginName != null">login_name = #{loginName},</if>
            <if test="interfaceinfoId != null">interfaceinfo_id = #{interfaceinfoId},</if>
            <if test="interfaceinfoName != null">interfaceinfo_name = #{interfaceinfoName},</if>
            <if test="ipaddress != null">ipaddress = #{ipaddress},</if>
            <if test="os != null">os = #{os},</if>
            <if test="platformInterfacetype != null">platform_interfacetype = #{platformInterfacetype},</if>
            <if test="browser != null">browser = #{browser},</if>
            <if test="param != null">param = #{param},</if>
            <if test="results != null">results = #{results},</if>
            <if test="operationQuantity != null">operation_quantity = #{operationQuantity},</if>
            <if test="operationStatus != null">operation_status = #{operationStatus},</if>
            <if test="exceptionLog != null">exception_log = #{exceptionLog},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTULogById" parameterType="String">
        delete from t_u_log where id = #{id}
    </delete>

    <delete id="deleteTULogByIds" parameterType="String">
        delete from t_u_log where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getLogCount" resultType="java.lang.Long">
        SELECT count('ct') FROM t_u_log
    </select>

    <select id="selectImputationLog" resultType="java.util.LinkedHashMap">
        SELECT
            #{createTime} as year,
                        IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 1 THEN
                    1
                ELSE
                    0
                END
            ),0) AS jan,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 2 THEN
                    1
                ELSE
                    0
                END
            ),0) AS feb,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 3 THEN
                    1
                ELSE
                    0
                END
            ),0) AS mar,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 4 THEN
                    1
                ELSE
                    0
                END
            ),0) AS apr,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 5 THEN
                    1
                ELSE
                    0
                END
            ),0) AS may,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 6 THEN
                    1
                ELSE
                    0
                END
            ),0) AS jun,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 7 THEN
                    1
                ELSE
                    0
                END
            ),0) AS jul,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 8 THEN
                    1
                ELSE
                    0
                END
            ),0) AS aug,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 9 THEN
                    1
                ELSE
                    0
                END
            ),0) AS sep,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 10 THEN
                    1
                ELSE
                    0
                END
            ),0) AS oct,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 11 THEN
                    1
                ELSE
                    0
                END
            ),0) AS nov,
            IFNULL(SUM(
                CASE MONTH (create_time)
                WHEN 12 THEN
                    1
                ELSE
                    0
                END
            ),0) AS decb
        FROM
            (
                SELECT
                    create_time
                FROM
                    t_u_log
                WHERE
                    YEAR (create_time) = #{createTime}
            ) tb
    </select>

</mapper>
