<?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.sems.safecheck.mapper.TSpecDailycheckMapper">

    <resultMap type="TSpecDailycheck" id="TSpecDailycheckResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="checkDate"    column="check_date"    />
        <result property="checkerId"    column="checker_id"    />
        <result property="cPerson"    column="c_person"    />
        <result property="cDevice"    column="c_device"    />
        <result property="cSafety"    column="c_safety"    />
        <result property="cEnv"    column="c_env"    />
        <result property="cGov"    column="c_gov"    />
        <result property="cComplaint"    column="c_complaint"    />
        <result property="cOpinion"    column="c_opinion"    />
        <result property="cOther"    column="c_other"    />
        <result property="explain"    column="explain"    />
        <result property="isConfirm"    column="is_confirm"    />
        <result property="agentId"    column="agent_id"    />
    </resultMap>

    <sql id="selectTSpecDailycheckVo">
        select d.id,s.nick_name as checkerName,s1.nick_name as agentName,d.agent_id,d.is_confirm, d.plant_code, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.check_date, d.checker_id, d.c_person, d.c_device, d.c_safety, d.c_env, d.c_gov, d.c_complaint, d.c_opinion, d.c_other, d.explain  from t_spec_dailycheck d
        left join sys_user s on d.checker_id = s.user_id
        left join sys_user s1 on d.agent_id = s1.user_id
    </sql>

    <select id="selectTSpecDailycheckList" parameterType="TSpecDailycheck" resultMap="TSpecDailycheckResult">
        <include refid="selectTSpecDailycheckVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code like concat(concat('%',  #{plantCode}), '%')</if>
            <if test="checkDate != null "> and check_date = #{checkDate}</if>
            <if test="startDate != null ">and check_date <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and check_date <![CDATA[<=]]>#{endDate}</if>
            <if test="cPerson != null  and cPerson != ''"> and c_person = #{cPerson}</if>
            <if test="cDevice != null  and cDevice != ''"> and c_device = #{cDevice}</if>
            <if test="cSafety != null  and cSafety != ''"> and c_safety = #{cSafety}</if>
            <if test="cEnv != null  and cEnv != ''"> and c_env = #{cEnv}</if>
            <if test="cGov != null  and cGov != ''"> and c_gov = #{cGov}</if>
            <if test="cComplaint != null  and cComplaint != ''"> and c_complaint = #{cComplaint}</if>
            <if test="cOpinion != null  and cOpinion != ''"> and c_opinion = #{cOpinion}</if>
            <if test="cOther != null  and cOther != ''"> and c_other = #{cOther}</if>
            <if test="explain != null  and explain != ''"> and explain = #{explain}</if>
            <if test="isConfirm != null  and isConfirm != ''"> and is_confirm = #{isConfirm}</if>
            <if test="plants != null  and plants != ''">
                and
                d.plant_code in
                <foreach collection="plants.split(',')" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
        order by d.check_date desc
    </select>

    <select id="selectMyList" parameterType="TSpecDailycheck" resultMap="TSpecDailycheckResult">
        <include refid="selectTSpecDailycheckVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code like concat(concat('%',  #{plantCode}), '%')</if>
            <if test="checkDate != null "> and check_date = #{checkDate}</if>
            <if test="startDate != null ">and check_date <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and check_date <![CDATA[<=]]>#{endDate}</if>
            <if test="cPerson != null  and cPerson != ''"> and c_person = #{cPerson}</if>
            <if test="cDevice != null  and cDevice != ''"> and c_device = #{cDevice}</if>
            <if test="cSafety != null  and cSafety != ''"> and c_safety = #{cSafety}</if>
            <if test="cEnv != null  and cEnv != ''"> and c_env = #{cEnv}</if>
            <if test="cGov != null  and cGov != ''"> and c_gov = #{cGov}</if>
            <if test="cComplaint != null  and cComplaint != ''"> and c_complaint = #{cComplaint}</if>
            <if test="cOpinion != null  and cOpinion != ''"> and c_opinion = #{cOpinion}</if>
            <if test="cOther != null  and cOther != ''"> and c_other = #{cOther}</if>
            <if test="explain != null  and explain != ''"> and explain = #{explain}</if>
            <if test="isConfirm != null  and isConfirm != ''"> and is_confirm = #{isConfirm}</if>
            <if test="checkerId != null  and checkerId != ''"> and checker_id = #{checkerId}</if>
            and d.del_flag = 0 and d.agent_id is not null
        </where>
        order by d.check_date desc
    </select>

    <select id="selectTSpecDailycheckById" parameterType="Long" resultMap="TSpecDailycheckResult">
        <include refid="selectTSpecDailycheckVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSpecDailycheck" parameterType="TSpecDailycheck">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_spec_dailycheck.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_spec_dailycheck
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="checkDate != null">check_date,</if>
            <if test="checkerId != null">checker_id,</if>
            <if test="cPerson != null">c_person,</if>
            <if test="cDevice != null">c_device,</if>
            <if test="cSafety != null">c_safety,</if>
            <if test="cEnv != null">c_env,</if>
            <if test="cGov != null">c_gov,</if>
            <if test="cComplaint != null">c_complaint,</if>
            <if test="cOpinion != null">c_opinion,</if>
            <if test="cOther != null">c_other,</if>
            <if test="explain != null">explain,</if>
            <if test="agentId != null">agent_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="checkDate != null">#{checkDate},</if>
            <if test="checkerId != null">#{checkerId},</if>
            <if test="cPerson != null">#{cPerson},</if>
            <if test="cDevice != null">#{cDevice},</if>
            <if test="cSafety != null">#{cSafety},</if>
            <if test="cEnv != null">#{cEnv},</if>
            <if test="cGov != null">#{cGov},</if>
            <if test="cComplaint != null">#{cComplaint},</if>
            <if test="cOpinion != null">#{cOpinion},</if>
            <if test="cOther != null">#{cOther},</if>
            <if test="explain != null">#{explain},</if>
            <if test="agentId != null">#{agentId},</if>
         </trim>
    </insert>

    <update id="updateTSpecDailycheck" parameterType="TSpecDailycheck">
        update t_spec_dailycheck
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="checkDate != null">check_date = #{checkDate},</if>
            <if test="checkerId != null">checker_id = #{checkerId},</if>
            <if test="cPerson != null">c_person = #{cPerson},</if>
            <if test="cDevice != null">c_device = #{cDevice},</if>
            <if test="cSafety != null">c_safety = #{cSafety},</if>
            <if test="cEnv != null">c_env = #{cEnv},</if>
            <if test="cGov != null">c_gov = #{cGov},</if>
            <if test="cComplaint != null">c_complaint = #{cComplaint},</if>
            <if test="cOpinion != null">c_opinion = #{cOpinion},</if>
            <if test="cOther != null">c_other = #{cOther},</if>
            <if test="explain != null">explain = #{explain},</if>
            <if test="agentId != null">agent_id = #{agentId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <update id="batchConfirmByids" parameterType="String">
        update t_spec_dailycheck set is_confirm = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <update id="batchCancel" parameterType="String">
        update t_spec_dailycheck set is_confirm = 0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>


</mapper>
