<?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.ruoyi.quote.mapper.QuoteMapper">

    <resultMap type="MaterialDto" id="MaterialResult">
        <result property="uid"    column="uid"    />
        <result property="model"    column="model"    />
        <result property="specification"    column="specification"    />
        <result property="voltLevel"    column="voltLevel"    />
        <result property="measureUnit"    column="measureUnit"    />
        <result property="prodCategory"    column="prodCategory"    />
        <result property="matCostPrice"    column="matCostPrice"    />
        <result property="manuCost"    column="manuCost"    />
        <result property="wdFSurcharge"    column="wdFSurcharge"    />
        <result property="redBookPrice"    column="redBookPrice"    />
        <result property="rbFacPrice"    column="rbFacPrice"    />
        <result property="redBookCost"    column="redBookCost"    />
    </resultMap>

    <select id="selectMaterialListByParam" resultType="com.ruoyi.quote.domain.MaterialDto">
        select a.material_id AS uid,a.material_xingh AS model,a.material_guig AS specification,
               a.material_diany AS voltLevel,a.material_dw AS measureUnit,c.type_name As prodCategory,
               b.price matCostPrice, d.factory_total_ratio/100 manuCost,d.factory_pj_ratio/100 wdFSurcharge
        from c_material a
        left join
            (select a.cost_material_id,sum((isnull(a.cost_cl_qty,0)+isnull(a.cost_cl_qty_2,0))*b.material_price) price
            from c_material_cost a
            left join c_yl_material b on a.cost_cl_id=b.material_no
            group by a.cost_material_id
            )b on a.material_id=b.cost_material_id
        left join c_material_type_factory c on a.material_type_id = c.type_no
        left join c_factory d on d.factory_no = c.factory_id
        <where>
            <if test="precMaterialName != null  and precMaterialName != ''"> and a.material_xingh like concat('', #{precMaterialName}, '%')</if>
            <if test="vagueMaterialName != null  and vagueMaterialName != ''"> and a.material_xingh like concat('%', #{vagueMaterialName}, '%')</if>
            <if test="vagueModel != null  and vagueModel != ''"> and a.material_guig like concat('%', #{vagueModel}, '%')</if>

        </where>

    </select>

</mapper>
