<?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.TMonthlyQualityReportS0501Mapper">
    
    <resultMap type="TMonthlyQualityReportS0501" id="TMonthlyQualityReportS0501Result">
        <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="p"    column="p"    />
        <result property="i"    column="i"    />
        <result property="o"    column="o"    />
        <result property="n"    column="n"    />
        <result property="a"    column="a"    />
        <result property="pI"    column="p_i"    />
        <result property="density2"    column="density_2"    />
        <result property="ibp"    column="ibp"    />
        <result property="five"    column="five"    />
        <result property="ten"    column="ten"    />
        <result property="thrity"    column="thrity"    />
        <result property="fifty"    column="fifty"    />
        <result property="seventy"    column="seventy"    />
        <result property="ninety"    column="ninety"    />
        <result property="ninetyFive"    column="ninety_five"    />
        <result property="fbp"    column="fbp"    />
        <result property="totalSulfur"    column="total_sulfur"    />
        <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" />
        <result property="month" column="month" />
        <result property="year" column="year" />
    </resultMap>

    <sql id="selectTMonthlyQualityReportS0501Vo">
        select d.id, d.location_name, d.sample_point, d.sample_date, d.sample_name, d.p, d.i, d.o, d.n, d.a, d.p_i, d.density_2, d.ibp, d.five, d.ten, d.thrity, d.fifty, d.seventy, d.ninety, d.ninety_five, d.fbp, d.total_sulfur, 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_s0501 d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMonthlyQualityReportS0501ListMonth" parameterType="TMonthlyQualityReportS0501" resultMap="TMonthlyQualityReportS0501Result">
        select sum(translate(p, '0' || translate(p, '#.0123456789', '#'), '0')) as p,
            sum(translate(i, '0' || translate(i, '#.0123456789', '#'), '0')) as i,
            sum(translate(o, '0' || translate(o, '#.0123456789', '#'), '0')) as o,
            sum(translate(n, '0' || translate(n, '#.0123456789', '#'), '0')) as n,
            sum(translate(fifty, '0' || translate(fifty, '#.0123456789', '#'), '0')) as fifty
        from t_monthly_quality_report_s0501 d
        left join sys_dept s on s.dept_id = d.dept_id
        <where>
            <if test="month != null "> and extract(month from sample_date) = #{month}</if>
            <if test="year != null "> and extract(year from sample_date) = #{year}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMonthlyQualityReportS0501List" parameterType="TMonthlyQualityReportS0501" resultMap="TMonthlyQualityReportS0501Result">
        <include refid="selectTMonthlyQualityReportS0501Vo"/>
        <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="p != null  and p != ''"> and p = #{p}</if>
            <if test="i != null  and i != ''"> and i = #{i}</if>
            <if test="o != null  and o != ''"> and o = #{o}</if>
            <if test="n != null  and n != ''"> and n = #{n}</if>
            <if test="a != null  and a != ''"> and a = #{a}</if>
            <if test="pI != null  and pI != ''"> and p_i = #{pI}</if>
            <if test="density2 != null  and density2 != ''"> and density_2 = #{density2}</if>
            <if test="ibp != null  and ibp != ''"> and ibp = #{ibp}</if>
            <if test="five != null  and five != ''"> and five = #{five}</if>
            <if test="ten != null  and ten != ''"> and ten = #{ten}</if>
            <if test="thrity != null  and thrity != ''"> and thrity = #{thrity}</if>
            <if test="fifty != null  and fifty != ''"> and fifty = #{fifty}</if>
            <if test="seventy != null  and seventy != ''"> and seventy = #{seventy}</if>
            <if test="ninety != null  and ninety != ''"> and ninety = #{ninety}</if>
            <if test="ninetyFive != null  and ninetyFive != ''"> and ninety_five = #{ninetyFive}</if>
            <if test="fbp != null  and fbp != ''"> and fbp = #{fbp}</if>
            <if test="totalSulfur != null  and totalSulfur != ''"> and total_sulfur = #{totalSulfur}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTMonthlyQualityReportS0501ById" parameterType="Long" resultMap="TMonthlyQualityReportS0501Result">
        <include refid="selectTMonthlyQualityReportS0501Vo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTMonthlyQualityReportS0501" parameterType="TMonthlyQualityReportS0501">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_quality_report_s0501.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_monthly_quality_report_s0501
        <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="p != null">p,</if>
            <if test="i != null">i,</if>
            <if test="o != null">o,</if>
            <if test="n != null">n,</if>
            <if test="a != null">a,</if>
            <if test="pI != null">p_i,</if>
            <if test="density2 != null">density_2,</if>
            <if test="ibp != null">ibp,</if>
            <if test="five != null">five,</if>
            <if test="ten != null">ten,</if>
            <if test="thrity != null">thrity,</if>
            <if test="fifty != null">fifty,</if>
            <if test="seventy != null">seventy,</if>
            <if test="ninety != null">ninety,</if>
            <if test="ninetyFive != null">ninety_five,</if>
            <if test="fbp != null">fbp,</if>
            <if test="totalSulfur != null">total_sulfur,</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="p != null">#{p},</if>
            <if test="i != null">#{i},</if>
            <if test="o != null">#{o},</if>
            <if test="n != null">#{n},</if>
            <if test="a != null">#{a},</if>
            <if test="pI != null">#{pI},</if>
            <if test="density2 != null">#{density2},</if>
            <if test="ibp != null">#{ibp},</if>
            <if test="five != null">#{five},</if>
            <if test="ten != null">#{ten},</if>
            <if test="thrity != null">#{thrity},</if>
            <if test="fifty != null">#{fifty},</if>
            <if test="seventy != null">#{seventy},</if>
            <if test="ninety != null">#{ninety},</if>
            <if test="ninetyFive != null">#{ninetyFive},</if>
            <if test="fbp != null">#{fbp},</if>
            <if test="totalSulfur != null">#{totalSulfur},</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="updateTMonthlyQualityReportS0501" parameterType="TMonthlyQualityReportS0501">
        update t_monthly_quality_report_s0501
        <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="p != null">p = #{p},</if>
            <if test="i != null">i = #{i},</if>
            <if test="o != null">o = #{o},</if>
            <if test="n != null">n = #{n},</if>
            <if test="a != null">a = #{a},</if>
            <if test="pI != null">p_i = #{pI},</if>
            <if test="density2 != null">density_2 = #{density2},</if>
            <if test="ibp != null">ibp = #{ibp},</if>
            <if test="five != null">five = #{five},</if>
            <if test="ten != null">ten = #{ten},</if>
            <if test="thrity != null">thrity = #{thrity},</if>
            <if test="fifty != null">fifty = #{fifty},</if>
            <if test="seventy != null">seventy = #{seventy},</if>
            <if test="ninety != null">ninety = #{ninety},</if>
            <if test="ninetyFive != null">ninety_five = #{ninetyFive},</if>
            <if test="fbp != null">fbp = #{fbp},</if>
            <if test="totalSulfur != null">total_sulfur = #{totalSulfur},</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="deleteTMonthlyQualityReportS0501ById" parameterType="Long">
        update t_monthly_quality_report_s0501 set del_flag = 2 where id = #{id}
    </update>

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

    <update id="deleteTMonthlyQualityReportBranch" parameterType="com.ruoyi.project.production.controller.vo.MonthlyQualityRemoveVO">
        <if test="samplePoint == 1">update t_monthly_quality_report_s0501 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 2">update t_monthly_quality_report_s1301 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 3">update t_monthly_quality_report_s2002 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 4">update t_monthly_quality_report_s2005 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 5">update t_monthly_quality_report_s2007 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 6">update t_monthly_quality_report_s2011 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 7">update t_monthly_quality_report_s2400 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 8">update t_monthly_quality_report_s3004 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 9">update t_monthly_quality_report_s3009 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 10">update t_monthly_quality_report_s3010 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 11">update t_monthly_quality_report_s3011 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 12">update t_monthly_quality_report_s3012 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 13">update t_monthly_quality_report_s3022 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 14">update t_monthly_quality_report_s4012 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 15">update t_monthly_quality_report_s4013 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 16">update t_monthly_quality_report_s4501 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 17">update t_monthly_quality_report_s5001 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 18">update t_monthly_quality_report_s5003 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 19">update t_monthly_quality_report_s5010 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 20">update t_monthly_quality_report_s5012 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 21">update t_monthly_quality_report_s6101 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 22">update t_monthly_quality_report_s6107 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 23">update t_monthly_quality_report_s6301 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
        <if test="samplePoint == 24">update t_monthly_quality_report_z404 set del_flag = 2 where sample_date &gt;= #{startDate} and sample_date &lt;= #{endDate}</if>
    </update>

    <select id="selectTMonthlyQualityReportYearMonth" resultType="String">
        select distinct extract(year from t.SAMPLE_DATE)||'-'||extract(month from t.SAMPLE_DATE)
        from T_MONTHLY_QUALITY_REPORT_S0501 t
        where t.DEL_FLAG = 0
    </select>
</mapper>