<?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.ruoyi.system.mapper.InspectInforMapper">
    
    <resultMap type="com.ruoyi.system.domain.InspectInfor" id="InspectInforResult">
        <result property="inspectId"    column="inspect_id"    />
        <result property="sampleName"    column="sample_name"    />
        <result property="sampleNum"    column="sample_num"    />
        <result property="normsModel"    column="norms_model"    />
        <result property="testItems"    column="test_items"    />
        <result property="provideType"    column="provide_type"    />
        <result property="manufacturerName"    column="manufacturer_name"    />
        <result property="manufacturerPhone"    column="manufacturer_phone"    />
        <result property="inspectedName"    column="inspected_name"    />
        <result property="inspectedPhone"    column="inspected_phone"    />
        <result property="isReport"    column="is_report"    />
        <result property="isDel"    column="is_del"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectInspectInforVo">
        select inspect_id, sample_name, sample_num, norms_model, test_items, provide_type, manufacturer_name, manufacturer_phone, inspected_name, inspected_phone,is_report, is_del, create_by, create_time, update_by, update_time, remark from inspect_infor
    </sql>

    <select id="selectInspectInforList" parameterType="InspectInfor" resultMap="InspectInforResult">
        <include refid="selectInspectInforVo"/>
        <where>
            is_del = 'N'
            and is_report = 'Y'
            <if test="sampleName != null  and sampleName != ''"> and sample_name like concat('%', #{sampleName}, '%')</if>
            <if test="sampleNum != null "> and sample_num = #{sampleNum}</if>
            <if test="normsModel != null  and normsModel != ''"> and norms_model = #{normsModel}</if>
            <if test="testItems != null  and testItems != ''"> and test_items = #{testItems}</if>
            <if test="provideType != null  and provideType != ''"> and provide_type = #{provideType}</if>
            <if test="manufacturerName != null  and manufacturerName != ''"> and manufacturer_name like concat('%', #{manufacturerName}, '%')</if>
            <if test="manufacturerPhone != null  and manufacturerPhone != ''"> and manufacturer_phone = #{manufacturerPhone}</if>
            <if test="inspectedName != null  and inspectedName != ''"> and inspected_name like concat('%', #{inspectedName}, '%')</if>
            <if test="inspectedPhone != null  and inspectedPhone != ''"> and inspected_phone = #{inspectedPhone}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectInspectInforByInspectId" parameterType="Long" resultMap="InspectInforResult">
        <include refid="selectInspectInforVo"/>
        where inspect_id = #{inspectId} and is_del = 'N'
    </select>
        
    <insert id="insertInspectInfor" parameterType="InspectInfor" useGeneratedKeys="true" keyProperty="inspectId">
        insert into inspect_infor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sampleName != null and sampleName != ''">sample_name,</if>
            <if test="sampleNum != null">sample_num,</if>
            <if test="normsModel != null">norms_model,</if>
            <if test="testItems != null">test_items,</if>
            <if test="provideType != null">provide_type,</if>
            <if test="manufacturerName != null">manufacturer_name,</if>
            <if test="manufacturerPhone != null">manufacturer_phone,</if>
            <if test="inspectedName != null">inspected_name,</if>
            <if test="inspectedPhone != null">inspected_phone,</if>
            <if test="isReport != null">is_report,</if>
            <if test="isDel != null">is_del,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sampleName != null and sampleName != ''">#{sampleName},</if>
            <if test="sampleNum != null">#{sampleNum},</if>
            <if test="normsModel != null">#{normsModel},</if>
            <if test="testItems != null">#{testItems},</if>
            <if test="provideType != null">#{provideType},</if>
            <if test="manufacturerName != null">#{manufacturerName},</if>
            <if test="manufacturerPhone != null">#{manufacturerPhone},</if>
            <if test="inspectedName != null">#{inspectedName},</if>
            <if test="inspectedPhone != null">#{inspectedPhone},</if>
            <if test="isReport != null">#{isReport},</if>
            <if test="isDel != null">#{isDel},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateInspectInfor" parameterType="InspectInfor">
        update inspect_infor
        <trim prefix="SET" suffixOverrides=",">
            <if test="sampleName != null and sampleName != ''">sample_name = #{sampleName},</if>
            <if test="sampleNum != null">sample_num = #{sampleNum},</if>
            <if test="normsModel != null">norms_model = #{normsModel},</if>
            <if test="testItems != null">test_items = #{testItems},</if>
            <if test="provideType != null">provide_type = #{provideType},</if>
            <if test="manufacturerName != null">manufacturer_name = #{manufacturerName},</if>
            <if test="manufacturerPhone != null">manufacturer_phone = #{manufacturerPhone},</if>
            <if test="inspectedName != null">inspected_name = #{inspectedName},</if>
            <if test="inspectedPhone != null">inspected_phone = #{inspectedPhone},</if>
            <if test="isReport != null">is_report = #{isReport},</if>
            <if test="isDel != null">is_del = #{isDel},</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="remark != null">remark = #{remark},</if>
        </trim>
        where inspect_id = #{inspectId}
    </update>

    <delete id="deleteInspectInforByInspectId" parameterType="Long">
        delete from inspect_infor where inspect_id = #{inspectId}
    </delete>

    <update id="deleteInspectInforByInspectIds" parameterType="String">
        update  inspect_infor set is_del = 'Y' where inspect_id in
        <foreach item="inspectId" collection="array" open="(" separator="," close=")">
            #{inspectId}
        </foreach>
    </update>

    <select id="checkSampleNameUnique" resultMap="InspectInforResult">
        <include refid="selectInspectInforVo"/>
        where sample_name=#{sampleName} and is_del = 'N' limit 1
    </select>

    <select id="selectInspectInforCount" parameterType="Date" resultType="int">
       select ifnull(count(1),0) as num from inspect_infor
        <where>
            is_del = 'N'
            <if test="today != null">and DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(#{today},'%Y-%m-%d')</if>
            <if test="startTime != null">and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d')</if>
            <if test="endTime != null">and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d')</if>
        </where>
    </select>
</mapper>