零配件入库 Trigger 插入触发台账和零配件更新

Posted pipidan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了零配件入库 Trigger 插入触发台账和零配件更新相关的知识,希望对你有一定的参考价值。

trigger PartsInTrigger on PartsIn__c (after insert) {
    PartsInHandler handler = new PartsInHandler();
    if(Trigger.IsAfter){
        if(Trigger.isInsert){
            handler.PartsIninsert(Trigger.New);
        }
    }
}

  

public with sharing class PartsInHandler {
    public void PartsIninsert(List<PartsIn__c> partsNew){
        Map<String,PartsIn__c> MapSpin = new Map<String,PartsIn__c>();  //入库map   型号,对象
        Map<String,Integer> MapSpinQ = new Map<String,Integer>();       //入库数量map  型号,数量
        List<Parts__c> addparList = new List<Parts__c>();
        Set<Id> partIds = new Set<Id>();      
        
        For(PartsIn__c par: partsNew){
            MapSpin.put(par.Name, par);  
            MapSpinQ.put(par.Name, Integer.valueOf(par.Quantity__c));             
        }  
        //system.debug(MapSpinQ.keySet());         
                
        //查询与入库对应的台账                            
        List<Parts__c> parList = [SELECT Id,Name,Status__c,SPPrice__c,PartsModel__c,Position__c,LotNo__c,STContractNo__c 
                   From Parts__c 
                   Where Name in: MapSpin.keySet()
                   AND Status__c =‘缺货‘
                   ORDER BY CreatedDate];
         
        For(Parts__c plist: parList){
            if(MapSpinQ.containsKey(plist.Name)){
                Integer pi = MapSpinQ.get(plist.Name);
                //system.debug(‘pi=‘+pi); 
                if(pi > 0){
                PartsIn__c pts = MapSpin.get(plist.Name);
                    plist.Status__c = ‘已预约‘;
                    plist.SPPrice__c = pts.SPPrice__c;
                    plist.NetPrice__c = pts.Net_to_YTR__c; 
                    pi -= 1;
                    MapSpinQ.put(plist.Name, pi);
                    partIds.add(plist.Id);
                }
            }
        }
         
        //查询与台账对应的零配件                            
        List<PartsAU__c> AUList = [SELECT Id,SparePartsModel__c,Status__c,WorkOrderItem__c,DetailsSpareParts__c
                   From PartsAU__c 
                   Where DetailsSpareParts__c in: partIds 
                   AND Status__c =‘缺货‘];
       
        For(PartsAU__c paulist: AUList){
            paulist.Status__c = ‘已预约‘;
           // paulist.Type__c= ‘预约‘;
        } 
        
        for(String piq: MapSpinQ.keyset()) {
            if(MapSpinQ.get(piq) > 0){
                for(Integer i = 0; i < MapSpinQ.get(piq); i++){
                    PartsIn__c pi = MapSpin.get(piq);
                    Parts__c ps = new Parts__c();
                    ps.Name = pi.Name;
                    ps.PartsModel__c = pi.SparePartsModel__c;
                    ps.Position__c =pi.Location__c; 
                    ps.LotNo__c =pi.BatchNo__c;
                    ps.STContractNo__c =pi.ContractNo__c; 
                    ps.InDate__c =pi.InDate__c; 
                    ps.SPPrice__c =pi.SPPrice__c; 
                    ps.Status__c = ‘可使用‘;
                    ps.NetPrice__c = pi.Net_to_YTR__c;
                    addparList.add(ps);
                }
            }
        }      
        //system.debug(addparList); 
        update parList;
        insert addparList;
        update AUList;
    }
}

 

 

以上是关于零配件入库 Trigger 插入触发台账和零配件更新的主要内容,如果未能解决你的问题,请参考以下文章

当外部配件通过 BT 配对或插入底座连接器时如何启动 iphone 应用程序

由于HomeKit配件中的事件而推送通知

苹果手机显示不支持此配件怎么解决?

如果苹果手机充电显示不支持此配件怎么办

homekit怎么用

iOS 设备与外部配件(Lightning)通讯