<?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.BusinessOutsourcerInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.business.BusinessOutsourcerInfo">
        <id column="id" property="id" />
        <result column="outsourcer_no" property="outsourcerNo" />
        <result column="outsourcer_name" property="outsourcerName" />
        <result column="outsourcer_brief_name" property="outsourcerBriefName" />
        <result column="outsourcer_size" property="outsourcerSize" />
        <result column="business_size" property="businessSize" />
        <result column="grade" property="grade" />
        <result column="evaluation" property="evaluation" />
        <result column="business_content" property="businessContent" />
        <result column="tax_number" property="taxNumber" />
        <result column="bank_account" property="bankAccount" />
        <result column="bank_name" property="bankName" />
        <result column="bank_account_number" property="bankAccountNumber" />
        <result column="postal_code" property="postalCode" />
        <result column="director" property="director" />
        <result column="phone" property="phone" />
        <result column="mobile" property="mobile" />
        <result column="email" property="email" />
        <result column="website" property="website" />
        <result column="address_country" property="addressCountry" />
        <result column="address_province" property="addressProvince" />
        <result column="address_city" property="addressCity" />
        <result column="address_area" property="addressArea" />
        <result column="full_address" property="fullAddress" />
        <result column="address_country_name" property="addressCountryName" />
        <result column="address_province_name" property="addressProvinceName" />
        <result column="address_city_name" property="addressCityName" />
        <result column="address_area_name" property="addressAreaName" />
        <result column="invoice_country" property="invoiceCountry" />
        <result column="invoice_province" property="invoiceProvince" />
        <result column="invoice_city" property="invoiceCity" />
        <result column="invoice_area" property="invoiceArea" />
        <result column="invoice_full_address" property="invoiceFullAddress" />
        <result column="invoice_country_name" property="invoiceCountryName" />
        <result column="invoice_province_name" property="invoiceProvinceName" />
        <result column="invoice_city_name" property="invoiceCityName" />
        <result column="invoice_area_name" property="invoiceAreaName" />
        <result column="business_scope" property="businessScope" />
        <result column="minio_file_name" property="minioFileName" />
        <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" resultMap="BaseResultMap">
        SELECT *
        FROM business_outsourcer_info
        WHERE is_del = 0
        AND approval_status = #{request.approvalStatus}
        AND create_user = #{request.createUserId}
        <if test="request.outsourcerNo != null and request.outsourcerNo !=''">
            and outsourcer_no like concat('%',#{request.outsourcerNo},'%')
        </if>
        <if test="request.outsourcerName != null and request.outsourcerName !=''">
            and outsourcer_name like concat('%',#{request.outsourcerName},'%')
        </if>
        <if test="request.businessSize != null and request.businessSize !=''">
            and business_size = #{request.businessSize}
        </if>
        <if test="request.grade != null and request.grade !=''">
            and grade = #{request.grade}
        </if>
        <if test="request.evaluation != null and request.evaluation !=''">
            and evaluation = #{request.evaluation}
        </if>
    </select>

    <select id="selectBatchForApproval" resultMap="BaseResultMap">
        SELECT *
        FROM business_outsourcer_info
        WHERE is_del = 0
        <if test="request.outsourcerNo != null and request.outsourcerNo !=''">
            and outsourcer_no like concat('%',#{request.outsourcerNo},'%')
        </if>
        <if test="request.outsourcerName != null and request.outsourcerName !=''">
            and outsourcer_name like concat('%',#{request.outsourcerName},'%')
        </if>
        <if test="request.businessSize != null and request.businessSize !=''">
            and business_size = #{request.businessSize}
        </if>
        <if test="request.grade != null and request.grade !=''">
            and grade = #{request.grade}
        </if>
        <if test="request.evaluation != null and request.evaluation !=''">
            and evaluation = #{request.evaluation}
        </if>
        and id in
        <foreach collection="businessKey" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

    <select id="selectMaxOutsourcerNo" resultType="java.lang.Long">
        SELECT IFNULL(max(RIGHT(outsourcer_no, 12)), 0) from business_outsourcer_info
    </select>
</mapper>
