liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
public without sharing class lexTransferRoomCompoentController {
 
    @AuraEnabled
    public static  Tender_information__c  init(String recordId){
        Tender_information__c  res = new Tender_information__c();
        try{
            res = [SELECT Hospital__c,Hospital1__c,Hospital2__c,Hospital3__c,Hospital4__c,department_selection__c,status__c,
                        department_selection1__c,department_selection2__c,department_selection3__c,department_selection4__c
                            FROM  Tender_information__c
                                WHERE Id=:recordId];
            return res;
        }
        catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            return null;
        }
    }
 
    @AuraEnabled(cacheable=true)
    public static String getCurrentUserProfileName() {
        // 获取当前用户的简档名
        return [SELECT Profile.Name FROM User WHERE Id = :UserInfo.getUserId()].Profile.Name;
    }
    //传输新旧信息给  转科室对象
    @AuraEnabled
    public static String transferTenderSumbit(String recordId,String[] arrayOld,String[] arrayNew){
        Savepoint sp = Database.setSavepoint(); // 创建保存点
        TenderTansforSubmmit__c  tts = new TenderTansforSubmmit__c();
        try {
 
 
            tts.TenderInfo__c=recordId;
 
            //不需要判断数组越界  js传来的是长度固定5的数组
            //关联战略科室 赋值  转科室前数据
            String oldValue = lexTransferRoomCompoentController.getApiIdData(arrayOld[0]);
            if(oldValue !='1'){
                tts.tender_Oldselection__c= oldValue;
            }
            tts.tender_Oldselection1__c=arrayOld[1];
            tts.tender_Oldselection2__c=arrayOld[2];
            tts.tender_Oldselection3__c=arrayOld[3];
            tts.tender_Oldselection4__c=arrayOld[4];
            //关联战略科室 赋值  转科室后数据
            String newValue = lexTransferRoomCompoentController.getApiIdData(arrayNew[0]);
            if(newValue !='1'){
                tts.tender_selection__c =newValue;
            }
            tts.tender_selection1__c=arrayNew[1];
            tts.tender_selection2__c=arrayNew[2];
            tts.tender_selection3__c=arrayNew[3];
            tts.tender_selection4__c=arrayNew[4];
 
            //关联医院赋值   ps:转科室不涉及关联医院改变  后续如转科室涉及修改医院可扩展
            Tender_information__c  tInfo  = lexTransferRoomCompoentController.init(recordId);
            //转科室后   
            tts.TransFom_Hospital__c = tInfo.hospital__c;
            tts.TransFom_Hospital1__c = tInfo.hospital1__c;
            tts.TransFom_Hospital2__c = tInfo.hospital2__c;
            tts.TransFom_Hospital3__c = tInfo.hospital3__c;
            tts.TransFom_Hospital4__c = tInfo.hospital4__c;
 
            //转科室前
            tts.TransFom_OldHospital__c = tInfo.hospital__c;
            tts.TransFom_OldHospital1__c = tInfo.hospital1__c;
            tts.TransFom_OldHospital2__c = tInfo.hospital2__c;
            tts.TransFom_OldHospital3__c = tInfo.hospital3__c;
            tts.TransFom_OldHospital4__c = tInfo.hospital4__c;
 
            tts.status__c='草案中';
            insert tts;
 
           Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
           req.setObjectId(tts.Id);
           Approval.ProcessResult result = Approval.process(req);
           if(result!=null&&result.getErrors()!=null&&result.getErrors().size()>0) return result.getErrors().get(0).getMessage();
           return 'success';
        }
        catch (Exception e) {
            System.debug('********lexConsumApplyController*****'+e.getMessage());
            Database.rollback(sp); // 发生异常,回滚到保存点
            return e.getMessage();
        }
        
    }
 
    @AuraEnabled
    public static String getApiIdData(String arr){
            //构造映射关系  
            Map<String, String> optionMapping = new Map<String, String>(); 
            optionMapping.put(System.Label.Department_Class_GI,'消化科');
            optionMapping.put(System.Label.Department_Class_BF,'呼吸科');
            optionMapping.put(System.Label.Department_Class_GS,'普外科');
            optionMapping.put(System.Label.Department_Class_URO,'泌尿科');
            optionMapping.put(System.Label.Department_Class_GYN,'妇科');
            optionMapping.put(System.Label.Department_Class_ENT,'耳鼻喉科');
            List<String> options;
            if(arr == null || arr == ''){
                return '';
            }
            else {
                options = arr.split(';');
            }
 
            System.debug('********transferTenderSumbit*****'+optionMapping);
            String  selectedOptionValues='';
            //遍历查找对应值
            for (String optionId : options) {
                if (optionMapping.containsKey(optionId)) {
                    selectedOptionValues = selectedOptionValues + (optionMapping.get(optionId)) + ';';
                }
            }
            selectedOptionValues = selectedOptionValues.substring(0, selectedOptionValues.length() - 1);   
            System.debug('********transferTenderSumbit*****'+selectedOptionValues);
            return selectedOptionValues;
 
    }
 
    //反向的映射关系
    //用于触发器中,由于招标项目旧的关联战略科室字段值的api是Id,在数据库中的表现形式也是id。而转科室审批对象的关联战略科室的api不一样。
    @AuraEnabled
    public static String getApiIdByValue(String arr){
            //构造映射关系  
            Map<String, String> optionMapping = new Map<String, String>(); 
            optionMapping.put('消化科',System.Label.Department_Class_GI);
            optionMapping.put('呼吸科',System.Label.Department_Class_BF);
            optionMapping.put('普外科',System.Label.Department_Class_GS);
            optionMapping.put('泌尿科',System.Label.Department_Class_URO);
            optionMapping.put('妇科',System.Label.Department_Class_GYN);
            optionMapping.put('耳鼻喉科',System.Label.Department_Class_ENT);
 
            List<String> options;
            if(arr == null || arr == ''){
                return '';
            }
            else {
                options = arr.split(';');
            }
            System.debug('********transferTenderSumbit*****'+optionMapping);
            String  selectedOptionIds='';
            //遍历查找对应值
            for (String optionValue : options) {
                if (optionMapping.containsKey(optionValue)) {
                    selectedOptionIds = selectedOptionIds + (optionMapping.get(optionValue)) + ';';
                }
            }
            selectedOptionIds = selectedOptionIds.substring(0, selectedOptionIds.length() - 1);   
            System.debug('********transferTenderSumbit*****'+selectedOptionIds);
            return selectedOptionIds;
 
    }
    
}