From 6c756e2a0ec1d67b1c13d3b9c2a387e046456ffa Mon Sep 17 00:00:00 2001
From: 张宇恒 <bxyun0@163.com>
Date: 星期五, 15 四月 2022 18:04:48 +0800
Subject: [PATCH] NFM612报修子单相关

---
 force-app/main/default/classes/RepairOrderHandler.cls-meta.xml     |    5 +
 force-app/main/default/triggers/RepairOrder.trigger-meta.xml       |    5 +
 force-app/main/default/classes/NFM612Rest.cls                      |   40 +++++++--
 force-app/main/default/classes/RepairOrderHandler.cls              |   31 +++++++
 force-app/main/default/classes/ChoiceAssetController.cls           |   55 ++++++++++++-
 force-app/main/default/classes/NFM612RestTest.cls                  |    2 
 force-app/main/default/triggers/RepairOrder.trigger                |    4 +
 force-app/main/default/classes/RepairOrderHandlerTest.cls-meta.xml |    5 +
 force-app/main/default/classes/ChoiceAssetControllerTest.cls       |    3 
 force-app/main/default/classes/RepairOrderHandlerTest.cls          |   62 +++++++++++++++
 10 files changed, 196 insertions(+), 16 deletions(-)

diff --git a/force-app/main/default/classes/ChoiceAssetController.cls b/force-app/main/default/classes/ChoiceAssetController.cls
index e5729b9..14da60f 100644
--- a/force-app/main/default/classes/ChoiceAssetController.cls
+++ b/force-app/main/default/classes/ChoiceAssetController.cls
@@ -76,8 +76,9 @@
                                             Order_No__c,Account.Name,Status,Department_Class__c,Hospital__r.Owner.Name,
                                             Hospital__r.Owner.Phone,Installation_Site__c,CurrentContract__c,
                                             Product2.Asset_Model_No__c,Hospital__r.Name,Department_Class__r.Name ,
-                                            Department_Class__r.Id,Ji_Zhong_Guan_Li_Ku_Cun__c
+                                            Department_Class__r.Id,Ji_Zhong_Guan_Li_Ku_Cun__c,Account.RecordTypeId
                                             ,Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c
+                                            ,Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c
                                         FROM Asset where Id != null AND Repairing_Count__c >= 0 AND SerialNumber like :serialNumber LIMIT 100
 
                                         ];
