<?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.njzscloud.dispose.wh.mapper.PurchaseRecordMapper">
    <resultMap id="BaseResultMap" type="com.njzscloud.dispose.wh.pojo.result.PurchaseRecordResult">
        <id column="id" property="id"/>
        <result column="sn" property="sn"/>
        <result column="handler_id" property="handlerId"/>
        <result column="handler_name" property="handlerName"/>
        <result column="supplier_name" property="supplierName"/>
        <result column="product_name" property="productName"/>
        <result column="spec" property="spec"/>
        <result column="quantity" property="quantity"/>
        <result column="unit" property="unit"/>
        <result column="unit_price" property="unitPrice"/>
        <result column="total_amount" property="totalAmount"/>
        <result column="purchase_date" property="purchaseDate"/>
        <result column="remark" property="remark"/>
        <result column="creator_id" property="creatorId"/>
        <result column="modifier_id" property="modifierId"/>
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
        <result column="deleted" property="deleted"/>
    </resultMap>

    <sql id="Base_Column_List">
        SELECT wpr.id              AS id,
               wpr.sn              AS sn,
               wpr.handler_id      AS handler_id,
               su.nickname         AS handler_name,
               wpr.supplier_name   AS supplier_name,
               wpr.product_name   AS product_name,
               wpr.spec            AS spec,
               wpr.quantity        AS quantity,
               wpr.unit            AS unit,
               wpr.unit_price      AS unit_price,
               wpr.total_amount    AS total_amount,
               wpr.purchase_date   AS purchase_date,
               wpr.remark          AS remark,
               wpr.creator_id      AS creator_id,
               wpr.modifier_id     AS modifier_id,
               wpr.create_time     AS create_time,
               wpr.modify_time     AS modify_time,
               wpr.deleted         AS deleted
        FROM wh_purchase_record wpr
                 LEFT JOIN sys_user su ON su.id = wpr.handler_id AND su.deleted = 0
    </sql>

    <select id="detail" resultMap="BaseResultMap">
        <include refid="Base_Column_List"/>
        WHERE wpr.id = #{id}
    </select>

    <select id="paging" resultMap="BaseResultMap">
        <include refid="Base_Column_List"/>
        <if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>
