<?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.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateLimitMapper">



    <resultMap id="MachineTemplateMap" type="com.cf.imes.module.system.controller.admin.machine.vo.OrganTemplateResp">

        <result property="organId" column="organId"/>
        <result property="organName" column="organName"/>

<!--        <collection property="machineTemplateBrandReqVOS" ofType="com.cf.imes.module.system.controller.admin.machine.vo.MachineTemplateBrandReqVO" resultMap="TemplateBrandMap"/>-->

    </resultMap>


    <select id="selectMachinePage" resultMap="MachineTemplateMap">


        select distinct
        so.id as organId,
        so.name as organName

        from system_machine_template_limit smtl

                 join system_organization so on smtl.organ_id = so.id

                 join system_machine_template smt on smtl.machine_id = smt.id

        <where>

            so.status = 0
          and so.deleted = false
          and smtl.deleted = false

            <if test="page.organName !=null ">
                and so.name like  concat('%', #{page.organName},'%')
            </if>
            <if test="page.templateName !=null ">
                and smt.name like  concat('%', #{page.templateName},'%')
            </if>


        </where>


    </select>



    <resultMap id="TemplateBrandMap" type="com.cf.imes.module.system.controller.admin.machine.vo.MachineTemplateBrandReqVO">

        <result property="organId" column="organId"/>
        <result property="machineType" column="machineType"/>
        <result property="id" column="id"/>

        <collection property="organMachineVOS" ofType="com.cf.imes.module.system.controller.admin.machine.vo.OrganTemplateVO" resultMap="OrganMachineMap"/>


    </resultMap>


    <resultMap id="OrganMachineMap" type="com.cf.imes.module.system.controller.admin.machine.vo.OrganTemplateVO">

        <result property="templateId" column="templateId"/>
        <result property="brandId" column="id"/>
        <result property="templateName" column="templateName"/>
        <result property="machineType" column="machineType"/>
        <result property="showPriorFacing" column="showPriorFacing"/>
        <result property="showDualWorkstation" column="showDualWorkstation"/>
        <result property="showAutoNotePrinter" column="showAutoNotePrinter"/>

    </resultMap>


    <select id="selectMachineList"
            resultMap="TemplateBrandMap">
        select distinct
                smtl.organ_id as organId,
                smt.machine_type as machineType,
                smt.brand_id as id,
                smtl.machine_id as templateId,
                smt.name as templateName,
                smtl.show_auto_note_printer as showAutoNotePrinter,
                smtl.show_dual_workstation as showDualWorkstation,
                smtl.show_prior_facing as showPriorFacing
        from system_machine_template_limit smtl

        join system_machine_template smt on smtl.machine_id = smt.id

        <where>
            smtl.deleted = false
            and smtl.organ_id in
        <foreach item="organIds" collection="organIds" open="(" separator="," close=")">
            #{organIds}
        </foreach>

        <if test="templateName !=null ">
            and smt.name like  concat('%', #{templateName},'%')
        </if>

        </where>

    </select>

</mapper>