<?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.bonus.canteen.core.drp.mapper.DrpOutInventoryMapper">

    <!-- 分页获取出库记录列表 -->
<!--    <select id="selectAllList" resultType="net.xnzn.core.drp.vo.DrpOutInventoryPageVO">-->
<!--        SELECT-->
<!--        doi.out_id,-->
<!--        doi.warehouse_id,-->
<!--        dw.warehouse_name,-->
<!--        doi.out_date,-->
<!--        doi.total_amount,-->
<!--        doi.total_num,-->
<!--        doi.fetch_user_id,-->
<!--        IF-->
<!--        ( mu.real_name IS NULL OR mu.real_name = '', mu.username, mu.real_name ) fetchUserName,-->
<!--        doi.out_type outType,-->
<!--        doi.STATUS,-->
<!--        doi.remark,-->
<!--        doi.crby,-->
<!--        doi.crtime,-->
<!--        doi.upby,-->
<!--        doi.uptime,-->
<!--        dw.area_id,-->
<!--        aa.area_name,-->
<!--        doi.fetch_material_id-->
<!--        FROM-->
<!--        drp_out_inventory doi-->
<!--        LEFT JOIN drp_warehouse dw ON doi.warehouse_id = dw.warehouse_id-->
<!--        LEFT JOIN mgr_user mu ON doi.fetch_user_id = mu.user_id-->
<!--        left join alloc_area aa on aa.area_id = dw.area_id-->
<!--        where-->
<!--        doi.del_flag = #{delFlag}-->
<!--        <if test="content.outId != null">-->
<!--            and doi.out_id = #{content.outId}-->
<!--        </if>-->
<!--        <if test="content.startTime != null">-->
<!--            and doi.out_date <![CDATA[ >= ]]> #{content.startTime}-->
<!--        </if>-->
<!--        <if test="content.endTime != null">-->
<!--            and doi.out_date <![CDATA[ <= ]]> #{content.endTime}-->
<!--        </if>-->
<!--        <if test="content.fetchUserId != null ">-->
<!--            and doi.fetch_user_id = #{content.fetchUserId}-->
<!--        </if>-->
<!--        <if test="content.status != null ">-->
<!--            and doi.status = #{content.status}-->
<!--        </if>-->
<!--        <if test="content.outType != null ">-->
<!--            and doi.out_type = #{content.outType}-->
<!--        </if>-->
<!--        <if test="warehouseAuthority != null and warehouseAuthority.size() > 0">-->
<!--            and dw.warehouse_id in-->
<!--            <foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">-->
<!--                #{warehouseId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="areaAuth != null and areaAuth.size() > 0">-->
<!--            and dw.area_id in-->
<!--            <foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">-->
<!--                #{areaId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--            AND dw.area_id in-->
<!--            <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="content.warehouseIdList != null and content.warehouseIdList.size() > 0">-->
<!--            AND dw.warehouse_id in-->
<!--            <foreach collection="content.warehouseIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        order by-->
<!--        doi.uptime desc-->
<!--    </select>-->

