<?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.glxp.mipsdl.dao.basic.UdiRlSupDao">

    <select id="filterUdiGp" parameterType="com.glxp.mipsdl.req.base.CompanyProductRelevanceRequest"
            resultType="com.glxp.mipsdl.res.udiwms.UdiRlSupResponse">
        select company_product_relevance.id,
               company_product_relevance.customerId,
               company_product_relevance.auditStatus,
               company_product_relevance.price,
               basic_udirel.uuid,
               basic_udirel.thirdId,
               basic_udirel.id      rlId,
               basic_udirel.isUseDy,
               basic_udirel.useMuti,
               basic_udirel.isLock,
               basic_udirel.thirdId1,
               basic_udirel.thirdId2,
               basic_udirel.thirdId3,
               basic_udirel.thirdId4,
               basic_udirel.lockStatus,
               basic_udirel.mainId,
               basic_udirel.isAdavence,
               basic_udirel.purType,
               basic_udirel.attributeType,
               basic_udirel.lowStockNum,
               basic_udirel.overStockNum,
               basic_udirel.recentDateTime,
               basic_udirel.isDateBy,
               bht.name             classifyName,
               basic_products.id as PRId,
               basic_products.originUuid,
               basic_products.nameCode,
               basic_products.deviceRecordKey,
               basic_products.packRatio,
               basic_products.packUnit,
               basic_products.packLevel,
               basic_products.bhxjsl,
               basic_products.bhzxxsbzsl,
               basic_products.zxxsbzbhsydysl,
               basic_products.bhxjcpbm,
               basic_products.bzcj,
               basic_products.cpmctymc,
               basic_products.cplb,
               basic_products.flbm,
               basic_products.ggxh,
               basic_products.qxlb,
               basic_products.tyshxydm,
               basic_products.ylqxzcrbarmc,
               basic_products.zczbhhzbapzbh,
               basic_products.ylqxzcrbarywmc,
               basic_products.sydycpbs,
               basic_products.sjcpbm,
               basic_products.versionNumber,
               basic_products.diType,
               basic_products.ybbm,
               basic_products.sptm,
               basic_products.manufactory,
               basic_products.measname,
               basic_products.productType,
               basic_products.scbssfbhph,
               basic_products.scbssfbhxlh,
               basic_products.scbssfbhscrq,
               basic_products.scbssfbhsxrq,
               basic_products.cpms,
               basic_products.allowNoBatch,
               basic_products.allowNoExpire,
               basic_products.allowNoProduct,
               basic_products.allowNoSerial,
               basic_products.spmc,
               basic_products.cplx,
               basic_products.hchzsb,
               basic_products.cpdls,
               basic_products.basicPrductRemak1,
               basic_products.basicPrductRemak2,
               basic_products.basicPrductRemak3,
               basic_products.basicPrductRemak4,
               basic_products.basicPrductRemak5,
               basic_products.basicPrductRemak6,
               basic_products.basicPrductRemak7,
               basic_products.basicPrductRemak8,
               basic_corp.name      companyName
        FROM company_product_relevance
                     inner JOIN basic_udirel
                ON company_product_relevance.udiRlIdFk = basic_udirel.id
                     inner JOIN basic_products
                ON basic_udirel.uuid = basic_products.uuid
                     left JOIN basic_corp on basic_corp.erpId = company_product_relevance.customerId
                     left join basic_hosp_type bht on basic_udirel.relCode = bht.code
                     left join thr_products tp on tp.code = basic_udirel.mainId
        <where>
            <if test="ylqxzcrbarmc != '' and ylqxzcrbarmc != null">
                AND basic_products.ylqxzcrbarmc LIKE concat(#{ylqxzcrbarmc}, '%')
            </if>
            <if test="manufactory != '' and manufactory != null">
                AND basic_products.manufactory LIKE concat(#{manufactory}, '%')
            </if>
            <if test="cpmctymc != '' and cpmctymc != null">
                AND cpmctymc LIKE concat('%', #{cpmctymc}, '%')
            </if>
            <if test="nameCode != '' and nameCode != null">
                AND nameCode LIKE concat(#{nameCode}, '%')
            </if>
            <if test="ggxh != '' and ggxh != null">
                AND ggxh LIKE concat('%', #{ggxh}, '%')
            </if>
            <if test="unionCode != '' and unionCode != null">
                and (
                        nameCode LIKE concat('%', #{unionCode}, '%')
                                or basic_products.ybbm LIKE concat('%', #{unionCode}, '%')
                                or basic_products.sptm LIKE concat('%', #{unionCode}, '%')
                        )
            </if>
            <if test="thrPiId != '' and thrPiId != null">
                and (
                        basic_udirel.thirdId LIKE concat('%', #{thrPiId}, '%')
                                or basic_udirel.thirdId1 LIKE concat('%', #{thrPiId}, '%')
                                or basic_udirel.thirdId2 LIKE concat('%', #{thrPiId}, '%')
                                or basic_udirel.thirdId3 LIKE concat('%', #{thrPiId}, '%')
                                or basic_udirel.thirdId4 LIKE concat('%', #{thrPiId}, '%')
                        )
            </if>
            <if test="uuid != '' and uuid != null">
                AND basic_udirel.uuid = #{uuid}
            </if>
            <if test="thirdId != '' and thirdId != null">
                AND basic_udirel.thirdId = #{thirdId}
            </if>
            <if test="zczbhhzbapzbh != '' and zczbhhzbapzbh != null">
                AND basic_products.zczbhhzbapzbh LIKE concat(#{zczbhhzbapzbh}, '%')
            </if>
            <if test="diType != '' and diType != null">
                AND diType = #{diType}
            </if>
            <if test="filterType != null and filterType == 1">
                AND (basic_udirel.thirdId <![CDATA[<>]]> '' or basic_udirel.thirdId1 <![CDATA[<>]]> '' or
                     basic_udirel.thirdId2 <![CDATA[<>]]> '' or
                     basic_udirel.thirdId3 <![CDATA[<>]]> '' or basic_udirel.thirdId4 <![CDATA[<>]]> '')
                and basic_products.originUuid <![CDATA[<>]]> ''
            </if>
            <if test="filterType != null and filterType == 2">
                AND basic_products.originUuid is NULL
            </if>
            <if test="filterType != null and filterType == 3">
                AND (basic_udirel.thirdId IS NULL or basic_udirel.thirdId = '')
                and basic_products.originUuid <![CDATA[<>]]> ''
            </if>
            <if test="filterType != null and filterType == 4">
                AND basic_udirel.thirdId1 is NULL
                and basic_products.originUuid <![CDATA[<>]]> ''
            </if>
            <if test="filterType != null and filterType == 5">
                AND basic_udirel.thirdId2 is NULL
                and basic_products.originUuid <![CDATA[<>]]> ''
            </if>
            <if test="filterType != null and filterType == 6">
                AND basic_udirel.thirdId3 is NULL
                and basic_products.originUuid <![CDATA[<>]]> ''
            </if>
            <if test="filterType != null and filterType == 7">
                AND basic_udirel.thirdId4 is NULL
                and basic_products.originUuid <![CDATA[<>]]> ''
            </if>
            <if test="filterType != null and filterType == 10">
                AND basic_udirel.updateTime is NULL
            </if>
            <if test="pinyinInitial != null and pinyinInitial != ''">
                AND basic_products.pinyinInitial like concat('%', #{pinyinInitial}, '%')
            </if>
            <if test="code != '' and code != null">
                AND basic_udirel.mainId = #{code}
            </if>
            <if test="customerId != '' and customerId != null">
                AND company_product_relevance.customerId = #{customerId}
            </if>
            <if test="auditStatus != '' and auditStatus != null">
                AND company_product_relevance.auditStatus = #{auditStatus}
            </if>
            <if test="id != '' and id != null">
                AND basic_udirel.id = #{id}
            </if>
            <if test="companyName != '' and companyName != null">
                AND basic_corp.name like concat('%', #{companyName}, '%')
            </if>
            <if test="basicPrductRemak1 != '' and basicPrductRemak1 != null">
                AND basic_products.basicPrductRemak1 like concat('%', #{basicPrductRemak1}, '%')
            </if>
            <if test="basicPrductRemak2 != '' and basicPrductRemak2 != null">
                AND basic_products.basicPrductRemak2 like concat('%', #{basicPrductRemak2}, '%')
            </if>
            <if test="basicPrductRemak3 != '' and basicPrductRemak3 != null">
                AND basic_products.basicPrductRemak3 like concat('%', #{basicPrductRemak3}, '%')
            </if>
            <if test="basicPrductRemak4 != '' and basicPrductRemak4 != null">
                AND basic_products.basicPrductRemak4 like concat('%', #{basicPrductRemak4}, '%')
            </if>
            <if test="basicPrductRemak5 != '' and basicPrductRemak5 != null">
                AND basic_products.basicPrductRemak5 like concat('%', #{basicPrductRemak5}, '%')
            </if>
            <if test="basicPrductRemak6 != '' and basicPrductRemak6 != null">
                AND basic_products.basicPrductRemak6 like concat('%', #{basicPrductRemak6}, '%')
            </if>
            <if test="basicPrductRemak7 != '' and basicPrductRemak7 != null">
                AND basic_products.basicPrductRemak7 like concat('%', #{basicPrductRemak7}, '%')
            </if>
            <if test="basicPrductRemak8 != '' and basicPrductRemak8 != null">
                AND basic_products.basicPrductRemak8 like concat('%', #{basicPrductRemak8}, '%')
            </if>
            <if test="lockStatus != '' and lockStatus != null">
                AND basic_udirel.lockStatus = #{lockStatus}
            </if>
            <if test="isAdavence != '' and isAdavence != null">
                AND basic_udirel.isAdavence = #{isAdavence}
            </if>
            <if test="unitFk != null and unitFk != ''">
                and unitFk = #{unitFk}
            </if>
            <if test="isDisable == false">
                AND (basic_udirel.isDisable is null or basic_udirel.isDisable = false)
            </if>

            <if test="flbm != '' and flbm != null">
                and (tp.flbm = #{flbm} or basic_products.flbm = #{flbm})
            </if>
        </where>
        ORDER BY company_product_relevance.updateTime DESC
    </select>


</mapper>
