<?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.nasc.custom.mapper.NascPrintLogMapper">

    <insert id="insertPrintLog" parameterType="NascPrintLog" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO nasc_print_log (serial_number, user_id, user_name, matter, matter_name, with_type, contacts,
                                    phone, id_card, content, enterprise_name, print_type, print_time)
        VALUES (#{serialNumber}, #{userId}, #{userName}, #{matter}, #{matterName}, #{withType}, #{contacts},
            #{phone}, #{idCard}, #{content}, #{enterpriseName}, #{printType}, sysdate());
    </insert>

    <resultMap id="printLogResult" type="java.util.HashMap">
        <result property="id" column="id"/>
        <result property="serialNumber" column="serial_number"/>
        <result property="userName" column="user_name"/>
        <result property="matterName" column="matter_name"/>
        <result property="withType" column="with_type"/>
        <result property="contacts" column="contacts"/>
        <result property="phone" column="phone"/>
        <result property="idCard" column="id_card"/>
        <result property="content" column="content"/>
        <result property="printType" column="print_type"/>
        <result property="enterpriseName" column="enterprise_name"/>
        <result property="deptName" column="dept_name"/>
        <result property="printTime" column="print_time"/>
    </resultMap>

    <select id="selectPrintLogList" resultMap="printLogResult">
        SELECT pl.id, pl.serial_number, pl.user_name, pl.matter_name, pl.with_type, pl.contacts, pl.phone,
               pl.id_card, pl.content, pl.enterprise_name, pl.print_type, d.dept_name,
               DATE_FORMAT(pl.print_time, '%Y-%m-%d %H:%i:%s') AS print_time
        FROM nasc_print_log pl
        LEFT JOIN sys_user u ON u.user_id = pl.user_id
        LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
        <where>
            <if test="matterName != null and matterName != ''">
                AND pl.matter_name = #{matterName}
            </if>
            <if test="printType != null">
                AND pl.print_type = #{printType}
            </if>
        </where>
        ORDER BY pl.print_time DESC
    </select>

</mapper> 