twysparks
2023-04-20 74e6a383570060d05c58f731fa7cd9f241db50bd
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
public with sharing class MonthlyReportController {
    //为取消提交相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForCancelSubmitButton (String recordId){
        InitData res = new initData();
        try{
            Monthly_Report__c report = [SELECT     OwnerId,Id,Next_week_plan__c FROM Monthly_Report__c WHERE Id = :recordId LIMIT 1];
            res.OwnerId = report.OwnerId;
            res.Id = report.Id;
            res.nextWeekPlan = report.Next_week_plan__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //为创建notes邮箱操作提供初始化数据
    @AuraEnabled
    public static InitData initForCreateNoteEmailButton (String recordId) {
        InitData res = new initData();
        try{
            Monthly_Report__c report = [SELECT
            Owner_email__c,
            Owner_alias__c,
            Key_issue__c,
            Feedback__c,
            Task_follow__c,
            Other_issue__c,
            Next_week_plan__c,
            Dr_Sum_URL__c
            FROM Monthly_Report__c WHERE Id = :recordId LIMIT 1];
            String userName = UserInfo.getUserName();
            User activeUser = [Select Email From User where Username = : userName limit 1];
            String userEmail = activeUser.Email;
            res.ownerEmail = report.Owner_email__c;
            res.ownerAlias = report.Owner_alias__c;
            res.keyIssue = report.Key_issue__c;
            res.feedBack = report.Feedback__c;
            res.taskFollow = report.Task_follow__c;
            res.otherIssue = report.Other_issue__c;
            res.nextWeekPlan = report.Next_week_plan__c;
            res.drSumUrl = report.Dr_Sum_URL__c;
            res.userEmail = activeUser.Email;
            
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //取消提交操作更新相应数据
    @AuraEnabled
    public static String cancel(String recordId) {
       try {
        Monthly_Report__c report = [SELECT     Id,Status__c,Submit_check_flag__c,RecordTypeId,Submit_time__c FROM Monthly_Report__c WHERE Id = :recordId LIMIT 1];
        report.Status__c = LightingButtonConstant.STATUS_DRAFT;
        report.RecordTypeId =  Schema.SObjectType.Monthly_Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_MONTHLY_REPORT).getRecordTypeId();
        report.Submit_check_flag__c = false;
        report.Submit_time__c = null;
        update report;
        return null;
       } catch (Exception e) {
        String eMessage = e.getMessage();
        Integer left = eMessage.indexOf(',') + 1;
        Integer right = eMessage.length();
        return eMessage.substring(left,right);
       }
    }
 
 
    public class InitData{
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public String OwnerId;
        @AuraEnabled
        public String ownerEmail;
        @AuraEnabled
        public String ownerAlias;
        @AuraEnabled
        public String keyIssue;
        @AuraEnabled
        public String feedBack;
        @AuraEnabled
        public String taskFollow;
        @AuraEnabled
        public String otherIssue;
        @AuraEnabled
        public String nextWeekPlan;
        @AuraEnabled
        public String drSumUrl;
        @AuraEnabled
        public String userEmail;
    }
}