<?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.ProcessStepItemMapper">


    <select id="selectPlateName"
            resultType="com.cf.imes.module.manage.controller.admin.query.vo.productionStatus.OrderModuleVO"
            parameterType="java.lang.Long">


        select CONCAT(ob.room_name,'_',ob.name) as name ,ob.id as bodyId,og.name as groupName,og.id as groupId
        from order_process_step_item opsn
            join order_body ob on opsn.body_id = ob.id
            left join order_group og on ob.id = og.body_id
        where opsn.process_step_id = #{processStepId};


    </select>



    <update id="updateStatus"
            parameterType="java.lang.Long">

        update order_process_step_item
            SET status = TRUE
        WHERE process_step_id = #{id};


    </update>

    <update id="updateStemStatus" parameterType="java.lang.Object">

        update order_process_step_item opsi

            set opsi.status = true

        where opsi.process_step_id = #{processStepId}  and opsi.name = #{name}


    </update>


    <select id="selectStatusById" resultType="com.cf.imes.module.manage.controller.admin.process.vo.ProcessStepStatus"
            parameterType="java.lang.Object">

        select distinct
               opsi.status as processStepItemStatus,
               ops.status as processStepStatus,
               ops.type as type
        from order_process_step_item opsi
                 join order_process_step ops on opsi.process_step_id = ops.id and opsi.organ_id = ops.organ_id
        where opsi.process_step_id = #{id} and opsi.name = #{name} and opsi.organ_id = #{organId};


    </select>



    <resultMap id="PlateMap" type="com.cf.imes.module.manage.controller.admin.process.vo.OrderBodyRespVo">

            <result property="id" column="bodyId"/>
            <result property="name" column="bodyName"/>

    </resultMap>
    <select id="selectBodyIds"
            resultMap="PlateMap"
            parameterType="java.lang.Object">


        select distinct
            oi.body_id as bodyId,
            ob.name as bodyName,
        from order_process_step_item opsi
                 join order_item oi on opsi.body_id = oi.body_id and opsi.organ_id = oi.organ_id
                 join order_body ob on oi.body_id = ob.id and oi.organ_id = ob.organ_id
        where opsi.process_step_id = #{processStepId} and opsi.name = #{name} and opsi.organ_id = #{organId} ;


    </select>


    <select id="selectAreaByProcessStepId" resultType="java.math.BigDecimal">


        select distinct
            sum(op.area)

        from order_process_step_item opsi
                 join order_body ob on opsi.body_id = ob.id and opsi.organ_id = ob.organ_id
                 join order_item oi on ob.id = oi.body_id and ob.organ_id = oi.organ_id
                 join order_plate op on oi.plate_id = op.id and oi.organ_id = op.organ_id
        where opsi.process_step_id = #{processStepId};




    </select>


</mapper>