<?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.manage.dal.mysql.plate.OrderPlateMapper">





    <resultMap id="PlateDetailMap" type="com.cf.imes.module.manage.controller.admin.patching.vo.PatchingDetailRespVO">

        <result property="cabinetName" column="cabinetName"/>
        <result property="plateNo" column="plateNo"/>
        <result property="name" column="name"/>
        <result property="height" column="height"/>
        <result property="width" column="width"/>
        <result property="thickness" column="thickness"/>
        <result property="area" column="area"/>
        <result property="remark" column="remark"/>
        <result property="customOrderId" column="customOrderId"/>
        <result property="customer" column="customer"/>
        <result property="address" column="address"/>
        <result property="specialShaped" column="specialShaped"/>
        <result property="profiling" column="profiling"/>
        <result property="rowHole" column="rowHole"/>
        <result property="plateCombinationName" column="plateCombinationName"/>
        <result property="material" column="material"/>
        <result property="color" column="color"/>
    </resultMap>
    <select id="selectPlateDetail"
            resultMap="PlateDetailMap"
            parameterType="com.cf.imes.module.manage.controller.admin.patching.vo.PatchingPlatePageReqVO">


        select
            o.id as orderId,
            ob.name as cabinetName,
            op.id as plateNo,
            op.name as name,
            op.height as height,
            op.width as width,
            op.thickness as thickness,
            op.area as area,
            op.remark as remark,
            o.custom_order_no as customOrderId,
            o.customer as customer,
            o.address as address,

            CASE WHEN op.unregular_point_count = 0  THEN '否' ELSE '是' END AS specialShaped,
            CASE WHEN front_model_count = 0 or op.back_hole_count = 0 or op.side_hole_count = 0 THEN '否' ELSE '是' END AS profiling,
            CASE WHEN front_hole_count = 0 or op.back_model_count = 0 THEN '否' ELSE '是' END AS rowHole,

            CONCAT(
                    TRIM(TRAILING '.' from TRIM(TRAILING '0' FROM p.thickness)),'mm-',p.material,'-',p.color) AS plateCombinationName,

            p.material as material,
            p.color as color
        from order_plate op

                 join order_item oi on op.id = oi.plate_id
                 join order_body ob on oi.body_id = ob.id
                 join `orders` o on op.order_id = o.id
                 join plate p on op.goods_id = p.goods_id


        <where>
            <if test="orderNo != null">
                and op.order_id = #{orderNo}
            </if>
            <if test="customOrderNo != null">
                and o.custom_order_no = #{customOrderNo}
            </if>
            <if test="groupId != null">
                and oi.body_id = #{groupId}
            </if>
            <if test="customer != null">
                and o.customer = #{customer}
            </if>
            <if test="address != null">
                and o.address = #{address}
            </if>
            <if test="startTime != null and  endTime != null">
                and op.update_time between #{startTime} and #{endTime}
            </if>

        </where>

    </select>





    <select id="selectPlate"
            resultMap="PlateDetailMap">

        select
            op.*,
            oi.room_id as roomId,
            oi.body_id as bodyId,
            ob.room_name as roomName,
            ob.name as cabinetName,
/*            op.id as plateNo,
            op.name as plateName,
            op.height as height,
            op.width as width,
            op.thickness as thickness,
            op.area as area,
            op.remark as remark,*/
            o.custom_order_no as customOrderId,
            o.customer as customer,
            o.address as address,

            CASE WHEN op.unregular_point_count = 0  THEN '否' ELSE '是' END AS specialShaped,
            CASE WHEN front_model_count = 0 or op.back_hole_count = 0 or op.side_hole_count = 0 THEN '否' ELSE '是' END AS profiling,
            CASE WHEN front_hole_count = 0 or op.back_model_count = 0 THEN '否' ELSE '是' END AS rowHole,

            CONCAT(
                    TRIM(TRAILING '.' from TRIM(TRAILING '0' FROM p.thickness)),'mm-',p.material,'-',p.color) AS plateCombinationName,

                p.material as material,
            p.color as color
        from order_plate op

                 join order_item oi on op.id = oi.plate_id
                 join order_body ob on oi.body_id = ob.id
                 join `orders` o on op.order_id = o.id
                 join plate p on op.goods_id = p.goods_id

        where op.id = #{plateId}
    </select>





    <select id="selectOtherPlateList"
            resultMap="PlateDetailMap"
            parameterType="java.lang.Long">


        select op.*,
               oi.room_id as roomId,
               oi.body_id as bodyId,
               ob.room_name as roomName,
               ob.name as cabinetName,
               p.material as material,
               p.color as color,

               CONCAT(
                    TRIM(TRAILING '.' from TRIM(TRAILING '0' FROM p.thickness)),'mm-',p.material,'-',p.color) AS plateCombinationName

        from order_plate op
                 join order_item oi on op.id = oi.plate_id
                 join order_body ob on oi.body_id = ob.id
                 join plate p on op.goods_id = p.goods_id

        where op.id in
        <foreach item="id" collection="plateIdList" open="(" separator="," close=")">
            #{id}
        </foreach>


    </select>
    <select id="selectListByOrderId"
            resultType="com.cf.imes.module.manage.controller.admin.process.vo.PlateDetails">


        select  id as plateId ,plate_no,height as length, width,thickness
        from order_plate  where order_id = #{orderId} and organ_id = #{organId};


    </select>


</mapper>