<!--    &lt;!&ndash; 分页获取出库记录列表(安卓) &ndash;&gt;-->
<!--    <select id="selectOutAllList" resultType="net.xnzn.core.drp.vo.AndroidOutInventoryPageVO">-->
<!--        select-->
<!--        doi.out_id outId,-->
<!--        doi.warehouse_id warehouseId,-->
<!--        dw.warehouse_name warehouseName,-->
<!--        doi.out_date outDate,-->
<!--        doi.fetch_user_id fetchUserId,-->
<!--        doi.total_num totalNum,-->
<!--        doi.total_amount totalAmount,-->
<!--        if(mu.real_name is null or mu.real_name = '', mu.username, mu.real_name) fetchUserName,-->
<!--        doi.out_type outType,-->
<!--        doi.status,-->
<!--        doi.remark,-->
<!--        doi.crby,-->
<!--        doi.crtime,-->
<!--        doi.upby,-->
<!--        doi.uptime,-->
<!--        doi.fetch_material_id-->
<!--        from-->
<!--        drp_out_inventory doi-->
<!--        left join drp_warehouse dw on doi.warehouse_id = dw.warehouse_id-->
<!--        left join mgr_user mu on doi.fetch_user_id = mu.user_id-->
<!--        where-->
<!--        doi.del_flag = #{delFlag}-->
<!--        <if test="content.outId != null">-->
<!--            and doi.out_id = #{content.outId}-->
<!--        </if>-->
<!--        <if test="content.warehouseId != null">-->
<!--            and doi.warehouse_id = #{content.warehouseId}-->
<!--        </if>-->
<!--        <if test="content.startTime != null">-->
<!--            and doi.out_date <![CDATA[ >= ]]> #{content.startTime}-->
<!--        </if>-->
<!--        <if test="content.endTime != null">-->
<!--            and doi.out_date <![CDATA[ <= ]]> #{content.endTime}-->
<!--        </if>-->
<!--        <if test="content.fetchUserId != null ">-->
<!--            and doi.fetch_user_id = #{content.fetchUserId}-->
<!--        </if>-->
<!--        <if test="content.outType != null ">-->
<!--            and doi.out_type = #{content.outType}-->
<!--        </if>-->
<!--        <if test="content.status != null ">-->
<!--            and doi.status = #{content.status}-->
<!--        </if>-->
<!--        <if test="warehouseAuthority != null and warehouseAuthority.size() > 0">-->
<!--            and dw.warehouse_id in-->
<!--            <foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">-->
<!--                #{warehouseId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        order by-->
<!--        doi.uptime desc,doi.out_date desc-->
<!--    </select>-->

<!--    <select id="selectExcelOutTable" resultType="net.xnzn.core.drp.vo.DrpExcelOutVO">-->
<!--        SELECT-->
<!--        a.out_id,-->
<!--        b.warehouse_name,-->
<!--        a.out_date,-->
<!--        a.total_amount neTotalAmount,-->
<!--        a.total_num,-->
<!--        a.out_type,-->
<!--        if(c.real_name is null or c.real_name = '', c.username, c.real_name) fetchUserName,-->
<!--        a.remark,-->
<!--        a.`status`,-->
<!--        a.crby,-->
<!--        aa.area_name-->
<!--        FROM-->
<!--        drp_out_inventory a-->
<!--        LEFT JOIN drp_warehouse b ON a.warehouse_id = b.warehouse_id-->
<!--        LEFT JOIN mgr_user c ON a.fetch_user_id = c.user_id-->
<!--        left join alloc_area aa on aa.area_id = b.area_id-->
<!--        where-->
<!--        a.out_id = #{outId}-->
<!--    </select>-->
    <select id="getWarehouseByOutId" resultType="com.bonus.canteen.core.supermarket.po.WarehouseModel">
        SELECT
            a.warehouse_id,
            b.warehouse_name
        FROM
            drp_out_inventory a
            LEFT JOIN drp_warehouse b ON a.warehouse_id = b.warehouse_id
        WHERE
            out_id = #{outId}
    </select>
<!--    <select id="selectOutInventoryListSum" resultType="net.xnzn.core.drp.vo.DrpOutInventoryPageVO">-->
<!--        SELECT-->
<!--            sum( doi.total_amount ) totalAmount,-->
<!--            sum( doi.total_num ) totalNum-->
<!--        FROM-->
<!--            drp_out_inventory doi-->
<!--            LEFT JOIN drp_warehouse dw ON doi.warehouse_id = dw.warehouse_id-->
<!--            LEFT JOIN mgr_user mu ON doi.fetch_user_id = mu.user_id-->
<!--            left join alloc_area aa on aa.area_id = dw.area_id-->
<!--        where-->
<!--            doi.del_flag = #{delFlag}-->
<!--            <if test="content.outId != null">-->
<!--                and doi.out_id = #{content.outId}-->
<!--            </if>-->
<!--            <if test="content.startTime != null">-->
<!--                and doi.out_date <![CDATA[ >= ]]> #{content.startTime}-->
<!--            </if>-->
<!--            <if test="content.endTime != null">-->
<!--                and doi.out_date <![CDATA[ <= ]]> #{content.endTime}-->
<!--            </if>-->
<!--            <if test="content.fetchUserId != null ">-->
<!--                and doi.fetch_user_id = #{content.fetchUserId}-->
<!--            </if>-->
<!--            <if test="content.status != null ">-->
<!--                and doi.status = #{content.status}-->
<!--            </if>-->
<!--            <if test="content.outType != null ">-->
<!--                and doi.out_type = #{content.outType}-->
<!--            </if>-->
<!--            <if test="warehouseAuthority != null and warehouseAuthority.size() > 0">-->
<!--                and dw.warehouse_id in-->
<!--                <foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">-->
<!--                    #{warehouseId}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="areaAuth != null and areaAuth.size() > 0">-->
<!--                and dw.area_id in-->
<!--                <foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">-->
<!--                    #{areaId}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--                AND dw.area_id in-->
<!--                <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="content.warehouseIdList != null and content.warehouseIdList.size() > 0">-->
<!--                AND dw.warehouse_id in-->
<!--                <foreach collection="content.warehouseIdList" item="item" separator="," open="(" close=")">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--    </select>-->

