<?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.shkj.wms.mapper.BaseCompanyMapper">

    <resultMap type="com.shkj.wms.vo.BaseCompanyVo" id="BaseCompanyResult">
            <result property="id" column="id"/>
            <result property="companyNum" column="company_num"/>
            <result property="companyNo" column="company_no"/>
            <result property="companyName" column="company_name"/>
            <result property="mnemonic" column="mnemonic"/>
            <result property="type" column="type"/>
            <result property="consignorId" column="consignor_id"/>
            <result property="specifications" column="specifications"/>
            <result property="storageConditions" column="storage_conditions"/>
            <result property="storageClassify" column="storage_classify"/>
            <result property="branchId" column="branch_id"/>
            <result property="extend1" column="extend1"/>
            <result property="extend2" column="extend2"/>
            <result property="extend3" column="extend3"/>
            <result property="extend4" column="extend4"/>
            <result property="extend5" column="extend5"/>
            <result property="extend6" column="extend6"/>
            <result property="extend7" column="extend7"/>
            <result property="extend8" column="extend8"/>
            <result property="extend9" column="extend9"/>
            <result property="extend10" column="extend10"/>
            <result property="remark" column="remark"/>
            <result property="isDel" column="is_del"/>
            <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="consignorCode" column="consignor_code"/>
            <result property="consignorName" column="consignor_name"/>
    </resultMap>

        <select id="queryBaseCompanyList" parameterType="com.shkj.wms.bo.BaseCompanyQueryListBo" resultMap="BaseCompanyResult">
                select
                bcp.*,
                bcs.consignor_code,
                bcs.consignor_name
                from base_company bcp
                join base_consignor bcs
                on bcp.consignor_id = bcs.id
                left join base_address ba
                on ba.company_id = bcp.id
                where bcp.is_del = '0'
                <if test="consignorName != null and consignorName != ''">
                        AND LOWER(bcs.consignor_name) like LOWER(concat('%', #{consignorName}, '%'))
                </if>
                <if test="consignorCode != null and consignorCode != ''">
                        AND LOWER(bcs.consignor_code) like LOWER(concat('%', #{consignorCode}, '%'))
                </if>
                <if test="companyNo != null and companyNo != ''">
                        AND LOWER(bcp.company_no) like LOWER(concat('%', #{companyNo}, '%'))
                </if>
                <if test="mnemonic != null and mnemonic != ''">
                        AND LOWER(bcp.mnemonic) like LOWER(concat('%', #{mnemonic}, '%'))
                </if>
                <if test="linename != null and linename != ''">
                        AND LOWER(ba.linename) like LOWER(concat('%', #{linename}, '%'))
                </if>
                ${consignorParams.dataScopeConsignor}
                order by bcp.create_time desc
        </select>

        <select id="getBaseCompany" resultMap="BaseCompanyResult">
                select
                bcp.*,
                bcs.consignor_code,
                bcs.consignor_name
                from base_company bcp
                join base_consignor bcs
                on bcp.consignor_id = bcs.id
                where bcp.id = #{id}
        </select>
</mapper>