高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@RestResource(urlMapping='/OFSAddReportOP/*')
global with sharing class OFSAddReportOPRest {
    /**
     * sTime yyyy/MM/dd HH24:mm
     */
    @HttpPost
    global static void addReportOP() {
        Map<String, String> requestMap = (Map<String, String>) JSON.deserializeStrict(RestContext.request.requestBody.toString(), Map<String, String>.class);
        String repOwnerId = UserInfo.getUserId();
        String reportId = requestMap.get('reportId');
        String dailyReportId = requestMap.get('dailyReportId');
        String eventCId = requestMap.get('eventCId');
        String recordType = requestMap.get('recordType');
        String accId = requestMap.get('accId');
        String visitor1 = requestMap.get('visitor1');
        String visitor2 = requestMap.get('visitor2');
        String visitor3 = requestMap.get('visitor3');
        String visitor4 = requestMap.get('visitor4');
        String visitor5 = requestMap.get('visitor5');
        String opp1Id = requestMap.get('opp1Id');
        String opp2Id = requestMap.get('opp2Id');
        String opp3Id = requestMap.get('opp3Id');
        String opp4Id = requestMap.get('opp4Id');
        String opp5Id = requestMap.get('opp5Id');
        String reportDate = requestMap.get('reportDate');
 
        system.debug('OFSAddReportOPRest.start');
        RestResponse res = RestContext.response;
        res.addHeader('Content-Type', 'application/json');
        res.statusCode = 200;
        if (String.isBlank(eventCId)) {
            Map<String, String> responseMap = OFSEventEditRest.createDailyReport(requestMap);
            if (responseMap.get('System.Label.OFSErrorStatus') == System.Label.OFSErrorFailure) {
                String eventResponse = JSON.serialize(responseMap);
                res.responseBody = blob.valueOf(eventResponse);
                return;
            }
            eventCId = responseMap.get(System.Label.OFSErrorMessage);
            dailyReportId = responseMap.get('drId');
        } else {
            Map<String, String> responseMap = OFSEventEditRest.createDailyReport(requestMap);
            if (responseMap.get('System.Label.OFSErrorStatus') == System.Label.OFSErrorFailure) {
                String eventResponse = JSON.serialize(responseMap);
                res.responseBody = blob.valueOf(eventResponse);
                return;
            }
        }
        String jsonResponse;
        try {
            String rtnId = Add_Report.addReportOP(repOwnerId, reportId, dailyReportId, eventCId, recordType, accId, visitor1, visitor2, visitor3, visitor4,visitor5, opp1Id, opp2Id, opp3Id, opp4Id, opp5Id, reportDate);
            // JSONを戻す
            jsonResponse = '{"'+ System.Label.OFSErrorStatus +'": "'+ System.Label.OFSErrorSuccess +'", "'+ System.Label.OFSErrorMessage +'": "' + rtnId + '"}';
        } catch (Exception ex) {
            //error message:cannot update exception
            jsonResponse = '{"'+ System.Label.OFSErrorStatus +'": "'+ System.Label.OFSErrorFailure +'", "'+ System.Label.OFSErrorMessage +'": "'+ ex +'"}';
        }
        res.responseBody = blob.valueOf(jsonResponse);
        return;
    }
}