<?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.gree.mall.miniapp.commonmapper.stock.MaterialGoodsStockCMapper">


    <select id="queryWebsitGoodsCategoryList" resultType="com.gree.mall.miniapp.plus.entity.WebsitGoodsCategory">
        select
            distinct
            a.*
        from websit_goods_category a
        join worker_goods b on a.category_id = b.goods_category_id
        join worker_stock c on c.goods_id = b.goods_id
        <where>
            <if test="goodsType != null and goodsType !=''">
                and c.goods_type = #{goodsType}
            </if>
            <if test="websitId != null and websitId !=''">
                and c.websit_id = #{websitId}
            </if>
            <if test="userId != null and userId !=''">
                and c.worker_id = #{userId}
            </if>
        </where>
    </select>

    <select id="queryWorkerStockList" resultType="com.gree.mall.miniapp.bean.material.stock.WorkerStockBean">
          select
                a.*,
        <if test="goodsType != null and goodsType == 'M'.toString()">
                c.category_name,
        </if>
                b.goods_category_id
            from worker_stock a
        join worker_goods b on a.goods_id=b.goods_id
        <if test="goodsType != null and goodsType == 'M'.toString()">
            join websit_goods_category c on c.category_id = b.goods_category_id
        </if>
        <where>
            <if test="goodsType != null and goodsType !=''">
                and a.goods_type = #{goodsType}
            </if>
            <if test="websitId != null and websitId !=''">
                and a.websit_id = #{websitId}
            </if>
            <if test="userId != null and userId !=''">
                and a.worker_id = #{userId}
            </if>
            <if test="categoryId != null and categoryId !=''">
                and b.goods_category_id = #{categoryId}
            </if>
        </where>
    </select>

    <select id="queryExistWebsitStockList" resultType="com.gree.mall.miniapp.plus.entity.WebsitStock">
        SELECT
        *
        FROM
        websit_stock
        WHERE
        company_wechat_id = #{companyWechatId}
        AND
        websit_id = #{websitId}
        AND
        storage_id = #{storageId}
        AND
        goods_id IN
        <foreach item="item" index="index" collection="stockList" open="(" separator=","
                 close=")">
            #{item.goodsId}
        </foreach>
        FOR UPDATE
    </select>

    <select id="queryExistWorkerStockList" resultType="com.gree.mall.miniapp.plus.entity.WorkerStock">
        SELECT
        *
        FROM
        worker_stock
        WHERE
        company_wechat_id = #{companyWechatId}
        AND
        worker_id = #{workerId}
        AND
        goods_id IN
        <foreach item="item" index="index" collection="stockList" open="(" separator=","
                 close=")">
            #{item.goodsId}
        </foreach>
        FOR UPDATE
    </select>


</mapper>