<?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.fgw.FgwJdapMapper">
    
    <resultMap type="FgwJdap" id="FgwJdapResult">
        <result property="id"    column="id"    />
        <result property="xmId"    column="xm_id"    />
        <result property="xmmc"    column="xmmc"    />
        <result property="year"    column="year"    />
        <result property="month"    column="month"    />
        <result property="jdsj"    column="jdsj"    />
        <result property="jdannr"    column="jdannr"    />
        <result property="shjg"    column="shjg"    />
        <result property="shyj"    column="shyj"    />
        <result property="sfwc"    column="sfwc"    />
        <result property="cqts"    column="cqts"    />
        <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="selectFgwJdapVo">
        select id, xm_id, xmmc, year, month, jdsj, jdannr, shjg, shyj, sfwc, cqts, create_by, create_time, update_by, update_time, remark from fgw_jdap
    </sql>

    <select id="selectFgwJdapList" parameterType="FgwJdap" resultMap="FgwJdapResult">
        <include refid="selectFgwJdapVo"/>
        <where>  
            <if test="xmId != null "> and xm_id = #{xmId}</if>
            <if test="xmmc != null  and xmmc != ''"> and xmmc = #{xmmc}</if>
            <if test="year != null  and year != ''"> and year = #{year}</if>
            <if test="month != null  and month != ''"> and month = #{month}</if>
            <if test="jdsj != null "> and jdsj like concat( #{jdsj}, '%')</if>
            <if test="jdannr != null  and jdannr != ''"> and jdannr = #{jdannr}</if>
            <if test="shjg != null  and shjg != ''"> and shjg = #{shjg}</if>
            <if test="shyj != null  and shyj != ''"> and shyj = #{shyj}</if>
            <if test="sfwc != null  and sfwc != ''"> and sfwc = #{sfwc}</if>
            <if test="cqts != null "> and cqts = #{cqts}</if>
        </where>
    </select>
    
    <select id="selectFgwJdapById" parameterType="Long" resultMap="FgwJdapResult">
        <include refid="selectFgwJdapVo"/>
        where id = #{id}
    </select>

    <select id="selectFgwJdapNum" resultMap="FgwJdapResult">
        SELECT
            ANY_VALUE(id) as id,
            xm_id
        FROM
            fgw_jdap
        WHERE
            DATEDIFF(NOW(), jdsj) &gt;= - #{yjts}
          AND DATEDIFF(NOW(), jdsj) &lt;=0
          and shjg = '1'
          and sfwc = '0'
        GROUP BY
            xm_id
    </select>

    <!--<select id="selectFgwJdapNum" resultMap="FgwJdapResult">
        SELECT
            id,
            xm_id
        FROM
            fgw_jdap
        WHERE
            DATEDIFF(NOW(), jdsj) &gt;= - #{yjts}
          AND DATEDIFF(NOW(), jdsj) &lt;=0
          and shjg = '1'
          and sfwc = '0'
        GROUP BY
            xm_id
    </select>-->
    <select id="selectFgwJdapCqxmNum" resultMap="FgwJdapResult">
        SELECT
            xm_id
        FROM
            fgw_jdap
        WHERE
            DATEDIFF(NOW(), jdsj) &gt;0
          and shjg = '1'
          and sfwc != '3'
        GROUP BY
            xm_id
    </select>
    <select id="selectFgwJdapListByIdList" resultMap="FgwJdapResult">
        <include refid="selectFgwJdapVo"/>
        where shjg = '1' and sfwc != '3'
        and id in
        <foreach item="id" collection="jdapIdList" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertFgwJdap" parameterType="FgwJdap" useGeneratedKeys="true" keyProperty="id">
        insert into fgw_jdap
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="xmId != null">xm_id,</if>
            <if test="xmmc != null and xmmc != ''">xmmc,</if>
            <if test="year != null and year != ''">year,</if>
            <if test="month != null">month,</if>
            <if test="jdsj != null">jdsj,</if>
            <if test="jdannr != null and jdannr != ''">jdannr,</if>
            <if test="shjg != null">shjg,</if>
            <if test="shyj != null">shyj,</if>
            <if test="sfwc != null">sfwc,</if>
            <if test="cqts != null">cqts,</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="xmId != null">#{xmId},</if>
            <if test="xmmc != null and xmmc != ''">#{xmmc},</if>
            <if test="year != null and year != ''">#{year},</if>
            <if test="month != null">#{month},</if>
            <if test="jdsj != null">#{jdsj},</if>
            <if test="jdannr != null and jdannr != ''">#{jdannr},</if>
            <if test="shjg != null">#{shjg},</if>
            <if test="shyj != null">#{shyj},</if>
            <if test="sfwc != null">#{sfwc},</if>
            <if test="cqts != null">#{cqts},</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="updateFgwJdap" parameterType="FgwJdap">
        update fgw_jdap
        <trim prefix="SET" suffixOverrides=",">
            <if test="xmId != null">xm_id = #{xmId},</if>
            <if test="xmmc != null and xmmc != ''">xmmc = #{xmmc},</if>
            <if test="year != null and year != ''">year = #{year},</if>
            <if test="month != null">month = #{month},</if>
            <if test="jdsj != null">jdsj = #{jdsj},</if>
            <if test="jdannr != null and jdannr != ''">jdannr = #{jdannr},</if>
            <if test="shjg != null">shjg = #{shjg},</if>
            <if test="shyj != null">shyj = #{shyj},</if>
            <if test="sfwc != null">sfwc = #{sfwc},</if>
            <if test="cqts != null">cqts = #{cqts},</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 id = #{id}
    </update>
    <update id="updateFgwJdapJdsh">
        update fgw_jdap
        <trim prefix="SET" suffixOverrides=",">
            <if test="shjg != null">shjg = #{shjg},</if>
            <if test="shyj != null">shyj = #{shyj},</if>
        </trim>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteFgwJdapById" parameterType="Long">
        delete from fgw_jdap where id = #{id}
    </delete>

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