高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@RestResource(urlMapping='/OFSAddReportNT/*')
global with sharing class OFSAddReportNTRest {
    /**
     * sTime yyyy/MM/dd HH24:mm
     */
    @HttpPost
    global static void addReportNT() {
        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 sTimeStr = requestMap.get('sTimeStr');
        String eTimeStr = requestMap.get('eTimeStr');
        String mainPlace = requestMap.get('mainPlace');
 
        system.debug('OFSAddReportNTRest.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.addReportNT(repOwnerId, reportId, dailyReportId, eventCId, recordType, accId, visitor1, visitor2, visitor3, visitor4, visitor5, sTimeStr, eTimeStr, mainPlace);
            // 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;
    }
}