InventoryMapper.xml 16.1 KB
<?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.huaheng.pc.inventory.inventory.mapper.InventoryMapper">

    <select id="getInventoryBySearchModel" resultType="com.huaheng.pc.inventory.inventory.domain.Inventory" >
        select * from inventory
        <where>
            <if test="companyIdList != null ">
                AND companyId in
                <foreach collection="companyIdList" item="companyIdItem" open="(" separator="," close=")">
                    #{companyIdItem}
                </foreach>
            </if>
            <if test="companyId != null">
                AND companyId = #{companyId}
            </if>
            <if test="companyCodeList != null ">
                AND companyCode in
                <foreach collection="companyCodeList" item="companyCodeItem" open="(" separator="," close=")">
                    #{companyCodeItem}
                </foreach>
            </if>
            <if test="companyCode != null">
                AND companyCode = #{companyCode}
            </if>
            <if test="materialCode != null">
                and  materialCode = #{materialCode}
            </if>
            <if test="locationCode != null">
                and  locationCode = #{locationCode}
            </if>
            <if test="containerCode != null">
                and  containerCode = #{containerCode}
            </if>
            <if test="beginTime != null">
                and  created > #{beginTime}
            </if>
            <if test="endTime != null">
                and  created &lt; #{endTime}
            </if>
        </where>
    </select>
    <select id="getInventryMaterialCode" resultType="java.lang.String">
        select distinct materialCode from inventory where materialCode like #{code}
    </select>

    <select id="selectListEntityByLikeLocationCode" resultType="com.huaheng.pc.inventory.inventory.domain.Inventory">
        SELECT distinct  warehouseCode, locationCode, materialCode, qty, taskQty, deleted
        FROM inventory
        <where>
            <if test="warehouseCode != null and warehouseCode != ''">
                AND warehouseCode = #{warehouseCode}
            </if>
            <if test="locationCode != null and locationCode != ''">
                <bind name="locationCodePattern" value="'%' + locationCode + '%'" />
                AND locationCode like #{locationCodePattern}
            </if>
            <if test="materialCode != null and materialCode != ''">
                <bind name="materialCodePattern" value="'%' + materialCode + '%'" />
                AND materialCode like #{materialCodePattern}
            </if>
            <if test="qty != null ">
                AND qty = #{qty}
            </if>
            <if test="taskQty != null ">
                AND taskQty = #{taskQty}
            </if>
            <if test="deleted != null ">
                AND deleted = #{deleted}
            </if>
            <if test="companyIdList != null ">
                AND companyId in
                <foreach collection="companyIdList" item="companyIdItem" open="(" separator="," close=")">
                    #{companyIdItem}
                </foreach>
            </if>
            <if test="companyId != null">
                AND companyId = #{companyId}
            </if>
            <if test="companyCodeList != null ">
                AND companyCode in
                <foreach collection="companyCodeList" item="companyCodeItem" open="(" separator="," close=")">
                    #{companyCodeItem}
                </foreach>
            </if>
            <if test="companyCode != null">
                AND companyCode = #{companyCode}
            </if>
        </where>
        GROUP BY locationCode
    </select>

    <select id="selectListEntityByLikeMaterialCode" resultType="com.huaheng.pc.inventory.inventory.domain.Inventory">
        SELECT distinct  warehouseCode, locationCode, materialCode, qty, taskQty, deleted
        FROM inventory
        <where>
            <if test="warehouseCode != null and warehouseCode != ''">
                AND warehouseCode = #{warehouseCode}
            </if>
            <if test="locationCode != null and locationCode != ''">
                <bind name="locationCodePattern" value="'%' + locationCode + '%'" />
                AND locationCode like #{locationCodePattern}
            </if>
            <if test="materialCode != null and materialCode != ''">
                <bind name="materialCodePattern" value="'%' + materialCode + '%'" />
                AND materialCode like #{materialCodePattern}
            </if>
            <if test="qty != null ">
                AND qty = #{qty}
            </if>
            <if test="taskQty != null ">
                AND taskQty = #{taskQty}
            </if>
            <if test="deleted != null ">
                AND deleted = #{deleted}
            </if>
            <if test="companyIdList != null ">
                AND companyId in
                <foreach collection="companyIdList" item="companyIdItem" open="(" separator="," close=")">
                    #{companyIdItem}
                </foreach>
            </if>
            <if test="companyId != null">
                AND companyId = #{companyId}
            </if>
            <if test="companyCodeList != null ">
                AND companyCode in
                <foreach collection="companyCodeList" item="companyCodeItem" open="(" separator="," close=")">
                    #{companyCodeItem}
                </foreach>
            </if>
            <if test="companyCode != null">
                AND companyCode = #{companyCode}
            </if>
        </where>
        GROUP BY materialCode
    </select>
    <select id="getUncompleteReceiptContainer" resultType="java.lang.Integer">
        SELECT count(*) from receipt_container_header WHERE locationCode = #{locationCode} and `status`&lt;20 and warehouseId = #{warehouseId}
    </select>
    <select id="getUncompleteShipmentContainer" resultType="java.lang.Integer">
        SELECT count(*) from shipment_container_header t join location b ON t.warehouseId = b.warehouseId and t.shipmentContainerCode = b.containerCode
        WHERE b.`code` = #{locationCode}  AND t.`status`&lt;20 and t.warehouseId = #{warehouseId}
    </select>
    <select id="searchInventoryByLike" resultType="com.huaheng.pc.inventory.inventory.domain.InventorySearch">
        SELECT  inv.*,ma.specification as 'materialSpec',ma.name as 'materialName', rh.supplierCode, ma.userDef1 as 'materialOldCode' ,ma.zoneCode
        FROM inventory inv
        INNER JOIN material ma ON inv.materialCode=ma.`code`
        LEFT JOIN receipt_header rh ON inv.receiptId=rh.id
        <where>
            <if test="id != null ">
                AND inv.id = #{id}
            </if>
            <if test="warehouseId != null ">
                AND inv.warehouseId = #{warehouseId}
            </if>
            <if test="warehouseCode != null and warehouseCode != ''">
                <bind name="warehouseCodePattern" value="'%' + warehouseCode + '%'" />
                AND inv.warehouseCode like #{warehouseCodePattern}
            </if>
            <if test="locationId != null ">
                AND inv.locationId = #{locationId}
            </if>
            <if test="locationCode != null and locationCode != ''">
                <bind name="locationCodePattern" value="locationCode" />
                AND inv.locationCode = #{locationCodePattern}
            </if>
            <if test="containerCode != null and containerCode != ''">     <!--//容器编号-->
                <bind name="containerCodePattern" value="containerCode" />
                AND inv.containerCode = #{containerCodePattern}
            </if>
            <if test="sourceCode != null and sourceCode != ''">
                <bind name="sourceCodePattern" value="'%' + sourceCode + '%'" />
                AND inv.sourceCode like #{sourceCodePattern}
            </if>
            <if test="sourceLine != null and sourceLine != ''">
                <bind name="sourceLinePattern" value="'%' + sourceLine + '%'" />
                AND inv.sourceLine like #{sourceLinePattern}
            </if>
            <if test="companyIdList != null ">
                AND inv.companyId in
                <foreach collection="companyIdList" item="companyIdItem" open="(" separator="," close=")">
                    #{companyIdItem}
                </foreach>
            </if>
            <if test="companyId != null">
                AND inv.companyId = #{companyId}
            </if>
            <if test="companyCodeList != null ">
                AND inv.companyCode in
                <foreach collection="companyCodeList" item="companyCodeItem" open="(" separator="," close=")">
                    #{companyCodeItem}
                </foreach>
            </if>
            <if test="companyCode != null">
                AND inv.companyCode = #{companyCode}
            </if>
            <if test="materialId != null ">
                AND inv.materialId = #{materialId}
            </if>
            <if test="materialCode != null and materialCode != ''">
                <bind name="materialCodePattern" value="materialCode" />
                AND inv.materialCode = #{materialCodePattern}
            </if>
            <if test="receiptId != null ">
                AND inv.receiptId = #{receiptId}
            </if>
            <if test="receiptCode != null and receiptCode != ''">
                AND inv.receiptCode = #{receiptCodePattern}
            </if>
            <if test="receiptDetailId != null ">
                AND inv.receiptDetailId = #{receiptDetailId}
            </if>
            <if test="batch != null and batch != ''">
                AND inv.batch = #{batchPattern}
            </if>
            <if test="lot != null and lot != ''">
                AND inv.lot = #{lotPattern}
            </if>
            <if test="project != null and project != ''">
                AND inv.project = #{projectPattern}
            </if>
            <if test="params != null and params.manufactureDateBegin != null and params.manufactureDateBegin != ''">
                AND inv.manufactureDate &gt;= #{params.manufactureDateBegin}
            </if>
            <if test="params != null and params.manufactureDateEnd != null and params.manufactureDateEnd != ''">
                AND inv.manufactureDate &lt;= #{params.manufactureDateEnd}
            </if>
            <if test="params != null and params.expirationDateBegin != null and params.expirationDateBegin != ''">
                AND inv.expirationDate &gt;= #{params.expirationDateBegin}
            </if>
            <if test="params != null and params.expirationDateEnd != null and params.expirationDateEnd != ''">
                AND inv.expirationDate &lt;= #{params.expirationDateEnd}
            </if>
            <if test="status != null and status != ''">
                AND inv.status = #{status}
            </if>
            <if test="qty != null ">
                AND inv.qty = #{qty}
            </if>
            <if test="taskQty != null ">
                AND inv.taskQty = #{taskQty}
            </if>
            <if test="costPrice != null ">
                AND inv.costPrice = #{costPrice}
            </if>
            <if test="listPrice != null ">
                AND inv.listPrice = #{listPrice}
            </if>
            <if test="netPrice != null ">
                AND inv.netPrice = #{netPrice}
            </if>
            <if test="params != null and params.createdBegin != null and params.createdBegin != ''">
                AND inv.created &gt;= #{params.createdBegin}
            </if>
            <if test="params != null and params.createdEnd != null and params.createdEnd != ''">
                AND inv.created &lt;= #{params.createdEnd}
            </if>
            <if test="createdBy != null and createdBy != ''">
                <bind name="createdByPattern" value="'%' + createdBy + '%'" />
                AND inv.createdBy like #{createdByPattern}
            </if>
            <if test="params != null and params.lastUpdatedBegin != null and params.lastUpdatedBegin != ''">
                AND inv.lastUpdated &gt;= #{params.lastUpdatedBegin}
            </if>
            <if test="params != null and params.lastUpdatedEnd != null and params.lastUpdatedEnd != ''">
                AND inv.lastUpdated &lt;= #{params.lastUpdatedEnd}
            </if>
            <if test="lastUpdatedBy != null and lastUpdatedBy != ''">
                <bind name="lastUpdatedByPattern" value="'%' + lastUpdatedBy + '%'" />
                AND inv.lastUpdatedBy like #{lastUpdatedByPattern}
            </if>
            <if test="userDef1 != null and userDef1 != ''">
                <bind name="userDef1Pattern" value="'%' + userDef1 + '%'" />
                AND inv.userDef1 like #{userDef1Pattern}
            </if>
            <if test="userDef2 != null and userDef2 != ''">
                <bind name="userDef2Pattern" value="'%' + userDef2 + '%'" />
                AND inv.userDef2 like #{userDef2Pattern}
            </if>
            <if test="userDef3 != null and userDef3 != ''">
                <bind name="userDef3Pattern" value="'%' + userDef3 + '%'" />
                AND inv.userDef3 like #{userDef3Pattern}
            </if>
            <if test="deleted != null ">
                AND inv.deleted = #{deleted}
            </if>
            <if test="materialOldCode != null and materialOldCode != ''">
                <bind name="materialOldCodePattern" value="'%' + materialOldCode + '%'" />
                AND ma.userDef1 like #{materialOldCodePattern}
            </if>
            <if test="materialName != null and materialName != ''">
                <bind name="materialNamePattern" value="'%' + materialName + '%'" />
                AND ma.name like #{materialNamePattern}
            </if>
            <if test="materialSpec != null and materialSpec != ''">
                <bind name="materialSpecPattern" value="'%' + materialSpec + '%'" />
                AND ma.specification like #{materialSpecPattern}
            </if>
            <if test="supplierCode != null and supplierCode != ''">
                AND rh.supplierCode = #{supplierCode}
            </if>
            <if test="zoneCode != null and zoneCode != ''">
                AND ma.zoneCode = #{zoneCode}
            </if>
        </where>
    </select>

    <select id="selectFirstInvertory" resultType="com.huaheng.pc.inventory.inventory.domain.Inventory">
        select  i.materialCode,i.containerCode,i.locationCode,i.qty from inventory i
        inner join container c on i.containerCode=c.code
        where
        i.containerCode&lt;>#{condition.receiptContainerCode} and i.materialCode=#{condition.materialCode} and c.status='some' and i.containerCode like CONCAT('%',#{code},'%')
        limit 1
    </select>

    <select id="selectList" resultType="com.huaheng.pc.inventory.inventory.domain.Inventory">
        select  i.materialCode,i.containerCode,i.locationCode,i.qty from inventory i
        inner join container c on i.containerCode=c.code
        where
        c.goodsShelfNo&lt;>#{code} and c.status='some' and i.materialCode=#{record.materialCode}
        limit 1
    </select>
    

<select id="getSumQtyByZoneId" resultType="java.math.BigDecimal">
    SELECT SUM(b.qty) FROM `location` a RIGHT JOIN `inventory` b ON a.CODE = b.locationCode WHERE a.zoneId = #{zoneid} AND b.materialCode = #{materialCode} AND a.`enable` = TRUE AND b.deleted = FALSE
</select>
    <!--<insert id="insertForeach" >-->
        <!--insert into inventory-->
        <!--( id,fund_name,fund_code,date_x,data_y,create_by,create_date,update_by,update_date,remarks,del_flag)-->
        <!--values-->
        <!--<foreach collection="list" item="item" index="index" separator=",">-->
            <!--(-->
            <!--#{item.id},-->
            <!--#{item.fundName},-->
            <!--#{item.fundCode},-->
            <!--#{item.dateX},-->
            <!--#{item.dataY},-->
            <!--#{item.createBy},-->
            <!--#{item.createDate},-->
            <!--#{item.updateBy},-->
            <!--#{item.updateDate},-->
            <!--#{item.remarks},-->
            <!--#{item.delFlag}-->
            <!--)-->
        <!--</foreach>-->
    <!--</insert>-->
    
</mapper>