INSERT INTO exam_teacher_salary (id_,examination_basic_id_,exam_mode_,teacher_id_,settlement_type_,share_profit_amount_,
total_invigilation_num_,total_invigilation_student_num_,total_settlement_fee_,create_time_,update_time_,tenant_id_)
VALUES(#{id},#{examinationBasicId},#{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{teacherId},#{settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{shareProfitAmount},
#{totalInvigilationNum},#{totalInvigilationStudentNum},#{totalSettlementCost},NOW(),NOW(),#{tenantId})
INSERT INTO exam_teacher_salary (examination_basic_id_,exam_mode_,teacher_id_,settlement_type_,share_profit_amount_,
total_invigilation_num_,total_invigilation_student_num_,total_settlement_fee_,create_time_,update_time_,tenant_id_)
VALUES
(#{ets.examinationBasicId},#{ets.examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{ets.teacherId},
#{ets.settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{ets.shareProfitAmount},
#{ets.totalInvigilationNum},#{ets.totalInvigilationStudentNum},#{ets.totalSettlementCost},NOW(),NOW(),#{ets.tenantId})
UPDATE exam_teacher_salary
examination_basic_id_ = #{examinationBasicId},
teacher_id_ = #{teacherId},
tenant_id_ = #{tenantId},
exam_mode_ = #{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
share_profit_amount_ = #{shareProfitAmount},
settlement_type_ = #{settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
total_invigilation_num_ = #{totalInvigilationNum},
total_invigilation_student_num_ = #{totalInvigilationStudentNum},
total_settlement_fee_ = #{totalSettlementCost},
update_time_ = NOW()
WHERE id_ = #{id}
UPDATE exam_teacher_salary
examination_basic_id_ = #{ts.examinationBasicId},
teacher_id_ = #{ts.teacherId},
tenant_id_ = #{ts.tenantId},
exam_mode_ = #{ts.examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
share_profit_amount_ = #{ts.shareProfitAmount},
settlement_type_ = #{ts.settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
total_invigilation_num_ = #{ts.totalInvigilationNum},
total_invigilation_student_num_ = #{ts.totalInvigilationStudentNum},
total_settlement_fee_ = #{ts.totalSettlementCost},
update_time_ = NOW()
WHERE id_ = #{ts.id}
DELETE FROM exam_teacher_salary WHERE id_ = #{id}
examination_basic_id_ = #{examId}
AND ets.examination_basic_id_ = #{examId}
AND ets.teacher_id_=#{teacherId}
AND ets.settlement_type_ = #{settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler}
AND (ets.teacher_id_=#{search} OR su.real_name_ LIKE CONCAT('%', #{search}, '%'))
t.tenant_id_=#{tenantId}
AND NOT EXISTS ( SELECT teacher_id_ FROM exam_teacher_salary WHERE teacher_id_ = t.user_id_ AND examination_basic_id_ = #{examId} )