<?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.muchinfo.mtp3interface.mapper.IWrstandardMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.muchinfo.mtp3pojos.entity.Wrstandard">
        <id column="WRSTANDARDID" property="wrstandardid" />
        <result column="WRSTANDARDCODE" property="wrstandardcode" />
        <result column="WRSTANDARDNAME" property="wrstandardname" />
        <result column="DELIVERYGOODSID" property="deliverygoodsid" />
        <result column="UNITID" property="unitid" />
        <result column="MINIVALUE" property="minivalue" />
        <result column="MINIVALUEDP" property="minivaluedp" />
        <result column="REALMINIVALUE" property="realminivalue" />
        <result column="REALMINIVALUEDP" property="realminivaluedp" />
        <result column="WRSSTATUS" property="wrsstatus" />
        <result column="CREATORID" property="creatorid" />
        <result column="CREATETIME" property="createtime" />
        <result column="UPDATORID" property="updatorid" />
        <result column="UPDATETIME" property="updatetime" />
        <result column="FACTORYITEMJSON" property="factoryitemjson" />
        <result column="ISVALID" property="isvalid" />
        <result column="AREAUSERID" property="areauserid" />
        <result column="REMARK" property="remark" />
        <result column="CONVERTFACTOR" property="convertfactor" />
        <result column="VATRATE" property="vatrate" />
        <result column="STORAGEFEE" property="storagefee" />
        <result column="THUMURLS" property="thumurls" />
        <result column="PICTUREURLS" property="pictureurls" />
        <result column="BANNERPICURL" property="bannerpicurl" />
        <result column="PROVIDERUSERID" property="provideruserid" />
        <result column="PROVIDERACCOUNTID" property="provideraccountid" />
        <result column="REFGOODSID" property="refgoodsid" />
        <result column="REFGOODSCODE" property="refgoodscode" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        WRSTANDARDID, WRSTANDARDCODE, WRSTANDARDNAME, DELIVERYGOODSID, UNITID, MINIVALUE, MINIVALUEDP, REALMINIVALUE, REALMINIVALUEDP, WRSSTATUS, CREATORID, CREATETIME, UPDATORID, UPDATETIME, FACTORYITEMJSON, ISVALID, AREAUSERID, REMARK, CONVERTFACTOR, VATRATE, STORAGEFEE, THUMURLS, PICTUREURLS, BANNERPICURL, PROVIDERUSERID, PROVIDERACCOUNTID, REFGOODSID, REFGOODSCODE
    </sql>

    <select id="queryWRStandard" parameterType="com.muchinfo.mtp3pojos.vo.query.deliveryorder.DeliveryOrderWrsParam"
            resultType="com.muchinfo.mtp3pojos.vo.query.deliveryorder.DeliveryOrderWrsResult">
        select t.* , edi.enumdicname unitname, mgedi.enumdicname mgunitname, cd.convertratio mgconvertfactor,
        decode(t.wrstandardcode,null,t.wrstandardname,t.wrstandardcode||'/'||t.wrstandardname) wrcodeandname,
        dg.deliverygoodsname
        from WRStandard t
        left join deliverygoods dg on t.deliverygoodsid = dg.deliverygoodsid
        left join enumdicitem edi on t.unitid = edi.enumitemname and edi.enumdiccode='goodsunit'
        left join ERMS2_WRSConvertDetail cd on t.deliverygoodsid = cd.deliverygoodsid and t.wrstandardid = cd.wrstandardid
        left join ERMS_MIDDLEGOODS mg on cd.middlegoodsid = mg.middlegoodsid
        left join enumdicitem mgedi on mg.goodsunitid = mgedi.enumitemname and mgedi.enumdiccode='goodsunit'
        <where>
            <if test="vo.searchcode != null and vo.searchcode != ''">
                and t.wrstandardname like '%'||#{vo.searchcode}||'%'
            </if>
            <if test="vo.isvalid != null">
                and t.isvalid = #{vo.isvalid}
            </if>
        </where>
        order by t.updatetime desc, t.wrstandardcode
    </select>
</mapper>
