<?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.gysl.mapper.BasicInformationMapper">

    <resultMap id="ProjectExcelInfoResult" type="com.ruoyi.gysl.entity.response.ProjectExcelInfo">
        <result property="name" column="name"/>
        <result property="xmfrdwxz" column="xmfrdwxz"/>
        <result property="nature" column="nature"/>

        <result property="xzfl" column="xzfl"/>
        <result property="begainTime" column="begain_time"/>
        <result property="endTime" column="end_time"/>
        <result property="jhtze" column="jhtze"/>

        <result property="zydmj" column="zydmj"/>
        <result property="rjl" column="rjl"/>
        <result property="zjzmj" column="zjzmj"/>
        <result property="bzcjzmj" column="bzcjzmj"/>

        <result property="prioritize" column="prioritize"/>
        <result property="projectLeader" column="project_leader"/>
        <result property="phone" column="phone"/>
        <result property="jsjd" column="jsjd"/>
        <result property="jsms" column="jsms"/>

    </resultMap>
    <insert id="insert1" parameterType="BasicInformation">
        insert into copy_gysl_basic_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="xmfrdwxz != null">xmfrdwxz,</if>
            <if test="nature != null">nature,</if>
            <if test="sgdw != null">sgdw,</if>
            <if test="ztze != null">ztze,</if>
            <if test="ssgnq != null">ssgnq,</if>
            <if test="begainTime != null">begain_time,</if>
            <if test="xzfl != null">xzfl,</if>
            <if test="jsdd != null">jsdd,</if>
            <if test="prioritize != null">prioritize,</if>
            <if test="jsms != null">jsms,</if>
            <if test="label != null">label,</if>
            <if test="projectLeader != null">project_leader,</if>
            <if test="phone != null">phone,</if>
            <if test="issuingTime != null">Issuing_time,</if>
            <if test="acceptanceTime != null">acceptance_time,</if>
            <if test="unitIntroduction != null">unit_introduction,</if>
            <if test="introduction != null">introduction,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="sjdw != null">sjdw,</if>
            <if test="fj != null">fj,</if>
            <if test="endTime != null">end_time,</if>
            <if test="jsjd != null">jsjd,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="tyshxydm != null">tyshxydm,</if>
            <if test="status != null">status,</if>
            <if test="isFmqd != null">is_fmqd,</if>
            <if test="jhtze != null">jhtze,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="xmfrdwxz != null">#{xmfrdwxz},</if>
            <if test="nature != null">#{nature},</if>
            <if test="sgdw != null">#{sgdw},</if>
            <if test="ztze != null">#{ztze},</if>
            <if test="ssgnq != null">#{ssgnq},</if>
            <if test="begainTime != null">#{begainTime},</if>
            <if test="xzfl != null">#{xzfl},</if>
            <if test="jsdd != null">#{jsdd},</if>
            <if test="prioritize != null">#{prioritize},</if>
            <if test="jsms != null">#{jsms},</if>
            <if test="label != null">#{label},</if>
            <if test="projectLeader != null">#{projectLeader},</if>
            <if test="phone != null">#{phone},</if>
            <if test="issuingTime != null">#{issuingTime},</if>
            <if test="acceptanceTime != null">#{acceptanceTime},</if>
            <if test="unitIntroduction != null">#{unitIntroduction},</if>
            <if test="introduction != null">#{introduction},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="sjdw != null">#{sjdw},</if>
            <if test="fj != null">#{fj},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="jsjd != null">#{jsjd},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="tyshxydm != null">#{tyshxydm},</if>
            <if test="status != null">#{status},</if>
            <if test="isFmqd != null">#{isFmqd},</if>
            <if test="jhtze != null">#{jhtze},</if>
        </trim>
    </insert>
    <insert id="insert2" parameterType="PlanInformation">
        insert into copy_gysl_plan_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="xmId != null">xm_id,</if>
            <if test="zydmj != null">zydmj,</if>
            <if test="rjl != null">rjl,</if>
            <if test="zjzmj != null">zjzmj,</if>
            <if test="bzcjzmj != null">bzcjzmj,</if>
            <if test="jrjljzmj != null">jrjljzmj,</if>
            <if test="jzmd != null">jzmd,</if>
            <if test="ldl != null">ldl,</if>
            <if test="jzds != null">jzds,</if>
            <if test="dsjzmj != null">dsjzmj,</if>
            <if test="dxjzmj != null">dxjzmj,</if>
            <if test="zgjzcs != null">zgjzcs,</if>
            <if test="zgjzgd != null">zgjzgd,</if>
            <if test="jdctcw != null">jdctcw,</if>
            <if test="fjdctcw != null">fjdctcw,</if>
            <if test="ghwj != null">ghwj,</if>
            <if test="fhdj != null">fhdj,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="xmId != null">#{xmId},</if>
            <if test="zydmj != null">#{zydmj},</if>
            <if test="rjl != null">#{rjl},</if>
            <if test="zjzmj != null">#{zjzmj},</if>
            <if test="bzcjzmj != null">#{bzcjzmj},</if>
            <if test="jrjljzmj != null">#{jrjljzmj},</if>
            <if test="jzmd != null">#{jzmd},</if>
            <if test="ldl != null">#{ldl},</if>
            <if test="jzds != null">#{jzds},</if>
            <if test="dsjzmj != null">#{dsjzmj},</if>
            <if test="dxjzmj != null">#{dxjzmj},</if>
            <if test="zgjzcs != null">#{zgjzcs},</if>
            <if test="zgjzgd != null">#{zgjzgd},</if>
            <if test="jdctcw != null">#{jdctcw},</if>
            <if test="fjdctcw != null">#{fjdctcw},</if>
            <if test="ghwj != null">#{ghwj},</if>
            <if test="fhdj != null">#{fhdj},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <insert id="insert3" parameterType="WysmxInformation">
        insert into copy_gysl_wysmx_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="xmId != null">xm_id,</if>
            <if test="ysmc != null">ysmc,</if>
            <if test="zdname != null">zdname,</if>
            <if test="zdinfor != null">zdinfor,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="xmId != null">#{xmId},</if>
            <if test="ysmc != null">#{ysmc},</if>
            <if test="zdname != null">#{zdname},</if>
            <if test="zdinfor != null">#{zdinfor},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <insert id="insert4" parameterType="QyrzInformation">
        insert into copy_gysl_qyrz_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="xmId != null">xm_id,</if>
            <if test="rzqys != null">rzqys,</if>
            <if test="rzqyhylx != null">rzqyhylx,</if>
            <if test="rysl != null">rysl,</if>
            <if test="rzl != null">rzl,</if>
            <if test="yczmj != null">yczmj,</if>
            <if test="kzczmj != null">kzczmj,</if>
            <if test="gycfpjzj != null">gycfpjzj,</if>
            <if test="gycfpjwyf != null">gycfpjwyf,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="xmId != null">#{xmId},</if>
            <if test="rzqys != null">#{rzqys},</if>
            <if test="rzqyhylx != null">#{rzqyhylx},</if>
            <if test="rysl != null">#{rysl},</if>
            <if test="rzl != null">#{rzl},</if>
            <if test="yczmj != null">#{yczmj},</if>
            <if test="kzczmj != null">#{kzczmj},</if>
            <if test="gycfpjzj != null">#{gycfpjzj},</if>
            <if test="gycfpjwyf != null">#{gycfpjwyf},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <insert id="insert5" parameterType="ProjectOtherInfo">
        insert into copy_gysl_project_other_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="xmId != null">xm_id,</if>
            <if test="zdname != null">zdname,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="zdinfor != null">zdinfor,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="xmId != null">#{xmId},</if>
            <if test="zdname != null">#{zdname},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="zdinfor != null">#{zdinfor},</if>
        </trim>
    </insert>
    <delete id="delete1">
        delete from copy_gysl_basic_information where id = #{id}
    </delete>
    <delete id="delete2">
        delete from copy_gysl_plan_information
        where xm_id = #{id}
    </delete>
    <delete id="delete3">
        delete
        from copy_gysl_wysmx_information
        where xm_id = #{id}
    </delete>
    <delete id="delete4">
        delete
        from copy_gysl_qyrz_information
        where xm_id = #{id}
    </delete>
    <delete id="delete5">
        delete from copy_gysl_project_other_info
        where xm_id = #{id}
    </delete>
    <select id="select1" resultType="com.ruoyi.gysl.entity.BasicInformation">
        select * from copy_gysl_basic_information where id =#{id}
    </select>
    <select id="select2" resultType="com.ruoyi.gysl.entity.PlanInformation">
        select * from copy_gysl_plan_information where xm_id =#{id}
    </select>
    <select id="select3" resultType="com.ruoyi.gysl.entity.WysmxInformation">
        select * from copy_gysl_wysmx_information where xm_id =#{id}
    </select>
    <select id="select4" resultType="com.ruoyi.gysl.entity.QyrzInformation">
        select * from copy_gysl_qyrz_information where xm_id =#{id}
    </select>
    <select id="select5" resultType="com.ruoyi.gysl.entity.ProjectOtherInfo">
        select * from copy_gysl_project_other_info where xm_id =#{id}
    </select>
    <select id="selectProjectList" resultMap="ProjectExcelInfoResult">
        SELECT
        a.xmfrdwxz,
        a.nature,
        a.name,
        a.xzfl,
        a.begain_time,
        a.end_time,
        a.jhtze,
        a.project_leader,
        a.phone,
        a.jsjd,
        a.jsms,
        b.zydmj,
        b.rjl,
        b.zjzmj,
        b.bzcjzmj,
        a.prioritize
        FROM
        gysl_basic_information a
        LEFT JOIN gysl_plan_information b ON a.id = b.xm_id
    </select>
    <select id="page" resultType="com.ruoyi.gysl.entity.BasicInformation">
        SELECT a.*,b.zydmj
        FROM gysl_basic_information a left join gysl_plan_information b on a.id = b.xm_id
        <where>
            <if test="req.name != null and req.name != ''">
                AND a.name like concat('%',#{req.name},'%')
            </if>
            <if test="req.xmfrdwxz != null and req.xmfrdwxz != ''">
                AND a.xmfrdwxz like concat('%',#{req.xmfrdwxz},'%')
            </if>
            <if test="req.xzfl != null and req.xzfl != ''">
                AND a.xzfl = #{req.xzfl}
            </if>
            <if test="req.startTime != null">
                AND a.begain_time &gt;= #{req.startTime}  <!-- 大于等于 -->
            </if>
            <if test="req.endTime != null">
                AND a.begain_time &lt;= #{req.endTime}     <!-- 小于等于 -->
            </if>
            <if test="req.tyshxydm != null and req.tyshxydm!=''">
                AND a.tyshxydm = #{req.tyshxydm}
            </if>
            <if test="req.isFmqd != null">
                AND a.is_fmqd = #{req.isFmqd}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="projectList" resultType="com.ruoyi.gysl.entity.BasicInformation">
        SELECT a.*,
            ROUND( IFNULL( SUM( b.zjzmj ), 0 ) / 10000, 2 ) AS zjzmj
        FROM gysl_basic_information a left join gysl_plan_information b on a.id = b.xm_id
        where a.longitude is not null and a.latitude is not null
    </select>

    <resultMap type="com.ruoyi.gysl.entity.response.BasicInformationResponse" id="BasicInformationResponseMap">
        <association property="basicInformation"  javaType="BasicInformation" resultMap="BasicInfor"/>
        <association property="qyrzInformation"  javaType="QyrzInformation" resultMap="QyrzInfor"/>
        <association property="planInformation"  javaType="PlanInformation" resultMap="PlanInfor"/>
        <collection ofType="com.ruoyi.gysl.entity.BuildingInformation" property="buildingInformation" javaType="java.util.List">
            <result property="id" column="id"/>
        </collection>
    </resultMap>
    <resultMap type="com.ruoyi.gysl.entity.BasicInformation" id="BasicInfor">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="ztze" column="ztze"/>
        <result property="label" column="label"/>
        <result property="xzfl" column="xzfl"/>
        <result property="prioritize" column="prioritize"/>
        <result property="ssgnq" column="ssgnq"/>
        <result property="jsms" column="jsms"/>
    </resultMap>
    <resultMap type="com.ruoyi.gysl.entity.PlanInformation" id="PlanInfor">
        <result property="id" column="id"/>
        <result property="zjzmj" column="zjzmj"/>
        <result property="zydmj" column="zydmj"/>
        <result property="bzcjzmj" column="bzcjzmj"/>
        <result property="zgjzgd" column="zgjzgd"/>
        <result property="jzds" column="jzds"/>
        <result property="zgjzcs" column="zgjzcs"/>
        <result property="fhdj" column="fhdj"/>
        <result property="jdctcw" column="jdctcw"/>
        <result property="fjdctcw" column="fjdctcw"/>
    </resultMap>
    <resultMap type="com.ruoyi.gysl.entity.QyrzInformation" id="QyrzInfor">
        <result property="id" column="id"/>
        <result property="yczmj" column="yczmj"/>
        <result property="kzczmj" column="kzczmj"/>
        <result property="gycfpjzj" column="gycfpjzj"/>
        <result property="gycfpjwyf" column="gycfpjwyf"/>
    </resultMap>

    <select id="idListToProject" resultMap="BasicInformationResponseMap">
        SELECT a.*,b.*,
               c.*
        FROM gysl_basic_information a
            left join gysl_plan_information b on a.id = b.xm_id
            left join gysl_building_information c on a.id = c.xm_id
        <where>
            <if test="idList != null">
                and a.id in
                <foreach collection="idList" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by a.create_time desc
    </select>


</mapper>