unknown
2023-07-19 0c38eae1aa2b9a9318c0bbe0513d48cde5fe9af3
button-lexAddSubmitApprovalProcess

提交追加待审批
1个文件已修改
2个文件已添加
428 ■■■■ 已修改文件
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 269 ●●●● 补丁 | 查看 | 原始文档 | 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,143 +43,143 @@
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return;
            // }
            const SUBMIT = LightningConfirm.open({
            LightningConfirm.open({
                message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            }).then(submit=>{
                if(!submit){
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }else{
            if(SUBMIT==false){
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
            // 希望到货日不能早于申请提交日-0418追加
            //if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') {
            // alert('希望到货日不能早于申请提交日');
            // return;
            // }
            console.log(JSON.stringify(result));
            if(result.repairId != null){
                if(result.demoPurpose1 == '维修代用' && result.demoPurpose2 == '一般用户'){
                    if(result.repairEstimatedDateFormula == null){
                        this.ToastShow('一般维修无报价日,不可借用备品','warning');
                        return;
                    }else if(result.repairEstimatedDateFormula <'2019-07-01' && result.agreedDate == null){
                        this.ToastShow('报价日在2019/7/1之前且户同意日为空,不可借用备品','warning');
                        return;
                    }
                }
                //备品申请 过去历史转移
                if(result.recordTypeId != result.demoRequestPastDataId && result.newProductGuaranteeObject=='2: 服务多年保修' && (result.assetModelNo=='CV-V1' ||result.assetModelNo=='CV-V1(A)'||result.assetModelNo=='CV-V1(B)'||result.assetModelNo=='GIF-LV1'||result.assetModelNo=='CF-LV1L'||result.assetModelNo=='CF-LV1I'||result.assetModelNo=='MAJ-1910') &&(result.demoPurpose2=='一般用户'||result.demoPurpose2=='再修理')){
                    this.ToastShow('奥辉设备,保修期内不提供备品.','warning');
                    return;
                }
            }
            if(result.campaignId!=null || result.campaignId!=''){
                if(result.campaignStatus == '草案中'){
                    this.ToastShow('学会状态为草案中,不能提交','warning');
                    return;
                }
                if(result.campaignStatus == '申请中'){
                    this.ToastShow('学会状态为申请中,不能提交','warning');
                    return;
                }
                if(result.campaignStatus == '已结束'){
                    this.ToastShow('学会状态为已结束,不能提交','warning');
                    return;
                }
                if(result.campaignStatus == '已提交报告'){
                    this.ToastShow('学会状态为已提交报告,不能提交','warning');
                    return;
                }
                if(result.campaignStatus == '取消申请中'){
                    this.ToastShow('学会状态为取消申请中,不能提交','warning');
                    return;
                }
                if(result.campaignStatus == '取消'){
                    this.ToastShow('学会状态为取消,不能提交','warning');
                    return;
                }
            }
            if(result.qISNumber!=null || result.qISNumber!=''){
                if(result.nextAction=='送回'){
                    this.ToastShow('QIS 已送回,不能再申请备品了','warning');
                    return;
                }
            }
            //share
            var userAccess = new Array();
            userAccess.push(result.applyUserId + '_Edit');
            //SWAG-BZMA8W 去掉 服务经理部长共享 start
            //update lxy DLIU-BZNBG9 去掉服务经理部长共享
            //userAccess.push('{!Rental_Apply__c.JingliApprovalManagerId__c}_Read');
            //userAccess.push('{!Rental_Apply__c.SalesManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
            //update lxy DLIU-BZNBG9 去掉服务经理部长共享
            //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerId__c}_Read');
            //SWAG-BZMA8W 去掉 服务经理部长共享 end
            //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerSalesId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
            //userAccess.push('{!Rental_Apply__c.ZongjianApprovalManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
            //userAccess.push('{!Rental_Apply__c.Status__c}_Read');
            console.log('参数==='+result.rentalApplyId+' '+userAccess+' '+result.ownerId);
            setSObjectShare({
                sobjectName:'Rental_Apply__Share',
                rowCause:'ApplyUserShare__c',
                parentId:result.rentalApplyId,
                userAccess:userAccess,
                ownerId:result.ownerId
            }).then(res=>{
                if(res!='OK'){
                    this.ToastShow(res,'warning');
                    return;
                }else{
                    console.log('setSObjectShareSuccess====OK');
                    //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c
                    if (result.rentalApplyStatus != '已批准' && result.rentalApplyStatus != '已出库指示') {
                        this.ToastShow('请备品申请状态确认,申请状态已批准后才可以提交追加审批','warning');
                        return;
                    // 希望到货日不能早于申请提交日-0418追加
                    //if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') {
                    // alert('希望到货日不能早于申请提交日');
                    // return;
                    // }
                    console.log(JSON.stringify(result));
                    if(result.repairId != null){
                        if(result.demoPurpose1 == '维修代用' && result.demoPurpose2 == '一般用户'){
                            if(result.repairEstimatedDateFormula == null){
                                this.ToastShow('一般维修无报价日,不可借用备品','warning');
                                return;
                            }else if(result.repairEstimatedDateFormula <'2019-07-01' && result.agreedDate == null){
                                this.ToastShow('报价日在2019/7/1之前且户同意日为空,不可借用备品','warning');
                                return;
                            }
                        }
                        //备品申请 过去历史转移
                        if(result.recordTypeId != result.demoRequestPastDataId && result.newProductGuaranteeObject=='2: 服务多年保修' && (result.assetModelNo=='CV-V1' ||result.assetModelNo=='CV-V1(A)'||result.assetModelNo=='CV-V1(B)'||result.assetModelNo=='GIF-LV1'||result.assetModelNo=='CF-LV1L'||result.assetModelNo=='CF-LV1I'||result.assetModelNo=='MAJ-1910') &&(result.demoPurpose2=='一般用户'||result.demoPurpose2=='再修理')){
                            this.ToastShow('奥辉设备,保修期内不提供备品.','warning');
                            return;
                        }
                    }
                    changeAddApprovalStatus({
                        recordId: this.recordId,
                        status: '填写完毕'
                    }).then(changeResult=>{
                        if(changeResult == '更新成功'){
                            submitApproval({
                                recordId: this.recordId
                            }).then(submitApprovalRes=>{
                                if(submitApprovalRes == 'OK'){
                                    this.ToastShow('提交追加待审批','success');
                                    this.updateRecordView(this.recordId);
                                }else{
                                    this.ToastShow('追加待审批失败','ERROR');
                                }
                            })
                    if(result.campaignId!=null || result.campaignId!=''){
                        if(result.campaignStatus == '草案中'){
                            this.ToastShow('学会状态为草案中,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '申请中'){
                            this.ToastShow('学会状态为申请中,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '已结束'){
                            this.ToastShow('学会状态为已结束,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '已提交报告'){
                            this.ToastShow('学会状态为已提交报告,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '取消申请中'){
                            this.ToastShow('学会状态为取消申请中,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '取消'){
                            this.ToastShow('学会状态为取消,不能提交','warning');
                            return;
                        }
                    }
                    if(result.qISNumber!=null || result.qISNumber!=''){
                        if(result.nextAction=='送回'){
                            this.ToastShow('QIS 已送回,不能再申请备品了','warning');
                            return;
                        }
                    }
                    //share
                    var userAccess = new Array();
                    userAccess.push(result.applyUserId + '_Edit');
                    //SWAG-BZMA8W 去掉 服务经理部长共享 start
                    //update lxy DLIU-BZNBG9 去掉服务经理部长共享
                    //userAccess.push('{!Rental_Apply__c.JingliApprovalManagerId__c}_Read');
                    //userAccess.push('{!Rental_Apply__c.SalesManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
                    //update lxy DLIU-BZNBG9 去掉服务经理部长共享
                    //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerId__c}_Read');
                    //SWAG-BZMA8W 去掉 服务经理部长共享 end
                    //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerSalesId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
                    //userAccess.push('{!Rental_Apply__c.ZongjianApprovalManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
                    //userAccess.push('{!Rental_Apply__c.Status__c}_Read');
                    console.log('参数==='+result.rentalApplyId+' '+userAccess+' '+result.ownerId);
                    setSObjectShare({
                        sobjectName:'Rental_Apply__Share',
                        rowCause:'ApplyUserShare__c',
                        parentId:result.rentalApplyId,
                        userAccess:userAccess,
                        ownerId:result.ownerId
                    }).then(res=>{
                        if(res!='OK'){
                            this.ToastShow(res,'warning');
                            return;
                        }else{
                            this.ToastShow(changeResult,'error');
                        }
                            console.log('setSObjectShareSuccess====OK');
                            //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c
                            if (result.rentalApplyStatus != '已批准' && result.rentalApplyStatus != '已出库指示') {
                                this.ToastShow('请备品申请状态确认,申请状态已批准后才可以提交追加审批','warning');
                                return;
                            }
                            changeAddApprovalStatus({
                                recordId: this.recordId,
                                status: '填写完毕'
                            }).then(changeResult=>{
                                if(changeResult == '更新成功'){
                                    submitApproval({
                                        recordId: this.recordId
                                    }).then(submitApprovalRes=>{
                                        if(submitApprovalRes == 'OK'){
                                            this.ToastShow('提交追加待审批成功','success');
                                            this.updateRecordView(this.recordId);
                                        }else{
                                            this.ToastShow('追加待审批失败','ERROR');
                                        }
                                    })
                                }else{
                                    this.ToastShow(changeResult,'error');
                                }
                            })
                        }
                    }).catch(err=>{
                        console.log('setSObjectShareErr===='+err);
                    })
                }
            }).catch(err=>{
                console.log('setSObjectShareErr===='+err);
            })
                }
            })
        }).catch(err=>{
            console.log('====1111====',err);
        })
        })
    }
    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);
        }
    }
}