@@ -126,6 +127,10 @@
             if (info.check) {
                 ast = info.ast;
                 quantity += 1;
+                // if (info.ast.Ji_Zhong_Guan_Li_Ku_Cun__c <= 0){
+                //     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '璁惧闆嗕腑绠$悊搴撳瓨涓嶈冻'));
+                //     return null;
+                // }
             }
         }
         if (quantity == 0) {
@@ -154,6 +159,9 @@
             String zhanlueKeshiId = '00N10000002Dx5t'; //鎴樼暐绉戝
             String keshiId = '00N10000002Dx5n'; //绉戝
             String guzhang = '00N10000002Dx5y'; //鏁呴殰鍙戠敓鏃�
+            //add     wangweipeng        2022/01/26       start
+            String guzhangxcx = '00N1m000006vXqw'; //1.鏁呴殰鍙戠敓鏃ワ紙灏忕▼搴忥級
+            //add     wangweipeng        2022/01/26       end
             String Repair_Source_Id = '00N10000002FH86';//鏂板缓淇悊鏉ユ簮
             String Incharge_Staff_Id = '00N10000002EMHw';//淇悊濮旀墭鑰�(FSE)   
 
@@ -232,10 +240,13 @@
             url += joint_4 + RepairApplicantHospital_Id + joint_1 + repairSubOrder.Hospital__r.Name;//鎶ヤ慨浜哄尰闄�
             url += joint_4 + RepairApplicantDepartment_Id + joint_1 + repairSubOrder.Department__r.Name;//鎶ヤ慨浜虹瀹�
 
-            if (repairSubOrder.ProblemDescription__c != null) {
-                url += joint_4 + Repair_Detail_Id + joint_1 + repairSubOrder.ProblemDescription__c;
+            if (repairSubOrder.ResponseResultDesc__c != null) { //2022/04/07   zhangyuheng  ProblemDescription__c>ResponseResultDesc__c
+                url += joint_4 + Repair_Detail_Id + joint_1 + repairSubOrder.ResponseResultDesc__c;
             }
             url += joint_4 + guzhang + joint_1 + NFMUtil.formatDateTime2StrSprit(repairSubOrder.FaultTime__c);
+            //add         wangweipeng                 2022/02/11              start
+            url += joint_4 + guzhangxcx + joint_1 + NFMUtil.formatDateTime2StrDateTime(repairSubOrder.FaultTime__c);
+            //add         wangweipeng                 2022/02/11              end
             url += joint_4 + faqiri + joint_1 + NFMUtil.formatDateTime2StrSprit(repairSubOrder.RepairsReportDate__c);
             url += joint_4 +  PlannedVisitDay_Id + joint_1 + NFMUtil.formatDateTime2StrSprit(repairSubOrder.PlannedVisitDay__c);//璁″垝涓婇棬鏃�
             url += joint_4 +  ActualVisitDateFirst_Id+ joint_1 + NFMUtil.formatDateTime2StrSprit(repairSubOrder.ActualVisitDateFirst__c);//涓�娆′笂闂ㄦ棩
@@ -247,8 +258,42 @@
             url += joint_4 + shouliri + joint_1 + NFMUtil.formatDateTime2StrSprit(repairSubOrder.ReceiverTime__c);
 
             //add     wangweipeng        2022/01/26       start
-            url += joint_4 +  SalesOfficeCode_selection_Id+ joint_1 + ast.Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c;//淇悊鍝佽繑閫佸湴
+            // url += joint_4 +  SalesOfficeCode_selection_Id+ joint_1 + ast.Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c;//淇悊鍝佽繑閫佸湴      //2022/4/7  zhangyuheng 娉ㄩ噴
             //add     wangweipeng        2022/01/26       end
+            //add     zhangyuheng        2022/04/07       start
+            if (String.isNotBlank(ast.Account.RecordTypeId)) {
+                if (ast.Account.RecordTypeId == '01210000000QemQAAS' || //鎴樼暐绉戝 ET
+                    ast.Account.RecordTypeId == '01210000000QemL' || //鎴樼暐绉戝 娑堝寲绉�
+                    ast.Account.RecordTypeId == '01210000000Qezy' || //鎴樼暐绉戝 鍏朵粬
+                    ast.Account.RecordTypeId == '01210000000Qf03' || //鎴樼暐绉戝 涓嶆槑
+                    ast.Account.RecordTypeId == '01210000000QezZ' || //鎴樼暐绉戝 鍛煎惛绉�
+                    ast.Account.RecordTypeId == '01210000000Qezo' || //鎴樼暐绉戝 濡囩
+                    ast.Account.RecordTypeId == '01210000000Qeze' || //鎴樼暐绉戝 鏅绉�
+                    ast.Account.RecordTypeId == '01210000000Qezj' || //鎴樼暐绉戝 娉屽翱绉�
+                    ast.Account.RecordTypeId == '01210000000Qezt'    //鎴樼暐绉戝 鑰抽蓟鍠夌
+                    ) { //鎴樼暐绉戝
+                    if (String.isNotBlank(ast.Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c)) {
+                        url += joint_4 +  SalesOfficeCode_selection_Id+ joint_1 + ast.Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c;//淇悊鍝佽繑閫佸湴
+                    }else {
+                        // continue;
+                    }
+                }
+                if (ast.Account.RecordTypeId == '01210000000QfmRAAS' || //绉戝 鍛煎惛绉�
+                    ast.Account.RecordTypeId == '01210000000QfmH' || //绉戝 鏅绉�
+                    ast.Account.RecordTypeId == '01210000000Qfmb' || //绉戝 鍏朵粬
+                    ast.Account.RecordTypeId == '01210000000QfmM' || //绉戝 濡囩
+                    ast.Account.RecordTypeId == '01210000000QfmC' || //绉戝 娉屽翱绉�
+                    ast.Account.RecordTypeId == '01210000000Qfm7' || //绉戝 娑堝寲绉�
+                    ast.Account.RecordTypeId == '01210000000Qfm2'    //绉戝 鑰抽蓟鍠夌
+                    ) { //绉戝
+                    if (String.isNotBlank(ast.Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c)) {
+                        url += joint_4 +  SalesOfficeCode_selection_Id+ joint_1 + ast.Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c;//淇悊鍝佽繑閫佸湴
+                    }else {
+                        // continue;
+                    }
+                }
+            }
+            //add     zhangyuheng        2022/04/07       end
             
             url += joint_3 + Incharge_Staff_Id + joint_1 + repairSubOrder.Owner.Name;
             url += joint_3 + Incharge_Staff_Id + joint_2 + repairSubOrder.OwnerId;
@@ -310,7 +355,7 @@
         String soql = 'select Id,name,SerialNumber,InstallDate,Information_From__c,Asset_situation__c,Order_No__c,Account.Name,Status,Department_Class__c, ';
 
         soql += 'Hospital__r.Owner.Name,Hospital__r.Owner.Phone,Installation_Site__c,CurrentContract__c,Product2.Asset_Model_No__c,Hospital__r.Name,Department_Class__r.Name ,Department_Class__r.Id,';
-        soql += 'Ji_Zhong_Guan_Li_Ku_Cun__c,Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c';
+        soql += 'Ji_Zhong_Guan_Li_Ku_Cun__c,Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c,Account.RecordTypeId';
         soql += ' from Asset where Id != null AND Repairing_Count__c = 0 ';
         if (String.isNotBlank(FuselageNumber) || String.isNotBlank(AssetModel) || String.isNotBlank(HospitalName)) {
             soql += ' AND (';
diff --git a/force-app/main/default/classes/ChoiceAssetControllerTest.cls b/force-app/main/default/classes/ChoiceAssetControllerTest.cls
index 77826d8..d7d9ec0 100644
--- a/force-app/main/default/classes/ChoiceAssetControllerTest.cls
+++ b/force-app/main/default/classes/ChoiceAssetControllerTest.cls
@@ -2,6 +2,7 @@
 private class ChoiceAssetControllerTest {
  @testSetup
 static void setupTestData() {
+        Oly_TriggerHandler.bypass('ContactTriggerHandler');
         ControllerUtil.EscapeNFM001Trigger = true;
         // 鐪�
         Address_Level__c al = new Address_Level__c();
@@ -113,7 +114,7 @@
 	    ChoiceAssetController conTest = new ChoiceAssetController();
 	    conTest.init();
 	    conTest.searchAsset();
-	    conTest.choiceAssetInfoRecordsview[1].check= true;
+	    conTest.choiceAssetInfoRecordsview[0].check= true;
 	    conTest.save();
     }
     // 娴嬭瘯鍒涘缓QIS
diff --git a/force-app/main/default/classes/NFM612Rest.cls b/force-app/main/default/classes/NFM612Rest.cls
index 105bc7d..9918df4 100644
--- a/force-app/main/default/classes/NFM612Rest.cls
+++ b/force-app/main/default/classes/NFM612Rest.cls
@@ -54,6 +54,11 @@
         public String applicantId; //鐢宠淇悊浜虹紪鍙�
         public String applyDate; //鐢宠鏃堕棿
         public String repairOrderNo2FSEID; //鎶ヤ慨瀛愬崟鎵�灞濬SE鐨処D
+        //  2022/4/6    zhangyuheng update start
+        public String RepairFinishDate; //淇悊鍝佸鐞嗗畬鎴愭棩
+        public String ApplicanterPhone; //澶勭悊浜虹數璇�
+        public String CancelDate;   //鍙楃悊浜哄彇娑堟姤淇棩
+        //  2022/4/6    zhangyuheng update end
 
         // 涓婄嚎鍓� 鎶ヤ慨瀛愬崟涓庝慨鐞嗕笂鐨勭浉鍏冲瓧娈甸兘鍒犻櫎
         public String responseResultsFirst; //涓婇棬搴斿缁撴灉(鏆傛椂娉ㄦ帀)
@@ -131,6 +136,7 @@
             List < String > managementCodeList = new List < String > (); //瀛樻斁绉戝缂栫爜
             List < String > rpersonList = new List < String > (); //瀛樻斁鎶ヤ慨浜虹敤鎴风紪鐮�
             List < String > canIdList = new List < String > (); //瀛樻斁鍙栨秷浜虹敤鎴风紪鍙�
+            List < String > repairNoList = new List < String > ();  //瀛樻斁鎶ヤ慨瀛愬崟鍙� 
             for (GeData ged: itemMasterList) {
                 String dataComplete = verify(ged);
                 if (!String.isBlank(dataComplete)) {
@@ -226,12 +232,12 @@
                     repair.StartTimeFirst__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.startTimeFirst); //寮�濮嬫椂闂�
                     repair.EndTimeFirst__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.endTimeThird); //缁撴潫鏃堕棿
                     repair.FaultDescriptionFirst__c = ged.repairOderInfo.faultDescriptionFirst; //鏁呴殰鎻忚堪
-                    repair.ActualVisitTimeSecond__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.actualVisitTimeSecond); //浜屾涓婇棬鏃�
-                    repair.StartTimeSecond__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.startTimeSecond); //浜屾涓婇棬寮�濮嬫椂闂�
+                    repair.ActualVisitTimeSecond__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.actualVisitTimeSecond); //浜屾涓婇棬鏃�--->浜屾璁″垝涓婇棬鏃�
+                    repair.StartTimeSecond__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.startTimeSecond); //浜屾涓婇棬寮�濮嬫椂闂�--->浜屾涓婇棬鏃�
                     repair.EndTimeSecond__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.endTimeSecond); //浜屾涓婇棬缁撴潫鏃堕棿
                     repair.FaultDescriptionSecond__c = ged.repairOderInfo.faultDescriptionSecond; //浜屾鏁呴殰鎻忚堪
