<?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="org.jeecg.modules.fbsInventory.mapper.FbsInventoryMapper">
    <select id="getInventoryGetByOrderId" resultType="org.jeecg.modules.fbsInventory.entity.FbsInventory" >
        SELECT
        i.cInvDefine13,i.cInvCode as cinvcode,i.cInvName as cinvname,m.CostItemName,Convert(decimal(18,2),m.Qty) as qty,m.SortSeq as sortSeq
        FROM
        mom_orderdetail m
        LEFT JOIN Inventory i ON m.InvCode = i.cInvCode
        WHERE
        m.MoId = #{moId}
    </select>

    <select id="getStockList" resultType="java.util.HashMap">

        select top 20 a.iQuantity realStockSum,b.iSafeNum safeStockSum ,b.cInvCode materialCode,b.cInvName materialName,cInvStd specs from

        (select cInvCode,sum(iQuantity) as iQuantity  from CurrentStock group by cInvCode) a

        left join Inventory b on a.cInvCode = b.cInvCode
        where b.iSafeNum is not null

    </select>

    <select id="getAllStockList" resultType="java.util.HashMap">

        select a.iQuantity realStockSum,b.cInvName materialName,b.cInvCode cInvCode from
        (select cInvCode,sum(iQuantity) as iQuantity  from CurrentStock group by cInvCode) a
        left join Inventory b on a.cInvCode = b.cInvCode
        where b.cInvCCode='0101' and a.iQuantity>0
       <!-- SELECT
          cInvName materialName,
          SUM ( iSafeNum ) realStockSum
        FROM
          Inventory
        where cInvCCode='0101'
        GROUP BY
          cInvCode,
          cInvName -->

    </select>

    <select id="getByInvCode" resultType="java.lang.String">
        select cInvDefine13 from Inventory where cInvCode=#{invCode}
    </select>

    <update id="updateCInvDefine13">
        UPDATE Inventory
            set cInvDefine13=#{standardWorkingHoursZ}
        where
            cInvCode=#{invCode}
    </update>

    <select id="getDrawingCode" resultType="org.jeecg.modules.fbsInventory.entity.FbsInventory">
        SELECT
            i.cInvCode,
            i.cInvDefine6
        FROM
            bom_opcomponent bop
            LEFT JOIN bas_part basp ON bop.ComponentId = basp.PartId
            LEFT JOIN Inventory i ON basp.InvCode = i.cInvCode
            left join mom_orderdetail momo on momo.BomId=bop.BomId
            left join mom_order mo ON mo.MoId = momo.MoId
        WHERE
            mo.MoCode = #{moCode}
            AND i.cInvCCode = '020206'
    </select>

    <select id="getInventory" resultType="org.jeecg.modules.fbsInventory.entity.FbsInventory">
        select * from Inventory where cInvCode=#{cInvCode}
    </select>

</mapper>