<?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.tc.mapper.AssetCurrentMapper">
    <delete id="deleteIdList">
        DELETE FROM asset_current
        WHERE id =#{id}

    </delete>


    <select id="page" resultType="com.ruoyi.tc.entity.AssetCurrent">
        select a.*,c.dept_name as deptName,e.audit_state as auditState from asset_current a
        left join unit_info b on a.dwmc = b.nick_name
        left join sys_dept c on b.dept_id = c.dept_id
        left join (select * from asset_current_cp where task_id is null) e on a.id = e.id
        <where>
           a.del_flag = '0'
            <if test="req.xtmc!=null and req.xtmc!='' ">
                and a.xtmc like concat('%',#{req.xtmc},'%')
            </if>
            <if test="req.dwmc!=null and req.dwmc!='' ">
                and a.dwmc like concat('%',#{req.dwmc},'%')
            </if>
            <if test="req.xtlx!=null">
                and a.xtlx = #{req.xtlx}
            </if>
            <if test="req.xtzt!=null">
                and a.xtzt = #{req.xtzt}
            </if>
            <if test="req.startTime != null ">
                and a.create_time &gt;= #{req.startTime}
            </if>
            <if test="req.endTime != null">
                and a.create_time &lt;= #{req.endTime}
            </if>
            <if test="req.deptId != null">
                AND (b.dept_id = #{req.deptId} OR b.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE
                find_in_set(#{req.deptId}, ancestors) ))
            </if>
        </where>
        order by a.create_time desc
    </select>

    <select id="page1" resultType="com.ruoyi.tc.entity.AssetExport">
        SELECT
        a.*,
        b.*,
        c.*,
        d.*,
        e.*,
        l.*
        FROM
        asset_current a
        LEFT JOIN (
        SELECT
        asset_id,
        NAME,
        tyshxydm,
        lxr,
        lxdh,
        gyszcdz,
        sfwtc,
        ROW_NUMBER() OVER (PARTITION BY asset_id ORDER BY create_time) AS row_num
        FROM
        asset_supply_chain
        WHERE
        type = 5
        ) b ON a.id = b.asset_id AND b.row_num = 1
        LEFT JOIN (
        SELECT
        asset_id,
        NAME AS name1,
        tyshxydm AS tyshxydm1,
        lxr AS lxr1,
        lxdh AS lxdh1,
        gyszcdz AS gyszcdz1,
        sfwtc AS sfwtc1,
        ROW_NUMBER() OVER (PARTITION BY asset_id ORDER BY create_time) AS row_num
        FROM
        asset_supply_chain
        WHERE
        type = 7
        ) c ON a.id = c.asset_id AND c.row_num = 1
        LEFT JOIN (
        SELECT
        asset_id,
        sblx,
        pp,
        sb_ip AS sbIp,
        czxt,
        czxtbb,
        yjxh,
        yjxlh,
        yjbbxx,
        yjyt,
        yjbsxx,
        ROW_NUMBER() OVER (PARTITION BY asset_id ORDER BY create_time) AS row_num
        FROM
        asset_basic_network
        WHERE
        type = 1
        ) d ON a.id = d.asset_id AND d.row_num = 1
        LEFT JOIN (
        SELECT
        asset_id,
        sblx AS wlsblx,
        pp AS wlpp,
        sb_ip AS wlsbIp,
        yjxh AS wlyjxh,
        yjxlh AS wlyjxlh,
        yjbbxx AS wlyjbbxx,
        yjyt AS wlyjyt,
        yjbsxx AS wlyjbsxx,
        ROW_NUMBER() OVER (PARTITION BY asset_id ORDER BY create_time) AS row_num
        FROM
        asset_basic_network
        WHERE
        type = 2
        ) e ON a.id = e.asset_id AND e.row_num = 1
        LEFT JOIN (
        SELECT
        asset_id,
        sblx AS aqwlsblx,
        pp AS aqwlpp,
        sb_ip AS aqwlsbIp,
        yjxh AS aqyjxh,
        yjxlh AS aqyjxlh,
        yjbbxx AS aqyjbbxx,
        yjyt AS aqyjyt,
        yjbsxx AS aqyjbswz,
        ROW_NUMBER() OVER (PARTITION BY asset_id ORDER BY create_time) AS row_num
        FROM
        asset_basic_network
        WHERE
        type = 3
        ) l ON a.id = l.asset_id AND l.row_num = 1
        <where>
            a.del_flag = '0'
            <if test="req.xtmc!=null and req.xtmc!='' ">
                and a.xtmc like concat('%',#{req.xtmc},'%')
            </if>
            <if test="req.dwmc!=null and req.dwmc!='' ">
                and a.dwmc like concat('%',#{req.dwmc},'%')
            </if>
            <if test="req.xtlx!=null">
                and a.xtlx = #{req.xtlx}
            </if>
            <if test="req.xtzt!=null">
                and a.xtzt = #{req.xtzt}
            </if>
            <if test="req.startTime != null ">
                and a.create_time &gt;= #{req.startTime}
            </if>
            <if test="req.endTime != null">
                and a.create_time &lt;= #{req.endTime}
            </if>
        </where>
        order by create_time desc
    </select>
    <delete id="deleteByUnitIds">
        delete from  asset_current
        where id = #{id}
    </delete>
    <resultMap type="com.ruoyi.tc.entity.AssetCurrent" id="AssetCurrentMap">
        <result property="id" column="id"/>
        <result property="xtmc" column="xtmc"/>
        <result property="dwmc" column="dwmc"/>
        <result property="xtym" column="xtym"/>
        <result property="fwwz" column="fwwz"/>
        <result property="ipAddress" column="ip_address"/>
        <result property="ipPort" column="ip_port"/>
        <result property="ymdqsj" column="ymdqsj"/>
        <result property="ymtxrXm" column="ymtxr_xm"/>
        <result property="ymtxrLxfs" column="ymtxr_lxfs"/>
        <result property="glym" column="glym"/>
        <result property="glIp" column="gl_ip"/>
        <result property="xtlx" column="xtlx"/>
        <result property="xtzyx" column="xtzyx"/>
        <result property="gjxt" column="gjxt"/>
        <result property="xtbq" column="xtbq"/>
        <result property="jfxx" column="jfxx"/>
        <result property="sysj" column="sysj"/>
        <result property="hlwxt" column="hlwxt"/>
        <result property="xtbh" column="xtbh"/>
        <result property="xtzt" column="xtzt"/>
        <result property="zxzt" column="zxzt"/>
        <result property="cjmx" column="cjmx"/>
        <result property="iwzx" column="iwzx"/>
        <result property="akyx" column="akyx"/>
        <result property="chl" column="chl"/>
        <result property="sheng" column="sheng"/>
        <result property="shi" column="shi"/>
        <result property="qu" column="qu"/>
        <result property="jd" column="jd"/>
        <result property="wd" column="wd"/>
        <result property="xttz" column="xttz"/>
        <result property="yhgm" column="yhgm"/>
        <result property="hlwjryys" column="hlwjryys"/>
        <result property="zcwljrdz" column="zcwljrdz"/>
        <result property="bsypt" column="bsypt"/>
        <result property="yfwsmc" column="yfwsmc"/>
        <result property="wzfwxy" column="wzfwxy"/>
        <result property="xtbsfs" column="xtbsfs"/>
        <result property="tgdw" column="tgdw"/>
        <result property="yfws" column="yfws"/>
        <result property="dgzkf" column="dgzkf"/>
        <result property="hlwkfyt" column="hlwkfyt"/>
        <result property="xtfhqkFcg" column="xtfhqk_fcg"/>
        <result property="xtfhqkFxl" column="xtfhqk_fxl"/>
        <result property="xtfhqkFzd" column="xtfhqk_fzd"/>
        <result property="xtfhqkFls" column="xtfhqk_fls"/>
        <result property="xgywFgfw" column="xgyw_fgfw"/>
        <result property="xgywWlxz" column="xgyw_wlxz"/>
        <result property="xgywYwlx" column="xgyw_ywlx"/>
        <result property="xgywHlqk" column="xgyw_hlqk"/>
        <result property="xgywFwdx" column="xgyw_fwdx"/>
        <result property="xgywFwfw" column="xgyw_fwfw"/>
        <result property="xgywYwms" column="xgyw_ywms"/>
        <result property="fgfzrxm" column="fgfzrxm"/>
        <result property="fgfzrlxfs" column="fgfzrlxfs"/>
        <result property="fgfzryx" column="fgfzryx"/>
        <result property="bmfzrxm" column="bmfzrxm"/>
        <result property="bmfzrlxfs" column="bmfzrlxfs"/>
        <result property="bmfzryx" column="bmfzryx"/>
        <result property="dylxrxm" column="dylxrxm"/>
        <result property="dylxrlxfs" column="dylxrlxfs"/>
        <result property="dylxryx" column="dylxryx"/>
        <result property="ipcSfba" column="ipc_sfba"/>
        <result property="ipcBayxx" column="ipc_bayxx"/>
        <result property="ipcBawzmc" column="ipc_bawzmc"/>
        <result property="ipcBawzsy" column="ipc_bawzsy"/>
        <result property="ipcIpcbabh" column="ipc_ipcbabh"/>
        <result property="ipcBaym" column="ipc_baym"/>
        <result property="ipcBadwmc" column="ipc_badwmc"/>
        <result property="ipcBadwxz" column="ipc_badwxz"/>
        <result property="ipcBalxr" column="ipc_balxr"/>
        <result property="ipcBalxrdh" column="ipc_balxrdh"/>
        <result property="shsj" column="shsj"/>
        <result property="gajgSfba" column="gajg_sfba"/>
        <result property="gajgBajg" column="gajg_bajg"/>
        <result property="gajgBah" column="gajg_bah"/>
        <result property="gajgBarq" column="gajg_barq"/>
        <result property="xtjgKfs" column="xtjg_kfs"/>
        <result property="xtjgXtbb" column="xtjg_xtbb"/>
        <result property="xtjgJsjg" column="xtjg_jsjg"/>
        <result property="xtjgFwzj" column="xtjg_fwzj"/>
        <result property="xtjgWebMc" column="xtjg_web_mc"/>
        <result property="xtjgWebBb" column="xtjg_web_bb"/>
        <result property="xtjgGcxt" column="xtjg_gcxt"/>
        <result property="xtjgGcsb" column="xtjg_gcsb"/>
        <result property="xtjgGchl" column="xtjg_gchl"/>
        <result property="dbxxSfdbxt" column="dbxx_sfdbxt"/>
        <result property="dbxxDbcpbah" column="dbxx_dbcpbah"/>
        <result property="dbxxDbdj" column="dbxx_dbdj"/>
        <result property="dbxxZgbm" column="dbxx_zgbm"/>
        <result property="dbxxZjps" column="dbxx_zjps"/>
        <result property="dbxxZgbmps" column="dbxx_zgbmps"/>
        <result property="dbxxDjsj" column="dbxx_djsj"/>
        <result property="dbxxSfydsfcp" column="dbxx_sfydsfcp"/>
        <result property="dbxxCpdf" column="dbxx_cpdf"/>
        <result property="sfCpjgmc" column="sf_cpjgmc"/>
        <result property="sfCpjglxr" column="sf_cpjglxr"/>
        <result property="sfCpjgdz" column="sf_cpjgdz"/>
        <result property="sfCpjglxrdh" column="sf_cpjglxrdh"/>
        <result property="sfCpslxr" column="sf_cpslxr"/>
        <result property="sfCpsxm" column="sf_cpsxm"/>
        <result property="sfCpslxrdh" column="sf_cpslxrdh"/>
        <result property="sfCpsdh" column="sf_cpsdh"/>
        <result property="sfTjdbb" column="sf_tjdbb"/>
        <result property="sfCpszsdj" column="sf_cpszsdj"/>
        <result property="sfCpdj" column="sf_cpdj"/>
        <result property="sfTjrq" column="sf_tjrq"/>
        <result property="sfBgrq" column="sf_bgrq"/>
        <result property="sfCpjl" column="sf_cpjl"/>
        <result property="mpSfmpxt" column="mp_sfmpxt"/>
        <result property="mpMpdf" column="mp_mpdf"/>
        <result property="whoisYxx" column="whois_yxx"/>
        <result property="whoisZcm" column="whois_zcm"/>
        <result property="whoisFws" column="whois_fws"/>
        <result property="whoisZcyx" column="whois_zcyx"/>
        <result property="whoisZcgj" column="whois_zcgj"/>
        <result property="whoisZcs" column="whois_zcs"/>
        <result property="whoisZcdz" column="whois_zcdz"/>
        <result property="whoisZcjg" column="whois_zcjg"/>
        <result property="whoisZcsj" column="whois_zcsj"/>
        <result property="whoisZhgxsj" column="whois_zhgxsj"/>
        <result property="whoisDqsj" column="whois_dqsj"/>
        <result property="sjzcSjkmc" column="sjzc_sjkmc"/>
        <result property="sjzcSjklx" column="sjzc_sjklx"/>
        <result property="sjzcDk" column="sjzc_dk"/>
        <result property="sjzcSjkbb" column="sjzc_sjkbb"/>
        <result property="sjzcSjkIp" column="sjzc_sjk_ip"/>
        <result property="sjzcGxsx" column="sjzc_gxsx"/>
        <result property="sjzcKfsx" column="sjzc_kfsx"/>
        <result property="sjzcSjly" column="sjzc_sjly"/>
        <result property="sjzcGxzq" column="sjzc_gxzq"/>
        <result property="sjzcSjlx" column="sjzc_sjlx"/>
        <result property="sjzcSjl" column="sjzc_sjl"/>
        <result property="sjzcSmsj" column="sjzc_smsj"/>
        <result property="sjzcCj" column="sjzc_cj"/>
        <result property="sjzcSjfjfl" column="sjzc_sjfjfl"/>
        <result property="sjzcSjzycd" column="sjzc_sjzycd"/>
        <result property="sjzcSjms" column="sjzc_sjms"/>
        <result property="ywxttpt" column="ywxttpt"/>
        <result property="createId" column="create_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateId" column="update_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
        <result property="isbf" column="isbf"/>
        <result property="ywxttpwj" column="ywxttpwj"/>
        <result property="bfyy" column="bfyy"/>
        <association property="xjgywxt"  javaType="AssetBusinessForm" resultMap="AssetBusinessFormMap"/>

        <collection ofType="com.ruoyi.tc.entity.AssetBasicNetwork" property="jcwlList" javaType="java.util.List">
            <result property="id" column="id"/>
            <result property="assetId" column="asset_id"/>
            <result property="type" column="type"/>
            <result property="sblx" column="sblx"/>
            <result property="pp" column="pp"/>
            <result property="ipType" column="ip_type"/>
            <result property="sbIp" column="sb_ip"/>
            <result property="czxt" column="czxt"/>
            <result property="czxtbb" column="czxtbb"/>
            <result property="yjxh" column="yjxh"/>
            <result property="yjxlh" column="yjxlh"/>
            <result property="yjbbxx" column="yjbbxx"/>
            <result property="yjyt" column="yjyt"/>
            <result property="yjbsxx" column="yjbsxx"/>
            <result property="createId" column="create_id"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateId" column="update_id"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
            <result property="remark" column="remark"/>
            <result property="delFlag" column="del_flag"/>
        </collection>
        <collection ofType="com.ruoyi.tc.entity.AssetSupplyChain" property="gylxxList" javaType="java.util.List">
            <result property="id" column="id"/>
            <result property="assetId" column="asset_id"/>
            <result property="type" column="type"/>
            <result property="name" column="name"/>
            <result property="tyshxydm" column="tyshxydm"/>
            <result property="lxr" column="lxr"/>
            <result property="lxdh" column="lxdh"/>
            <result property="gyszcdz" column="gyszcdz"/>
            <result property="sfwtc" column="sfwtc"/>
            <result property="createId" column="create_id"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateId" column="update_id"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
            <result property="remark" column="remark"/>
            <result property="delFlag" column="del_flag"/>
        </collection>
        <collection ofType="com.ruoyi.tc.entity.UnitOtherConcat" property="otherConcat" javaType="java.util.List">
            <result property="concatId" column="concat_id"/>
            <result property="unitId" column="unit_id"/>
            <result property="assetId" column="asset_id"/>
            <result property="qtlxrxm" column="qtlxrxm"/>
            <result property="qtlxrlxfs" column="qtlxrlxfs"/>
            <result property="qtlxryx" column="qtlxryx"/>
            <result property="qtlxrzwzc" column="qtlxrzwzc"/>
            <result property="createId" column="create_id"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateId" column="update_id"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
            <result property="remark" column="remark"/>
            <result property="delFlag" column="del_flag"/>
        </collection>
    </resultMap>

    <resultMap type="com.ruoyi.tc.entity.AssetBusinessForm" id="AssetBusinessFormMap">
        <result property="assetId" column="asset_id"/>
        <result property="yptFws" column="ypt_fws"/>
        <result property="yptSfzh" column="ypt_sfzh"/>
        <result property="yptLx" column="ypt_lx"/>
        <result property="yptYjzydx" column="ypt_yjzydx"/>
        <result property="yptPtjg" column="ypt_ptjg"/>
        <result property="yptIp" column="ypt_ip"/>
        <result property="yptJflxr" column="ypt_jflxr"/>
        <result property="yptJflxrdh" column="ypt_jflxrdh"/>
        <result property="yptFwqsblx" column="ypt_fwqsblx"/>
        <result property="dsjPtfws" column="dsj_ptfws"/>
        <result property="dsjMgsjlx" column="dsj_mgsjlx"/>
        <result property="dsjYjzy" column="dsj_yjzy"/>
        <result property="dsjXtsjl" column="dsj_xtsjl"/>
        <result property="dsjJflxr" column="dsj_jflxr"/>
        <result property="dsjJflxrdh" column="dsj_jflxrdh"/>
        <result property="dsjSfsjsj" column="dsj_sfsjsj"/>
        <result property="wlwsbXtjcs" column="wlwsb_xtjcs"/>
        <result property="wlwsbYhsl" column="wlwsb_yhsl"/>
        <result property="wlwsbFwdx" column="wlwsb_fwdx"/>
        <result property="wlwsbZdsl" column="wlwsb_zdsl"/>
        <result property="wlwsbWlhlqk" column="wlwsb_wlhlqk"/>
        <result property="wlwsbLxr" column="wlwsb_lxr"/>
        <result property="wlwsbFwfw" column="wlwsb_fwfw"/>
        <result property="wlwsbLxrdh" column="wlwsb_lxrdh"/>
        <result property="wlwsbFwnr" column="wlwsb_fwnr"/>
        <result property="sxtPp" column="sxt_pp"/>
        <result property="sxtWz" column="sxt_wz"/>
        <result property="sxtIp" column="sxt_ip"/>
        <result property="sxtQy" column="sxt_qy"/>
        <result property="sxtSl" column="sxt_sl"/>
        <result property="sxtDk" column="sxt_dk"/>
        <result property="sxtSbxh" column="sxt_sbxh"/>
        <result property="sxtGdbb" column="sxt_gdbb"/>
        <result property="appXt" column="app_xt"/>
        <result property="appYm" column="app_ym"/>
        <result property="appQd" column="app_qd"/>
        <result property="appIp" column="app_ip"/>
        <result property="appLxr" column="app_lxr"/>
        <result property="appLxrdh" column="app_lxrdh"/>
        <result property="appSfysfrz" column="app_sfysfrz"/>
        <result property="gykzJcs" column="gykz_jcs"/>
        <result property="gykzYxsj" column="gykz_yxsj"/>
        <result property="gykzFwdx" column="gykz_fwdx"/>
        <result property="gykzJcsqk" column="gykz_jcsqk"/>
        <result property="gykzWlhxqk" column="gykz_wlhxqk"/>
        <result property="gykzLxr" column="gykz_lxr"/>
        <result property="gykzFwfw" column="gykz_fwfw"/>
        <result property="gykzLxrdh" column="gykz_lxrdh"/>
        <result property="gykzSbmc" column="gykz_sbmc"/>
        <result property="gykzSbpp" column="gykz_sbpp"/>
        <result property="gykzSblb" column="gykz_sblb"/>
        <result property="gykzYys" column="gykz_yys"/>
        <result property="gykzHlwIp" column="gykz_hlw_ip"/>
        <result property="gykzWlcj" column="gykz_wlcj"/>
        <result property="gykzKztIp" column="gykz_kzt_ip"/>
        <result property="gykzMs" column="gykz_ms"/>
        <result property="cdnGys" column="cdn_gys"/>
        <result property="cdnSfsy" column="cdn_sfsy"/>
        <result property="cdnLx" column="cdn_lx"/>
        <result property="cdnYm" column="cdn_ym"/>
        <result property="cdnLxr" column="cdn_lxr"/>
        <result property="cdnLxrdh" column="cdn_lxrdh"/>
        <result property="cdnJsxx" column="cdn_jsxx"/>
    </resultMap>
    <select id="selectAllAsset" resultMap="AssetCurrentMap">
        select a.*,b.*,c.*,d.*,e.* from asset_current  as a
        left join asset_business_form b on a.id = b.asset_id
        left join asset_basic_network c on a.id = c.asset_id
        left join asset_supply_chain d on a.id = d.asset_id
        left join unit_other_contact e on a.id = e.asset_id
        <where>
            a.del_flag = '0'
            <if test="req.xtmc!=null and req.xtmc!='' ">
                and a.xtmc like concat('%',#{req.xtmc},'%')
            </if>
            <if test="req.dwmc!=null and req.dwmc!='' ">
                and a.dwmc like concat('%',#{req.dwmc},'%')
            </if>
            <if test="req.xtlx!=null">
                and a.xtlx = #{req.xtlx}
            </if>
            <if test="req.xtzt!=null">
                and a.xtzt = #{req.xtzt}
            </if>
            <if test="req.startTime != null ">
                and a.update_time &gt;= #{req.startTime}
            </if>
            <if test="req.endTime != null">
                and a.update_time &lt;= #{req.endTime}
            </if>
        </where>
        order by a.create_time
    </select>
    <select id="findBydwmc" resultType="java.lang.Integer" parameterType="java.lang.String">

        select count(*)
        from asset_current
        where dwmc = #{part} and del_flag=0
    </select>
</mapper>