From be102ae06e8f986bd9d1a544cd2752e5fa94231a Mon Sep 17 00:00:00 2001
From: binxie <137736985@qq.com>
Date: 星期二, 11 七月 2023 14:23:51 +0800
Subject: [PATCH] LEX Community Deploy0711

---
 force-app/main/default/aura/WeeklyReport/WeeklyReportHelper.js |  209 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 205 insertions(+), 4 deletions(-)

diff --git a/force-app/main/default/aura/WeeklyReport/WeeklyReportHelper.js b/force-app/main/default/aura/WeeklyReport/WeeklyReportHelper.js
index 4122f49..7816c68 100644
--- a/force-app/main/default/aura/WeeklyReport/WeeklyReportHelper.js
+++ b/force-app/main/default/aura/WeeklyReport/WeeklyReportHelper.js
@@ -221,7 +221,8 @@
                             b = true;
                             Foo();
                         }else{
-                            this.error('AWS search status2 : ' + result.status);
+                            //this.error('AWS search status2 : ' + result.status);
+                            this.success('璇烽噸鏂板埛鏂伴〉闈㈣繘琛岃В瀵�');
                         }
                     },component);
                 }else{
@@ -438,6 +439,7 @@
                     }
 
                     if (reportDate != null) {
+                        console.log('reportDate = ' + reportDate);
                         component.set('v.data.Report_Date__c', reportDate);
                     }
                     
@@ -962,6 +964,7 @@
         component.find('select_Product1').set('v.value','');
         component.find('select_Product2').set('v.value','');
         component.find('select_Product3').set('v.value','');
+        console.log('reportDate = 绌�');
         component.set('v.data.Report_Date__c', '');
         component.set('v.oppdata.Close_Forecasted_Date__c', '');
         component.set('v.oppdata.Amount__c', '');
