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

    <resultMap type="WmsChangeapplyitem" id="WmsChangeapplyitemResult">
        <result property="changeapplyitemId" column="changeapplyitemId"/>
        <result property="changeapplyId" column="changeapplyId"/>
        <result property="goodsId" column="goodsId"/>
        <result property="warehouseId" column="warehouseId"/>
        <result property="changeapplyitemName" column="changeapplyitemName"/>
        <result property="changeapplyitemType" column="changeapplyitemType"/>
        <result property="changeapplyitemUnit" column="changeapplyitemUnit"/>
        <result property="changeapplyitemSpec" column="changeapplyitemSpec"/>
        <result property="changeapplyitemNum" column="changeapplyitemNum"/>
        <result property="changeapplyitemPriceunit" column="changeapplyitemPriceunit"/>
        <result property="changeapplyitemPricetotal" column="changeapplyitemPricetotal"/>
    </resultMap>

    <sql id="selectWmsChangeapplyitemVo">
        select changeapplyitemId, changeapplyId, goodsId,warehouseId, changeapplyitemName, changeapplyitemType,
        changeapplyitemUnit, changeapplyitemSpec, changeapplyitemNum, changeapplyitemPriceunit,
        changeapplyitemPricetotal from WmsChangeapplyitem
    </sql>

    <select id="selectWmsChangeapplyitemList" parameterType="WmsChangeapplyitem" resultMap="WmsChangeapplyitemResult">
        <include refid="selectWmsChangeapplyitemVo"/>
        <where>
            <if test="changeapplyId != null  and changeapplyId != ''">and changeapplyId = #{changeapplyId}</if>
            <if test="goodsId != null  and goodsId != ''">and goodsId = #{goodsId}</if>
            <if test="warehouseId != null and warehouseId != ''">and warehouseId =#{warehouseId}</if>
            <if test="changeapplyitemName != null  and changeapplyitemName != ''">and changeapplyitemName like
                concat('%', #{changeapplyitemName}, '%')
            </if>
            <if test="changeapplyitemType != null  and changeapplyitemType != ''">and changeapplyitemType =
                #{changeapplyitemType}
            </if>
            <if test="changeapplyitemUnit != null  and changeapplyitemUnit != ''">and changeapplyitemUnit =
                #{changeapplyitemUnit}
            </if>
            <if test="changeapplyitemSpec != null  and changeapplyitemSpec != ''">and changeapplyitemSpec =
                #{changeapplyitemSpec}
            </if>
            <if test="changeapplyitemNum != null ">and changeapplyitemNum = #{changeapplyitemNum}</if>
            <if test="changeapplyitemPriceunit != null ">and changeapplyitemPriceunit = #{changeapplyitemPriceunit}</if>
            <if test="changeapplyitemPricetotal != null ">and changeapplyitemPricetotal = #{changeapplyitemPricetotal}
            </if>
        </where>
    </select>

    <select id="selectWmsChangeapplyitemByChangeapplyitemId" parameterType="String"
            resultMap="WmsChangeapplyitemResult">
        <include refid="selectWmsChangeapplyitemVo"/>
        where changeapplyitemId = #{changeapplyitemId}
    </select>

    <insert id="insertWmsChangeapplyitem" parameterType="WmsChangeapplyitem">
        insert into WmsChangeapplyitem
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="changeapplyitemId != null">changeapplyitemId,</if>
            <if test="changeapplyId != null">changeapplyId,</if>
            <if test="goodsId != null">goodsId,</if>
            <if test="warehouseId != null">warehouseId,</if>
            <if test="changeapplyitemName != null">changeapplyitemName,</if>
            <if test="changeapplyitemType != null">changeapplyitemType,</if>
            <if test="changeapplyitemUnit != null">changeapplyitemUnit,</if>
            <if test="changeapplyitemSpec != null">changeapplyitemSpec,</if>
            <if test="changeapplyitemNum != null">changeapplyitemNum,</if>
            <if test="changeapplyitemPriceunit != null">changeapplyitemPriceunit,</if>
            <if test="changeapplyitemPricetotal != null">changeapplyitemPricetotal,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="changeapplyitemId != null">#{changeapplyitemId},</if>
            <if test="changeapplyId != null">#{changeapplyId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="changeapplyitemName != null">#{changeapplyitemName},</if>
            <if test="changeapplyitemType != null">#{changeapplyitemType},</if>
            <if test="changeapplyitemUnit != null">#{changeapplyitemUnit},</if>
            <if test="changeapplyitemSpec != null">#{changeapplyitemSpec},</if>
            <if test="changeapplyitemNum != null">#{changeapplyitemNum},</if>
            <if test="changeapplyitemPriceunit != null">#{changeapplyitemPriceunit},</if>
            <if test="changeapplyitemPricetotal != null">#{changeapplyitemPricetotal},</if>
        </trim>
    </insert>
    <insert id="insertWmsChangeapplyitemList" parameterType="WmsChangeapplyitem">
        <foreach collection="wmsChangeapplyitemList" item="item" index="index">
            insert into WmsChangeapplyitem
            (
            changeapplyitemId,
            changeapplyId,
            goodsId,
            warehouseId,
            changeapplyitemName,
            changeapplyitemType,
            changeapplyitemUnit,
            changeapplyitemSpec,
            changeapplyitemNum,
            changeapplyitemPriceunit,
            changeapplyitemPricetotal
            )
            values
            (
            #{item.changeapplyitemId},
            #{item.changeapplyId},
            #{item.goodsId},
            #{item.warehouseId},
            #{item.changeapplyitemName},
            #{item.changeapplyitemType},
            #{item.changeapplyitemUnit},
            #{item.changeapplyitemSpec},
            #{item.changeapplyitemNum},
            #{item.changeapplyitemPriceunit},
            #{item.changeapplyitemPricetotal}
            );
        </foreach>
    </insert>
    <select id="selectWmsChangeApplyDetails" parameterType="string" resultType="com.alibaba.fastjson2.JSONObject">
        SELECT
        s.userName,
        c.changeapplyApplydate,
        c.changeapplyInoutdate,
        c.changeapplyBiztype,
        c.changeapplyRemark,
        ag.assetgoodsType AS goodsType,
        g.goodsName,
        w.warehouseName,
        g.goodsUnit,
        g.goodsSpec,
        su.supplierName,
        ag.assetgoodsManufactor,
        i.changeapplyitemNum as changeNum,
        i.changeapplyitemPriceunit,
        i.changeapplyitemPricetotal
        FROM
        WmsChangeapplyitem i
        LEFT JOIN WmsWarehouse w ON w.warehouseId = i.warehouseId
        LEFT JOIN WmsChangeapply c ON c.changeapplyId = i.changeapplyId
        LEFT JOIN SysUser s ON s.userId = c.changeapplyApplyer
        LEFT JOIN WmsGoods g ON g.goodsId = i.goodsId
        LEFT JOIN WmsAssetgoods ag ON ag.goodsId = g.goodsId
        LEFT JOIN WmsSupplier su ON su.supplierId = ag.supplierId
        where i.changeapplyId = #{changeapplyId}
    </select>

    <update id="updateWmsChangeapplyitem" parameterType="WmsChangeapplyitem">
        update WmsChangeapplyitem
        <trim prefix="SET" suffixOverrides=",">
            <if test="changeapplyId != null">changeapplyId = #{changeapplyId},</if>
            <if test="goodsId != null">goodsId = #{goodsId},</if>
            <if test="warehouseId != null">warehouseId = #{warehouseId},</if>
            <if test="changeapplyitemName != null">changeapplyitemName = #{changeapplyitemName},</if>
            <if test="changeapplyitemType != null">changeapplyitemType = #{changeapplyitemType},</if>
            <if test="changeapplyitemUnit != null">changeapplyitemUnit = #{changeapplyitemUnit},</if>
            <if test="changeapplyitemSpec != null">changeapplyitemSpec = #{changeapplyitemSpec},</if>
            <if test="changeapplyitemNum != null">changeapplyitemNum = #{changeapplyitemNum},</if>
            <if test="changeapplyitemPriceunit != null">changeapplyitemPriceunit = #{changeapplyitemPriceunit},</if>
            <if test="changeapplyitemPricetotal != null">changeapplyitemPricetotal = #{changeapplyitemPricetotal},</if>
        </trim>
        where changeapplyitemId = #{changeapplyitemId}
    </update>

    <delete id="deleteWmsChangeapplyitemByChangeapplyitemId" parameterType="String">
        delete from WmsChangeapplyitem where changeapplyitemId = #{changeapplyitemId}
    </delete>

    <delete id="deleteWmsChangeapplyitemByChangeapplyitemIds" parameterType="String">
        delete from WmsChangeapplyitem where changeapplyitemId in
        <foreach item="changeapplyitemId" collection="array" open="(" separator="," close=")">
            #{changeapplyitemId}
        </foreach>
    </delete>
</mapper>