public with sharing class RentalApplyESetRefreshStatusController {
    @AuraEnabled
    public static String eSetRefreshStatus(String raeSetId) {
        return eSetRefreshStatusBatch(new List<String> {raeSetId});
    }
  
    public static String eSetRefreshStatusBatch(List<String> raeSetIds) {
        List<Rental_Apply_Equipment_Set__c> updateList1 = new List<Rental_Apply_Equipment_Set__c>();

        if (!raeSetIds.isEmpty()) {
            for (Rental_Apply_Equipment_Set__c raes: [
                    select Id,Repair_Status1__c,Repair_Status_Text__c,Final_reply_day__c,Final_reply_day_text__c,
                            Received_Confirm_NG_Not_Return__c,Received_Confirm_NG_Not_Return_Text__c,
                            Received_Confirm_Status_Text__c, Received_Confirm_Status_F__c
                              , NG_Final_reply_day_Text__c
                              , NG_Final_reply_day_F__c
                              , Yizhouweixiu_Final_reply_day_Text__c
                              , Yizhouweixiu_Final_reply_day_F__c
                              , Extend_Final_reply_day_Text__c
                              , Extend_Final_reply_day_F__c
                              , QIS_Final_reply_day_Text__c
                              , QIS_Final_reply_day_F__c
                              , Repair_cancel_Final_reply_day_Text__c
                              , Repair_cancel_Final_reply_day_F__c
                              , Return_to_office_Final_reply_day_Text__c
                              , Return_to_office_Final_reply_day_F__c
                              , Repair_delete_Final_reply_day_Text__c
                              , Repair_delete_Final_reply_day_F__c
                              , Yigoudaihuo_Final_reply_day_Text__c
                              , Yigoudaihuo_Final_reply_day_F__c
                              , Guzhangpaicha_Final_reply_day_Text__c
                              , Guzhangpaicha_Final_reply_day_F__c
                              , Repair_Agreed_Quotation_Text__c
                              , Repair_Agreed_Quotation_F__c
                              , Return_to_office_Final_reply_day_U_RC__c
                              , Return_to_office_Final_reply_day_U_RC_F__c
                              , Extend_Date__c
                              , Extend_Date_F__c
                              , Received_NG_ReAssign_Text__c
                              , Received_NG_ReAssign__c
                        //【FY23大及巨大课题】长假备品借用延期开发 2022/12/27 start xxf
                              , Final_reply_day_Holiday_backup__c
                              , NG_Final_reply_day_F_Holiday_backup__c
                              , NG_Final_reply_day_Text_Holiday_backup__c
                              , Yizhouweixiu_Final_reply_day_F_Holiday__c
                              , Yizhouweixiu_Final_reply_day_TextHoliday__c
                              , Extend_Final_reply_day_F_Holiday_backup__c
                              , Extend_Final_reply_day_Text_Holiday_back__c
                              , QIS_Final_reply_day_F_Holiday_backup__c
                              , QIS_Final_reply_day_Text_Holiday_backup__c
                              , Repair_cancel_Final_reply_day_F_Holiday__c
                              , Repair_cancel_Final_reply_day_Text_Holid__c
                              , Return_to_office_Final_reply_day_F_Ho__c
                              , Return_to_office_Final_reply_day_Text_Ho__c
                              , Repair_delete_Final_reply_day_F_Holiday__c
                              , Repair_delete_Final_reply_day_Text_Ho__c
                              , Yigoudaihuo_Final_reply_day_F_Holiday__c
                              , Yigoudaihuo_Final_reply_day_Text_Holiday__c
                              , FGuzhangpaicha_Final_reply_day_F_Holiday__c
                              , Guzhangpaicha_Final_reply_day_Text_Holid__c
                              , Return_to_office_Final_reply_day_U_RC_Ho__c
                              , Return_to_office_Final_reply_day_U_RC_FH__c
                        //【FY23大及巨大课题】长假备品借用延期开发 2022/12/27 end xxf
                      from Rental_Apply_Equipment_Set__c
                     where Id IN :raeSetIds
            ]) {
                Rental_Apply_Equipment_Set__c upd = UpdateRentalApplyEquipmentSetBatch.setRAES(raes);
                if (upd != null) {
                    updateList1.add(upd);
                }
            }
        }
//bp2
//        List<Equipment_Set_Detail__c> esdList = [
//                select Id,Asset_condition__c,Asset_condition_Text__c,
//                       Serial_Lot__c,Serial_Lot_text__c,
//                       Asset__r.Loaner_accsessary__c, Loaner_accsessary_text__c,
//                       Active_judgement__c,Active_judgement_select__c,Active_judgement_text__c,
//                       Last_Reserve_RAES_Detail_RAES_F__c,Last_Reserve_RAES_Detail_RAES_Id__c,
//                       Equipment_Set_Last_Reserve_RAES_F__c,Equipment_Set_Last_Reserve_RAES_Id__c
//                  from Equipment_Set_Detail__c 
//                 where Equipment_Set__c IN :eSetIds];
//        List<Equipment_Set_Detail__c> updateList2 = UpdateRentalApplyEquipmentSetBatch.setESD(esdList);

        Savepoint sp = Database.setSavepoint();
        try {
            if (!updateList1.isEmpty()) update updateList1;
//bp2            if (updateList2.size() > 0) update updateList2;
            return '1';
        } catch (System.Exception e) {
            Database.rollback(sp);
            return e.getMessage();
        }
        // return '1';
    }
    
}