@@ -1446,6 +1449,9 @@
         // });
     },
     search_core : function(token,searchUrl,payload,callback,component) {
+        console.log('token = ' + token);
+        console.log('searchUrl = ' + searchUrl);
+        console.log('payload = ' + payload);
         fetch(searchUrl, {
             method: 'POST',
             body: payload,
@@ -1459,6 +1465,7 @@
             component.set('v.login',false);
             if(callback)callback(result);
         }).catch(error => {
+            console.log('error = ' + JSON.stringify(error));
             this.error('AWS search error.');
             component.set('v.login',false);
         });
@@ -1898,20 +1905,25 @@
     },
     
     saveRecords : function(component,event,helper){
+        debugger
         component.set('v.login',true);
         //fy 瀵煎叆 20220424 start
         var action1 = component.get("c.processDataAWSId");
         action1.setParams({ 
             fileData : component.get("v.fileContentData"),
         }); 
+        debugger
         action1.setCallback(this, function(response) {
+            console.log('response = '  + JSON.stringify(response));
             var state = response.getState();
             if (state === "SUCCESS") {
                 var ress = response.getReturnValue();
+                console.log('ress = '  + JSON.stringify(ress));
                 if(ress){
                     var valur =ress.split('error1');
                     if(valur.length<=1){
                         var res = JSON.parse(response.getReturnValue());
+                        console.log('res = '  + JSON.stringify(res));
                         var dataArr = new Array();
                         var dataMap = new Map();
                         res.forEach(item => {
@@ -1921,10 +1933,11 @@
                                 dataMap.set(item.AWS_Data_Id__c,item.AWS_Data_Id__c);       //zhj 鏂版柟妗堟敼閫� 2022-12-21
                             }
                         });
-                        debugger
                         let obj= Object.create(null);
                         obj['dataIds'] = dataArr;
                         var payload = JSON.stringify(obj);
+                        console.log('payload zhj = ' + JSON.stringify(payload));
+                        
                         this.search_contact_url(component, 'Agency_Contact__c', (result)=>{
                             var token = result.token;
                             var searchUrl = result.searchUrl;
@@ -1941,7 +1954,7 @@
                                         component.set('v.login',true);
                                         this.saveRecordsEditFile(component,dataMap,result.object,helper);
                                     }else{
-                                        this.error('AWS search status5 ' );
+                                        this.error('AWS 鏌ヨ鏁版嵁涓虹┖ ' );
                                         component.set('v.login',false);
                                     }
                                 }else{
@@ -2019,7 +2032,10 @@
         // });
         // $A.enqueueAction(action);
 
+    },isNumber: function(str) {
+        return /^\d+$/.test(str);
     },ImportMethod : function(component,fileStr){
+        debugger
         var actionss = component.get("c.processData");
          var selectDate = component.find('select_date').get('v.value');
         var fieldsList=['Name','Phone','AccountNumber']; //Please write your code dynamic 
@@ -2042,10 +2058,64 @@
                     if(res != 'success'){
                         var ress = res.split('=');
                         console.log(ress);
+                        let errorDatas = [];
+                        let errorDataRow = [];
+                        debugger
+                        var fileContentData = component.get("v.fileContentData").split('\n');
                         for (var i=0; i<ress.length; i++) {
                             res1 += ress[i].substr(7)+'\n';
+                            if (ress[i] != '') {
+                                let errorData = {}
+                                if(!this.isNumber(ress[i].substr(7).substring(1, 2))){
+                                    continue
+                                }
+                                let index = errorDataRow.indexOf(ress[i].substr(7).substring(1, 2));
+                                if (index == -1) {
+                                    errorData.errorRow = ress[i].substr(7).substring(1, 2);
+                                    errorDataRow.push(errorData.errorRow);
+                                    errorData.errorInfo = ress[i].substr(7).substring(5).replace('=','');
+                                    if(errorData.errorInfo == '鎷滆浜轰笉瀛樺湪'){
+                                        console.log('errorData.errorRow = ' + errorData.errorRow)
+                                        errorData.errorInfo ='鎷滆浜� ' + fileContentData[errorData.errorRow].split(',')[4] + '涓嶅瓨鍦�';
+                                    }
+                                    errorDatas.push(errorData);
+                                } else {
+                                    if(ress[i].substr(7).substring(5) == '鎷滆浜轰笉瀛樺湪'){
+                                        errorDatas[index].errorInfo += '; ' + '鎷滆浜� ' + fileContentData[errorDatas[index].errorRow].split(',')[4] + '涓嶅瓨鍦�';
+                                    }else{
+                                        errorDatas[index].errorInfo += '; ' + ress[i].substr(7).substring(5);
+                                    }
+                                }
+                            }
                         }
-                        // $('.forceToastManager').css('white-space', 'pre-wrap');
+                        let errorColumns = [
+                            { label: '閿欒琛�', fieldName: 'errorRow', type: 'text', hideDefaultActions: true, initialWidth: 100 },
+                            { label: '閿欒淇℃伅', fieldName: 'errorInfo', type: 'text', hideDefaultActions: true, initialWidth: 300, wrapText: true }
+                        ];
+                        for (var i = 0; i < fileContentData[0].split(',').length; i++) {
+                            errorColumns.push({
+                                label: fileContentData[0].split(',')[i], 
+                                fieldName: 'field' + i, 
+                                type: 'text', 
+                                hideDefaultActions: true, 
+                                wrapText: true,
+                                initialWidth: 120
+                            });
+                        }
+
+                        for (var i = 0; i < errorDatas.length; i++) {
+                            let data = fileContentData[errorDatas[i].errorRow];
+                            console.log('data = ' + JSON.stringify(data));
+                            if(data){
+                                for (var j = 0; j < data.split(',').length; j++) {
+                                    let label = 'field' + j;
+                                    errorDatas[i][label] = data.split(',')[j];
+                                }
+                            }
+                        }
+                        component.set('v.errorColumns', errorColumns);
+                        component.set('v.errorData', errorDatas);
+                        component.set("v.showErrorInfo", true);
                         console.log("=="+res1);
                         this.error(res1+"璇蜂慨鏀瑰悗閲嶆柊涓婁紶");
                         component.set('v.login',false);
@@ -2080,6 +2150,7 @@
         var searchDataMap = new Map();
          for (var i = 0; i < searchData.length; i++) {
          var sd = searchData[i];
+         if(sd.name)
          searchDataMap.set(sd.name.replace(' ',''),sd.dataId);
          }
          console.log('searchDataMap='+searchDataMap);
@@ -2111,6 +2182,71 @@
         }
 
         if (error != '') {
+            console.log('zhj error = ' + error);
+            let errorArray = error.split('error1');
+            let errorDatas = [];
+            let errorDataRow = [];
+            debugger
+            var fileContentData = component.get("v.fileContentData").split('\n');
+            console.log('errorArray = ' + JSON.stringify(errorArray))
+            for (var i in errorArray) {
+                if (errorArray[i] != '') {
+                    let errorData = {}
+                    if(!this.isNumber(errorArray[i].trim().substring(1, 2))){
+                        continue
+                    }
+                    let index = errorDataRow.indexOf(errorArray[i].trim().substring(1, 2));
+                    if (index == -1) {
+                        errorData.errorRow = errorArray[i].trim().substring(1, 2);
+                        errorDataRow.push(errorData.errorRow);
+                        errorData.errorInfo = errorArray[i].trim().substring(5,errorArray[i].trim().length).replace('=','');
+                        if(errorData.errorInfo == '鎷滆浜篈WS涓嶅瓨鍦�'){
+                            errorData.errorInfo ='鎷滆浜� ' + fileContentData[errorData.errorRow].split(',')[4] + '涓嶅瓨鍦�';
+                        }
+                        errorDatas.push(errorData);
+                    } else {
+                        if(errorArray[i].trim().substring(5) == '鎷滆浜篈WS涓嶅瓨鍦�'){
+                            errorData[index].errorInfo = '; ' + '鎷滆浜� ' + fileContentData[errorDatas[index].errorRow].split(',')[4] + '涓嶅瓨鍦�';
+                        }else{
+                            errorDatas[index].errorInfo += '; ' + errorArray[i].trim().substring(5,errorArray[i].trim().length);
+                        }
+                    }
+                }
+            }
+            var fileContentData = component.get("v.fileContentData").split('\n');
+            let errorColumns = [
+                { label: '閿欒琛�', fieldName: 'errorRow', type: 'text', hideDefaultActions: true, initialWidth: 100 },
+                { label: '閿欒淇℃伅', fieldName: 'errorInfo', type: 'text', hideDefaultActions: true, initialWidth: 300, wrapText: true }
+            ];
+            for (var i = 0; i < fileContentData[0].split(',').length; i++) {
+                errorColumns.push({
+                    label: fileContentData[0].split(',')[i], 
+                    fieldName: 'field' + i, 
+                    type: 'text', 
+                    hideDefaultActions: true, 
+                    wrapText: true,
+                    initialWidth: 120
+                });
+            }
+
+            for (var i = 0; i < errorDatas.length; i++) {
+                let data = fileContentData[errorDatas[i].errorRow];
+                console.log('data = ' + JSON.stringify(data));
+                for (var j = 0; j < data.split(',').length; j++) {
+                    let label = 'field' + j;
+                    errorDatas[i][label] = data.split(',')[j];
+                }
+            }
+            console.log('errorDatas =' + JSON.stringify(errorDatas))
+            component.set('v.errorColumns', errorColumns);
+            component.set('v.errorData', errorDatas);
+            component.set("v.showErrorInfo", true);
+
+
+
+            console.log('error = ' + error);
+            component.set('v.errorMessage', error);
+
             this.error(error);
             console.log('error='+error);
             component.set('v.login',false);
@@ -2345,6 +2481,71 @@
 	},
     //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
 
+    //zhj 瀵煎嚭閿欒淇℃伅 2023-05-16 start
+    exportErrorInfoHelper: function (component) {
+        var errorData = component.get('v.errorData');
+        var errorColumns = component.get('v.errorColumns');
+
+        var datas = [];
+        let errorColumnsArray = [];
+        for(var i in errorColumns){
+            errorColumnsArray.push(errorColumns[i].label);
+        }
+        datas.push(errorColumnsArray);
+        //datas.push(errorColumns);
+
+        for (var i in errorData) {
+            let data = [];
+            data.push(errorData[i].errorRow)
+            data.push(errorData[i].errorInfo)
+            for(var j = 0 ; j < Object.keys(errorData[i]).length - 2 ; j++){
+                data.push(errorData[i]['field' + j])
+            }
+            datas.push(data);
+        }
+
+        console.log('datas = ' + JSON.stringify(datas));
+        var csv = this.convertToCSV(component, datas);
+        console.log('csv = ' + JSON.stringify(csv))
+        this.downloadCSV(component, csv);
+    },
+
+    convertToCSV: function (component, data) {
+        console.log('enter convertToCSV')
+        console.log('data = ' + data);
+        var csv = '';
+        for (var i = 0; i < data.length; i++) {
+            var row = data[i];
+            console.log('row = ' + JSON.stringify(row));
+            for (var j = 0; j < row.length; j++) {
+                var val = '';
+                val = row[j] === null ? '' : row[j].toString();
+                console.log('val = ' + val);
+                if (val.indexOf(',') !== -1 || val.indexOf('"') !== -1 || val.indexOf('\n') !== -1) {
+                    //val = '"' + val.replace(/"/g,'""') + '"';
+                }
+                if (j > 0) {
+                    csv += ',';
+                }
+                csv += val;
+            }
+            csv += '\n';
+        }
+        return csv;
+    },
+
+    downloadCSV: function (component, csv) {
+        var link = document.createElement('a');
+        // 璁剧疆瀛楃闆嗗拰鏂囦欢澶�
+        var bom = "\uFEFF";
+        link.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(bom + csv);
+        link.download = 'data.csv';
+        document.body.appendChild(link);
+        link.click();
+        document.body.removeChild(link);
+    },
+    //zhj 瀵煎嚭閿欒淇℃伅 2023-05-16 end
+
     // searchAgencyContact : function(res) {
     //     var agencyContacts = [];
     //     for (let idx = 0; idx < res.length; idx++) {

--
Gitblit v1.9.1