unknown
2023-07-19 0c38eae1aa2b9a9318c0bbe0513d48cde5fe9af3
button-lexAddSubmitApprovalProcess

提交追加待审批
1个文件已修改
2个文件已添加
202 ■■■■■ 已修改文件
force-app/main/default/classes/LexAddSubmitApprovalProcessController.cls 154 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/LexAddSubmitApprovalProcessController.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/lwc/lexAddSubmitApprovalProcess/lexAddSubmitApprovalProcess.js 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/LexAddSubmitApprovalProcessController.cls
New file
@@ -0,0 +1,154 @@
/**
 * *
    ODescription:
    GAuthor: sun xia
    @Date: 2023-07-11 15:31:56
    GIastEditors: sun xia
    @IastEditTime: 2023-07-11 15:31:56
 * */
public with sharing class LexAddSubmitApprovalProcessController {
     @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new InitData();
        try {
            List<Rental_Apply__c> raList = [SELECT Id, Request_shipping_day__c, Add_Approval_Status__c, Repair__c,
                        Demo_purpose1__c, demo_purpose2__c, Repair__r.Repair_Estimated_date_formula__c,
                        Repair__r.Agreed_Date__c, Repair__r.NewProductGuaranteeObject__c,
                        Repair__r.Repair_Final_Inspection_Date__c, Repair__r.Repair_Shipped_Date__c,
                        Repair__r.Status1__c, Repair__r.ReRepairObject_F__c, Repair__r.Number_of_EffectiveContract__c,
                        Repair__r.Delivered_Product__r.Product2.Asset_Model_No__c, Campaign__c,
                        Campaign__r.Status, Campaign__r.Rental_Apply_Flag__c, QIS_number__c, QIS_number__r.next_action__c,
                        applyUser__r.Id, Owner.Id, Status__c,RecordTypeId from Rental_Apply__c WHERE Id = :recordId];
            if(raList.size()>0){
                Rental_Apply__c ra = raList[0];
                res.rentalApplyId = ra.Id;
                res.recordTypeId = ra.RecordTypeId;
                res.addApprovalStatus = ra.Add_Approval_Status__c;
                res.requestShippingDay = ra.Request_shipping_day__c;
                res.repairId = ra.Repair__c;
                res.demoPurpose1 = ra.Demo_purpose1__c;
                res.demoPurpose2 = ra.demo_purpose2__c;
                res.repairEstimatedDateFormula = ra.Repair__r.Repair_Estimated_date_formula__c;
                res.agreedDate = ra.Repair__r.Agreed_Date__c;
                res.newProductGuaranteeObject = ra.Repair__r.NewProductGuaranteeObject__c;
                res.repairFinalInspectionDate = ra.Repair__r.Repair_Final_Inspection_Date__c;
                res.repairShippedDate = ra.Repair__r.Repair_Shipped_Date__c;
                res.status1 = ra.Repair__r.Status1__c;
                res.reRepairObjectF = ra.Repair__r.ReRepairObject_F__c;
                res.numberOfEffectiveContract = ra.Repair__r.Number_of_EffectiveContract__c;
                res.assetModelNo = ra.Repair__r.Delivered_Product__r.Product2.Asset_Model_No__c;
                res.campaignId = ra.Campaign__c;
                res.campaignStatus = ra.Campaign__r.Status;
                res.rentalApplyFlag = Integer.valueOf(ra.Campaign__r.Rental_Apply_Flag__c);
                res.qISNumber = ra.QIS_number__c;
                res.nextAction = ra.QIS_number__r.next_action__c;
                res.applyUserId = ra.applyUser__r.Id;
                res.ownerId = ra.OwnerId;
                res.rentalApplyStatus = ra.Status__c;
                res.demoRequestPastDataId = Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName().get('Demo_request_past_data').getRecordTypeId();
                List<Rental_Apply_Equipment_Set_Detail__c> raeSet = [SELECT Id from Rental_Apply_Equipment_Set_Detail__c WHERE Rental_Apply__c = :recordId AND Draft_Appended__c=1];
                res.detailSize = raeSet.size();
            }
        }
        catch (Exception e) {
            System.debug(LoggingLevel.INFO, '****e:' + e);
        }
        return res;
    }
    //提交审批
    @AuraEnabled
    public static String submitApproval(String recordId){
        Savepoint sp = Database.setSavepoint();
        try {
            Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
            req1.setObjectId(recordId);
            Approval.ProcessResult submitResult = Approval.process(req1);
            return 'OK';
        }
        catch (Exception e) {
            Database.rollback(sp);
            return e.getMessage();
        }
    }
    //更新备品借出申请的提交追加待审批状态
    @AuraEnabled
    public static String changeAddApprovalStatus(String recordId, String status){
        Savepoint sp = Database.setSavepoint();
        try {
            Rental_Apply__c ra = new Rental_Apply__c();
            ra.Id = recordId;
            ra.Add_Approval_Status__c = status;
            Update ra;
            return '更新成功';
        }
        catch (Exception e) {
            Database.rollback(sp);
            return e.getMessage();
        }
    }
    private class InitData{
        @AuraEnabled
        public String rentalApplyId;        //备品借出申请Id
        @AuraEnabled
        public String recordTypeId;
        @AuraEnabled
        public String addApprovalStatus;    //备品借出申请.追加备品审批状态
        @AuraEnabled
        public Integer detailSize;          //明细Size
        @AuraEnabled
        public Date requestShippingDay;     //备品借出申请.希望到货日
        @AuraEnabled
        public String repairId;             //修理Id
        @AuraEnabled
        public String demoPurpose1;         //备品借出申请.使用目的1
        @AuraEnabled
        public String demoPurpose2;         //备品借出申请.使用目的2
        @AuraEnabled
        public Date repairEstimatedDateFormula; //修理.6.报价日
        @AuraEnabled
        public Date agreedDate;             //修理.7.用户同意日
        @AuraEnabled
        public String newProductGuaranteeObject;    //修理.无偿区别标志
        @AuraEnabled
        public Date repairFinalInspectionDate;      //修理.10.最终检测日
        @AuraEnabled
        public Date repairShippedDate;          //修理.11.RC修理品返送日
        @AuraEnabled
        public String status1;                  //修理.状态1
        @AuraEnabled
        public Boolean reRepairObjectF;         //修理.再受理对象品参考
        @AuraEnabled
        public String numberOfEffectiveContract;    //修理.有无维修合同对象(SFDC)
        @AuraEnabled
        public String assetModelNo;                 //修理.资产.产品.产品型号(MDM)
        @AuraEnabled
        public String campaignId;                   //备品借出申请.学会
        @AuraEnabled
        public String campaignStatus;               //学会.状态
        @AuraEnabled
        public Integer rentalApplyFlag;              //学会.提交申请FLG
        @AuraEnabled
        public String qISNumber;                    //备品借出申请.QIS
        @AuraEnabled
        public String nextAction;                   //QIS.对应方法
        @AuraEnabled
        public String applyUserId;                  //备品借出申请.操作者Id
        @AuraEnabled
        public String ownerId;                      //备品借出申请.所有人Id
        @AuraEnabled
        public String rentalApplyStatus;            //备品借出申请.状态
        @AuraEnabled
        public String demoRequestPastDataId;        //备品申请 过去历史转移Id
    }
}
force-app/main/default/classes/LexAddSubmitApprovalProcessController.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/lwc/lexAddSubmitApprovalProcess/lexAddSubmitApprovalProcess.js
@@ -4,10 +4,10 @@
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { updateRecord } from 'lightning/uiRecordApi';
import LightningConfirm from 'lightning/confirm';
import init from '@salesforce/apex/AddSubmitApprovalProcessController.init';
import submitApproval from '@salesforce/apex/AddSubmitApprovalProcessController.submitApproval';
import init from '@salesforce/apex/LexAddSubmitApprovalProcessController.init';
import submitApproval from '@salesforce/apex/LexAddSubmitApprovalProcessController.submitApproval';
import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
import changeAddApprovalStatus from '@salesforce/apex/AddSubmitApprovalProcessController.changeAddApprovalStatus';
import changeAddApprovalStatus from '@salesforce/apex/LexAddSubmitApprovalProcessController.changeAddApprovalStatus';
export default class lexAddSubmitApprovalProcess extends LightningElement {
    @api recordId;
@@ -29,6 +29,12 @@
        init({
            recordId: this.recordId
        }).then(result=>{
            console.log('result==='+JSON.stringify(result));
            if(JSON.stringify(result) == '{}'){
                this.ToastShow('没有查到需要的数据','warning');
                return;
            }
            if(result.addApprovalStatus != '草案中' || result.detailSize == 0){
                this.ToastShow('没有需要审批的追加附属品','warning');
                return;
@@ -37,17 +43,16 @@
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return;
            // }
            const SUBMIT = LightningConfirm.open({
            LightningConfirm.open({
                message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if(SUBMIT==false){
            }).then(submit=>{
                if(!submit){
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
                }else{
            // 希望到货日不能早于申请提交日-0418追加
            //if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') {
@@ -150,7 +155,7 @@
                                recordId: this.recordId
                            }).then(submitApprovalRes=>{
                                if(submitApprovalRes == 'OK'){
                                    this.ToastShow('提交追加待审批','success');
                                            this.ToastShow('提交追加待审批成功','success');
                                    this.updateRecordView(this.recordId);
                                }else{
                                    this.ToastShow('追加待审批失败','ERROR');
@@ -164,7 +169,8 @@
            }).catch(err=>{
                console.log('setSObjectShareErr===='+err);
            })
                }
            })
        }).catch(err=>{
            console.log('====1111====',err);
        })
@@ -172,8 +178,8 @@
    ToastShow(msg,type){
        const evt = new ShowToastEvent({
            title : msg,
            message: '',
            //title : msg,
            message: msg,
            variant: type
        });
        this.dispatchEvent(evt);
@@ -183,4 +189,17 @@
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
    async handleConfirmClick(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.ll();
        } else {
            window.history.go(-1);
        }
    }
}