<?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.ximai.mes.pro.mapper.productionSolution.ProProductionSolutionProcessMapper">

    <resultMap type="com.ximai.mes.pro.domain.vo.ProProductionSolutionProcessVo" id="ProProductionSolutionProcessResult">
        <result property="productionSolutionProcessId" column="production_solution_process_id"/>
        <result property="productionSolutionId" column="production_solution_id"/>
        <result property="recordId" column="record_id"/>
        <result property="processId" column="process_id"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="workstationName" column="workstation_Name"/>
        <result property="keyFlag" column="key_flag"/>
        <result property="isCheck" column="is_check"/>
        <result property="idx" column="idx"/>
        <result property="serial" column="serial"/>
        <result property="outsourced" column="outsourced"/>
        <result property="workstationCode" column="workstation_code"/>
        <result property="processingMethod" column="processing_method"/>
        <result property="processName" column="process_name"/>
        <result property="processCode" column="process_code"/>
        <result property="processId" column="process_id"/>
        <result property="processRemark" column="process_remark"/>
        <result property="quantity" column="quantity"/>
        <result property="unitOfMeasure" column="unit_of_measure"/>
        <result property="deputyUnitOfMeasure" column="deputy_unit_of_measure"/>
        <result property="unitConvert" column="unit_convert"/>
        <result property="employeesNum" column="employees_num"/>
        <result property="stdWorkingTime" column="std_working_time"/>
        <result property="lineBreakTime" column="line_break_time"/>
        <result property="stdWorkingTimeUom" column="std_working_time_uom"/>
        <result property="procurementInformationId" column="procurement_information_id"/>
        <result property="vendorSubjectId" column="vendor_subject_id"/>
        <result property="netPrice" column="net_price"/>
        <result property="procurementOrganization" column="procurement_organization"/>
        <result property="remark" column="remark"/>
        <result property="processCode" column="process_code"/>
        <result property="solidifyTime" column="solidify_time"/>
        <result property="sacmForEdgeOpening"    column="sacm_for_edge_opening"    />
        <result property="sacmForPasteComposite"    column="sacm_for_paste_composite"    />
        <result property="sacmForThermalComposite"    column="sacm_for_thermal_composite"    />
        <result property="sacmForLabeling"    column="sacm_for_labeling"    />
        <result property="sacmForBuckleUp"    column="sacm_for_buckle_up"    />
        <result property="sacmForCreasing"    column="sacm_for_creasing"    />
        <result property="sacmForOrgan"    column="sacm_for_organ"    />
        <result property="sacmForThermalCutting"    column="sacm_for_thermal_cutting"    />
        <result property="sacmForThermalSelfFusion"    column="sacm_for_thermal_self_fusion"    />
        <result property="sacmForMolarTooth"    column="sacm_for_molar_tooth"    />
        <result property="sacmForSlitting"    column="sacm_for_slitting"    />
    </resultMap>

    <sql id="selectProProductionSolutionProcessVo">
        select ppsp.production_solution_process_id,
               ppsp.production_solution_id,
               ppsp.record_id,
               ppsp.process_id,
               ppsp.workstation_id,
               mw.workstation_name,
               ppsp.key_flag,
               ppsp.is_check,
               ppsp.idx,
               ppsp.outsourced,
               ppsp.serial,
               ppsp.workstation_code,
               ppsp.processing_method,
               ppsp.process_name,
               ppsp.process_remark,
               ppsp.quantity,
               ppsp.deputy_unit_of_measure,
               ppsp.unit_convert,
               ppsp.unit_of_measure,
               ppsp.employees_num,
               ppsp.std_working_time,
               ppsp.line_break_time,
               ppsp.std_working_time_uom,
               ppsp.procurement_information_id,
               ppsp.vendor_subject_id,
               ppsp.net_price,
               ppsp.solidify_time,
               ppsp.procurement_organization,
               ppsp.remark,
               ppsp.sacm_for_edge_opening,
               ppsp.sacm_for_paste_composite,
               ppsp.sacm_for_thermal_composite,
               ppsp.sacm_for_labeling,
               ppsp.sacm_for_buckle_up,
               ppsp.sacm_for_creasing,
               ppsp.sacm_for_organ,
               ppsp.sacm_for_thermal_cutting,
               ppsp.sacm_for_thermal_self_fusion,
               ppsp.sacm_for_molar_tooth,
               ppsp.sacm_for_slitting,
               pro.process_code,
               pro.process_name,
               pro.process_id,
               pro.remark as processRemarkNew,
               ppsp.unit_price,
               ppsp.direction_process_id,
               ppsp.direction_process_code,
               ppsp.direction_process_name
        from pro_production_solution_process ppsp
                 left join pro_process pro on pro.process_id = ppsp.process_id
                 left join md_workstation mw on ppsp.workstation_id = mw.workstation_id
    </sql>

    <select id="selectProProductionSolutionProcessList" parameterType="ProProductionSolutionProcess"
            resultMap="ProProductionSolutionProcessResult">
        <include refid="selectProProductionSolutionProcessVo"/>
        <where>
            <if test="productionSolutionId != null ">and ppsp.production_solution_id = #{productionSolutionId}</if>
            <if test="recordId != null ">and ppsp.record_id = #{recordId}</if>
            <if test="workstationId != null ">and ppsp.workstation_id = #{workstationId}</if>
            <if test="processId != null ">and ppsp.process_id = #{processId}</if>
        </where>
        order by ppsp.serial
    </select>

    <select id="selectProProductionSolutionProcessByProductionSolutionProcessId" parameterType="Long"
            resultMap="ProProductionSolutionProcessResult">
        <include refid="selectProProductionSolutionProcessVo"/>
        where ppsp.production_solution_process_id = #{productionSolutionProcessId}
    </select>
    <select id="selectProProductionSolutionProcessByProductionSolutionId" parameterType="Long"
            resultMap="ProProductionSolutionProcessResult">
        <include refid="selectProProductionSolutionProcessVo"/>
        where ppsp.production_solution_id = #{productionSolutionId}
    </select>

    <insert id="insertProProductionSolutionProcess" parameterType="ProProductionSolutionProcess" useGeneratedKeys="true"
            keyProperty="productionSolutionProcessId">
        insert into pro_production_solution_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionSolutionId != null">production_solution_id,</if>
            <if test="recordId != null">record_id,</if>
            <if test="processId != null">process_id,</if>
            <if test="workstationId != null">workstation_id,</if>
            <if test="keyFlag != null">key_flag,</if>
            <if test="isCheck != null">is_check,</if>
            <if test="idx != null">idx,</if>
            <if test="serial != null">serial,</if>
            <if test="outsourced != null">outsourced,</if>
            <if test="workstationCode != null">workstation_code,</if>
            <if test="processingMethod != null">processing_method,</if>
            <if test="processName != null">process_name,</if>
            <if test="processRemark != null">process_remark,</if>
            <if test="quantity != null">quantity,</if>
            <if test="unitOfMeasure != null">unit_of_measure,</if>
            <if test="deputyUnitOfMeasure != null">deputy_unit_of_measure,</if>
            <if test="unitConvert != null">unit_convert,</if>
            <if test="employeesNum != null">employees_num,</if>
            <if test="stdWorkingTime != null">std_working_time,</if>
            <if test="lineBreakTime != null">line_break_time,</if>
            <if test="stdWorkingTimeUom != null">std_working_time_uom,</if>
            <if test="procurementInformationId != null">procurement_information_id,</if>
            <if test="vendorSubjectId != null">vendor_subject_id,</if>
            <if test="netPrice != null">net_price,</if>
            <if test="procurementOrganization != null">procurement_organization,</if>
            <if test="remark != null">remark,</if>
            <if test="solidifyTime != null">solidify_time,</if>
            <if test="sacmForEdgeOpening != null">sacm_for_edge_opening,</if>
            <if test="sacmForPasteComposite != null">sacm_for_paste_composite,</if>
            <if test="sacmForThermalComposite != null">sacm_for_thermal_composite,</if>
            <if test="sacmForLabeling != null">sacm_for_labeling,</if>
            <if test="sacmForBuckleUp != null">sacm_for_buckle_up,</if>
            <if test="sacmForCreasing != null">sacm_for_creasing,</if>
            <if test="sacmForOrgan != null">sacm_for_organ,</if>
            <if test="sacmForThermalCutting != null">sacm_for_thermal_cutting,</if>
            <if test="sacmForThermalSelfFusion != null">sacm_for_thermal_self_fusion,</if>
            <if test="sacmForMolarTooth != null">sacm_for_molar_tooth,</if>
            <if test="sacmForSlitting != null">sacm_for_slitting,</if>
            <if test="unitPrice != null">unit_price,</if>

            <if test="directionProcessId != null">direction_process_id,</if>
            <if test="directionProcessCode != null">direction_process_code,</if>
            <if test="directionProcessName != null">direction_process_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionSolutionId != null">#{productionSolutionId},</if>
            <if test="recordId != null">#{recordId},</if>
            <if test="processId != null">#{processId},</if>
            <if test="workstationId != null">#{workstationId},</if>
            <if test="keyFlag != null">#{keyFlag},</if>
            <if test="isCheck != null">#{isCheck},</if>
            <if test="idx != null">#{idx},</if>
            <if test="serial != null">#{serial},</if>
            <if test="outsourced != null">#{outsourced},</if>
            <if test="workstationCode != null">#{workstationCode},</if>
            <if test="processingMethod != null">#{processingMethod},</if>
            <if test="processName != null">#{processName},</if>
            <if test="processRemark != null">#{processRemark},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="unitOfMeasure != null">#{unitOfMeasure},</if>
            <if test="deputyUnitOfMeasure != null">#{deputyUnitOfMeasure},</if>
            <if test="unitConvert != null">#{unitConvert},</if>
            <if test="employeesNum != null">#{employeesNum},</if>
            <if test="stdWorkingTime != null">#{stdWorkingTime},</if>
            <if test="lineBreakTime != null">#{lineBreakTime},</if>
            <if test="stdWorkingTimeUom != null">#{stdWorkingTimeUom},</if>
            <if test="procurementInformationId != null">#{procurementInformationId},</if>
            <if test="vendorSubjectId != null">#{vendorSubjectId},</if>
            <if test="netPrice != null">#{netPrice},</if>
            <if test="procurementOrganization != null">#{procurementOrganization},</if>
            <if test="remark != null">#{remark},</if>
            <if test="solidifyTime != null">#{solidifyTime},</if>
            <if test="sacmForEdgeOpening != null">#{sacmForEdgeOpening},</if>
            <if test="sacmForPasteComposite != null">#{sacmForPasteComposite},</if>
            <if test="sacmForThermalComposite != null">#{sacmForThermalComposite},</if>
            <if test="sacmForLabeling != null">#{sacmForLabeling},</if>
            <if test="sacmForBuckleUp != null">#{sacmForBuckleUp},</if>
            <if test="sacmForCreasing != null">#{sacmForCreasing},</if>
            <if test="sacmForOrgan != null">#{sacmForOrgan},</if>
            <if test="sacmForThermalCutting != null">#{sacmForThermalCutting},</if>
            <if test="sacmForThermalSelfFusion != null">#{sacmForThermalSelfFusion},</if>
            <if test="sacmForMolarTooth != null">#{sacmForMolarTooth},</if>
            <if test="sacmForSlitting != null">#{sacmForSlitting},</if>
            <if test="unitPrice != null">#{unitPrice},</if>


            <if test="directionProcessId != null">#{directionProcessId},</if>
            <if test="directionProcessCode != null">#{directionProcessCode},</if>
            <if test="directionProcessName != null">#{directionProcessName},</if>
        </trim>
    </insert>

    <update id="updateProProductionSolutionProcess" parameterType="ProProductionSolutionProcess">
        update pro_production_solution_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionSolutionId != null">production_solution_id = #{productionSolutionId},</if>
            <if test="recordId != null">record_id = #{recordId},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="workstationId != null">workstation_id = #{workstationId},</if>
            <if test="keyFlag != null">key_flag = #{keyFlag},</if>
            <if test="isCheck != null">is_check = #{isCheck},</if>
            <if test="idx != null">idx = #{idx},</if>
            <if test="serial != null">serial = #{serial},</if>
            <if test="outsourced != null">outsourced = #{outsourced},</if>
            <if test="workstationCode != null">workstation_code = #{workstationCode},</if>
            <if test="processingMethod != null">processing_method = #{processingMethod},</if>
            <if test="processName != null">process_name = #{processName},</if>
            <if test="processRemark != null">process_remark = #{processRemark},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="unitOfMeasure != null">unit_of_measure = #{unitOfMeasure},</if>
            <if test="deputyUnitOfMeasure != null">deputy_unit_of_measure = #{deputyUnitOfMeasure},</if>
            <if test="unitConvert != null">unit_convert = #{unitConvert},</if>
            <if test="employeesNum != null">employees_num = #{employeesNum},</if>
            <if test="stdWorkingTime != null">std_working_time = #{stdWorkingTime},</if>
            <if test="lineBreakTime != null">line_break_time = #{lineBreakTime},</if>
            <if test="stdWorkingTimeUom != null">std_working_time_uom = #{stdWorkingTimeUom},</if>
            <if test="procurementInformationId != null">procurement_information_id = #{procurementInformationId},</if>
            <if test="vendorSubjectId != null">vendor_subject_id = #{vendorSubjectId},</if>
            <if test="netPrice != null">net_price = #{netPrice},</if>
            <if test="procurementOrganization != null">procurement_organization = #{procurementOrganization},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="solidifyTime != null">solidify_time = #{solidifyTime},</if>
            <if test="sacmForEdgeOpening != null">sacm_for_edge_opening = #{sacmForEdgeOpening},</if>
            <if test="sacmForPasteComposite != null">sacm_for_paste_composite = #{sacmForPasteComposite},</if>
            <if test="sacmForThermalComposite != null">sacm_for_thermal_composite = #{sacmForThermalComposite},</if>
            <if test="sacmForLabeling != null">sacm_for_labeling = #{sacmForLabeling},</if>
            <if test="sacmForBuckleUp != null">sacm_for_buckle_up = #{sacmForBuckleUp},</if>
            <if test="sacmForCreasing != null">sacm_for_creasing = #{sacmForCreasing},</if>
            <if test="sacmForOrgan != null">sacm_for_organ = #{sacmForOrgan},</if>
            <if test="sacmForThermalCutting != null">sacm_for_thermal_cutting = #{sacmForThermalCutting},</if>
            <if test="sacmForThermalSelfFusion != null">sacm_for_thermal_self_fusion = #{sacmForThermalSelfFusion},</if>
            <if test="sacmForMolarTooth != null">sacm_for_molar_tooth = #{sacmForMolarTooth},</if>
            <if test="sacmForSlitting != null">sacm_for_slitting = #{sacmForSlitting},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>

            <if test="directionProcessId != null">direction_process_id = #{directionProcessId},</if>
            <if test="directionProcessCode != null">direction_process_code = #{directionProcessCode},</if>
            <if test="directionProcessName != null">direction_process_name = #{directionProcessName},</if>
        </trim>
        where production_solution_process_id = #{productionSolutionProcessId}
    </update>

    <delete id="deleteProProductionSolutionProcessByProductionSolutionProcessId" parameterType="Long">
        delete
        from pro_production_solution_process
        where production_solution_process_id = #{productionSolutionProcessId}
    </delete>

    <delete id="deleteProProductionSolutionProcessByProductionSolutionProcessIds" parameterType="String">
        delete from pro_production_solution_process where production_solution_process_id in
        <foreach item="productionSolutionProcessId" collection="array" open="(" separator="," close=")">
            #{productionSolutionProcessId}
        </foreach>
    </delete>
</mapper>