<?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.fjhx.wms.mapper.stock.StockMapper">
    <select id="getPage" resultType="com.fjhx.wms.entity.stock.vo.StockVo">
        SELECT
            s.id,
            pi.definition,
            s.warehouse_id,
            s.product_id,
            s.quantity,
            s.create_user,
            s.create_time,
            s.update_user,
            s.update_time,
            s.victoriatourist_json
        FROM
            stock s
                LEFT JOIN bytesailing_item.product_info pi ON s.product_id = pi.id
            ${ew.customSqlSegment}
    </select>
    <select id="pageByProduct" resultType="com.fjhx.wms.entity.stock.vo.StockVo">
        SELECT
            s.id,
            s.warehouse_id,
            s.product_id,
            sum( s.quantity ) quantity,
            s.create_user,
            s.create_time,
            s.update_user,
            s.update_time,
            sum(json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )) frozenQuantity,
            sum(json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )) defectiveQuantity
        FROM
            stock s
                LEFT JOIN bytesailing_item.product_info pi ON s.product_id = pi.id
            ${ew.customSqlSegment}
    </select>
    <select id="pageByProductSpu" resultType="com.fjhx.wms.entity.stock.vo.StockVo">
        SELECT
            s.id,
            ps.id productSpuId,
            ps.`code` productSpuCode,
            ps.`name` productSpuName,
            sum( s.quantity ) quantity,
            pi.victoriatourist_json
        FROM
            stock s
                LEFT JOIN bytesailing_item.product_info pi ON s.product_id = pi.id
                LEFT JOIN bytesailing_item.product_spu ps ON pi.product_spu_id = ps.id
            ${ew.customSqlSegment}
    </select>

</mapper>