-                    repair.ActualVisitTimeThird__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.actualVisitTimeThird); //涓夋涓婇棬鏃�
-                    repair.StartTimeThird__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.startTimeThird); //涓夋涓婇棬寮�濮嬫椂闂�
+                    repair.ActualVisitTimeThird__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.actualVisitTimeThird); //涓夋涓婇棬鏃�--->涓夋璁″垝涓婇棬鏃�
+                    repair.StartTimeThird__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.startTimeThird); //涓夋涓婇棬寮�濮嬫椂闂�--->涓夋涓婇棬鏃�
                     repair.EndTimeThird__c = NFMUtil.parseStr2DateTime(ged.repairOderInfo.endTimeThird); //涓夋涓婇棬缁撴潫鏃堕棿
                     repair.FaultDescriptionThird__c = ged.repairOderInfo.faultDescriptionThird; //涓夋鏁呴殰鎻忚堪
                     repair.ApplicantType__c = ged.repairOderInfo.applicantType; //鐢宠淇悊浜虹被鍨�
@@ -245,12 +251,20 @@
                     repair.Ownerid = canidMap.get(ged.repairOderInfo.repairOrderNo2FSEID).Id; //鎶ヤ慨瀛愬崟鎵�灞濬SE鐨処D
                     repair.AssetModel__c = ged.applyRepairInfo.equipmentModel; //璁惧鍨嬪彿
                     repair.AirframeCodeEngineer__c = ged.applyRepairInfo.equipmentCd; //鏈鸿韩缂栫爜(宸ョ▼甯�)
