<?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.casic.missiles.mapper.business.BusinessSiteExecutiveInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.business.BusinessSiteExecutiveInfo">
        <id column="id" property="id" />
        <result column="site_executive_no" property="siteExecutiveNo" />
        <result column="site_executive_name" property="siteExecutiveName" />
        <result column="director_id" property="directorId" />
        <result column="director_name" property="directorName" />
        <result column="apply_time" property="applyTime" />
        <result column="task_source" property="taskSource" />
        <result column="order_id" property="orderId" />
        <result column="customer_id" property="customerId" />
        <result column="pre_cost" property="preCost" />
        <result column="pre_start_time" property="preStartTime" />
        <result column="pre_end_time" property="preEndTime" />
        <result column="executive_address" property="executiveAddress" />
        <result column="executive_environment" property="executiveEnvironment" />
        <result column="hazard_source_and_prevention_method" property="hazardSourceAndPreventionMethod" />
        <result column="executive_item" property="executiveItem" />
        <result column="approval_status" property="approvalStatus" />
        <result column="process_id" property="processId" />
        <result column="remark" property="remark" />
        <result column="create_user" property="createUser" />
        <result column="is_del" property="isDel" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <select id="selectDraftListForApproval" resultType="com.casic.missiles.dto.business.siteExecutive.SiteExecutiveApprovalListResponse">
        SELECT *
        FROM business_site_executive_info
        JOIN (
            SELECT  id as orderId,customer_name AS customerName,customer_address AS customerAddress,
            customer_phone AS customerPhone,deliverer,deliverer_tel AS delivererTel
            FROM business_order
            where   is_del = 0
            <if test="request.customerName != null and request.customerName !=''">
                and customer_name like concat('%',#{request.customerName},'%')
            </if>
        )bo  ON bo.orderId=order_id
        WHERE is_del = 0
        AND approval_status = #{request.approvalStatus}
        AND create_user = #{request.createUserId}
        <if test="request.siteExecutiveNo != null and request.siteExecutiveNo !=''">
            and site_executive_no like concat('%',#{request.siteExecutiveNo},'%')
        </if>
        <if test="request.directorName != null and request.directorName !=''">
            and director_name like concat('%',#{request.directorName},'%')
        </if>
    </select>

    <select id="selectBatchForApproval" resultType="com.casic.missiles.dto.business.siteExecutive.SiteExecutiveApprovalListResponse">
        SELECT *
        FROM business_site_executive_info
        JOIN (
           SELECT  id as orderId,customer_name AS customerName,customer_address AS customerAddress,
                    customer_phone AS customerPhone,deliverer,deliverer_tel AS delivererTel
           FROM business_order
           where   is_del = 0
            <if test="request.customerName != null and request.customerName !=''">
                and customer_name like concat('%',#{request.customerName},'%')
            </if>
        )bo  ON bo.orderId=order_id
        WHERE is_del = 0
        <if test="request.siteExecutiveNo != null and request.siteExecutiveNo !=''">
            and site_executive_no like concat('%',#{request.siteExecutiveNo},'%')
        </if>
        <if test="request.directorName != null and request.directorName !=''">
            and director_name like concat('%',#{request.directorName},'%')
        </if>
        and id in
        <foreach collection="businessKeys" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
</mapper>
