高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/NFM608Rest.cls
@@ -54,11 +54,25 @@
        main(rowData_Id);
    }
    global static void main(String rowData_Id) {
        Map<String, String> transferMap = new Map<String, String>();
        List<BatchIF_Transfer__c> transferList = [select Table__c,
                                  Column__c,
                                  External_value__c,
                                  Internal_value__c
                                  from BatchIF_Transfer__c
                                  where Dropped_Flag__c = false
                                          and (Table__c = 'Event__c')
                                          ];
        for (BatchIF_Transfer__c t : transferList) {
            transferMap.put(t.Column__c + t.External_value__c, t.Internal_value__c);
        }
        BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Id =: rowData_Id];
        String logstr = rowData.MessageGroupNumber__c + ' start\n';
        String logstr = rowData.Name + ' start\n';//MessageGroupNumber__c
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Type__c = LOG_TYPE;
        iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c;
        iflog.MessageGroupNumber__c = rowData.Name;//rowData.MessageGroupNumber__c;
        iflog.Log__c = logstr;
        iflog.ErrorLog__c = '';
        insert iflog;
@@ -69,7 +83,7 @@
        }
        Savepoint sp = Database.setSavepoint();
        try {
            rowData.retry_cnt__c = 0; //必加
            // 必填字段验证 Start
            String dataComplete = verify(ged);
            // 必填字段验证 End
@@ -91,15 +105,45 @@
                // 获取科室
                Account departmentAccount = getdepartmentAccount(ged.departmentCd);
                if (departmentAccount == null) {
                    logstr += '客户 [ ' + ged.departmentCd + ' ] 不存在或已无效,此条数据跳过不执行\n';
                    // 20230109 ljh start
                    // logstr += '客户 [ ' + ged.departmentCd + ' ] 不存在或已无效,此条数据跳过不执行\n';
                    logstr += '[ '+ged.replyID+' ]'+'客户 [ ' + ged.departmentCd + ' ] 不存在或已无效,此条数据跳过不执行\n';
                    // 20230109 ljh end
                    return;
                }
                String strType = getVisitType(ged.visitDistinction);
                if (String.isBlank(strType)) {
                    logstr += '拜访区分 [ ' + ged.visitDistinction + ' ]无效,此条数据跳过不执行 \n';
                    // 20230109 ljh start
                    // logstr += '拜访区分 [ ' + ged.visitDistinction + ' ]无效,此条数据跳过不执行 \n';
                    logstr += '[ '+ged.replyID+' ]'+'拜访区分 [ ' + ged.visitDistinction + ' ]无效,此条数据跳过不执行 \n';
                    // 20230109 ljh end
                    return;
                }
                //日报审批通过之后,不能在创建报告一览
                if(null!=drc){
                    // 20230109 ljh start
                    // if(drc.Status__c=='承認'){
                    if(drc.Status__c=='承認' || drc.Status__c=='申請中'){
                        // logstr += '日报状态 [' + drc.Status__c +' ],此条数据跳过不执行 \n';
                        logstr += '[ '+ged.replyID+' ]'+'日报状态 [' + drc.Status__c +' ],此条数据跳过不执行 \n';
                    // 20230109 ljh end
                        return;
                    }
                }
                Datetime startdate1 = NFMUtil.parseStr2DateTime(ged.visitStartDate);
                Datetime enddate1 = NFMUtil.parseStr2DateTime(ged.visitEndDate);
                Long timeDif = enddate1.getTime() - startdate1.getTime();
                Integer ts = Integer.valueOf((enddate1.getTime() - startdate1.getTime()) / 1000 / 3600 /24);
                system.debug( startdate1.getTime()+'==='+enddate1.getTime()+'==='+startdate1+'==='+enddate1+'==='+ts);
                if(ts > 14){
                    // 20230109 ljh start
                    // logstr += '事件的持续时间不能超过 14 天,此条数据跳过不执行 \n';
                    logstr += '[ '+ged.replyID+' ]'+'事件的持续时间不能超过 14 天,此条数据跳过不执行 \n';
                    // 20230109 ljh start
                   return;
                }
                // 查找访问对象
                String contactId = null;
                if (String.isNotBlank(ged.applicantId)) {
@@ -109,7 +153,7 @@
                    }    
                }
                Event__c report = new Event__c();
                Event__c report = new Event__c();//报告一览
                report.ServicePlatformCode__c = ged.replyID;//AWS活动编码
                report.Account_ID__c = departmentAccount.Id;//科室
                report.whatid__c = departmentAccount.Id;
@@ -123,14 +167,18 @@
                report.Location__c = departmentAccount.Name; //位置
                report.Activity_Type2__c = strType;//拜访区分
                // report.Activity_PurposeEscFSE__c  = ged.visitPurpose;//拜访目的
                // report.Purpose_TypeFSE__c  = ged.activityDifferentiation;//活动区分
                //report.Activity_PurposeEscFSE__c  = ged.visitPurpose;//拜访目的
                //report.Activity_PurposeFSE__c  = ged.visitPurpose;//拜访目的
                //report.Purpose_TypeFSE__c  = ged.activityDifferentiation;//活动区分
                report.Activity_PurposeFSE__c  = NFMUtil.getMapValue(transferMap, 'Activity_PurposeFSE__c', string.valueof(ged.visitPurpose), iflog);
                report.Purpose_TypeFSE__c  = NFMUtil.getMapValue(transferMap, 'Purpose_TypeFSE__c', string.valueof(ged.activityDifferentiation), iflog);
                report.Daily_Report__c = drc.Id;//日报
                report.IsFromApplet__c = true;//20221226 ljh DB202212307127 是否小程序来源
                insert report;
                logstr +=  '报告一览 [ '+ged.replyID+' ] 保存成功!\n';
            }
           // rowData.retry_cnt__c = 0; //必加
            
            rowData.retry_cnt__c = 0; //必加
        } catch (Exception ex) {
            // エラーが発生した場合
            Database.rollback(sp);
@@ -175,7 +223,7 @@
        }
        List < Daily_Report__c > drcs = [select Id, Reporter__r.Employee_No__c from Daily_Report__c where Reported_Date__c =: visitStartDate and Reporter__r.Employee_No__c =: ged.mngCd];
        List < Daily_Report__c > drcs = [select Id, Reporter__r.Employee_No__c,Status__c from Daily_Report__c where Reported_Date__c =: visitStartDate and Reporter__r.Employee_No__c =: ged.mngCd];
        if (drcs.size() > 0) {
            result = drcs[0];
        } else {