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

    <resultMap type="com.shkj.wms.domain.BasRule" id="BasRuleResult">
        <result property="ruleId" column="rule_id"/>
        <result property="ruleName" column="rule_name"/>
        <result property="ruleNum" column="rule_num"/>
        <result property="description" column="description"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>
    <select id="selectRuleOne" parameterType="java.lang.String" resultType="com.shkj.wms.vo.BasRuleVo">
        select b.rule_name as ruleName,d.ruledetail_id as ruledetailId,
        d.rule_value as ruleValue,
        d.rule_item as ruleItem,
        d.rule_zeroize as ruleZero,d.rule_zeroize as ruleZeroize,d.rule_length as ruleLength,d.rule_variable as ruleVariable from base_rule b
        left join base_rule_detail d on b.rule_id = d.rule_id
        where b.rule_num = #{ruleNum}
        order by d.ruledetail_id desc
    </select>
    <select id="selectRuleList" parameterType="java.lang.Long" resultType="com.shkj.wms.vo.BasRuleVo">
        select b.*,
        bc.customer_name as customerName,
        bs.supplier_name as supplierName
        from base_material b
        left join base_supplier bs on b.supplier_id = bs.supplier_id
        left join base_customer bc on b.customer_id = bc.customer_id

        where 1 = 1
        <if test="materialName != null and materialName != ''">
            and b.material_name like concat('%', #{materialName}, '%')
            or b.product_code like concat('%', #{materialName}, '%')
        </if>
        <if test="supplierId != null">
            and b.supplier_id = #{supplierId}
        </if>
        <if test="source != null">
            and b.source = #{source}
        </if>
        <if test="customerId != null">
            and b.customer_id = #{customerId}
        </if>
        order by b.customer_id desc
    </select>
</mapper>
