<?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.bonus.sgzb.base.mapper.BmProjectLotMapper">
    
    <resultMap type="com.bonus.sgzb.base.domain.BmProjectLot" id="BmProjectLotResult">
        <id     property="lotId"      column="lot_id"      />
    	<result property="proId"      column="pro_id"      />
        <result property="lotName"    column="lot_name"    />
        <result property="status"     column="status"     />
        <result property="typeId"     column="type_id"   />
        <result property="linkMan"    column="link_man"    />
        <result property="telphone"   column="telphone"      />
        <result property="ownPro"     column="own_pro"      />
        <result property="deptId"     column="dept_id"    />
        <result property="isShare"    column="is_share"    />
        <result property="lon"        column="lon"    />
        <result property="lat"        column="lat"    />
        <result property="delFlag"    column="del_flag"      />
        <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"    />
        <result property="companyId"  column="company_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="typeName"    column="name"    />
        <result property="costIndicators"    column="cost_indicators"    />
        <result property="detailsAddress"    column="details_address"    />
        <result property="province"    column="province"    />
        <result property="address"    column="address"    />
        <result property="latitude"    column="latitude"    />
        <result property="longitude"    column="longitude"    />
        <result property="startDate"    column="start_date"    />
        <result property="completionDate"    column="completion_date"    />
    </resultMap>

    <sql id="bmProjectInfo">
        select lot_id, pro_id, lot_name, status, type_id, link_man, telphone, own_pro, dept_id, is_share,
               lon, lat, del_flag, create_by,create_time,remark,company_id
		from bm_project_lot
    </sql>

    <select id="getProjectLotAll"  parameterType="com.bonus.sgzb.base.domain.BmProjectLot" resultMap="BmProjectLotResult">
        <!--<include refid="bmProjectInfo"/>-->
        select a.lot_id, a.pro_id, a.lot_name, a.status, a.type_id, a.link_man, a.telphone, a.own_pro, a.dept_id, a.is_share,
        a.lon, a.lat, a.del_flag, a.create_by, a.create_time,a.remark,a.company_id ,b.dept_name, c.name,a.cost_indicators,
        a.longitude, a.latitude, a.address, a.province,a.details_address,a.completion_date,a.start_date
        from bm_project_lot a
        left join sys_dept b on a.dept_id = b.dept_id
        left join sys_dic c on a.type_id = c.id
        where a.del_flag ='0'
        <if test="lotId != null and lotId != ''">
            AND lot_id = #{lotId}
        </if>
        <if test="lotName != null and lotName != ''">
            AND lot_name like concat('%', #{lotName}, '%')
        </if>
        <if test="status != null and status != ''">
            AND status = #{status}
        </if>
        <if test="typeId != null and typeId != ''">
            AND type_id = #{typeId}
        </if>
        <if test="linkMan != null and linkMan != ''">
            and link_man = #{linkMan}
        </if>
        <if test="telphone != null and telphone != ''">
            and telphone = #{telphone}
        </if>
        <if test="deptId != null and deptId != ''">
            and dept_id = #{deptId}
        </if>
        <if test="delFlag != null and delFlag != ''">
            and del_flag = #{delFlag}
        </if>
        <if test="createBy != null and createBy != ''">
            and create_by = #{createBy}
        </if>
        <if test="createTime != null and createTime != ''">
            and create_time = #{createTime}
        </if>
        <if test="updateBy != null and updateBy != ''">
            and update_by = #{updateBy}
        </if>
        <if test="updateTime != null and updateTime != ''">
            and update_time = #{updateTime}
        </if>
        <if test="remark != null and remark != ''">
            and remark = #{remark}
        </if>
        <if test="companyId != null and companyId != ''">
            and company_id = #{companyId}
        </if>
        <if test="dataCondition != null and dataCondition.size()>0">
            AND a.lot_id in
            <foreach collection="dataCondition" item="lotId" index="index" open="(" separator="," close=")">
                #{lotId}
            </foreach>
        </if>
        ORDER BY a.lot_id DESC
    </select>
    <select id="selectByName" resultType="com.bonus.sgzb.base.domain.BmProjectLot">
        select * from bm_project_lot
        where
        del_flag = '0' and status = '0'
        <if test="lotName != null and lotName != ''">and lot_name = #{lotName}</if>
    </select>

    <insert id="projectLotAdd" parameterType="com.bonus.sgzb.base.domain.BmProjectLot">
        insert into bm_project_lot (
			<if test="lotName != null and lotName != '' ">lot_name,</if>
            <if test="proId != null and proId != '' ">pro_id,</if>
			<if test="status != null and status != '' ">status,</if>
			<if test="typeId != null and typeId != '' ">type_id,</if>
            <if test="ownPro != null and ownPro != '' ">own_pro,</if>
			<if test="linkMan != null and linkMan != '' ">link_man,</if>
			<if test="telphone != null and telphone != ''">telphone,</if>
			<if test="deptId != null and deptId != ''">dept_id,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null and updateTime != ''">update_time,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="companyId != null and companyId != ''">company_id,</if>
            <if test="costIndicators != null and costIndicators != ''">cost_indicators,</if>
            <if test="startDate != null and startDate != ''">start_date,</if>
            <if test="completionDate != null and completionDate != ''">completion_date,</if>
            <if test="longitude != null and longitude != ''">longitude,</if>
            <if test="latitude != null and latitude != ''">latitude,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="province != null and province != ''">province,</if>
            <if test="detailsAddress != null and detailsAddress != ''">details_address,</if>
            create_time
        )values(
			<if test="lotName != null and lotName != ''">#{lotName},</if>
            <if test="proId != null and proId != '' ">#{proId},</if>
			<if test="status != null and status != ''">#{status},</if>
			<if test="typeId != null and typeId != ''">#{typeId},</if>
            <if test="ownPro != null and ownPro != '' ">#{ownPro},</if>
			<if test="linkMan != null and linkMan != ''">#{linkMan},</if>
			<if test="telphone != null and telphone != ''">#{telphone},</if>
			<if test="deptId != null and deptId != ''">#{deptId},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="companyId != null and companyId != ''">#{companyId},</if>
            <if test="costIndicators != null and costIndicators != ''">#{costIndicators},</if>
            <if test="startDate != null and startDate != ''">#{startDate},</if>
            <if test="completionDate != null and completionDate != ''">#{completionDate},</if>
            <if test="longitude != null and longitude != ''">#{longitude},</if>
            <if test="latitude != null and latitude != ''">#{latitude},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="province != null and province != ''">#{province},</if>
            <if test="detailsAddress != null and detailsAddress != ''">#{detailsAddress},</if>
            sysdate()
		)
    </insert>

    <insert id="projectLotImport">
        insert into bm_project_lot (
        <if test="examineStatus != null and examineStatus != '' ">examine_status,</if>
        <if test="createTime != null and createTime != '' ">create_time,</if>
        <if test="projectCategory != null and projectCategory != '' ">project_category,</if>
        <if test="lotName != null and lotName != '' ">lot_name,</if>
        <if test="lotCode != null and lotCode != '' ">lot_code,</if>
        <if test="isFrameworkProject != null and isFrameworkProject != '' ">is_framework_project,</if>
        <if test="isSubProject != null and isSubProject != ''">is_sub_project,</if>
        <if test="ownPro != null and ownPro != ''">own_pro,</if>
        <if test="ownProId != null and ownProId != ''">own_pro_Id,</if>
        <if test="projectStatus != null and projectStatus != ''">project_status,</if>
        <if test="businessSource != null and businessSource != ''">business_source,</if>
        <if test="voltageLevel != null and voltageLevel != ''">voltage_level,</if>
        <if test="linkMan != null and linkMan != ''">link_man,</if>
        <if test="constructionUnit != null and constructionUnit != ''">construction_unit,</if>
        <if test="implementationUnit != null and implementationUnit != ''">implementation_unit,</if>
        <if test="department != null and department != ''">department,</if>
        <if test="creatorCompany != null and creatorCompany != ''">creator_company,</if>
        <if test="designUnit != null and designUnit != ''">design_unit,</if>
        <if test="constructionControlUnit != null and constructionControlUnit != ''">construction_control_unit,</if>
        <if test="plannedStartDate != null and plannedStartDate != ''">planned_start_date,</if>
        <if test="plannedCompletionDate != null and plannedCompletionDate != ''">planned_completion_date,</if>
        <if test="projectCategoryId != null and projectCategoryId != ''">project_category_id,</if>
        <if test="constructionUnitId != null and constructionUnitId != ''">construction_unit_id,</if>
        <if test="implementationUnitId != null and implementationUnitId != ''">implementation_unit_id,</if>
        <if test="designUnitId != null and designUnitId != ''">design_unit_id,</if>
        <if test="constructionControlUnitId != null and constructionControlUnitId != ''">construction_control_unit_id,</if>
        <if test="projectLocation != null and projectLocation != ''">project_location,</if>
        <if test="projectLocationProvince != null and projectLocationProvince != ''">project_location_province,</if>
        <if test="projectLocationCity != null and projectLocationCity != ''">project_location_city,</if>
        <if test="endTime != null and endTime != ''">end_time,</if>
        <if test="constructionUnitType != null and constructionUnitType != ''">construction_unit_type,</if>
        <if test="constructionUnitCode != null and constructionUnitCode != ''">construction_unit_code</if>

        ) VALUES (
        <if test="examineStatus != null and examineStatus != '' ">#{examineStatus},</if>
        <if test="createTime != null and createTime != '' ">#{createTime},</if>
        <if test="projectCategory != null and projectCategory != '' ">#{projectCategory},</if>
        <if test="lotName != null and lotName != '' ">#{lotName},</if>
        <if test="lotCode != null and lotCode != '' ">#{lotCode},</if>
        <if test="isFrameworkProject != null and isFrameworkProject != '' ">#{isFrameworkProject},</if>
        <if test="isSubProject != null and isSubProject != ''">#{isSubProject},</if>
        <if test="ownPro != null and ownPro != ''">#{ownPro},</if>
        <if test="ownProId != null and ownProId != ''">#{ownProId},</if>
        <if test="projectStatus != null and projectStatus != ''">#{projectStatus},</if>
        <if test="businessSource != null and businessSource != ''">#{businessSource},</if>
        <if test="voltageLevel != null and voltageLevel != ''">#{voltageLevel},</if>
        <if test="linkMan != null and linkMan != ''">#{linkMan},</if>
        <if test="constructionUnit != null and constructionUnit != ''">#{constructionUnit},</if>
        <if test="implementationUnit != null and implementationUnit != ''">#{implementationUnit},</if>
        <if test="department != null and department != ''">#{department},</if>
        <if test="creatorCompany != null and creatorCompany != ''">#{creatorCompany},</if>
        <if test="designUnit != null and designUnit != ''">#{designUnit},</if>
        <if test="constructionControlUnit != null and constructionControlUnit != ''">#{constructionControlUnit},</if>
        <if test="plannedStartDate != null and plannedStartDate != ''">#{plannedStartDate},</if>
        <if test="plannedCompletionDate != null and plannedCompletionDate != ''">#{plannedCompletionDate},</if>
        <if test="projectCategoryId != null and projectCategoryId != ''">#{projectCategoryId},</if>
        <if test="constructionUnitId != null and constructionUnitId != ''">#{constructionUnitId},</if>
        <if test="implementationUnitId != null and implementationUnitId != ''">#{implementationUnitId},</if>
        <if test="designUnitId != null and designUnitId != ''">#{designUnitId},</if>
        <if test="constructionControlUnitId != null and constructionControlUnitId != ''">#{constructionControlUnitId},</if>
        <if test="projectLocation != null and projectLocation != ''">#{projectLocation},</if>
        <if test="projectLocationProvince != null and projectLocationProvince != ''">#{projectLocationProvince},</if>
        <if test="projectLocationCity != null and projectLocationCity != ''">#{projectLocationCity},</if>
        <if test="endTime != null and endTime != ''">#{endTime},</if>
        <if test="constructionUnitType != null and constructionUnitType != ''">#{constructionUnitType},</if>
        <if test="constructionUnitCode != null and constructionUnitCode != ''">#{constructionUnitCode}</if>

        )
    </insert>
	 
    <update id="updateBmProjectLot" parameterType="com.bonus.sgzb.base.domain.BmProjectLot">
        update bm_project_lot
        <set>
            <if test="lotName != null and lotName != ''">lot_name = #{lotName},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="typeId != null and typeId != ''">type_id = #{typeId},</if>
            <if test="ownPro != null and ownPro != '' ">own_pro = #{ownPro},</if>
            <if test="linkMan != null and linkMan != ''">link_man = #{linkMan},</if>
            <if test="telphone != null and telphone != ''">telphone = #{telphone},</if>
            <if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null and createBy != ''">create_by =#{createBy},</if>
            <if test="updateBy != null and updateBy != ''">update_by =#{updateBy},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="companyId != null and companyId != ''">company_id = #{companyId},</if>
            <if test="costIndicators != null and costIndicators != ''">cost_indicators = #{costIndicators},</if>
            <if test="longitude != null and longitude != ''">longitude = #{longitude},</if>
            <if test="latitude != null and latitude != ''">latitude = #{latitude},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="province != null and province != ''">province = #{province},</if>
            <if test="detailsAddress != null and detailsAddress != ''">details_address  = #{detailsAddress} ,</if>
            <if test="completionDate != null and completionDate != ''">completion_date = #{completionDate},</if>
            <if test="startDate != null and startDate != ''">start_date  = #{startDate} ,</if>
            update_time = sysdate()
        </set>
        where lot_id = #{lotId}
    </update>
	
    <delete id="deleteProjectLotById" parameterType="Long">
        update bm_project_lot set del_flag = '2'
        where lot_id = #{lotId}
    </delete>
    
    <delete id="remove" parameterType="Long">
        delete from bm_project_lot where loc_id in
        <foreach item="proId" collection="array" open="(" separator="," close=")">
        	#{lotId}
        </foreach>
    </delete>
    
</mapper>