<?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.executor.dal.mysql.processStep.ProcessStepMapper">

    <select id="calculateSalary"
            parameterType="map"
            resultType="com.cf.imes.module.executor.controller.admin.plan.bo.ProcessStepSalaryIds">

        select distinct ROUND(ops.piece_rate *

        <foreach collection="processStepAreaIds" item="processStepAreaIds" open="(" close=")" separator=",">
            (#{processStepAreaIds.area})
        </foreach>,3) as salary,

            ops.id as processStepId
        from order_process_step ops

        where  ops.organ_id = #{organId}
        and ops.id in
        <foreach collection="processStepAreaIds" item="processStepAreaIds" open="(" close=")" separator=",">
            (#{processStepAreaIds.processStepId})
        </foreach>

        group by ops.piece_rate,ops.id;

    </select>



    <update id="updateStatus" parameterType="map">


        update  order_process_step
        set status = true,
            finish_time = now(),
            manager = #{nickname},
            salary_amount =
        <foreach collection="processStepSalaryIds" item="processStepSalaryIds" open="(" close=")" separator=",">
            (#{processStepSalaryIds.salary})
        </foreach>

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


    </update>




</mapper>