<?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.ezhizao.project.business.mapper.BizDayworkItemConsultMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizDayworkItemConsult" id="BizDayworkItemConsultResult">
        <id column="id" property="id"/>
        <collection property="pictureList" ofType="cn.ezhizao.project.business.domain.BizDayworkItemConsultPicture" column="id" select="getConsultPictures"/>
    </resultMap>

    <select id="getList" resultMap="BizDayworkItemConsultResult" parameterType="cn.ezhizao.project.business.domain.BizDayworkItemConsult">
        SELECT t1.*,t2.type,(select nick_name from sys_user where user_id = t1.technician_id and del_flag = 0) as technicianName,(select nick_name from sys_user where user_id = t1.reviewer_id and del_flag = 0) as reviewerName
        FROM biz_daywork_item_consult t1
        left join biz_process_inspecion t2 on t1.process_inspection_id = t2.id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="type != null ">
                <if test="type == 0">
                    AND t1.process_inspection_id = 0
                </if>
                <if test="type == 1">
                    AND t2.type = "patrolInspection"
                </if>
                <if test="type == 2">
                    AND t2.type = "deliveryInspection"
                </if>
                <if test="type == 3">
                    AND t2.type = "firstArticleInspection"
                </if>
                <if test="type == 4">
                    AND t2.type = "instrumentRoomInspection"
                </if>
                <if test="type == 5">
                    AND t2.type = "outsourcedInspector"
                </if>
                <if test="type == 6">
                    AND t2.type = "factoryInspection"
                </if>
            </if>
            <if test="lotCode != null and lotCode != ''">AND t1.lot_code LIKE CONCAT('%', #{lotCode}, '%')</if>
            <if test="content != null and content != ''">AND t1.content LIKE CONCAT('%', #{content}, '%')</if>
            <if test="technicianId != null and flag == 'false' ">AND (t1.technician_id = #{technicianId} OR t1.technician_id=0 )</if>
            <if test="consultDepartment != null and consultDepartment != '-1'  ">AND t1.consult_department = #{consultDepartment}</if>
            <if test="status != null">AND t1.status = #{status}</if>
            <if test="tenantId != null and tenantId != 0 ">AND t1.tenant_id = #{tenantId}</if>
            <if test="productDescription != null and productDescription != ''">AND t1.product_description LIKE CONCAT('%',
                #{productDescription}, '%')
            </if>
        </trim>
<!--        order by (case when t1.consult_result_id = 0 then 0 else 1 end) asc, create_time asc-->
    </select>
<select id="getConsultPictures" resultType="cn.ezhizao.project.business.domain.BizDayworkItemConsultPicture">
    select * from biz_daywork_item_consult_picture where deleted = 0 and daywork_item_consult_id = #{id}
</select>
    <delete id="physicalDelete">
        DELETE FROM biz_daywork_item_consult WHERE deleted = 0
        <if test="id != null">
            AND id = #{id}
        </if>
    </delete>
</mapper>
