<?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.com.ty.lift.enterprise.oa.mapper.LiftCertificateMapper" >
	<resultMap id="BaseResultMap" type="cn.com.ty.lift.enterprise.oa.dto.LiftCertificateResponse" >
		<id column="id" property="id" jdbcType="BIGINT" />
        <result column="mt_company_id" property="mtCompanyId" jdbcType="BIGINT" />
		<result column="owner_id" property="ownerId" jdbcType="BIGINT" />
		<result column="code" property="code" jdbcType="CHAR" />
		<result column="issuance_agency" property="issuanceAgency" jdbcType="VARCHAR" />
		<result column="expiration_date" property="expirationDate" jdbcType="TIMESTAMP" />
		<result column="certificate_type" property="certificateType" jdbcType="VARCHAR" />
		<result column="status" property="status" jdbcType="TINYINT" />
		<result column="first_img_url" property="firstImgUrl" jdbcType="LONGVARCHAR" />
		<result column="second_img_url" property="secondImgUrl" jdbcType="LONGVARCHAR" />
        <result column="creator_id" property="creatorId" jdbcType="BIGINT" />
        <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
        <result column="update_id" property="updateId" jdbcType="BIGINT" />
        <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
		<result column="username" property="username" jdbcType="VARCHAR" />
	</resultMap>

    <!--根据条件分页查询-->
    <select id="pageByCondition" resultMap="BaseResultMap" parameterType="cn.com.ty.lift.enterprise.oa.dto.LiftCertificateRequest">
		SELECT
			lc.*,
			ui.`name` AS username
		FROM
			`lift_certificate` lc
			LEFT JOIN user_info ui ON ui.user_id = lc.owner_id
            LEFT JOIN mt_company_user mcu ON mcu.user_id = lc.owner_id AND mcu.mt_company_id = lc.mt_company_id
		<where>
            <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
                AND lc.mt_company_id = #{cond.mtCompanyId}
            </if>
            <if test="cond.status != null">
                AND lc.`status` = #{cond.status}
            </if>
			<if test="cond.username != null and cond.username !=''">
                AND ui.`name` LIKE concat('%',#{cond.username},'%')
            </if>
        </where>
    </select>

    <select id="countByCondition" resultType="java.lang.Long" parameterType="cn.com.ty.lift.enterprise.oa.dto.LiftCertificateRequest">
        SELECT
          count(*)
        FROM
          `lift_certificate` lc
        LEFT JOIN mt_company_user mcu ON mcu.user_id = lc.owner_id AND mcu.mt_company_id = lc.mt_company_id
        <where>
            <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
                AND lc.mt_company_id = #{cond.mtCompanyId}
            </if>
        </where>
    </select>

    <select id="infoById" resultMap="BaseResultMap" parameterType="cn.com.ty.lift.enterprise.oa.dto.LiftCertificateRequest">
        SELECT
            lc.*,
            ui.`name` AS username
        FROM
          `lift_certificate` lc
        LEFT JOIN user_info ui ON ui.user_id = lc.owner_id
        <where>
            <if test="cond.id != null and cond.id > 0">
                AND lc.id = #{cond.id}
            </if>
        </where>
    </select>
</mapper>