<?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.supply.purchase.mapper.DrpWarehouseMapper">

<!--    &lt;!&ndash; 分页获取仓库信息 &ndash;&gt;-->
<!--    <select id="selectAllList" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpWarehousePageVO">-->
<!--        select-->
<!--        dw.warehouse_id ,-->
<!--        dw.warehouse_num ,-->
<!--        dw.warehouse_name ,-->
<!--        dw.user_id ,-->
<!--        mu.username,-->
<!--        mu.real_name ,-->
<!--        mu.phone,-->
<!--        dw.region_province,-->
<!--        dw.region_city,-->
<!--        dw.region_district,-->
<!--        dw.address,-->
<!--        dw.type_id,-->
<!--        dwt.type_name,-->
<!--        dw.status,-->
<!--        dw.crby,-->
<!--        dw.crtime,-->
<!--        dw.upby,-->
<!--        dw.uptime,-->
<!--        dw.warehouse_type,-->
<!--        dw.area_id,-->
<!--        aa.area_name,-->
<!--        dw.parent_id,-->
<!--        dw.canteen_id,-->
<!--        ac.canteen_name,-->
<!--        dw.fetch_user_id,-->
<!--        if(mu2.real_name is null or mu2.real_name = '', mu2.username, mu2.real_name) fetchUserName-->
<!--        from-->
<!--        drp_warehouse dw-->
<!--        left join mgr_user mu on mu.user_id = dw.user_id-->
<!--        left join drp_warehouse_type dwt on dwt.type_id = dw.type_id-->
<!--        left join alloc_area aa on aa.area_id = dw.area_id-->
<!--        left join alloc_canteen ac on ac.canteen_id = dw.canteen_id-->
<!--        left join mgr_user mu2 on mu2.user_id = dw.fetch_user_id-->
<!--        where-->
<!--        dw.del_flag = #{delFlag}-->
<!--        <if test="content.warehouseName != null and content.warehouseName != ''">-->
<!--            and dw.warehouse_name like #{content.warehouseName}-->
<!--        </if>-->
<!--        <if test="content.warehouseType != null ">-->
<!--            and dw.warehouse_type like #{content.warehouseType}-->
<!--        </if>-->
<!--        <if test="content.realName != null and content.realName != ''">-->
<!--            and mu.real_name = #{content.realName,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--        </if>-->
<!--        <if test="content.status != null ">-->
<!--            and dw.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>-->
<!--        <if test="content.typeId != null ">-->
<!--            and dw.type_id = #{content.typeId}-->
<!--        </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>-->
<!--        <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.parentId != null ">-->
<!--            <if test="content.parentId == -1 ">-->
<!--                and dw.parent_id is null-->
<!--            </if>-->
<!--            <if test="content.parentId != -1 ">-->
<!--                and (dw.parent_id = #{content.parentId} or dw.warehouse_id = #{content.parentId} )-->
<!--            </if>-->
<!--        </if>-->

<!--        <if test="content.canteenId != null ">-->
<!--            and dw.canteen_id = #{content.canteenId}-->
<!--        </if>-->
<!--        order by-->
<!--        dw.crtime desc-->
<!--    </select>-->
<!--    <select id="selectAllWareHouse" resultType="net.xnzn.core.drp.vo.DrpWarehouseAllVO">-->
<!--        SELECT-->
<!--            a.warehouse_id,-->
<!--            a.warehouse_name,-->
<!--            a.warehouse_num,-->
<!--            a.address,-->
<!--            a.fetch_user_id,-->
<!--            IF( mu.real_name IS NULL OR mu.real_name = '', mu.username, mu.real_name ) fetchUserName-->
<!--        FROM-->
<!--            drp_warehouse a-->
<!--            left join alloc_area aa on aa.area_id = a.area_id-->
<!--        LEFT JOIN mgr_user mu ON a.fetch_user_id = mu.user_id-->
<!--        WHERE-->
<!--            a.del_flag = #{delFlag}-->
<!--            and a.status = #{status}-->
<!--            <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="areaAuth != null and areaAuth.size() > 0">-->
<!--                and a.area_id in-->
<!--                <foreach collection="areaAuth" item="areaId" separator="," open="(" close=")">-->
<!--                    #{areaId}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="warehouseName != null and warehouseName != ''">-->
<!--                and a.warehouse_name like concat('%', #{warehouseName}, '%')-->
<!--            </if>-->
<!--            <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--                AND a.area_id in-->
<!--                <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--    </select>-->
<!--    <select id="selectMaxNum" resultType="java.lang.String">-->
<!--        SELECT-->
<!--            MAX( warehouse_num )-->
<!--        FROM-->
<!--            drp_warehouse-->
<!--        WHERE-->
<!--            LENGTH( warehouse_num ) = #{warehouseNumLength}-->
<!--            AND del_flag = #{delFlag}-->
<!--    </select>-->

    <select id="getInventoryNumByWarehouseIds" resultType="com.bonus.canteen.core.supply.purchase.domain.bo.DrpWarehouseInventoryNum">
        SELECT
        di.warehouse_id,
        dw.warehouse_name,
        sum(di.material_num) inventoryNum
        FROM
        drp_inventory di
        left join drp_warehouse dw on dw.warehouse_id = di.warehouse_id
        WHERE
        di.material_id = #{materialId} AND di.unit_id = #{unitId}
        <if test="warehouseIdList != null and warehouseIdList.size() > 0">
            and di.warehouse_id in
            <foreach collection="warehouseIdList" item="warehouseId" separator="," open="(" close=")">
                #{warehouseId}
            </foreach>
        </if>
        group by
        di.warehouse_id,
        dw.warehouse_name
    </select>
    <select id="getFetchUserByWarehouseId" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpFetchUserVO">
        SELECT dw.fetch_user_id,
        IF
        (mu.nick_name IS NULL OR mu.nick_name = '', mu.user_name, mu.nick_name) fetchUserName

        FROM drp_warehouse dw
        LEFT JOIN sys_user mu ON dw.fetch_user_id = mu.user_id
        WHERE dw.warehouse_id = #{warehouseId}
    </select>
</mapper>















































