19626
2023-10-07 988f9735377909b6310301e582c15804e004783f
force-app/main/default/classes/OpportunityLightingButtonController.cls
@@ -2,17 +2,9 @@
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-09-09 13:27:58
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-09-12 17:40:11
 */
/*
 * @Description:
 * @version:
 * @Author: chen jing wu
 * @Date: 2023-04-12 11:16:07
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-09-08 16:58:57
 * @LastEditTime: 2023-09-25 13:20:57
 */
public with sharing class OpportunityLightingButtonController {
    @AuraEnabled
@@ -29,12 +21,6 @@
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    @AuraEnabled
    public static Id queryForProfileId(){
        return UserInfo.getProfileId();
    }
    @AuraEnabled
    public static InitData initForPredictedDateChangeButton(String recordId){
@@ -279,6 +265,7 @@
                select
                StageName,
                SAP_Send_OK__c,
                Cnt_Lost_cancel_Draft__c,
                Cnt_Lost_cancel_report__c,
                Name,
                Sales_assistant_name__c,
@@ -299,6 +286,7 @@
            res.salesManagerDepartmentID = opportunity.Sales_manager_departmentID__c;
            res.salesOwnerBuchang = opportunity.Sales_owner_buchang__c;
            res.salesOwnerBuchangID = opportunity.Sales_owner_buchangID__c;
            res.cntLostCancelDraft = opportunity.Cnt_Lost_cancel_Draft__c;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
@@ -810,6 +798,115 @@
        }
    }
    @AuraEnabled
    public static string queryForProfileId(){
        return UserInfo.getProfileId();
    }
    @AuraEnabled
    public static Boolean queryQuote(String estimationId){
        Boolean bo;
        try {
            Quote qu = [select Have_Virtual__c from Quote where Id =: estimationId];
            bo = qu.Have_Virtual__c;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return bo;
    }
    @AuraEnabled
    public static String initCopy(String recordId){
        String s='';
        try {
            String objectName = 'Opportunity'; // 要获取字段的对象名
            Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe();
            Schema.SObjectType objType = globalDescribe.get(objectName);
            if (objType != null) {
                Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
                Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
                s+='SELECT ';
                // 现在,fieldMap中包含了对象的所有字段信息
                for (String fieldName : fieldMap.keySet()) {
                    if(!fieldName.equals('id')
                        &&!fieldName.equals('Id') &&!fieldName.equals('Opportunity_No__c'))
                        s+=fieldName+',';
                }
                s=s.removeEnd(',');
                s+=' FROM Opportunity where id=\''+recordId+'\'';
                system.debug('SQL:'+s);
                List<Opportunity> opportunitys = Database.query(s);
                s='';
                if(opportunitys.size()>0){
                    system.debug('in!');
                    for (String fieldName : fieldMap.keySet()) {
                        String formaF=fieldMap.get(fieldName).getDescribe().getName();
                        if(opportunitys.get(0).get(fieldName)!=null&&!opportunitys.get(0).get(fieldName).equals('null')){
                            if(formaF.equals('Id')
                                ||formaF.equals('OwnerId')
                                ||formaF.equals('CreatedDate')
                                ||formaF.equals('CreatedById')
                                )
                            {
                                continue;
                            }
                            Object val=opportunitys.get(0).get(fieldName);
                            if(val instanceof Date ){
                                String str=String.valueOf(val);
                                str=str.replace(' ','T');
                                str+='.000Z';
                                s+=formaF+'='+str+',';
                            }else if (val instanceof DateTime){
                                String str=String.valueOf(val);
                                str=str.replace(' ','T');
                                str+='.000Z';
                                s+=formaF+'='+str+',';
                            }else{
                                s+=formaF+'='+opportunitys.get(0).get(fieldName)+',';
                            }
                        }
                    }
                    s=s.removeEnd(',');
                    return s;
                }
            }
         return s;
        } catch (Exception e) {
            System.debug(e.getMessage());
        }
        return s;
    }
    public static String forma(String str){
        String res='';
        String stra='a';
        Integer a=stra.charAt(0);
        String strz='z';
        Integer z=strz.charAt(0);
        String strAa='A';
        Integer bA=strAa.charAt(0);
        String strZz='Z';
        Integer bZ=strZz.charAt(0);
        String strx='_';
        Integer x=strx.charAt(0);
        List<Integer> charArr = new List<Integer>();
        Integer change=bA-a;
        Integer st=(str.charAt(0)+change);
        charArr.add(st);
        for(Integer i=0;i<str.length()-2;i++){
            Integer c=str.charAt(i);
            Integer nextC=str.charAt(i+1);
            if(c==x&&nextC>=a&&nextC<z&&i!=str.length()-2){
                nextC+=change;
            }
            charArr.add(nextC);
        }
        res=String.fromCharArray(charArr);
        res+=str.substring(str.length()-1,str.length());
        return res;
    }
    @AuraEnabled
    public static String changeTrade(String oppId){
        List<Quote> quoList = [select id from Quote where OpportunityId = :oppId];