<?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.projectV2.ZsyzLdpsMapper">

    <resultMap type="ZsyzLdps" id="ZsyzLdpsResult">
        <result property="ids"    column="ids"    />
        <result property="xmId"    column="xm_id"    />
        <result property="xmbh"    column="xmbh"    />
        <result property="xmmc"    column="xmmc"    />
        <result property="psnr"    column="psnr"    />
        <result property="remark"    column="remark"    />
        <result property="deptId"    column="dept_id"    />
        <result property="psnrId"    column="psnr_id"    />
        <result property="psr"    column="psr"    />
        <result property="cjsj"    column="cjsj"    />
        <result property="xgr"    column="xgr"    />
        <result property="xgsj"    column="xgsj"    />
    </resultMap>

    <sql id="selectZsyzLdpsVo">
        select id, xm_id, xmbh,xmmc, psnr,zcpsnr, remark, dept_id,psnr_id, psr, cjsj, xgr, xgsj from zsyz_ldps
    </sql>

    <select id="selectZsyzLdpsList" parameterType="ZsyzLdps" resultMap="ZsyzLdpsResult">
        <include refid="selectZsyzLdpsVo"/>
        <where>
            psnr is not null and psnr != ''
            <if test="xmId != null "> and xm_id = #{xmId}</if>
            <if test="xmbh != null  and xmbh != ''"> and xmbh = #{xmbh}</if>
            <if test="psnr != null  and psnr != ''"> and psnr = #{psnr}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="psnrId != null "> and psnr_id = #{psnrId}</if>
        </where>
        order by cjsj desc
    </select>
    
    <select id="selectZsyzLdpsById" parameterType="Long" resultMap="ZsyzLdpsResult">
        <include refid="selectZsyzLdpsVo"/>
        where id = #{id}
    </select>
    <select id="getInfoZc" resultMap="ZsyzLdpsResult">
        <include refid="selectZsyzLdpsVo"/>
        where psnr_id = #{psnrId}
        and xm_id = #{xmId}
        and zcpsnr !=''
        and zcpsnr is not null
        and (psnr = '' or psnr is null)
    </select>
    <select id="selectZsyzLdpsNew" resultMap="ZsyzLdpsResult">
        <include refid="selectZsyzLdpsVo"/>
        where xm_id = #{xmId}  and psnr is not null
        order by xgsj desc limit 2;
    </select>

    <insert id="insertZsyzLdps" parameterType="ZsyzLdps" useGeneratedKeys="true" keyProperty="id">
        insert into zsyz_ldps
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="xmId != null">xm_id,</if>
            <if test="xmbh != null">xmbh,</if>
            <if test="xmmc != null">xmmc,</if>
            <if test="psnr != null">psnr,</if>
            <if test="zcpsnr != null">zcpsnr,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="psr != null ">psr,</if>
            <if test="psnrId != null ">psnr_id,</if>
            <if test="cjsj != null">cjsj,</if>
            <if test="xgr != null">xgr,</if>
            <if test="xgsj != null">xgsj,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="xmId != null">#{xmId},</if>
            <if test="xmbh != null">#{xmbh},</if>
            <if test="xmmc != null">#{xmmc},</if>
            <if test="psnr != null">#{psnr},</if>
            <if test="zcpsnr != null">#{zcpsnr},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="psr != null ">#{psr},</if>
            <if test="psnrId != null ">#{psnrId},</if>
            <if test="cjsj != null">#{cjsj},</if>
            <if test="xgr != null">#{xgr},</if>
            <if test="xgsj != null">#{xgsj},</if>
         </trim>
    </insert>

    <update id="updateZsyzLdps" parameterType="ZsyzLdps">
        update zsyz_ldps
        <trim prefix="SET" suffixOverrides=",">
            <if test="xmId != null">xm_id = #{xmId},</if>
            <if test="xmbh != null">xmbh = #{xmbh},</if>
            <if test="xmmc != null">xmmc = #{xmmc},</if>
            <if test="psnr != null">psnr = #{psnr},</if>
            <if test="zcpsnr != null">zcpsnr = #{zcpsnr},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="psr != null ">psr = #{psr},</if>
            <if test="psnrId != null ">psnr_id = #{psnrId},</if>
            <if test="cjsj != null">cjsj = #{cjsj},</if>
            <if test="xgr != null">xgr = #{xgr},</if>
            <if test="xgsj != null">xgsj = #{xgsj},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteZsyzLdpsById" parameterType="Long">
        delete from zsyz_ldps where id = #{id}
    </delete>

    <delete id="deleteZsyzLdpsByIds" parameterType="String">
        delete from zsyz_ldps where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>