-                    repair.ResponseResultDesc__c = ged.applyRepairInfo.responseResultDesc; //搴斿鎻忚堪
+                    repair.ResponseResultDesc__c = ged.applyRepairInfo.responseResultDesc; //搴斿鎻忚堪--->闂鎻忚堪锛堝伐绋嬪笀锛�
                     repair.ProcessResult__c = ged.applyRepairInfo.processResult; //澶勭悊缁撴灉
-                    
+
+                    //  2022/4/6    zhangyuheng update start
+                    repair.RepairFinishDate__c = NFMUtil.parseDateTimeStr2Date(ged.repairOderInfo.RepairFinishDate) ;   //淇悊鍝佸鐞嗗畬鎴愭棩
+                    repair.ApplicanterPhone__c = ged.repairOderInfo.ApplicanterPhone;   //澶勭悊浜虹數璇�
+                    repair.CancelleRepairTime__c = NFMUtil.parseDateTimeStr2Date(ged.repairOderInfo.CancelDate);    //鍙楃悊浜哄彇娑堟姤淇棩
+                    // repair.CancelleRepairTime__c = NFMUtil.parseStr2Date(ged.repairOderInfo.CancelDate);    //鍙楃悊浜哄彇娑堟姤淇棩
+                    repair.RepairCancelReason__c = ged.repairOderInfo.cancelReportReason;   //淇悊鍙栨秷鍘熷洜
+                    //  2022/4/6    zhangyuheng update end
 
                     if ('闂宸茶В鍐�'.equals(ged.applyRepairInfo.processResult)) {
-                        repair.Status__c = '鍏抽棴';
+                        // repair.Status__c = '鍏抽棴';
+                        repair.Status__c = '宸插畬鎴�';   // 2022/4/6 zhangyuheng
                     } else {
                         repair.Status__c = '寰呭鐞�';
 
@@ -270,10 +284,16 @@
                     repair.AttachmentName__c = attachmentName;
                     repairOrderNo2Str += repairOrderNo2 + '\n';
                     repairList.add(repair);
+                    repairNoList.add(ged.repairOderInfo.repairOrderNo2);
                 }
