<?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.process.ProductionProcessMapper">




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

        <result property="groupId" column="groupId"/>
        <result property="orderId" column="orderId"/>
        <result property="customOrderId" column="customOrderId"/>
        <result property="customer" column="customer"/>
        <result property="address" column="address"/>
        <result property="orderStatus" column="orderStatus"/>
        <result property="plateName" column="plateName"/>
        <result property="plateNum" column="plateNum"/>
        <result property="thickness" column="thickness"/>
        <result property="material" column="material"/>
        <result property="color" column="color"/>

    </resultMap>
    <select id="selectPatchingPlate"
            resultMap="PatchingPlateMap"
            parameterType="com.cf.imes.module.manage.controller.admin.patching.vo.PatchingPlatePageReqVO">

        select

            p.goods_id,
            o.id as orderId,
            o.custom_order_no as customOrderId,
            o.customer as customer,
            o.address as address,
            o.status as orderStatus,
            oi.num as plateNum,
            <![CDATA[
            CONCAT(
                    TRIM(TRAILING '.' from TRIM(TRAILING '0' FROM p.thickness)),'mm-',p.material,'-',p.color) AS plateName,
                    ]]>
            p.thickness as thickness,
            p.material as material,
            p.color as color

        from `orders` o

        join order_item oi on o.id = oi.order_id
        join order_plate op on oi.plate_id = op.id
        join plate p on op.goods_id = p.goods_id

        <where>
                <choose>
                    <!-- 挖穿，挖孔，二维刀路判断 -->
                    <when test="isDigThrough == true">
                        (op.filter_type = 1
                        <if test="isDiggingHoles == true ">
                            or op.filter_type = 2
                        </if>
                        <if test="is2DCuttingPath == true ">
                            or op.filter_type = 4
                        </if>)

                        <!-- 其他的判断 -->
                        <if test="orderNo != null">
                            and o.id = #{orderNo}
                        </if>
                        <if test="customOrderNo != null">
                            and o.custom_order_no = #{customOrderNo}
                        </if>
                        <if test="customer != null">
                            and o.customer = #{customer}
                        </if>
                        <if test="address != null">
                            and o.address = #{address}
                        </if>
                        <if test="statusList != null">
                            and  o.status in
                            <foreach item="id" collection="statusList" open="(" separator="," close=")">
                                #{id}
                            </foreach>
                        </if>
                        <if test="startTime != null and  endTime != null">
                            and o.update_time between #{startTime} and #{endTime}
                        </if>

                        <if test="isRectangle == true ">
                            and op.unregular_point_count = 0
                        </if>

                        <if test="isSpecialShaped == true ">
                            and op.unregular_point_count &gt; 0
                        </if>

                        <if test="isProfiling == true ">
                            and front_model_count &gt; 0 or op.back_hole_count &gt; 0 or op.side_hole_count &gt; 0
                        </if>

                        <if test="isDoor == true ">
                            and op.is_door = 1
                        </if>

<!--                        <if test="longRangeList != null and !longRangeList.isEmpty()">
                            AND (
                            &lt;!&ndash; 根据 DataRangeList 中的属性进行条件判断 &ndash;&gt;
                            <foreach collection="longRangeList" item="range" separator=" OR ">
                                (#{op.width} &lt;= #{range.maxaa} AND #{op.width} &gt;= #{range.minbb})
                            </foreach>
                            )
                        </if>-->


                    </when>
                    <!-- 不传入挖穿等判断，走另一个判断逻辑 -->
                    <otherwise>

                        <if test="orderNo != null">
                            and o.id = #{orderNo}
                        </if>
                        <if test="customOrderNo != null">
                            and o.custom_order_no = #{customOrderNo}
                        </if>
                        <if test="customer != null">
                            and o.customer = #{customer}
                        </if>
                        <if test="address != null">
                            and o.address = #{address}
                        </if>
                        <if test="statusList != null">
                            and  o.status in
                            <foreach item="id" collection="statusList" open="(" separator="," close=")">
                                #{id}
                            </foreach>
                        </if>
                        <if test="startTime != null and  endTime != null">
                            and o.update_time between #{startTime} and #{endTime}
                        </if>

                        <if test="isRectangle == true ">
                            and op.unregular_point_count = 0
                        </if>

                        <if test="isSpecialShaped == true ">
                            and op.unregular_point_count &gt; 0
                        </if>

                        <if test="isProfiling == true ">
                            and front_model_count &gt; 0 or op.back_hole_count &gt; 0 or op.side_hole_count &gt; 0
                        </if>

                        <if test="isDoor == true ">
                            and op.is_door = 1
                        </if>
<!--
                        <if test="longRangeList != null and !longRangeList.isEmpty()">
                            AND
                            &lt;!&ndash; 根据 DataRangeList 中的属性进行条件判断 &ndash;&gt;
                            <foreach collection="longRangeList" item="range" open="(" separator="," close=")">
                                op.width between #{range.minbb} AND  #{range.maxaa}
                            </foreach>

                        </if>-->

                    </otherwise>

                </choose>

        </where>

        group by p.goods_id,orderId,customOrderId,customer,address,orderStatus,plateNum,plateName,thickness,material,color

    </select>
</mapper>