<?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="org.springblade.modules.mdjfdj.mapper.MdjfDjMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="mdjfdjResultMap" type="org.springblade.modules.mdjfdj.entity.MdjfDjEntity">
        <result column="id" property="id"/>
        <result column="jfmc" property="jfmc"/>
        <result column="jflx" property="jflx"/>
        <result column="jfyy" property="jfyy"/>
        <result column="jffssj" property="jffssj"/>
        <result column="jffsdd" property="jffsdd"/>
        <result column="jyaq" property="jyaq"/>
        <result column="jfdjsj" property="jfdjsj"/>
        <result column="jfsssq" property="jfsssq"/>
        <result column="jfsspcs" property="jfsspcs"/>
        <result column="jfssfj" property="jfssfj"/>
        <result column="sbzt" property="sbzt"/>
        <result column="sbsj" property="sbsj"/>
        <result column="sbdw" property="sbdw"/>
        <result column="yjzt" property="yjzt"/>
        <result column="yjsj" property="yjsj"/>
        <result column="yjdw" property="yjdw"/>
        <result column="fksj" property="fksj"/>
        <result column="fknr" property="fknr"/>
        <result column="fkr" property="fkr"/>
        <result column="fkdw" property="fkdw"/>
        <result column="hfr" property="hfr"/>
        <result column="hfnr" property="hfnr"/>
        <result column="hfsj" property="hfsj"/>
        <result column="mdjb_v" property="mdjbV"/>
        <result column="xhfcs" property="xhfcs"/>
        <result column="yhfcs" property="yhfcs"/>
        <result column="hfzt_new" property="hfztNew"/>
        <result column="cszt" property="cszt"/>
        <result column="csnr" property="csnr"/>
        <result column="hfjzsj" property="hfjzsj"/>
        <result column="hfjzsj2" property="hfjzsj2"/>
        <result column="hfjzsj3" property="hfjzsj3"/>
        <result column="cscs" property="cscs"/>
    </resultMap>


    <select id="selectmdjfDjPage" resultType="org.springblade.modules.mdjfdj.vo.MdjfDjVO">
        SELECT * FROM (

        SELECT
            md.*,
            jq.jjdbh AS jqbh,
            (SELECT mt.tjzt FROM mdjf_tj mt WHERE mt.jf_id = md.id ORDER BY mt.create_time DESC LIMIT 1) AS tjzt,
            case when sq.dept_category = 7 then sq.dept_name
            when sq.dept_category = 6 then null end as sqName,
            case when sq.dept_category = 7 then sq.Id
            when sq.dept_category = 6 then null end as sqId,
            case when sq.dept_category = 7 then pcs.dept_name
            when sq.dept_category = 6 then sq.dept_name end as pcsName,
            case when sq.dept_category = 7 then pcs.id
            when sq.dept_category = 6 then sq.id end as pcsId,
            case when sq.dept_category = 7 then fj.dept_name
            when sq.dept_category = 6 then pcs.dept_name end as fjName,
            case when sq.dept_category = 7 then fj.id
            when sq.dept_category = 6 then pcs.id end as fjId,
            case when sq.dept_category = 7 then sj.dept_name
            when sq.dept_category = 6 then fj.dept_name end as sjName,
            case when sq.dept_category = 7 then sj.id
            when sq.dept_category = 6 then fj.id end as sjId,
            uses.name as createName,
            coalesce (rw.rwzt, '无需签收') AS rwzt,
        CASE WHEN md.jfly != '110警情' THEN '无需回访'
        WHEN md.jfly = '110警情' AND md.hfsj IS NULL THEN '待回访' ELSE'已回访'
            END AS hfzt
        FROM
            mdjf_dj md
        LEFT JOIN mdjf_jq jq ON jq.id = md.id
        LEFT JOIN blade_dept sq ON sq.ID = md.jfsssq
        LEFT JOIN blade_dept pcs ON pcs.ID = sq.parent_id
        LEFT JOIN blade_dept fj ON fj.ID = pcs.parent_id
        LEFT JOIN blade_dept sj ON sj.ID = fj.parent_id
        LEFT JOIN blade_user uses ON md.create_user = uses.id
        LEFT JOIN rwxffkb rw ON ( rw.rwid = md.ID AND rw.rwly = 'mdjf_dj' )
        WHERE
            md.is_deleted = 0
            AND ((sq.id :: text = any(string_to_array(#{params.deptId},','))) OR (sq.ancestors LIKE '%' || #{params.deptId} || '%'))

        ) AS tem

        WHERE 1 = 1
          <if test="params.jfly != null and params.jfly != ''">
              AND tem.jfly = #{params.jfly}
          </if>
          <if test="params.jfmc != null and params.jfmc != ''">
              AND tem.jfmc like '%' || #{params.jfmc} || '%'
          </if>
          <if test="params.jflx != null and params.jflx != ''">
              AND tem.jflx like '%' || #{params.jflx} || '%'
          </if>
          <if test="params.sqName != null and params.sqName != ''">
              AND tem.sqId :: text like '%' || #{params.sqName} || '%'
          </if>
          <if test="params.pcsName != null and params.pcsName != ''">
              AND tem.pcsId :: text like '%' || #{params.pcsName} || '%'
          </if>
          <if test="params.fjName != null and params.fjName != ''">
              AND tem.fjId :: text like '%' || #{params.fjName} || '%'
          </if>
          <if test="params.sjName != null and params.sjName != ''">
              AND tem.sjId :: text like '%' || #{params.sjName} || '%'
          </if>
          <if test="params.rwzt != null and params.rwzt != ''">
              AND tem.rwzt = #{params.rwzt}
          </if>
          <if test="params.tjzt != null and params.tjzt != '' and params.tjzt != '未调解'">
              AND tem.tjzt = #{params.tjzt}
          </if>
          <if test="params.tjzt != null and params.tjzt != '' and params.tjzt == '未调解'">
              AND tem.tjzt is null
          </if>
          <if test="params.hfzt != null and params.hfzt != ''">
              AND tem.hfzt = #{params.hfzt}
          </if>
          <if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''">
              AND tem.create_time BETWEEN #{params.beginTime} :: timestamp AND #{params.endTime} :: timestamp
          </if>
          <if test="params.sfgl != null and params.sfgl != '' and params.sfgl == 0">
              AND tem.jqbh IS NULL
          </if>
          <if test="params.sfgl != null and params.sfgl != '' and params.sfgl == 1">
              AND tem.jqbh IS NOT NULL
          </if>
        ORDER BY tem.create_time DESC
    </select>

    <select id="pageToApp" resultType="org.springblade.modules.mdjfdj.vo.MdjfDjVO">
        SELECT
            *
        FROM
            (
                SELECT
                    ROW_NUMBER () OVER ( PARTITION BY md.id ORDER BY mt.create_time DESC ) maxRow,
                    md.*,
                    mt.tjzt,
                    (SELECT COUNT(1) FROM mdjf_hf hf WHERE hf.jf_id = md.id) AS hfzt
                FROM
                    mdjf_dj md
                LEFT JOIN mdjf_tj mt ON mt.jf_id = md.id
                LEFT JOIN blade_dept sq ON sq.id = md.jfsssq
                WHERE
                    md.is_deleted = 0
                AND ((sq.id :: text = any(string_to_array(#{params.deptId},','))) OR (sq.ancestors LIKE '%' || #{params.deptId} || '%'))
                <if test="null != params.jfIds and '' != params.jfIds">
                    AND EXISTS (
                    SELECT 1 FROM unnest(string_to_array(#{params.jfIds}, ',')::int8[]) AS id(val)
                    WHERE md.id = id.val
                    )
                </if>
            ) temp
        WHERE
            temp.maxRow = 1
        <if test="params.jfmc != null and params.jfmc != ''">
            AND temp.jfmc like '%' || #{params.jfmc} || '%'
        </if>
        <if test="params.jflx != null and params.jflx != ''">
            AND temp.jflx like '%' || #{params.jflx} || '%'
        </if>
        <if test="params.tjzt == 1">
            AND (temp.tjzt IS NULL OR temp.tjzt = '调解未果')
        </if>
        <if test="params.tjzt == 2">
            AND temp.tjzt IN ('已调解') and temp.hfzt_new = '2'
        </if>
        <if test="params.tjzt == 3">
            AND temp.tjzt = '已调解' AND temp.hfzt_new in ('0','1')
        </if>
        <if test="params.tjzt == 4">
            AND temp.tjzt IN ('已流转')
        </if>
        <if test="null != params.sfsc and 1 == params.sfsc">
            AND temp.sfsc = 1
        </if>
        <if test="null != params.mdId and '' != params.mdId">
            AND temp.id :: text in
            <foreach collection="mdIds" item="mdId" separator="," open="(" close=")">
                #{mdId}
            </foreach>
        </if>
        ORDER BY temp.create_time DESC
    </select>

    <select id="exportmdjfDj" resultType="org.springblade.modules.mdjfdj.excel.MdjfDjExcel">
        SELECT * FROM (

        SELECT
        md.*,
        (SELECT mt.tjzt FROM mdjf_tj mt WHERE mt.jf_id = md.id ORDER BY mt.create_time DESC LIMIT 1) AS tjzt,
        case when sq.dept_category = 7 then sq.dept_name
        when sq.dept_category = 6 then null end as sqName,
        case when sq.dept_category = 7 then sq.Id
        when sq.dept_category = 6 then null end as sqId,
        case when sq.dept_category = 7 then pcs.dept_name
        when sq.dept_category = 6 then sq.dept_name end as pcsName,
        case when sq.dept_category = 7 then pcs.id
        when sq.dept_category = 6 then sq.id end as pcsId,
        case when sq.dept_category = 7 then fj.dept_name
        when sq.dept_category = 6 then pcs.dept_name end as fjName,
        case when sq.dept_category = 7 then fj.id
        when sq.dept_category = 6 then pcs.id end as fjId,
        case when sq.dept_category = 7 then sj.dept_name
        when sq.dept_category = 6 then fj.dept_name end as sjName,
        case when sq.dept_category = 7 then sj.id
        when sq.dept_category = 6 then fj.id end as sjId,
        uses.name as createName,
        coalesce (rw.rwzt, '无需签收') AS rwzt,
        CASE WHEN md.jfly != '110警情' THEN '无需回访'
        WHEN md.jfly = '110警情' AND md.hfsj IS NULL THEN '待回访' ELSE'已回访'
        END AS hfzt
        FROM
        mdjf_dj md
        LEFT JOIN blade_dept sq ON sq.ID = md.jfsssq
        LEFT JOIN blade_dept pcs ON pcs.ID = sq.parent_id
        LEFT JOIN blade_dept fj ON fj.ID = pcs.parent_id
        LEFT JOIN blade_dept sj ON sj.ID = fj.parent_id
        LEFT JOIN blade_user uses ON md.create_user = uses.id
        LEFT JOIN rwxffkb rw ON ( rw.rwid = md.ID AND rw.rwly = 'mdjf_dj' )
        WHERE
        md.is_deleted = 0
        AND ((sq.id :: text = any(string_to_array(#{params.deptId},','))) OR (sq.ancestors LIKE '%' || #{params.deptId} || '%'))

        ) AS tem

        WHERE 1 = 1
        <if test="params.jfly != null and params.jfly != ''">
            AND tem.jfly = #{params.jfly}
        </if>
        <if test="params.jfmc != null and params.jfmc != ''">
            AND tem.jfmc like '%' || #{params.jfmc} || '%'
        </if>
        <if test="params.jflx != null and params.jflx != ''">
            AND tem.jflx like '%' || #{params.jflx} || '%'
        </if>
        <if test="params.sqName != null and params.sqName != ''">
            AND tem.sqId :: text like '%' || #{params.sqName} || '%'
        </if>
        <if test="params.pcsName != null and params.pcsName != ''">
            AND tem.pcsId :: text like '%' || #{params.pcsName} || '%'
        </if>
        <if test="params.fjName != null and params.fjName != ''">
            AND tem.fjId :: text like '%' || #{params.fjName} || '%'
        </if>
        <if test="params.sjName != null and params.sjName != ''">
            AND tem.sjId :: text like '%' || #{params.sjName} || '%'
        </if>
        <if test="params.rwzt != null and params.rwzt != ''">
            AND tem.rwzt = #{params.rwzt}
        </if>
        <if test="params.tjzt != null and params.tjzt != '' and params.tjzt != '未调解'">
            AND tem.tjzt = #{params.tjzt}
        </if>
        <if test="params.tjzt != null and params.tjzt != '' and params.tjzt == '未调解'">
            AND tem.tjzt is null
        </if>
        <if test="params.hfzt != null and params.hfzt != ''">
            AND tem.hfzt = #{params.hfzt}
        </if>
        ORDER BY tem.create_time DESC
    </select>

    <select id="getDetail" resultType="org.springblade.modules.mdjfdj.entity.MdjfDjEntity">
        select
            md.*,
            sq.dept_name as sqName,
            pcs.dept_name as pcsName,
            fj.dept_name as fjName,
            sj.dept_name as sjName,
            (SELECT mt.tjzt FROM mdjf_tj mt WHERE mt.jf_id = md.id ORDER BY mt.create_time DESC LIMIT 1) AS tjzt,
            (SELECT mt.tjsj FROM mdjf_tj mt WHERE mt.jf_id = md.id ORDER BY mt.create_time DESC LIMIT 1) AS tjsj,
            (SELECT mt.tjxq FROM mdjf_tj mt WHERE mt.jf_id = md.id ORDER BY mt.create_time DESC LIMIT 1) AS tjxq
        FROM
            mdjf_dj md
        LEFT JOIN blade_dept sq ON sq.ID = md.jfsssq
        LEFT JOIN blade_dept pcs ON pcs.ID = sq.parent_id
        LEFT JOIN blade_dept fj ON fj.ID = pcs.parent_id
        LEFT JOIN blade_dept sj ON sj.ID = fj.parent_id
        WHERE md.id = #{id}
    </select>

    <select id="getJfhf" resultType="int">
        SELECT
            COUNT(*)
        FROM
            rwxffkb rw
        LEFT JOIN mdjf_dj md ON md.ID = rw.rwid
        WHERE
            rw.rwly = 'mdjf_dj'
        AND rw.user_id = #{params.userId}
        AND date_part( 'day', now( ) - rw.rwjssj ) > 30
        AND md.hfsj IS NULL
    </select>

    <select id="getDbsxVOtj" resultType="org.springblade.modules.appmenu.vo.DbsxVO">
        SELECT COUNT (0) AS total
        FROM
            (
                SELECT ROW_NUMBER() OVER ( PARTITION BY md.id ORDER BY mt.create_time DESC ) maxRow,
                    mt.tjzt
                FROM
                    mdjf_dj md
                LEFT JOIN mdjf_tj mt ON mt.jf_id = md.id
                LEFT JOIN blade_dept sq ON sq.id = md.jfsssq
                WHERE
                    md.is_deleted = 0
                AND ((#{deptId} LIKE '%' || sq.id || '%') OR (sq.ancestors LIKE '%' || #{deptId} || '%'))
            ) TEMP
        WHERE
            TEMP.maxRow = 1
          AND ( TEMP.tjzt IS NULL OR TEMP.tjzt = '调解未果' )
    </select>

    <select id="getDbsxVOhf" resultType="org.springblade.modules.appmenu.vo.DbsxVO">
        SELECT COUNT (0) AS total
        FROM
            (
                SELECT ROW_NUMBER() OVER ( PARTITION BY md.ID ORDER BY mt.create_time DESC ) maxRow,
                    mt.tjzt,
                    ( SELECT COUNT ( 1 ) FROM mdjf_hf hf WHERE hf.jf_id = md.id ) AS hfzt
                FROM
                    mdjf_dj md
                LEFT JOIN mdjf_tj mt ON mt.jf_id = md.id
                LEFT JOIN blade_dept sq ON sq.id = md.jfsssq
                WHERE
                    md.is_deleted = 0
                AND ((#{deptId} LIKE '%' || sq.id || '%') OR (sq.ancestors LIKE '%' || #{deptId} || '%'))
            ) TEMP
        WHERE
            TEMP.maxRow = 1
          AND TEMP.tjzt = '已调解'
          AND TEMP.hfzt = 0
    </select>


    <select id="getMdHfjzsjIsNotNull" resultType="org.springblade.modules.mdjfdj.entity.MdjfDjEntity">
        select * from mdjf_dj where  hfjzsj is not null and hfzt != '2'
    </select>

    <select id="getMdjfSl" parameterType="java.lang.Long" resultType="int">
        SELECT
            COUNT(id)
        FROM
            jdrh.mdjf_dj
        WHERE
            create_user = #{userId}
          AND is_deleted = 0
    </select>

    <select id="getJqByLxdh" resultType="org.springblade.modules.mdjfdj.vo.JqVO">
        SELECT tem.* FROM (
            SELECT
                jj.xzqh,
                jj.sjdbh,
                jj.jjdbh,
                jj.bjsj,
                jj.bjrxm,
                jj.bjnr,
                jj.afdd,
                ROW_NUMBER () OVER ( PARTITION BY jj.sjdbh ORDER BY jj.hrsj DESC ) rn
            FROM
                jq_db.jjdb jj
            LEFT JOIN jq_db.dwb dw ON dw.dwbh = jj.gxdwdm
            WHERE
                jj.cllxdm = '1'
            AND jj.bjlbdm = '92'
            AND jj.bjdh = #{params.bjrdh}
        <if test="null != params.xzqh and '长春市' == params.xzqh">
            AND (substring(jj.xzqh, 1, 4) = '2201' OR substring(jj.xzqh, 1, 6) = '220381') AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '吉林市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2202' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '四平市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2203' AND substring(jj.xzqh, 1, 6) != '220381' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '辽源市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2204' AND dw.dwmc IS NOT NULL and dw.dwmc !=''
        </if>
        <if test="null != params.xzqh and '通化市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2205' AND substring(jj.xzqh, 1, 6) != '220581' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '梅河口市' == params.xzqh">
            AND substring(jj.xzqh, 1, 6) = '220581' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '白山市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2206' AND dw.dwmc IS NOT NULL and dw.dwmc !=''
        </if>
        <if test="null != params.xzqh and '松原市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2207' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '白城市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2208' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '延边州' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2224' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '长白山市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2299' AND dw.dwmc like '%派出所'
        </if>
        ) tem
        LEFT JOIN jdrh.mdjf_jq jq ON jq.jjdbh = tem.jjdbh
        WHERE tem.rn = 1 AND jq.id IS NULL
    </select>

    <select id="getJqFm" resultType="org.springblade.modules.mdjfdj.vo.JqVO">
        SELECT
            tem.*,
            md.jfmc,
            pcs.dept_name AS pcsName
        FROM (
            SELECT
                jj.xzqh,
                jj.sjdbh,
                jj.jjdbh,
                jj.hrsj AS bjsj,
                jj.bjdh,
                jj.bjrxm,
                jj.bjnr,
                jj.afdd,
                dw.dwmc,
                ROW_NUMBER () OVER ( PARTITION BY jj.sjdbh ORDER BY jj.hrsj DESC ) rn
            FROM
                jq_db.jjdb jj
            LEFT JOIN jq_db.dwb dw ON dw.dwbh = jj.gxdwdm
            WHERE
                jj.cllxdm = '1'
            AND jj.bjlbdm = '92'
            AND dw.dwbh not in('220100046100', '220100046000', '220100046300', '220100046200', '220100046500', '220100046400', '220100046700',
               '220100046600', '220100196100', '220100196200', '220100196300', '220100196400', '220100270600', '220100270700', '220100420400',
               '220102770000', '220199680000', '220108610000', '220108620000', '220200450100', '220555000000', '220799620000', '220799610000')
        <if test="null != params.beginTime and '' != params.beginTime and null != params.endTime and '' != params.endTime">
            AND jj.hrsj :: DATE BETWEEN #{params.beginTime} :: DATE and #{params.endTime} :: DATE
        </if>
        <if test="null != params.xzqh and '长春市' == params.xzqh">
            AND (substring(jj.xzqh, 1, 4) = '2201' OR substring(jj.xzqh, 1, 6) = '220381') AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '吉林市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2202' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '四平市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2203' AND substring(jj.xzqh, 1, 6) != '220381' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '辽源市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2204' AND dw.dwmc IS NOT NULL and dw.dwmc !=''
        </if>
        <if test="null != params.xzqh and '通化市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2205' AND substring(jj.xzqh, 1, 6) != '220581' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '梅河口市' == params.xzqh">
            AND substring(jj.xzqh, 1, 6) = '220581' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '白山市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2206' AND dw.dwmc IS NOT NULL and dw.dwmc !=''
        </if>
        <if test="null != params.xzqh and '松原市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2207' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '白城市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2208' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '延边州' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2224' AND dw.dwmc like '%派出所'
        </if>
        <if test="null != params.xzqh and '长白山市' == params.xzqh">
            AND substring(jj.xzqh, 1, 4) = '2299' AND dw.dwmc like '%派出所'
        </if>
        ) tem
        LEFT JOIN jdrh.mdjf_jq jq ON jq.jjdbh = tem.jjdbh
        LEFT JOIN jdrh.mdjf_dj md ON md.id = jq.id
        LEFT JOIN jdrh.blade_dept sq ON sq.id = md.jfsssq
        LEFT JOIN jdrh.blade_dept pcs ON pcs.id = sq.parent_id
        LEFT JOIN jdrh.blade_dept fj ON fj.id = pcs.parent_id
        LEFT JOIN jdrh.blade_dept sj ON sj.id = fj.parent_id
        WHERE tem.rn = 1 AND tem.bjdh != '' AND tem.bjdh IS NOT NULL
        <if test="null != params.sfgl and 0 == params.sfgl">
            AND jq.jjdbh IS NULL
        </if>
        <if test="null != params.sfgl and 1 == params.sfgl">
            AND jq.jjdbh IS NOT NULL
        </if>
        <if test="params.bjdh != null and params.bjdh != ''">
            AND tem.bjdh = #{params.bjdh}
        </if>
        <if test="params.pcsName != null and params.pcsName != ''">
            AND pcs.id = #{params.pcsName} :: int8
        </if>
        <if test="params.fjName != null and params.fjName != ''">
            AND fj.id = #{params.fjName} :: int8
        </if>
        <if test="params.sjName != null and params.sjName != ''">
            AND sj.id = #{params.sjName} :: int8
        </if>
    </select>

    <select id="getJqTx" resultType="org.springblade.modules.mdjfdj.vo.JqVO">
        SELECT
            tx.*
        FROM
            jq_db.jqtx tx
        LEFT JOIN jdrh.blade_dept pcs ON pcs.ID :: TEXT = tx.jjdwdm
        WHERE
            pcs.id = #{deptId} :: int8
    </select>

    <insert id="saveJl">
        INSERT INTO jdrh.mdjf_dj
        (id, jfmc, jflx, jfyy, jffssj, jffsdd, jyaq, jfdjsj, jfsssq, jfsspcs, jfssfj, sbzt, sbsj, sbdw, yjzt, yjsj, yjdw, fksj, fknr, fkr, fkdw, create_user, create_dept, create_time, update_user, update_time, status, is_deleted, djr, mdjb, zp, jfly, hfr, hfnr, hfsj, sfsc, sfmy, sfjj, wtjy, thjl, pj, pjly, pjsj, pjr, bz, zzdw, mdjb_v, xhfcs, yhfcs, hfzt_new, cszt, hfjzsj, cscs, hfjzsj2, hfjzsj3, csnr, dychf, dechf, dschf, bjrdh, fkdbh, jjdbh)
        VALUES(#{id},
        #{jfmc},
        #{jflx},
        #{jfyy},
        #{jffssj},
        #{jffsdd},
        #{jyaq},
        #{jfdjsj},
        #{jfsssq},
        #{jfsspcs},
        #{jfssfj},
        #{sbzt},
        #{sbsj},
        #{sbdw},
        #{yjzt},
        #{yjsj},
        #{yjdw},
        #{fksj},
        #{fknr},
        #{fkr},
        #{fkdw},
        #{createUser},
        #{createDept},
        #{createTime},
        #{updateUser},
        #{updateTime},
        #{status},
        #{isDeleted},
        #{djr},
        #{mdjb},
        #{zp},
        #{jfly},
        #{hfr},
        #{hfnr},
        #{hfsj},
        #{sfsc},
        #{sfmy},
        #{sfjj},
        #{wtjy},
        #{thjl},
        #{pj},
        #{pjly},
        #{pjsj},
        #{pjr},
        #{bz},
        #{zzdw},
        #{mdjbV},
        #{xhfcs},
        #{yhfcs},
        #{hfztNew},
        #{cszt},
        #{hfjzsj},
        #{cscs},
        #{hfjzsj2},
        #{hfjzsj3},
        #{csnr},
        #{dychf},
        #{dechf},
        #{dschf},
        #{bjrdh},
        #{fkdbh},
        #{jjdbh});
    </insert>
</mapper>
