<?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.project.business.mapper.TcProjectHistoryMapper">
    
    <resultMap type="TcProjectHistory" id="TcProjectHistoryResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNo"    column="project_no"    />
        <result property="projectName"    column="project_name"    />
        <result property="accountId"    column="account_id"    />
        <result property="address"    column="address"    />
        <result property="modelFlag"    column="model_flag"    />
        <result property="type"    column="type"    />
        <result property="segmentedMarket"    column="segmented_market"    />
        <result property="countryId"    column="country_id"    />
        <result property="city"    column="city"    />
        <result property="progress"    column="progress"    />
        <result property="developer"    column="developer"    />
        <result property="planDealMonth"    column="plan_deal_month"    />
        <result property="completionYear"    column="completion_year"    />
        <result property="startTime"    column="start_time"    />
        <result property="overTime"    column="over_time"    />
        <result property="currencyId"    column="currency_id"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="contact"    column="contact"    />
        <result property="jobTitle"    column="job_title"    />
        <result property="email"    column="email"    />
        <result property="status"    column="status"    />
        <result property="productSeries"    column="product_series"    />
        <result property="solution"    column="solution"    />
        <result property="owner"    column="owner"    />
        <result property="ownerAgent"    column="owner_agent"    />
        <result property="refuseReason"    column="refuse_reason"    />
        <result property="auditPerson"    column="audit_person"    />
        <result property="delayRemark"    column="delay_remark"    />
        <result property="loseRemark"    column="lose_remark"    />
        <result property="permissionChar"    column="permission_char"    />
        <result property="version"    column="version"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="areaId"    column="area_id"    />
        <result property="keyContactPerson"    column="key_contact_person"    />
        <result property="keyContact"    column="key_contact"    />
        <result property="keyJobTitle"    column="key_job_title"    />
        <result property="keyEmail"    column="key_email"    />
        <result property="specialRemark"    column="special_remark"    />
        <result property="equipmentQuantity"    column="equipment_quantity"    />
        <result property="equipmentType"    column="equipment_type"    />
        <result property="amount"    column="amount"    />
        <result property="expectedInstallStartDate"    column="expected_install_start_date"    />
        <result property="modifyRemark"    column="modify_remark"    />

        <result property="reasonType"    column="reason_type"    />
        <result property="competitor"    column="competitor"    />
    </resultMap>

    <sql id="selectTcProjectHistoryVo">
        select project_id, project_no, project_name, account_id, address, model_flag, type, segmented_market, country_id, city, progress, developer, plan_deal_month, completion_year, start_time, over_time, currency_id, contact_person, contact, job_title, email, status, product_series, solution, owner, owner_agent, refuse_reason, audit_person, delay_remark, lose_remark, permission_char, version, del_flag, create_time, create_by, update_time, update_by, remark, area_id, key_contact_person, key_contact, key_job_title, key_email, special_remark, equipment_quantity, equipment_type, amount, expected_install_start_date, modify_remark,reason_type,competitor from tc_project_history
    </sql>

    <select id="selectTcProjectHistoryList" parameterType="TcProjectHistory" resultMap="TcProjectHistoryResult">
        select h.*, u.nick_name as nickName from tc_project_history h
        left join sys_user u on u.user_id = h.create_by
        <where>  
            <if test="projectId != null  and projectId != ''"> and h.project_id = #{projectId}</if>
            <if test="projectNo != null  and projectNo != ''"> and h.project_no = #{projectNo}</if>
            <if test="projectName != null  and projectName != ''"> and h.project_name like concat('%', #{projectName}, '%')</if>
            <if test="accountId != null "> and h.account_id = #{accountId}</if>
            <if test="address != null  and address != ''"> and h.address = #{address}</if>
            <if test="modelFlag != null  and modelFlag != ''"> and h.model_flag = #{modelFlag}</if>
            <if test="type != null  and type != ''"> and h.type = #{type}</if>
            <if test="segmentedMarket != null  and segmentedMarket != ''"> and h.segmented_market = #{segmentedMarket}</if>
            <if test="countryId != null "> and h.country_id = #{countryId}</if>
            <if test="city != null  and city != ''"> and h.city = #{city}</if>
            <if test="progress != null  and progress != ''"> and h.progress = #{progress}</if>
            <if test="developer != null  and developer != ''"> and h.developer = #{developer}</if>
            <if test="planDealMonth != null "> and h.plan_deal_month = #{planDealMonth}</if>
            <if test="completionYear != null "> and h.completion_year = #{completionYear}</if>
            <if test="startTime != null "> and h.start_time = #{startTime}</if>
            <if test="overTime != null "> and h.over_time = #{overTime}</if>
            <if test="currencyId != null "> and h.currency_id = #{currencyId}</if>
            <if test="contactPerson != null  and contactPerson != ''"> and h.contact_person = #{contactPerson}</if>
            <if test="contact != null  and contact != ''"> and h.contact = #{contact}</if>
            <if test="jobTitle != null  and jobTitle != ''"> and h.job_title = #{jobTitle}</if>
            <if test="email != null  and email != ''"> and h.email = #{email}</if>
            <if test="status != null  and status != ''"> and h.status = #{status}</if>
            <if test="productSeries != null  and productSeries != ''"> and h.product_series = #{productSeries}</if>
            <if test="solution != null  and solution != ''"> and h.solution = #{solution}</if>
            <if test="owner != null "> and h.owner = #{owner}</if>
            <if test="ownerAgent != null "> and h.owner_agent = #{ownerAgent}</if>
            <if test="refuseReason != null  and refuseReason != ''"> and h.refuse_reason = #{refuseReason}</if>
            <if test="auditPerson != null "> and h.audit_person = #{auditPerson}</if>
            <if test="delayRemark != null  and delayRemark != ''"> and h.delay_remark = #{delayRemark}</if>
            <if test="loseRemark != null  and loseRemark != ''"> and h.lose_remark = #{loseRemark}</if>
            <if test="permissionChar != null  and permissionChar != ''"> and h.permission_char = #{permissionChar}</if>
            <if test="version != null "> and h.version = #{version}</if>
            <if test="areaId != null "> and h.area_id = #{areaId}</if>
            <if test="keyContactPerson != null  and keyContactPerson != ''"> and h.key_contact_person = #{keyContactPerson}</if>
            <if test="keyContact != null  and keyContact != ''"> and h.key_contact = #{keyContact}</if>
            <if test="keyJobTitle != null  and keyJobTitle != ''"> and h.key_job_title = #{keyJobTitle}</if>
            <if test="keyEmail != null  and keyEmail != ''"> and h.key_email = #{keyEmail}</if>
            <if test="specialRemark != null  and specialRemark != ''"> and h.special_remark = #{specialRemark}</if>
            <if test="equipmentQuantity != null "> and h.equipment_quantity = #{equipmentQuantity}</if>
            <if test="equipmentType != null  and equipmentType != ''"> and h.equipment_type = #{equipmentType}</if>
            <if test="amount != null "> and h.amount = #{amount}</if>
            <if test="expectedInstallStartDate != null "> and h.expected_install_start_date = #{expectedInstallStartDate}</if>
            <if test="modifyRemark != null "> and h.modify_remark = #{modifyRemark}</if>
        </where>
    </select>
    
    <select id="selectTcProjectHistoryByProjectId" parameterType="Long" resultMap="TcProjectHistoryResult">
        <include refid="selectTcProjectHistoryVo"/>
        where project_id = #{projectId} and version = #{version}
    </select>
        
    <insert id="insertTcProjectHistory" parameterType="TcProjectHistory" useGeneratedKeys="true" keyProperty="projectId">
        insert into tc_project_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="projectName != null">project_name,</if>
            <if test="accountId != null">account_id,</if>
            <if test="address != null">address,</if>
            <if test="modelFlag != null">model_flag,</if>
            <if test="type != null">type,</if>
            <if test="segmentedMarket != null">segmented_market,</if>
            <if test="countryId != null">country_id,</if>
            <if test="city != null">city,</if>
            <if test="progress != null">progress,</if>
            <if test="developer != null">developer,</if>
            <if test="planDealMonth != null">plan_deal_month,</if>
            <if test="completionYear != null">completion_year,</if>
            <if test="startTime != null">start_time,</if>
            <if test="overTime != null">over_time,</if>
            <if test="currencyId != null">currency_id,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="contact != null">contact,</if>
            <if test="jobTitle != null">job_title,</if>
            <if test="email != null">email,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="productSeries != null">product_series,</if>
            <if test="solution != null">solution,</if>
            <if test="owner != null">owner,</if>
            <if test="ownerAgent != null">owner_agent,</if>
            <if test="refuseReason != null">refuse_reason,</if>
            <if test="auditPerson != null">audit_person,</if>
            <if test="delayRemark != null">delay_remark,</if>
            <if test="loseRemark != null">lose_remark,</if>
            <if test="permissionChar != null">permission_char,</if>
            <if test="version != null">version,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="areaId != null">area_id,</if>
            <if test="keyContactPerson != null">key_contact_person,</if>
            <if test="keyContact != null">key_contact,</if>
            <if test="keyJobTitle != null">key_job_title,</if>
            <if test="keyEmail != null">key_email,</if>
            <if test="specialRemark != null">special_remark,</if>
            <if test="equipmentQuantity != null">equipment_quantity,</if>
            <if test="equipmentType != null">equipment_type,</if>
            <if test="amount != null">amount,</if>
            <if test="expectedInstallStartDate != null ">expected_install_start_date,</if>
            <if test="modifyRemark != null ">modify_remark,</if>
            <if test="competitor != null and competitor != ''">
                competitor,
            </if>
            <if test="reasonType != null">reason_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="address != null">#{address},</if>
            <if test="modelFlag != null">#{modelFlag},</if>
            <if test="type != null">#{type},</if>
            <if test="segmentedMarket != null">#{segmentedMarket},</if>
            <if test="countryId != null">#{countryId},</if>
            <if test="city != null">#{city},</if>
            <if test="progress != null">#{progress},</if>
            <if test="developer != null">#{developer},</if>
            <if test="planDealMonth != null">#{planDealMonth},</if>
            <if test="completionYear != null">#{completionYear},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="overTime != null">#{overTime},</if>
            <if test="currencyId != null">#{currencyId},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="contact != null">#{contact},</if>
            <if test="jobTitle != null">#{jobTitle},</if>
            <if test="email != null">#{email},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="productSeries != null">#{productSeries},</if>
            <if test="solution != null">#{solution},</if>
            <if test="owner != null">#{owner},</if>
            <if test="ownerAgent != null">#{ownerAgent},</if>
            <if test="refuseReason != null">#{refuseReason},</if>
            <if test="auditPerson != null">#{auditPerson},</if>
            <if test="delayRemark != null">#{delayRemark},</if>
            <if test="loseRemark != null">#{loseRemark},</if>
            <if test="permissionChar != null">#{permissionChar},</if>
            <if test="version != null">#{version},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="keyContactPerson != null">#{keyContactPerson},</if>
            <if test="keyContact != null">#{keyContact},</if>
            <if test="keyJobTitle != null">#{keyJobTitle},</if>
            <if test="keyEmail != null">#{keyEmail},</if>
            <if test="specialRemark != null">#{specialRemark},</if>
            <if test="equipmentQuantity != null">#{equipmentQuantity},</if>
            <if test="equipmentType != null">#{equipmentType},</if>
            <if test="amount != null">#{amount},</if>
            <if test="expectedInstallStartDate != null ">#{expectedInstallStartDate},</if>
            <if test="modifyRemark != null ">#{modifyRemark},</if>
            <if test="competitor != null and competitor != ''">#{competitor},</if>
            <if test="reasonType != null">#{reasonType},</if>
         </trim>
    </insert>

    <update id="updateTcProjectHistory" parameterType="TcProjectHistory">
        update tc_project_history
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectNo != null">project_no = #{projectNo},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="address != null">address = #{address},</if>
            <if test="modelFlag != null">model_flag = #{modelFlag},</if>
            <if test="type != null">type = #{type},</if>
            <if test="segmentedMarket != null">segmented_market = #{segmentedMarket},</if>
            <if test="countryId != null">country_id = #{countryId},</if>
            <if test="city != null">city = #{city},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="developer != null">developer = #{developer},</if>
            <if test="planDealMonth != null">plan_deal_month = #{planDealMonth},</if>
            <if test="completionYear != null">completion_year = #{completionYear},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="overTime != null">over_time = #{overTime},</if>
            <if test="currencyId != null">currency_id = #{currencyId},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="jobTitle != null">job_title = #{jobTitle},</if>
            <if test="email != null">email = #{email},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="productSeries != null">product_series = #{productSeries},</if>
            <if test="solution != null">solution = #{solution},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="ownerAgent != null">owner_agent = #{ownerAgent},</if>
            <if test="refuseReason != null">refuse_reason = #{refuseReason},</if>
            <if test="auditPerson != null">audit_person = #{auditPerson},</if>
            <if test="delayRemark != null">delay_remark = #{delayRemark},</if>
            <if test="loseRemark != null">lose_remark = #{loseRemark},</if>
            <if test="permissionChar != null">permission_char = #{permissionChar},</if>
            <if test="version != null">version = #{version},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="keyContactPerson != null">key_contact_person = #{keyContactPerson},</if>
            <if test="keyContact != null">key_contact = #{keyContact},</if>
            <if test="keyJobTitle != null">key_job_title = #{keyJobTitle},</if>
            <if test="keyEmail != null">key_email = #{keyEmail},</if>
            <if test="specialRemark != null">special_remark = #{specialRemark},</if>
            <if test="equipmentQuantity != null">equipment_quantity = #{equipmentQuantity},</if>
            <if test="equipmentType != null">equipment_type = #{equipmentType},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="expectedInstallStartDate != null ">expected_install_start_date = #{expectedInstallStartDate},</if>
            <if test="modifyRemark != null ">modify_remark = #{modifyRemark}</if>
        </trim>
        where project_id = #{projectId}
    </update>

    <delete id="deleteTcProjectHistoryByProjectId" parameterType="Long">
        delete from tc_project_history where project_id = #{projectId}
    </delete>

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