<?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.yunfeiyun.agmp.fms.mapper.WmsAssetgoodsMapper">

    <resultMap type="com.yunfeiyun.agmp.fms.domain.WmsAssetgoods" id="WmsGoodsResult">
        <result property="assetgoodsId"    column="assetgoodsId"    />
        <result property="supplierId"    column="supplierId"    />
        <result property="goodsId"    column="goodsId"    />
        <result property="assetgoodsManufactor"    column="assetgoodsManufactor"    />
        <result property="assetgoodsType"    column="assetgoodsType"    />
    </resultMap>


    <select id="selectWmsAssetgoodsVoList" parameterType="com.yunfeiyun.agmp.fms.domain.vo.WmsAssetgoodsVo" resultType="com.yunfeiyun.agmp.fms.domain.vo.WmsAssetgoodsVo">
        SELECT
        assetgoodsId,
        g.goodsId,
        goodsName,
        s.supplierId,
        assetgoodsManufactor as goodsManufactor,
        assetgoodsType as goodsType,
        goodsName,
        goodsUnit,
        goodsSpec,
        s.supplierName,
        s.supplierType
        FROM
        WmsAssetgoods ag
        LEFT JOIN WmsGoods g ON g.goodsId = ag.goodsId
        LEFT JOIN WmsSupplier s on s.supplierId = ag.supplierId
        <where>
            <if test="supplierId != null  and supplierId != ''"> and g.supplierId = #{supplierId}</if>
            <if test="goodsName != null  and goodsName != ''"> and g.goodsName like concat('%', #{goodsName}, '%')</if>
            <if test="goodsManufactor != null  and goodsManufactor != ''"> and ag.goodsManufactor = #{goodsManufactor}</if>
            <if test="goodsUnit != null  and goodsUnit != ''"> and g.goodsUnit = #{goodsUnit}</if>
            <if test="goodsSpec != null  and goodsSpec != ''"> and g.goodsSpec = #{goodsSpec}</if>
            <if test="goodsType != null  and goodsType != ''"> and ag.assetgoodsType = #{goodsType}</if>
        </where>
    </select>

    <select id="selectWmsAssetgoodsVoByGoodsId" parameterType="String" resultType="com.yunfeiyun.agmp.fms.domain.vo.WmsAssetgoodsVo">
        SELECT
        assetgoodsId,
        g.goodsId,
        goodsName
        supplierId,
        assetgoodsManufactor,
        assetgoodsType as goodsType,
        goodsName,
        goodsUnit,
        goodsSpec
        FROM
        WmsAssetgoods ag
        LEFT JOIN WmsGoods g ON g.goodsId = ag.goodsId
        where g.goodsId = #{goodsId}
    </select>

    <insert id="insertWmsAssetgoods" parameterType="com.yunfeiyun.agmp.fms.domain.WmsAssetgoods">
        insert into WmsAssetgoods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assetgoodsId != null">assetgoodsId,</if>
            <if test="goodsId != null">goodsId,</if>
            <if test="supplierId != null">supplierId,</if>
            <if test="assetgoodsManufactor != null">assetgoodsManufactor,</if>
            <if test="assetgoodsType != null">assetgoodsType,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="assetgoodsId != null">#{assetgoodsId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="supplierId != null">#{supplierId},</if>
            <if test="assetgoodsManufactor != null">#{assetgoodsManufactor},</if>
            <if test="assetgoodsType != null">#{assetgoodsType},</if>
        </trim>
    </insert>

    <update id="updateWmsAssetgoods" parameterType="com.yunfeiyun.agmp.fms.domain.WmsAssetgoods">
        update WmsAssetgoods
        <trim prefix="SET" suffixOverrides=",">
            <if test="supplierId != null">supplierId = #{supplierId},</if>
            <if test="assetgoodsManufactor != null">assetgoodsManufactor = #{assetgoodsManufactor},</if>
            <if test="assetgoodsType != null ">  assetgoodsType = #{assetgoodsType}</if>
        </trim>
        where assetgoodsId = #{assetgoodsId}
    </update>

    <delete id="deleteWmsAssetgoodsByGoodsId" parameterType="String">
        delete from WmsAssetgoods where assetgoodsId = #{assetgoodsId}
    </delete>

    <delete id="deleteWmsAssetgoodsByGoodsIds" parameterType="String">
        delete from WmsAssetgoods where assetgoodsId in
        <foreach item="assetgoodsId" collection="array" open="(" separator="," close=")">
            #{assetgoodsId}
        </foreach>
    </delete>

</mapper>