| | |
| | | } |
| | | // 数据录入 |
| | | @AuraEnabled |
| | | public static Map<String,String> dataEntry(String report1){ |
| | | public static Map<String,String> dataEntry(String report1,List<Id> deleteBrandIdList,List<Id> deleteProductIdList){ |
| | | LostReport report = (LostReport)JSON.deserialize(report1, LostReport.class); |
| | | Map<String,String> messageMap = new Map <String,String>(); |
| | | system.debug('save---start:'); |
| | |
| | | map<string,PCLLostProduct__c> upsertLostProductMap = new map<string,PCLLostProduct__c>(); |
| | | // 需要删掉的失单品牌 |
| | | list<PCLLostProduct__c> deleteLostProductList = new list<PCLLostProduct__c>(); |
| | | Integer lineNo = 0; |
| | | for(LostBrand tempLostBrand : report.LostBrands ) { |
| | | // 如果有失单品牌,那么就要插入更新; |
| | | system.debug('tempLostBrand.lostBrand.Lost_By_Company__c:'+tempLostBrand.lostBrand.Lost_By_Company__c); |
| | | if(string.isNotBlank(tempLostBrand.lostBrand.Lost_By_Company__c)) { |
| | | upsertLostBrandMap.put(tempLostBrand.lineNo,tempLostBrand.lostBrand); |
| | | tempLostBrand.lostBrand.Lost_cancel_report__c = report.lostReport.id; |
| | | upsertLostBrandMap.put(lineNo,tempLostBrand.lostBrand); |
| | | tempLostBrand.lostBrand.Lost_cancel_report__c = report.lostReport.Id; |
| | | tempLostBrand.lostBrand.Name = tempLostBrand.lostBrand.Lost_By_Company__c; |
| | | integer tempNo = 0; |
| | | for( PCLLostProducts tempLostProduct : tempLostBrand.LostProducts) { |
| | | system.debug('Name:'+ tempLostProduct.LostProductss.Name ); |
| | | if(tempLostProduct.LostProductss.Quantity__c !=null && tempLostProduct.LostProductss.Quantity__c >0) { |
| | | tempLostProduct.LostProductss.Name = tempLostBrand.lostBrand.Name + tempLostProduct.LostProductss.Quantity__c; |
| | | upsertLostProductMap.put(tempLostBrand.lineNo +':'+ tempNo,tempLostProduct.LostProductss); |
| | | }else if(string.isNotBlank(tempLostProduct.LostProductss.id)) { |
| | | upsertLostProductMap.put(lineNo +':'+ tempNo,tempLostProduct.LostProductss); |
| | | }else if(string.isNotBlank(tempLostProduct.LostProductss.Id)) { |
| | | deleteLostProductList.add(tempLostProduct.LostProductss); |
| | | } |
| | | tempNo++; |
| | | } |
| | | } |
| | | // 如果没有品牌,但是有id, 这样数据需要删除 |
| | | else if(string.isNotBlank(tempLostBrand.lostBrand.id)) { |
| | | deleteLostBrandMap.put(tempLostBrand.lineNo,tempLostBrand.lostBrand); |
| | | else if(string.isNotBlank(tempLostBrand.lostBrand.Id )) { |
| | | deleteLostBrandMap.put(lineNo,tempLostBrand.lostBrand); |
| | | // 这里可能需要也判断一下失单型号有没有需要删掉 |
| | | } |
| | | lineNo++; |
| | | } |
| | | if(upsertLostBrandMap.size()>0) { |
| | | upsert upsertLostBrandMap.values(); |
| | |
| | | for( string productNo :upsertLostProductMap.keyset()) { |
| | | PCLLostProduct__c tempLostProduct = upsertLostProductMap.get(productNo); |
| | | integer brandNo = integer.valueof(productNo.split(':')[0]); |
| | | tempLostProduct.PCLLostBrand__c = upsertLostBrandMap.get(brandNo).id; |
| | | tempLostProduct.PCLLostBrand__c = upsertLostBrandMap.get(brandNo).Id; |
| | | } |
| | | if(upsertLostProductMap.size()>0) { |
| | | upsert upsertLostProductMap.values(); |
| | |
| | | if(deleteLostBrandMap.size()>0) { |
| | | delete deleteLostBrandMap.values(); |
| | | for(PCLLostBrand__c pcl: deleteLostBrandMap.values()) { |
| | | pcl.id = null; |
| | | pcl.Id = null; |
| | | } |
| | | } |
| | | if (deleteProductIdList.size()>0) { |
| | | database.delete(deleteProductIdList); |
| | | |
| | | } |
| | | if (deleteBrandIdList.size()>0) { |
| | | database.delete(deleteBrandIdList); |
| | | } |
| | | if(deleteLostProductList.size()>0) { |
| | | delete deleteLostProductList; |
| | | for(PCLLostProduct__c pclp: deleteLostProductList) { |
| | | pclp.id = null; |
| | | pclp.Id = null; |
| | | } |
| | | } |
| | | if(deleteBrandIDSet.size() > 0) { |