<!--    <select id="listOutInventoryInfo" resultType="net.xnzn.core.drp.vo.OpenDrpOutInventoryListVO">-->
<!--        SELECT-->
<!--        a.out_id,-->
<!--        a.warehouse_id,-->
<!--        b.warehouse_name,-->
<!--        a.out_date,-->
<!--        a.total_amount,-->
<!--        a.fetch_user_id,-->
<!--        c.real_name fetchUserName,-->
<!--        a.out_type,-->
<!--        a.`status`,-->
<!--        a.remark-->
<!--        FROM-->
<!--        drp_out_inventory a-->
<!--        LEFT JOIN drp_warehouse b ON a.warehouse_id = b.warehouse_id-->
<!--        LEFT JOIN mgr_user c ON c.user_id = a.fetch_user_id-->
<!--        WHERE a.out_date <![CDATA[ >= ]]> #{content.startTime}-->
<!--        AND a.out_date <![CDATA[ <= ]]> #{content.endTime}-->
<!--        <if test="content.outId != null and content.outId != ''">-->
<!--            AND a.out_id = #{content.outId}-->
<!--        </if>-->
<!--        <if test="content.warehouseName != null and content.warehouseName != ''">-->
<!--            AND b.warehouse_name = #{content.warehouseName}-->
<!--        </if>-->
<!--        <if test="content.outType != null">-->
<!--            AND a.out_type = #{content.outType}-->
<!--        </if>-->
<!--        <if test="content.status != null">-->
<!--            AND a.`status` = #{content.status}-->
<!--        </if>-->
<!--    </select>-->
<!--    <select id="pageOutInventory" resultType="net.xnzn.core.drp.vo.DrpOutInventoryPageV2VO">-->
<!--        SELECT-->
<!--            a.out_id,-->
<!--            a.warehouse_id,-->
<!--            b.warehouse_name,-->
<!--            a.out_date,-->
<!--            a.total_num,-->
<!--            a.total_amount,-->
<!--            a.fetch_user_id,-->
<!--            c.real_name fetchUserName,-->
<!--            a.out_type,-->
<!--            a.`status`,-->
<!--            a.remark,-->
<!--            a.crby,-->
<!--            a.crtime,-->
<!--            a.upby,-->
<!--            a.uptime,-->
<!--            b.area_id,-->
<!--            aa.area_name-->
<!--        FROM-->
<!--            drp_out_inventory a-->
<!--            LEFT JOIN drp_warehouse b ON b.warehouse_id = a.warehouse_id-->
<!--            LEFT JOIN mgr_user c ON c.user_id = a.fetch_user_id-->
<!--            left join alloc_area aa on aa.area_id = b.area_id-->
<!--        where-->
<!--            a.del_flag = #{delFlag}-->
<!--        <if test="content.outId != null and content.outId != ''">-->
<!--            and a.out_id like CONCAT('%',#{content.outId},'%')-->
<!--        </if>-->
<!--        <if test="content.warehouseId != null">-->
<!--            and a.warehouse_id = #{content.warehouseId}-->
<!--        </if>-->
<!--        <if test="content.startTime != null">-->
<!--            and a.out_date <![CDATA[ >= ]]> #{content.startTime}-->
<!--        </if>-->
<!--        <if test="content.endTime != null">-->
<!--            and a.out_date <![CDATA[ <= ]]> #{content.endTime}-->
<!--        </if>-->
<!--        <if test="content.fetchUserId != null ">-->
<!--            and a.fetch_user_id = #{content.fetchUserId}-->
<!--        </if>-->
<!--        <if test="content.status != null ">-->
<!--            and a.status = #{content.status}-->
<!--        </if>-->
<!--        <if test="content.outType != null ">-->
<!--            and a.out_type = #{content.outType}-->
<!--        </if>-->
<!--        <if test="warehouseAuthority != null and warehouseAuthority.size() > 0">-->
<!--            and a.warehouse_id in-->
<!--            <foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">-->
<!--                #{warehouseId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="content.areaAuth != null and content.areaAuth.size() > 0">-->
<!--            and aa.area_id in-->
<!--            <foreach collection="content.areaAuth" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        order by-->
<!--        a.crtime desc-->
<!--    </select>-->
<!--    <select id="pageOutInventorySum" resultType="net.xnzn.core.drp.vo.DrpOutInventoryPageV2VO">-->
<!--        SELECT-->
<!--            '合计' AS outId,-->
<!--            sum( a.total_num ) totalNum,-->
<!--            sum( a.total_amount ) totalAmount-->
<!--        FROM-->
<!--            drp_out_inventory a-->
<!--            LEFT JOIN drp_warehouse b ON b.warehouse_id = a.warehouse_id-->
<!--            LEFT JOIN mgr_user c ON c.user_id = a.fetch_user_id-->
<!--            left join alloc_area aa on aa.area_id = b.area_id-->
<!--        where-->
<!--        a.del_flag = #{delFlag}-->
<!--        <if test="content.outId != null and content.outId != ''">-->
<!--            and a.out_id like CONCAT('%',#{content.outId},'%')-->
<!--        </if>-->
<!--        <if test="content.warehouseId != null">-->
<!--            and a.warehouse_id = #{content.warehouseId}-->
<!--        </if>-->
<!--        <if test="content.startTime != null">-->
<!--            and a.out_date <![CDATA[ >= ]]> #{content.startTime}-->
<!--        </if>-->
<!--        <if test="content.endTime != null">-->
<!--            and a.out_date <![CDATA[ <= ]]> #{content.endTime}-->
<!--        </if>-->
<!--        <if test="content.fetchUserId != null ">-->
<!--            and a.fetch_user_id = #{content.fetchUserId}-->
<!--        </if>-->
<!--        <if test="content.status != null ">-->
<!--            and a.status = #{content.status}-->
<!--        </if>-->
<!--        <if test="content.outType != null ">-->
<!--            and a.out_type = #{content.outType}-->
<!--        </if>-->
<!--        <if test="warehouseAuthority != null and warehouseAuthority.size() > 0">-->
<!--            and a.warehouse_id in-->
<!--            <foreach collection="warehouseAuthority" item="warehouseId" separator="," open="(" close=")">-->
<!--                #{warehouseId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="content.areaAuth != null and content.areaAuth.size() > 0">-->
<!--            and aa.area_id in-->
<!--            <foreach collection="content.areaAuth" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        order by-->
<!--        a.crtime desc-->
<!--    </select>-->
<!--  <select id="queryTotal" resultType="net.xnzn.core.drp.vo.DrpOutInventoryTotalVO">-->
<!--      SELECT-->
<!--          (SELECT COUNT(*) FROM drp_out_inventory WHERE DATE(crtime) = CURDATE() AND status = 2) AS 'today',-->
<!--          (SELECT COUNT(*) FROM drp_out_inventory WHERE status = 2) AS 'total',-->
<!--          (SELECT COALESCE(SUM(total_amount), '0.00') FROM drp_out_inventory WHERE status = 2) AS 'amount';-->
<!--  </select>-->

<!--    <select id="queryTotal" resultType="net.xnzn.core.drp.vo.DrpOutInventoryTotalVO" databaseId="kb">-->
<!--        SELECT-->
<!--            (SELECT COUNT(*) FROM drp_out_inventory WHERE crtime::date = CURRENT_DATE AND status = 2) AS "today",-->
<!--            (SELECT COUNT(*) FROM drp_out_inventory WHERE status = 2) AS "total",-->
<!--            (SELECT COALESCE(SUM(total_amount), '0.00') FROM drp_out_inventory WHERE status = 2) AS "amount";-->
<!--    </select>-->
</mapper>




