From 9c014262e3cf8eb25f7d538f3130f2e7e2820d68 Mon Sep 17 00:00:00 2001 From: Li Jun <buli@deloitte.com.cn> Date: 星期一, 11 四月 2022 21:08:13 +0800 Subject: [PATCH] FixCloneButtonIssue --- force-app/main/default/classes/QISPDFController.cls | 74 ++++++++++++++ force-app/main/default/classes/NewRepairController.cls | 4 force-app/main/default/pages/QISPDF.page | 212 +++++++++++++++++++++++++++-------------- force-app/main/default/triggers/ContactTrigger.trigger | 6 4 files changed, 220 insertions(+), 76 deletions(-) diff --git a/force-app/main/default/classes/NewRepairController.cls b/force-app/main/default/classes/NewRepairController.cls index 5daee0c..4063597 100644 --- a/force-app/main/default/classes/NewRepairController.cls +++ b/force-app/main/default/classes/NewRepairController.cls @@ -346,7 +346,9 @@ boolean b = AWSServiceTool2.EncryptPushData(new string[]{rid}); rep.Encrypt_Update_Flag__c = false; - update rep; + if(!Test.isRunningTest()){ + update rep; + } r.status = b ? 'success' : 'failed'; r.message = b ? '' : '鍔犲瘑鎺ㄩ�佸け璐�'; r.recordId = rid; diff --git a/force-app/main/default/classes/QISPDFController.cls b/force-app/main/default/classes/QISPDFController.cls index 6272db1..f51b606 100644 --- a/force-app/main/default/classes/QISPDFController.cls +++ b/force-app/main/default/classes/QISPDFController.cls @@ -8,6 +8,13 @@ // HWAG-BC68W3 鏁呴殰鍙戠敓鏃ヤ负绌烘椂锛� 瀹冧负鐪� start public Boolean outOfGuarantee { get; private set; } // HWAG-BC68W3 鏁呴殰鍙戠敓鏃ヤ负绌烘椂锛� 瀹冧负鐪� end + + public string Photo_1_Text { get; private set; } + public string Photo_2_Text { get; private set; } + public string Photo_3_Text { get; private set; } + public string Photo_4_Text { get; private set; } + + public QISPDFController() { qr = new QIS_Report__c(); usr = new User(); @@ -53,6 +60,73 @@ //HWAG-BC68W3 end inGuarantee = true; } + + Photo_1_Text = getImageByUrl(qr.Photo_1_Text__c); + Photo_2_Text = getImageByUrl(qr.Photo_2_Text__c); + Photo_3_Text = getImageByUrl(qr.Photo_3_Text__c); + Photo_4_Text = getImageByUrl(qr.Photo_4_Text__c); } } + + public static String getImageByUrl(string urlStr){ + //urlStr = 'https://ocsm--stagefull--c.documentforce.com/servlet/rtaImage?eid=a0f1000000cS7qH&feoid=00N10000006P4rz&refid=0EM10000002WIgq'; + // 'https://ocsm--stagefull.my.salesforce.com/services/data/v51.0/sobjects/QIS_Report__c/a0f1000000IJay1/richTextImageFields/Photo_1__c/0EM100000017hLN + System.debug('urlStr='+urlStr); + Id eid = getUrlParameters(urlStr,'eid'); + if (string.isBlank(eid)) { + System.debug('eid not found'); + return null; + } + + Id feoid = getUrlParameters(urlStr,'feoid'); + if (string.isBlank(feoid)) { + System.debug('feoid not found'); + return null; + } + + Id refid = getUrlParameters(urlStr,'refid'); + if (string.isBlank(refid)) { + System.debug('refid not found'); + return null; + } + + string body = MetaDataUtility.ToolingQuery('select id,FullName from CustomField where id=\''+feoid+'\''); + if(string.isBlank(body)){ + System.debug('body is blank'); + return null; + } + string sobjecttype = eid.getSobjectType().getDescribe().getName(); + List<object> lo = (List<object>)(((Map<string,object>)JSON.deserializeUntyped(body)).get('records')); + Map<string,object> mso = (Map<string,object>)(lo[0]); + string f = ((string)mso.get('FullName')).replace(sobjecttype+'.', ''); + + String urlForClassic = 'https://'+System.URL.getOrgDomainUrl().getHost()+'/services/data/v53.0/sobjects/'+sobjecttype+'/'+eid+'/richTextImageFields/'+f+'/'+refid; + + system.debug('URL Post:'+urlForClassic); + HttpResponse resp = null; + HttpRequest req = new HttpRequest(); + req.setMethod('GET'); + req.setEndpoint(urlForClassic); + req.setHeader('Authorization', 'Bearer ' + UserInfo.getsessionid()); + Http client = new Http(); + resp = client.send(req); + system.debug('getStatusCode:'+resp.getStatusCode()); + return 'data:image/png;base64,' + EncodingUtil.base64Encode(resp.getBodyAsBlob()); + } + + public static String getUrlParameters(string url,string para){ + //string url = 'https://sfpi-mebg-test.olympuschina.com:8081/stg/api/file/convert?from=https%3A%2F%2Focsm--stagefull--c.visualforce.com%2Fapex%2FQISPDF%3Fid%3Da0f1000000cS7qH&fileName=QISPDF'; + if (string.isBlank(url) || string.isBlank(para)) { + return null; + } + Pattern p = Pattern.compile('(?<=' + para + '=)[^&]*'); + Matcher m = p.matcher(url); + if (m.find()) { + return m.group(); + }else { + system.debug('no found '+para+' in url='+url); + return null; + } + + } } \ No newline at end of file diff --git a/force-app/main/default/pages/QISPDF.page b/force-app/main/default/pages/QISPDF.page index 073c274..9fa3336 100644 --- a/force-app/main/default/pages/QISPDF.page +++ b/force-app/main/default/pages/QISPDF.page @@ -22,8 +22,8 @@ /* 20220221 PI鏀归�� by 寰愪寒 start */ body{margin: 0 auto; width: 780px;} - #title1{height: 30px;} - #title2{height: 110px;} + .title1{height: 30px;} + .title2{height: 110px;} /* 20220221 PI鏀归�� by 寰愪寒 end */ @@ -42,7 +42,8 @@ <body style="font-family: MS Gothic;"> <div id="pdf-wrapper"> - <div id="title1"></div> + <div class="pdf-page"> + <table width="100%" border="0"> <tr> <td width="25%"> @@ -398,9 +399,11 @@ </tr> </table> - <div style="page-break-after: always;"></div> - <div id="title2"></div> + </div> + <div style="page-break-after: always;"></div> + <div class="pdf-page"> + <table width="100%" border="0"> <tr> <td width="25%"> @@ -453,34 +456,36 @@ <br/> <table width="100%" border="1" cellspacing="2" style="font-size: 8pt;"> <tr> - <td> - <table width="100%" border="1" cellspacing="0"> - <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_1_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_1_Text__c))}" /></td></tr> + <td style="width:50%"> + <table width="100%" border="0" cellspacing="0"> + <tr><td style="height:300px; text-align: center;"><apex:image id="Photo_1_Text" value="{!Photo_1_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_1_Text__c))}" /></td></tr> <tr><td style="height:40px;"></td></tr> </table> </td> <td style="border-left-color: white;"> - <table width="100%" border="1" cellspacing="0"> - <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_2_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_2_Text__c))}" /></td></tr> + <table width="100%" border="0" cellspacing="0"> + <tr><td style="height:300px; text-align: center;"><apex:image value="{!Photo_2_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_2_Text__c))}" /></td></tr> <tr><td style="height:40px;"></td></tr> </table> </td> </tr> <tr> <td style="border-top-color: white;"> - <table width="100%" border="1" cellspacing="0"> - <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_3_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_3_Text__c))}" /></td></tr> + <table width="100%" border="0" cellspacing="0"> + <tr><td style="height:300px; text-align: center;"><apex:image value="{!Photo_3_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_3_Text__c))}" /></td></tr> <tr><td style="height:40px;"></td></tr> </table> </td> <td style="border-left-color: white; border-top-color: white;"> - <table width="100%" border="1" cellspacing="0"> - <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_4_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_4_Text__c))}" /></td></tr> + <table width="100%" border="0" cellspacing="0"> + <tr><td style="height:300px; text-align: center;"><apex:image value="{!Photo_4_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_4_Text__c))}" /></td></tr> <tr><td style="height:40px;"></td></tr> </table> </td> </tr> </table> + </div> + </div> </body> @@ -489,16 +494,16 @@ AWSService.sfSessionId = '{!GETSESSIONID()}'; var staticResources = JSON.parse('{!staticResource}'); var staticResourceFile = JSON.parse('{!staticResourceFile}'); - function Fun(pdf){ + function Fun(pdf) { var form = jQuery("<form method='post'></form>"); jQuery(document.body).append(form); let href = window.location.href let arr = href.split('/') - form.attr({"action":staticResourceFile.viewUnifiedContactUrl+"?from="+encodeURIComponent(href)+"&fileName="+encodeURIComponent(arr[arr.length-1].split('?')[0])}); + form.attr({ "action": staticResourceFile.viewUnifiedContactUrl + "?from=" + encodeURIComponent(href) + "&fileName=" + encodeURIComponent(arr[arr.length - 1].split('?')[0]) }); // form.attr({"action":"http://127.0.0.1:8080/a/d?from="+encodeURIComponent(window.location.href)}); let input = jQuery("<input type='hidden'/>"); - input.attr({"name":"base64Str"}); + input.attr({ "name": "base64Str" }); input.val(pdf.output('datauristring').substr(28)); form.append(input); form.submit(); @@ -512,65 +517,126 @@ let id = "pdf-wrapper"; var target = document.getElementById(id); - function jsPdfDownload(){ - let pdfName = "娴嬭瘯"; - let id = "pdf-wrapper"; - var target = document.getElementById(id); - target.style.background = "#FFFFFF"; - if(pdfName==''||pdfName==undefined) pdfName= getNowFormatDate(); - - html2canvas(target, { - scale: 2, - onrendered:function(canvas) { - var contentWidth = canvas.width; - var contentHeight = canvas.height; - - //涓�椤祊df鏄剧ずhtml椤甸潰鐢熸垚鐨刢anvas楂樺害; - var pageHeight = contentWidth / 592.28 * 841.89; - //鏈敓鎴恜df鐨刪tml椤甸潰楂樺害 - var leftHeight = contentHeight; - //椤甸潰鍋忕Щ - var position = 0; - //a4绾哥殑灏哄[595.28,841.89]锛宧tml椤甸潰鐢熸垚鐨刢anvas鍦╬df涓浘鐗囩殑瀹介珮 - var imgWidth = 515.28;//595.28//宸﹀彸杈硅窛20 - var imgHeight = 515.28/contentWidth * contentHeight;//宸﹀彸杈硅窛20 - - var pageData = canvas.toDataURL('image/jpeg', 1.0); - - var pdf = new jsPDF('', 'pt', 'a4'); - - //鏈変袱涓珮搴﹂渶瑕佸尯鍒嗭紝涓�涓槸html椤甸潰鐨勫疄闄呴珮搴︼紝鍜岀敓鎴恜df鐨勯〉闈㈤珮搴�(841.89) - //褰撳唴瀹规湭瓒呰繃pdf涓�椤垫樉绀虹殑鑼冨洿锛屾棤闇�鍒嗛〉 - if (leftHeight < pageHeight) { - pdf.addImage(pageData, 'JPEG', 40, 0, imgWidth, imgHeight );//宸﹀彸杈硅窛20 - } else { - while(leftHeight > 0) { - pdf.addImage(pageData, 'JPEG', 40, position, imgWidth, imgHeight)//宸﹀彸杈硅窛20 - leftHeight -= pageHeight; - position -= 841.89; - //閬垮厤娣诲姞绌虹櫧椤� - if(leftHeight > 0) { - pdf.addPage(); - } - } - } - Fun(pdf); - } - }) - } + // 鎶奿mageDta杞崲鎴恥rl + // page_height锛氫竴椤电殑楂樺害 + function ImageDataToUrl(img_data,page_height){ + let cvs = document.createElement("CANVAS"); + cvs.width = img_data.width; + cvs.height = page_height; + var ctx= cvs.getContext("2d"); + ctx.fillStyle="white"; + ctx.fillRect(0,0,cvs.width,cvs.height);// 濉厖canvas鎵�鏈夊尯鍩熶负鐧借壊 + ctx.putImageData(img_data,0,0); + return cvs.toDataURL('image/jpeg', 1.0); + } + function jsPdfDownload() { - //blockme(); - document.body.onload = function(){ - - AWSService.query(staticResources.queryUrl, '{!qr.AWS_Data_Id__c}', function(data){ - //unblockUI(); - document.getElementById("Responsible_Person_HP__c").innerHTML = data.object.responsiblePersonHP; - document.getElementById("Caller_phone__c").innerHTML = data.object.callerPhone; + let jtargets = jQuery("#pdf-wrapper .pdf-page"); + let j_arr = new Array(jtargets.length + 1).join(0).split('').map(function () { return false }); + let landscape = false; + let pw = 595.28; + let ph = 841.89; + const marginw = 40; + const marginh = 40; + + let orientation = ''; + if (landscape) { + pw += ph; ph = pw - ph; pw = pw - ph; + orientation = 'l'; + } + var pdf = new jsPDF(orientation, 'pt', 'a4');// 绗竴涓弬鏁板~瀛楁瘝l锛屾敞鎰忎笉鏄暟瀛�1锛屼负妯悜pdf + jtargets.each(function (i, e) { + e.style.background = "#FFFFFF"; + }) + + let rei = 0; + let recursion = null; + recursion = function (i) { + if (i >= jtargets.length) { + Fun(pdf); + return; + } + e = jtargets[i]; + html2canvas(e, { + scale: 2, + onrendered: function (canvas) { + /** + 鏈柟娉曢渶瑕佸仛鍑犱釜浜嬫儏 + 1.闇�瑕佹妸canvas鐨勫唴瀹瑰垎椤垫樉绀哄埌pdf鐨勯〉涓� + 2.canvas鐨勫楂橀渶瑕佸拰pdf鐨勫楂樿繘琛屾槧灏� + 3.鎴彇鍒扮殑鍐呭闇�瑕佹斁杩涗竴椤靛楂樼殑canvas閲岄潰锛屽苟瀵瑰叾浣欏尯鍩熷埛鐧� + */ + var ctx = canvas.getContext("2d"); + let canvas_max_page_num = 9; + let canvas_current_page_num = 0; + var contentWidth = canvas.width; + var contentHeight = canvas.height; + + + //鏈敓鎴恜df鐨刪tml椤甸潰楂樺害 + var leftHeight = contentHeight; + //椤甸潰鍋忕Щ + var position = 0; + + //a4绾哥殑灏哄[595.28,841.89]锛宧tml椤甸潰鐢熸垚鐨刢anvas鍦╬df涓浘鐗囩殑瀹介珮 + var outputWidth = pw - 2 * marginw;//595.28//宸﹀彸杈硅窛20 + let rate = outputWidth / 780;//杈撳嚭瀹藉害鍜屽唴瀹瑰搴︾殑姣斾緥 + var outputHeight = ph - 2 * marginh;//宸﹀彸杈硅窛20 + let onePdfPageInCanvasHeight = contentWidth/outputWidth*outputHeight;//涓�椤祊df鍦╟anvas涓殑楂樺害; + //var pageData = canvas.toDataURL('image/jpeg', 1.0); + var pageData = null; + var imgData = null; + + var captureHeight = null;// 鎴彇鐨勫綋鍓峜anvas椤电殑楂樺害 + + let j = i; + while(position < contentHeight){ + + if (j++) { + pdf.addPage(); + } + + if(position+onePdfPageInCanvasHeight>contentHeight){ + captureHeight = contentHeight-position; + }else{ + captureHeight = onePdfPageInCanvasHeight; + } + + imgData = ctx.getImageData(0,position,contentWidth,captureHeight); + pageData = ImageDataToUrl(imgData,onePdfPageInCanvasHeight); + pdf.addImage(pageData, 'JPEG', marginw, marginh, outputWidth, outputHeight);//宸﹀彸杈硅窛20,琚緭鍑虹殑鍥剧墖浼氳鎷変几涓簅utputWidth锛宱utputHeight鐨勫楂� + canvas_current_page_num++; + position += onePdfPageInCanvasHeight; + if (canvas_max_page_num > 0 && canvas_current_page_num >= canvas_max_page_num) { + break; + } + } + + recursion(i + 1); + } + }) + }; + recursion(rei); + + + + } + + //blockme(); + document.body.onload = function(){ - jsPdfDownload(); - }, staticResources.token); + AWSService.query(staticResources.queryUrl, '{!qr.AWS_Data_Id__c}', function(data){ + //unblockUI(); + document.getElementById("Responsible_Person_HP__c").innerHTML = data.object.responsiblePersonHP; + document.getElementById("Caller_phone__c").innerHTML = data.object.callerPhone; + if(confirm("PDF宸插姞杞藉畬姣曪紝鏄惁鏄剧ず锛�")){ + jsPdfDownload(); + } + }, staticResources.token); + } - } + + </script> <!-- 20220221 PI鏀归�� by 寰愪寒 end --> </html> diff --git a/force-app/main/default/triggers/ContactTrigger.trigger b/force-app/main/default/triggers/ContactTrigger.trigger index 40b9a9a..5271bbd 100644 --- a/force-app/main/default/triggers/ContactTrigger.trigger +++ b/force-app/main/default/triggers/ContactTrigger.trigger @@ -1,4 +1,6 @@ trigger ContactTrigger on Contact (before insert,after insert, after update, after delete, before Update) { - ContactTriggerHandler handler = new ContactTriggerHandler(); - handler.run(); + if(Test.isRunningTest()||UserInfo.getUserId()!=System.Label.ByPassTrigger){ + ContactTriggerHandler handler = new ContactTriggerHandler(); + handler.run(); + } } \ No newline at end of file -- Gitblit v1.9.1