<?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.goods.mapper.GoodsMapper">
    <resultMap id="SearchGoodsResultMap" autoMapping="true" type="com.njzscloud.dispose.goods.pojo.result.SearchGoodsResult">
        <id property="id" column="id"/>
        <association property="goodsCategory"
                     javaType="com.njzscloud.dispose.goods.pojo.result.SearchGoodsCategoryResult"
                     autoMapping="true">
            <id property="id" column="goods_category_id"/>
            <result property="createTime" column="b_create_time"/>
            <result property="sort" column="b_sort"/>
            <result property="picture" column="b_picture"/>
        </association>
        <association property="expenseItem"
                     javaType="com.njzscloud.dispose.finance.pojo.result.SearchExpenseItemResult"
                     autoMapping="true">
            <id property="id" column="c_id"/>
            <result property="createTime" column="c_create_time"/>
            <result property="canuse" column="c_canuse"/>
            <result property="memo" column="c_memo"/>
            <result property="unit" column="c_unit"/>
        </association>
    </resultMap>
    <sql id="SearchGoodsResultSql">
        SELECT a.id,
               a.goods_category_id,
               a.sn,
               a.goods_name,
               a.spec_params,
               a.picture,
               a.unit,
               a.sort,
               a.canuse,
               a.memo,
               a.create_time,
               b.biz_type,
               b.category_name,
               b.picture     b_picture,
               b.sort        b_sort,
               b.create_time b_create_time,
               c.id          c_id,
               c.expense_item_category,
               c.expense_item_name,
               c.expense_strategy,
               c.unit        c_unit,
               c.tax_rate,
               c.unit_price,
               c.initial_price,
               c.initial_quantity,
               c.every_quantity,
               c.canuse      c_canuse,
               c.memo        c_memo,
               c.create_time c_create_time
        FROM gds_goods a
                 INNER JOIN gds_goods_category b ON a.goods_category_id = b.id
                 LEFT JOIN fin_expense_item c ON c.goods_id = a.id
    </sql>
    <select id="paging" resultMap="SearchGoodsResultMap">
        <include refid="SearchGoodsResultSql"/>
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="detail" resultMap="SearchGoodsResultMap">
        <include refid="SearchGoodsResultSql"/>
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>