-
-                if (repairList.size() > 0) {
-
+                //  2022/4/6    zhangyuheng update start
+                List<RepairSubOrder__c> repairList1 = [SELECT Id FROM RepairSubOrder__c WHERE RepairSubOrderNo__c in: repairNoList];
+                if (repairList1.size() > 0) {
+                    logstr += repairOrderNo2Str + ']-宸插瓨鍦�';
+                }
+                // if (repairList.size() > 0) {==== 2022/4/6 zhangyuheng娉ㄩ噴鎺�
+                else {
+                //  2022/4/6    zhangyuheng update end
                     insert repairList;
                     repairOrderNo2Str += ' ]\n';
                     logstr += repairOrderNo2Str + '鏂板瀹屾垚, 鏂板鎬绘暟鏁颁负锛�' + repairList.size() + '\n';
diff --git a/force-app/main/default/classes/NFM612RestTest.cls b/force-app/main/default/classes/NFM612RestTest.cls
index 78583d1..bf10886 100644
--- a/force-app/main/default/classes/NFM612RestTest.cls
+++ b/force-app/main/default/classes/NFM612RestTest.cls
@@ -5,6 +5,8 @@
     }
     @testSetup
     static void makeTestRepair() {
+        
+        Oly_TriggerHandler.bypass('ContactTriggerHandler');
         List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '鐥呴櫌'];
         if (rectCo.size() == 0) {
             throw new ControllerUtil.myException('not found 鐥呴櫌 recodetype');
diff --git a/force-app/main/default/classes/RepairOrderHandler.cls b/force-app/main/default/classes/RepairOrderHandler.cls
new file mode 100644
index 0000000..3b600a0
--- /dev/null
+++ b/force-app/main/default/classes/RepairOrderHandler.cls
@@ -0,0 +1,31 @@
+public without sharing class RepairOrderHandler extends Oly_TriggerHandler {
+    private Map<Id, Repair__c> newMap;
+    private Map<Id, Repair__c> oldMap;
+    private List<Repair__c> newList;
+    private List<Repair__c> oldList;
+    public RepairOrderHandler() {
+        this.newMap = (Map<Id, Repair__c>) Trigger.newMap;
+        this.oldMap = (Map<Id, Repair__c>) Trigger.oldMap;
+        this.newList = (List<Repair__c>) Trigger.new;
+        this.oldList = (List<Repair__c>) Trigger.old;
+    }
+	protected override void afterInsert() {
+		RepairInsert();
+	}
+    public void RepairInsert(){
+        List<RepairSubOrder__c> repairSubOrderList = new List<RepairSubOrder__c>();
+    	for (Repair__c repair : newList) {
+    		if (Trigger.isInsert) {
+    		    if (String.isNotBlank(repair.RepairSubOrder__c)) {
+    		        RepairSubOrder__c rso = new RepairSubOrder__c();
+    		        rso.Id = repair.RepairSubOrder__c;
+    		        rso.SFDCRepairApplyDate__c = Date.today();
+    		        repairSubOrderList.add(rso);
+    		    }
+    		}
+    	}
+    	if (repairSubOrderList.size() > 0) {
+    	    update repairSubOrderList;
+    	}
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/RepairOrderHandler.cls-meta.xml b/force-app/main/default/classes/RepairOrderHandler.cls-meta.xml
new file mode 100644
index 0000000..f3bac1f
--- /dev/null
+++ b/force-app/main/default/classes/RepairOrderHandler.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>41.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/classes/RepairOrderHandlerTest.cls b/force-app/main/default/classes/RepairOrderHandlerTest.cls
new file mode 100644
index 0000000..ab51d29
--- /dev/null
+++ b/force-app/main/default/classes/RepairOrderHandlerTest.cls
@@ -0,0 +1,62 @@
+@isTest
+private class RepairOrderHandlerTest {
+	 final static string ra1 = [select id , SobjectType, developername  from recordtype where SobjectType='Rental_Apply__c' and developername='StandardRequest'][0].id;
+    final static string acc1 = [select id , SobjectType, developername  from recordtype where SobjectType='Account' and developername='HP'][0].id;
+
+    static testMethod void testMethod1() {
+        RepairSubOrder__c subOrder = new RepairSubOrder__c();
+        subOrder.AttachmentDownload__c = true;
+        subOrder.AttachmentLink__c = 'https://albsylfw.s3.cn-northwest-1.amazonaws.com.cn/20211220/14/11/30/lessthan12/5e8cb69e-f935-48f5-825e-b8344d60f6d4.zip';
+        subOrder.AttachmentName__c = '娴嬭瘯闄勪欢涓嬭浇';
+        insert subOrder;
+        Account hp = new Account(RecordTypeId = acc1, Name = 'AccountTestHp1');
+        insert hp;
+        
+        Product2 prd1 = new Product2();
+        prd1.ProductCode_Ext__c     = 'Prd1';
+        prd1.ProductCode            = 'Prd1';
+        prd1.Repair_Product_Code__c = 'Prd1_RP';
+        prd1.Name                   = 'Prd1';
+        prd1.Manual_Entry__c        = false;
+        prd1.Category2__c = '鏈綋';
+        prd1.Category3__c = '绾ょ淮闀�';
+        prd1.Category4__c = 'CV';
+        prd1.Category5__c = '260SL绯诲垪';
+        prd1.Asset_Model_No__c = '1001';
+        insert prd1;
+        
+        Asset ast1 = new Asset();
+        ast1.Name                   = '淇濇湁瑷倷1';
+        ast1.Hospital__c            = hp.Id;
+        ast1.AccountId              = hp.Id;
+        ast1.Product2Id             = prd1.Id;
+        ast1.SerialNumber           = 'SerialNumber1';
+        ast1.Guarantee_period_for_products__c = Date.today();
+        ast1.InstallDate                      = Date.today();
+        insert ast1;
+        
+        final string acc2 = [select id , SobjectType, developername  from recordtype where SobjectType='Account' and developername='Department_Class_BF'][0].id; //鎴︾暐绉戝鍒嗛 鍛煎惛绉�
+        Account Department_Class_BF = new Account(RecordTypeId = acc2, Name = 'Department_Class_BF',ParentId=hp.id,Department_Class_Label__c='鍛煎惛绉�');
+        insert Department_Class_BF;
+        final string acc3 = [select id , SobjectType, developername  from recordtype where SobjectType='Account' and developername='Department_BF'][0].id; //鎴︾暐绉戝鍒嗛 鍛煎惛绉�
+        Account Department_BF = new Account(RecordTypeId = acc3, Name = 'Department_BF',ParentId=Department_Class_BF.id,Hospital__c=hp.id,Department_Class__c=Department_Class_BF.id);
+        insert Department_BF;
+        
+        Repair__c repair1 = new Repair__c();
+        repair1.Service_Repair_No__c = 'repair1';
+        repair1.Hospital__c            = hp.Id;
+        repair1.Account__c             = Department_BF.Id;
+        repair1.Department_Class__c = Department_Class_BF.id;
+        repair1.Delivered_Product__c = ast1.Id;
+        repair1.Repair_List_Price__c = 100;
+        repair1.Billing_Amount__c = 10;
+        repair1.Paid_Amount__c = 1;
+        repair1.Failure_Occurrence_Date__c = Date.today().addDays(-1);
+        repair1.Repair_Returned_To_HP_Date__c = Date.today().addDays(3);
+        repair1.Repair_Shipped_Date__c = Date.today().addDays(1);
+        repair1.RepairSubOrder__c = subOrder.Id;
+        repair1.DeliveryLogisticsMode__c = '鍏朵粬';
+        
+        insert repair1;
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/RepairOrderHandlerTest.cls-meta.xml b/force-app/main/default/classes/RepairOrderHandlerTest.cls-meta.xml
new file mode 100644
index 0000000..f3bac1f
--- /dev/null
+++ b/force-app/main/default/classes/RepairOrderHandlerTest.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>41.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/triggers/RepairOrder.trigger b/force-app/main/default/triggers/RepairOrder.trigger
new file mode 100644
index 0000000..9967147
--- /dev/null
+++ b/force-app/main/default/triggers/RepairOrder.trigger
@@ -0,0 +1,4 @@
+trigger RepairOrder on Repair__c(after insert) {
+    RepairOrderHandler roh = new RepairOrderHandler();
+    roh.run();
+}
\ No newline at end of file
diff --git a/force-app/main/default/triggers/RepairOrder.trigger-meta.xml b/force-app/main/default/triggers/RepairOrder.trigger-meta.xml
new file mode 100644
index 0000000..5a7409a
--- /dev/null
+++ b/force-app/main/default/triggers/RepairOrder.trigger-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>41.0</apiVersion>
+    <status>Active</status>
+</ApexTrigger>
\ No newline at end of file

--
Gitblit v1.9.1