<?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.StockCheckMapper">
    <select id="getPage" resultType="com.fjhx.wms.entity.stock.vo.StockCheckVo">
        select sc.id,
               sc.warehouse_id,
               sc.result,
               sc.create_user,
               sc.create_time,
               sc.update_user,
               sc.update_time,
               sc.code,
               sc.anomaly_num,
               sc.normal_num,
               sc.total_num
        from stock_check sc
            ${ew.customSqlSegment}
    </select>

    <resultMap id="detail" type="com.fjhx.wms.entity.stock.vo.StockCheckVo">
        <id property="id" column="id"/>
        <id property="result" column="result"/>
        <id property="warehouseId" column="warehouse_id"/>
        <id property="createTime" column="create_time"/>
        <result property="warehouseName" column="warehouseName"/>
        <collection property="list" javaType="java.util.ArrayList" ofType="com.fjhx.wms.entity.stock.vo.StockCheckDetailsVo">
            <id property="id" column="stockCheckDetails"/>
            <result property="productId" column="product_id"/>
            <result property="quantity" column="quantity"/>
            <result property="checkQuantity" column="check_quantity"/>
        </collection>
    </resultMap>

    <select id="detail" resultMap="detail">
        SELECT
            sc.id,
            sc.result,
            sc.warehouse_id,
            w.`name` warehousename,
            scd.id stockcheckdetails,
            scd.product_id,
            scd.quantity,
            scd.check_quantity,
            sc.create_time
        FROM
            stock_check sc
                LEFT JOIN stock_check_details scd ON scd.stock_check_id = sc.id
                LEFT JOIN warehouse w ON sc.warehouse_id = w.id where sc.id = #{id}
    </select>

</mapper>
