<?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.repair.mapper.RepairConsumeMapper">
    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.repair.model.vo.ConsumeVo" id="repairConsumeMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="price" column="price"/>
        <result property="schoolName" column="school_name"/>
        <result property="artileName" column="artile_name"/>
        <result property="entryName" column="entry_name"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="queryConsumeList" resultType="com.repair.model.vo.ConsumeVo" resultMap="repairConsumeMap">
       SELECT rc.id,rc.name,rc.price,rae.name as school_name,ra.username as entry_name,ra.update_time ,(select GROUP_CONCAT(name) from repair_article_type where find_in_set(id,rc.article_id) and deleted = 0) as artile_name FROM `repair_consume` rc
        left join repair_admin ra on ra.id = rc.update_user and ra.deleted = 0
        left join repair_area rae on rae.id = rc.school_id and rae.deleted = 0
        <where>
            and rc.deleted = 0
            <if test="name != null and name != ''">
                and rc.name like '%' #{name} '%'
            </if>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                and rc.update_time BETWEEN #{startTime} and #{endTime}
            </if>
        </where>
    </select>

    <resultMap type="com.repair.model.vo.RepairConsumeVo" id="repairConsumePageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="content" column="content"/>
        <result property="price" column="price"/>
        <result property="articleId" column="article_id"/>
        <result property="userName" column="user_name"/>
        <result property="articleName" column="article_name"/>
        <result property="updateTime" column="update_time"/>
        <result property="schoolId" column="school_id"/>
    </resultMap>

    <select id="queryConsumePageList" resultType="com.repair.model.vo.RepairConsumeVo" resultMap="repairConsumePageMap">
        select rc.school_id,rc.update_time,rc.id,rc.name,rc.content,rc.price,rc.article_id,ra.username as user_name,(select GROUP_CONCAT(name) from repair_article_type where find_in_set(id,rc.article_id)) as article_name from repair_consume rc
        left join repair_admin ra on rc.update_user = ra.id and ra.deleted = 0
        <where>
            and rc.deleted = 0
            <if test="name != null and name != ''">
                and rc.name like '%' #{name} '%'
            </if>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                and rc.update_time BETWEEN #{startTime} and #{endTime}
            </if>
        </where>
    </select>


    <resultMap type="com.repair.model.vo.RepairArticleConsumeVo" id="repairArticleConsumeMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="articleId" column="article_id"/>
        <result property="price" column="price"/>
    </resultMap>

    <select id="queryArticleConsumes" resultType="com.repair.model.vo.RepairArticleConsumeVo" resultMap="repairArticleConsumeMap">
        select id,article_id,name,price from repair_consume
        <where>
            and deleted =0
            <if test="schoolId != null and schoolId != ''">
                and school_id = #{schoolId}
            </if>
            <if test="keyWork != null and keyWork != ''">
                and name like '%' #{keyWork} '%'
            </if>
            <if test="findInSet != null and findInSet != ''">
                and (${findInSet})
            </if>
        </where>
    </select>
    <select id="queryArticleConsumesName" resultType="com.repair.model.vo.RepairArticleConsumeVo">
        select id,article_id,name,price from repair_consume
        <where>
        and deleted =0
        <if test="schoolId != null and schoolId != ''">
            and school_id = #{schoolId}
        </if>
        <if test="findInSet != null and findInSet != ''">
            and (${findInSet})
        </if>
        </where>
    </select>
</mapper>
