<?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.project.production.mapper.TMonthlyQualityReportS2005Mapper">
    
    <resultMap type="TMonthlyQualityReportS2005" id="TMonthlyQualityReportS2005Result">
        <result property="id"    column="id"    />
        <result property="locationName"    column="location_name"    />
        <result property="samplePoint"    column="sample_point"    />
        <result property="sampleDate"    column="sample_date"    />
        <result property="sampleName"    column="sample_name"    />
        <result property="ph"    column="ph"    />
        <result property="oilRatio"    column="oil_ratio"    />
        <result property="deptId"    column="dept_id"    />
        <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="deptName" column="dept_name" />
        <result property="startDate" column="start_date" />
        <result property="endDate" column="end_date" />
    </resultMap>

    <sql id="selectTMonthlyQualityReportS2005Vo">
        select d.id, d.location_name, d.sample_point, d.sample_date, d.sample_name, d.ph, d.oil_ratio, d.dept_id, d.del_flag, d.create_by, d.create_time, d.update_by, d.update_time ,s.dept_name from t_monthly_quality_report_s2005 d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMonthlyQualityReportS2005List" parameterType="TMonthlyQualityReportS2005" resultMap="TMonthlyQualityReportS2005Result">
        <include refid="selectTMonthlyQualityReportS2005Vo"/>
        <where>
            <if test="startDate != null "> and sample_date &gt;= #{startDate}</if>
            <if test="endDate != null "> and sample_date &lt;= #{endDate}</if>
            <if test="locationName != null  and locationName != ''"> and location_name like concat(concat('%', #{locationName}), '%')</if>
            <if test="samplePoint != null  and samplePoint != ''"> and sample_point = #{samplePoint}</if>
            <if test="sampleDate != null "> and sample_date = #{sampleDate}</if>
            <if test="sampleName != null  and sampleName != ''"> and sample_name like concat(concat('%', #{sampleName}), '%')</if>
            <if test="ph != null  and ph != ''"> and ph = #{ph}</if>
            <if test="oilRatio != null  and oilRatio != ''"> and oil_ratio = #{oilRatio}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTMonthlyQualityReportS2005ById" parameterType="Long" resultMap="TMonthlyQualityReportS2005Result">
        <include refid="selectTMonthlyQualityReportS2005Vo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTMonthlyQualityReportS2005" parameterType="TMonthlyQualityReportS2005">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_quality_report_s2005.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_monthly_quality_report_s2005
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="locationName != null">location_name,</if>
            <if test="samplePoint != null">sample_point,</if>
            <if test="sampleDate != null">sample_date,</if>
            <if test="sampleName != null">sample_name,</if>
            <if test="ph != null">ph,</if>
            <if test="oilRatio != null">oil_ratio,</if>
            <if test="deptId != null">dept_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="locationName != null">#{locationName},</if>
            <if test="samplePoint != null">#{samplePoint},</if>
            <if test="sampleDate != null">#{sampleDate},</if>
            <if test="sampleName != null">#{sampleName},</if>
            <if test="ph != null">#{ph},</if>
            <if test="oilRatio != null">#{oilRatio},</if>
            <if test="deptId != null">#{deptId},</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>
         </trim>
    </insert>

    <update id="updateTMonthlyQualityReportS2005" parameterType="TMonthlyQualityReportS2005">
        update t_monthly_quality_report_s2005
        <trim prefix="SET" suffixOverrides=",">
            <if test="locationName != null">location_name = #{locationName},</if>
            <if test="samplePoint != null">sample_point = #{samplePoint},</if>
            <if test="sampleDate != null">sample_date = #{sampleDate},</if>
            <if test="sampleName != null">sample_name = #{sampleName},</if>
            <if test="ph != null">ph = #{ph},</if>
            <if test="oilRatio != null">oil_ratio = #{oilRatio},</if>
            <if test="deptId != null">dept_id = #{deptId},</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>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTMonthlyQualityReportS2005ById" parameterType="Long">
        update t_monthly_quality_report_s2005 set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTMonthlyQualityReportS2005ByIds" parameterType="String">
        update t_monthly_quality_report_s2005 set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>