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

    <resultMap type="com.yunfeiyun.agmp.fms.domain.WmsChangeapply" id="WmsChangeapplyResult">
        <result property="changeapplyId"    column="changeapplyId"    />
        <result property="changeapplyWay"    column="changeapplyWay"    />
        <result property="changeapplyBiztype"    column="changeapplyBiztype"    />
        <result property="changeapplyPricetotal"    column="changeapplyPricetotal"    />
        <result property="changeapplyApplyer"    column="changeapplyApplyer"    />
        <result property="changeapplyApplydate"    column="changeapplyApplydate"    />
        <result property="changeapplyAuditor" column="changeapplyAuditor"/>
        <result property="changeapplyAuditstatus"    column="changeapplyAuditstatus"    />
        <result property="changeapplyAuditdate"    column="changeapplyAuditdate"    />
        <result property="changeapplyRemark"    column="changeapplyRemark"    />
        <result property="changeapplyInoutdate" column="changeapplyInoutdate"/>
        <result property="changeapplyComments" column="changeapplyComments"/>
    </resultMap>
    <resultMap type="com.yunfeiyun.agmp.fms.domain.resvo.WmsChangeApplyGoodsListResVo" id="WmsChangeApplyListResVo">
        <result column="changeapplyId" property="changeapplyId"/>
        <result column="goodsName" property="goodsName"/>
        <result column="goodsType" property="goodsType"/>
        <result column="warehouseName" property="warehouseName"/>
        <result column="changeapplyitemNum" property="changeapplyitemNum"/>
        <result column="changeapplyitemUnit" property="changeapplyitemUnit"/>
        <result column="changeapplyitemSpec" property="changeapplyitemSpec"/>
        <result column="userName" property="userName"/>
        <result column="changeapplyApplyer" property="changeapplyApplyer"/>
        <result column="changeapplyApplydate" property="changeapplyApplydate"/>
        <result column="changeapplyAuditstatus" property="changeapplyAuditstatus"/>
        <result property="changeapplyComments" column="changeapplyComments"/>
    </resultMap>

    <sql id="selectWmsChangeapplyVo">
        select changeapplyId, changeapplyWay, changeapplyBiztype, changeapplyPricetotal, changeapplyApplyer, changeapplyApplydate,changeapplyAuditor, changeapplyAuditstatus, changeapplyAuditdate, changeapplyRemark, changeapplyInoutdate, changeapplyComments from WmsChangeapply
    </sql>

    <select id="selectWmsChangeapplyList" parameterType="com.yunfeiyun.agmp.fms.domain.WmsChangeapply" resultMap="WmsChangeapplyResult">
        <include refid="selectWmsChangeapplyVo"/>
        <where>
            <if test="changeapplyWay != null  and changeapplyWay != ''"> and changeapplyWay = #{changeapplyWay}</if>
            <if test="changeapplyBiztype != null  and changeapplyBiztype != ''"> and changeapplyBiztype = #{changeapplyBiztype}</if>
            <if test="changeapplyPricetotal != null "> and changeapplyPricetotal = #{changeapplyPricetotal}</if>
            <if test="changeapplyApplyer != null  and changeapplyApplyer != ''"> and changeapplyApplyer = #{changeapplyApplyer}</if>
            <if test="changeapplyApplydate != null  and changeapplyApplydate != ''"> and changeapplyApplydate = #{changeapplyApplydate}</if>
            <if test="changeapplyAuditor != null and changeapplyAuditor !=''">and changeapplyAuditor =#{changeapplyAuditor}</if>
            <if test="changeapplyAuditstatus != null  and changeapplyAuditstatus != ''"> and changeapplyAuditstatus = #{changeapplyAuditstatus}</if>
            <if test="changeapplyAuditdate != null  and changeapplyAuditdate != ''"> and changeapplyAuditdate = #{changeapplyAuditdate}</if>
            <if test="changeapplyRemark != null  and changeapplyRemark != ''"> and changeapplyRemark = #{changeapplyRemark}</if>
            <if test="changeapplyInoutdate != null and changeapplyInoutdate != ''">and changeapplyInoutdate = #{changeapplyInoutdate}</if>
        </where>
    </select>
    <select id="selectWmsChangeApplyGoodsListResVoList" parameterType="com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeApplyGoodsListReqVo" resultType="com.yunfeiyun.agmp.fms.domain.resvo.WmsChangeApplyGoodsListResVo">
        SELECT
        c.changeapplyId,
        g.goodsId,
        g.goodsName,
        ag.assetgoodsType as goodsType,
        w.warehouseId,
        w.warehouseName,
        i.changeapplyitemNum,
        i.changeapplyitemUnit,
        i.changeapplyitemSpec,
        u.userName,
        c.changeapplyApplyer,
        c.changeapplyApplydate,
        c.changeapplyAuditstatus,
        c.changeapplyComments,
        c.changeapplyRemark,
        wc.changeOldnum
        FROM
        WmsChangeapply c
        LEFT JOIN SysUser u ON u.userId = c.changeapplyApplyer
        LEFT JOIN WmsChangeapplyitem i ON i.changeapplyId = c.changeapplyId
        LEFT JOIN WmsAssetgoods ag on ag.goodsId = i.goodsId
        LEFT JOIN WmsGoods g ON g.goodsId = ag.goodsId
        LEFT JOIN WmsWarehouse w ON w.warehouseId = i.warehouseId
        LEFT JOIN WmsChange wc on wc.changeapplyId = c.changeapplyId
        <where>
            <if test="changeapplyAuditstatus != null  and changeapplyAuditstatus != ''"> and c.changeapplyAuditstatus = #{changeapplyAuditstatus}</if>
            <if test="changeapplyApplyer != null  and changeapplyApplyer != ''"> and c.changeapplyApplyer = #{changeapplyApplyer}</if>
            <if test="warehouseId != null  and warehouseId != ''"> and w.warehouseId = #{warehouseId}</if>
            <if test="goodsType != null and goodsType != ''"> and ag.assetGoodsType = #{goodsType}</if>
            <if test="changeapplyApplydatestart != null  and changeapplyApplydatestart != '' and changeapplyApplydateend != null and changeapplyApplydateend != ''"> and c.changeapplyApplydate between #{changeapplyApplydatestart} and #{changeapplyApplydateend}</if>
            <if test="changeapplyBiztype != null and changeapplyBiztype != ''">and c.changeapplyBiztype = #{changeapplyBiztype}</if>
            <if test="warehouseType != null and warehouseType !=''">and w.warehouseType = #{warehouseType}</if>
        </where>
    </select>

    <select id="selectWmsChangeApplyListResVoList" parameterType="com.yunfeiyun.agmp.fms.domain.reqvo.WmsChangeApplyListReqVo" resultType="com.yunfeiyun.agmp.fms.domain.resvo.WmsChangeApplyListResVo">
        SELECT
        c.changeapplyId,
        c.changeapplyBiztype,
        s.userName,
        c.changeapplyApplyer,
        c.changeapplyInoutdate,
        c.changeapplyApplydate,
        c.changeapplyWay
        FROM
        WmsChangeapplyitem i
        LEFT JOIN WmsChangeapply c on c.changeapplyId = i.changeapplyId
        LEFT JOIN SysUser s on s.userId = c.changeapplyApplyer
        LEFT JOIn WmsAssetgoods ag on ag.goodsId = i.goodsId
        LEFT JOIN WmsWarehouse w on w.warehouseId = i.warehouseId
        <where>
            c.changeapplyBiztype not in ('IN_2','OUT_1')
            <if test="changeWay != null and changeWay != ''"> and c.changeapplyBiztype like CONCAT(#{changeWay},"%")</if>
            <if test="warehouseId != null and warehouseId != ''"> and i.warehouseId = #{warehouseId}</if>
            <if test="goodsType != null and goodsType != ''"> and ag.assetgoodsType = #{goodsType} </if>
            <if test="changeDateStart != null and changeDateStart != '' and changeDateEnd != null and changeDateEnd != ''"> and c.changeapplyInoutdate between #{changeDateStart} and #{changeDateEnd}</if>
            <if test="warehouseType != null and warehouseType != ''">and w.warehouseType = #{warehouseType}</if>
        </where>
        GROUP BY c.changeapplyId
    </select>
    
    <select id="selectWmsChangeapplyByChangeapplyId" parameterType="String" resultMap="WmsChangeapplyResult">
        <include refid="selectWmsChangeapplyVo"/>
        where changeapplyId = #{changeapplyId}
    </select>
        
    <insert id="insertWmsChangeapply" parameterType="com.yunfeiyun.agmp.fms.domain.WmsChangeapply">
        insert into WmsChangeapply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="changeapplyId != null">changeapplyId,</if>
            <if test="changeapplyWay != null">changeapplyWay,</if>
            <if test="changeapplyBiztype != null">changeapplyBiztype,</if>
            <if test="changeapplyPricetotal != null">changeapplyPricetotal,</if>
            <if test="changeapplyApplyer != null">changeapplyApplyer,</if>
            <if test="changeapplyApplydate != null">changeapplyApplydate,</if>
            <if test="changeapplyAuditor != null">changeapplyAuditor,</if>
            <if test="changeapplyAuditstatus != null">changeapplyAuditstatus,</if>
            <if test="changeapplyAuditdate != null">changeapplyAuditdate,</if>
            <if test="changeapplyRemark != null">changeapplyRemark,</if>
            <if test="changeapplyInoutdate != null">changeapplyInoutdate,</if>
            <if test="changeapplyComments != null">changeapplyComments,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="changeapplyId != null">#{changeapplyId},</if>
            <if test="changeapplyWay != null">#{changeapplyWay},</if>
            <if test="changeapplyBiztype != null">#{changeapplyBiztype},</if>
            <if test="changeapplyPricetotal != null">#{changeapplyPricetotal},</if>
            <if test="changeapplyApplyer != null">#{changeapplyApplyer},</if>
            <if test="changeapplyApplydate != null">#{changeapplyApplydate},</if>
            <if test="changeapplyAuditor !=null">#{changeapplyAuditor},</if>
            <if test="changeapplyAuditstatus != null">#{changeapplyAuditstatus},</if>
            <if test="changeapplyAuditdate != null">#{changeapplyAuditdate},</if>
            <if test="changeapplyRemark != null">#{changeapplyRemark},</if>
            <if test="changeapplyInoutdate != null">#{changeapplyInoutdate}, </if>
            <if test="changeapplyComments != null">#{changeapplyComments}, </if>
         </trim>
    </insert>

    <update id="updateWmsChangeapply" parameterType="com.yunfeiyun.agmp.fms.domain.WmsChangeapply">
        update WmsChangeapply
        <trim prefix="SET" suffixOverrides=",">
            <if test="changeapplyWay != null">changeapplyWay = #{changeapplyWay},</if>
            <if test="changeapplyBiztype != null">changeapplyBiztype = #{changeapplyBiztype},</if>
            <if test="changeapplyPricetotal != null">changeapplyPricetotal = #{changeapplyPricetotal},</if>
            <if test="changeapplyApplyer != null">changeapplyApplyer = #{changeapplyApplyer},</if>
            <if test="changeapplyAuditor !=null">changeapplyAuditor =#{changeapplyAuditor},</if>
            <if test="changeapplyApplydate != null">changeapplyApplydate = #{changeapplyApplydate},</if>
            <if test="changeapplyAuditstatus != null">changeapplyAuditstatus = #{changeapplyAuditstatus},</if>
            <if test="changeapplyAuditdate != null">changeapplyAuditdate = #{changeapplyAuditdate},</if>
            <if test="changeapplyRemark != null">changeapplyRemark = #{changeapplyRemark},</if>
            <if test="changeapplyInoutdate != null">changeapplyInoutdate = #{changeapplyInoutdate},</if>
            <if test="changeapplyComments != null">changeapplyComments = #{changeapplyComments},</if>
        </trim>
        where changeapplyId = #{changeapplyId}
    </update>

    <delete id="deleteWmsChangeapplyByChangeapplyId" parameterType="String">
        delete from WmsChangeapply where changeapplyId = #{changeapplyId}
    </delete>

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