global class OpportunityWebService { @AuraEnabled WebService static String changeTrade(String oppId){ List quoList = [select id from Quote where OpportunityId = :oppId]; List oppLI = [select id from OpportunityLineItem where Opportunity.id = :oppId]; Opportunity opp = new Opportunity(); opp.id = oppId; opp.Estimation_Decision__c = false; opp.Estimation_Id__c = null; opp.Quote_Update_Sum__c = null; opp.Estimation_No__c = null; opp.Estimation_Proposal_Date__c = null; opp.Estimation_Name__c = null; // LHJ SWAG-C9QAAJ 去掉 Start // opp.Authorized_Finish_Sales__c = null; // opp.Authorized_DB_No__c = null; // opp.Authorized_Date__c = null; // opp.Autholization_Activated_Date__c = null; // opp.Bidding_Content__c = null; // opp.Bid_Date__c = null; // opp.Bidding_No__c = null; // opp.Bidding_Project_Name__c = null; // LHJ End Savepoint sp = Database.setSavepoint(); try { delete quoList; delete oppLI; update opp; return '1'; } catch (Exception ex) { Database.rollback(sp); return ex.getMessage() + ' | Line:' + ex.getLineNumber(); } } // LHJ CBPR Start webservice String parameter { get; set; } public OpportunityWebService() { this.parameter = 'value'; } @AuraEnabled WebService static String oppCheck(String oppid, String saveFlg) { Map proMap= new Map(); List OppItemList = [select PricebookEntry.Product2Id, PricebookEntry.Product2.Name From OpportunityLineItem Where OpportunityId = :oppid]; if (OppItemList.size() > 0) { for (OpportunityLineItem opl : OppItemList) { proMap.put(opl.PricebookEntry.Product2Id, opl.PricebookEntry.Product2.Name); } } List oppList = [select Agency1__c from Opportunity where id = :oppid]; String angencyId = oppList[0].Agency1__c; String strRet = ''; if (saveFlg == '1') { strRet = checkProRegisterDecide(proMap, angencyId, oppid); } else { strRet = checkProRegisterDecide(proMap, angencyId, ''); } return strRet; } // LHJ 阿西赛多检查 Start @AuraEnabled WebService static String checkDangerItem(String agency1) { //没有危化品证照的提示信息 String licenseStr = '第一经销商没有有效的危险化学品经营许可证。'; //没有阿西赛多经销商协议的提示信息 String accStr = '第一经销商没有阿西赛多经销商协议。'; //检查是否有证照 List licenseList = [SELECT Id FROM License_Information__c WHERE LicenseAndAccount__c = :agency1 AND LicenseType__c = '危险化学品经营许可证' AND Is_Active_Formula__c = true ]; //检查是否有阿西赛多协议 List accountList = [SELECT Id FROM Account WHERE Parent.id = :agency1 //阿西赛多 增加检索阿西赛多协议 以及 可以做报价(复选框) 精琢技术 wql 2021/01/04 start AND Contract_Quote_Decide_Flag_checkbox__c =true AND Assiesedo_Dealer__c = true //阿西赛多 增加检索阿西赛多协议 以及 可以做报价(复选框) 精琢技术 wql 2021/01/04 end ]; system.debug('licenseList:'+licenseList.size()); system.debug('agency1:'+agency1); //①既没有危化品证也没有阿西赛多协议 if(licenseList.size() == 0 && accountList.size() ==0){ return licenseStr+accStr; } //②没有危化品证 else if(licenseList.size() ==0){ return licenseStr; } //②没有阿西赛多经销商协议 else if(accountList.size() ==0){ return accStr; } //③全都有 else{ return 'OK'; } } // LHJ 阿西赛多检查 End public static Map MapCheckProRegisterDecide(Map proMap, String agency1, String OppId) { Map retMap = new Map(); String errormessage = ''; Boolean error = false; Map> proAllBSstrMap; List proNotNeedList = new List(); Map> old_newMap = new Map>(); Map> new_oldMap = new Map>(); // 取得 经营范围对应产品关系 List midStr = new List(); List midStrO = new List(); // List rrList = Product_Register_contrast__c.getall().values(); // for (Product_Register_contrast__c rr : rrList) { // midStr = new List(); // midStrO = new List(); // // 经营范围对应产品关系 Map作成 旧-新对照 // if (old_newMap.containsKey(rr.Register_old__c)) { // old_newMap.get(rr.Register_old__c).add(rr.Register_new__c); // } else { // midStrO.add(rr.Register_new__c); // old_newMap.put(rr.Register_old__c, midStrO.clone()); // } // // 经营范围对应产品关系 Map作成 新-旧对照 // if (new_oldMap.containsKey(rr.Register_new__c)) { // new_oldMap.get(rr.Register_new__c).add(rr.Register_old__c); // } else { // midStr.add(rr.Register_old__c); // new_oldMap.put(rr.Register_new__c, midStr.clone()); // } // } // 取得经销商 医疗器械经营许可证 List licenseList = [SELECT Id, ScopeKey__c, LicenseType__c FROM License_Information__c WHERE LicenseAndAccount__c = :agency1 AND (LicenseType__c = '医疗器械经营许可证' OR LicenseType__c = '第二类医疗器械经营备案凭证') AND Is_Active_Formula__c = true ]; // 判断 医疗器械经营许可证 是否存在 if (licenseList.size() == 0) { error = true; errormessage = '第一经销商没有有效的医疗器械经营许可证。'; retMap.put('agency', '0'); } else { //经销商经营范围 List agListA = new List(); List agListTemp = new List(); List agList = new List(); //取经销商下 所有医疗器械经营许可证、第二类医疗器械经营备案凭证 for (License_Information__c li : licenseList) { if (li.ScopeKey__c != null) { agListA.addAll(li.ScopeKey__c.split(';')); agListTemp.addAll(li.ScopeKey__c.split(';')); } } for (String a : agListTemp) { if (a.length() >= 6) { agList.add(a.substring(0, a.length() - 1)); } else { agList.add(a.trim()); } } //产品注册证 Map> proBSMap = new Map>(); Map proMidMap = null; //产品所有有效注册证(可以和经销商匹配) proAllBSstrMap = new Map>(); set proIdList = new set(); for (String qli : proMap.keySet()) { proIdList.add(qli); proBSMap.put(qli, proMidMap); List empList = new List(); proAllBSstrMap.put(qli, empList); } List prls = [ Select Product2__c, Product2__r.Asset_Model_No__c, Product2__r.SFDA_Approbated_Status__c, Product2__r.SFDA_Status_New__c, // 产品的CFDA最终状态 20181225 Product_Register__r.Name, Product_Register__r.BusinessScopeKey__c, Product_Register__r.RegisterNoStatus__c, Product_Register__r.MedPrdClass__c From Product_Register_Link__c where Product2__c in :proIdList ]; // LHJ 20190102 增加跳过逻辑 Start List productList = [select ID,SFDA_Status__c from Product2 where id in :proIdList]; for (Product2 pro : productList) { if (pro.SFDA_Status__c == '不要') { proNotNeedList.add(pro.ID); } } // LHJ 20190102 增加跳过逻辑 End for (Product_Register_Link__c prl : prls) { // 设置产品类别MAP if (String.isNotBlank(prl.Product_Register__r.BusinessScopeKey__c)) { system.debug('Product2 +++++++' + prl.Product2__c); if (proBSMap.get(prl.Product2__c) != null) { proBSMap.get(prl.Product2__c).put(prl.Product_Register__r.Name, prl.Product_Register__r.BusinessScopeKey__c); } else { Map toooMap = new Map(); toooMap.put(prl.Product_Register__r.Name, prl.Product_Register__r.BusinessScopeKey__c); proBSMap.put(prl.Product2__c, toooMap.clone()); } } // 产品的产品注册证是"不要"状态 不需要匹配注册证 20181225 if (prl.Product2__r.SFDA_Approbated_Status__c == '不要' || prl.Product_Register__r.MedPrdClass__c == '1') { proNotNeedList.add(prl.Product2__c); } } system.debug('proBSMap +++++++' + proBSMap); for (String qli : proMap.keySet()) { String proId = qli; String proName = proMap.get(proId); if (proId != null) { Boolean haveBS = false; // 产品属于非医疗,不用判断经营范围 if (proNotNeedList.contains(proId)) { haveBS = true; continue; } if (proBSMap.get(proId) == null) { error = true; errormessage += '产品"' + proName + '"没有有效的产品注册证。\n'; retMap.put(proId, '1'); continue; } if (proBSMap.get(proId) != null) { system.debug('111 +++++++' + proBSMap); Map midMap = new Map(); midMap = proBSMap.get(proId); for (String str : midMap.keySet()) { // LHJ 20200711 Start String strMidMap = midMap.get(str); List proRegList = new List(); proRegList.addAll(strMidMap.split(';')); // LHJ 20200711 End for(String strReg:proRegList){ // 被定义为"6815A"的产品类别,经营范围中必须有6815或者6815A外才可以匹配。 if (strReg.length() == 6) { for(String strAg:agListA){ if(strAg.length() >= 5 && midMap.get(str.substring(0, str.length() - 1)) == strAg.substring(0,5)){ proAllBSstrMap.get(proId).add(str.substring(0, str.length() - 1)); haveBS = true; break; } } /*if (agListA.contains(midMap.get(str.substring(0, str.length() - 1)))) { proAllBSstrMap.get(proId).add(str.substring(0, str.length() - 1)); haveBS = true; }*/ } else { system.debug('agList +++++++' + agList); system.debug('midMap +++++++' + strReg); if (agList.contains(strReg)) { //产品类别,匹配到经销商类别 proAllBSstrMap.get(proId).add(str); haveBS = true; break; } } } } } if (!haveBS) { error = true; errormessage += '第一经销商的经营范围中不包含产品" ' + proName + '"。\n'; retMap.put(proId, '2'); } } } } if (retMap.isEmpty() == false) { //return errormessage; } else { if (OppId != '') { // 更新所有注册证信息 String strRegister_alleffective; List pro2List = new List(); Map pro2Map = new Map(); List updList = new List(); List OppItemList = [select id, Id__c, Register_alleffective__c,PricebookEntry.Product2Id From OpportunityLineItem Where OpportunityId = :OppId]; // 非医疗或1类产品,取得 if (proNotNeedList != null && proNotNeedList.size() > 0) { pro2List = [select id, SFDA_Approbated_Status__c, RegisterNo_ALL__c from Product2 where Id in :proNotNeedList]; } for (Product2 pro2 : pro2List) { pro2Map.put(pro2.Id, pro2); } for (OpportunityLineItem ol : OppItemList) { if (proAllBSstrMap.containsKey(ol.PricebookEntry.Product2Id)) { ol.Register_alleffective__c = ''; for(String str: proAllBSstrMap.get(ol.PricebookEntry.Product2Id)) { if (String.isNotBlank(ol.Register_alleffective__c)) { ol.Register_alleffective__c += ';' + str; } else { ol.Register_alleffective__c = str; } } // 非医疗或1类产品 if (pro2Map.containskey(ol.PricebookEntry.Product2Id)) { if (pro2Map.get(ol.PricebookEntry.Product2Id).SFDA_Approbated_Status__c == '不要') { ol.Register_alleffective__c = 'FYL'; } else { ol.Register_alleffective__c = pro2Map.get(ol.PricebookEntry.Product2Id).RegisterNo_ALL__c; } } } updList.add(ol); } if (updList.size() > 0) update updList; } } //如果不满足阿西赛多的条件,进入这个变量 20200821 ljh return retMap; } public static String checkProRegisterDecide(Map proMap, String agency1, String OppId) { String errormessage = ''; Boolean error = false; Map CheckMap = new Map(); CheckMap = MapCheckProRegisterDecide(proMap, agency1, OppId); if (CheckMap.isEmpty()) { return 'OK'; } else { return '有不可销售产品或超出经销商经营范围,请更新报价单' + CheckMap; } } @AuraEnabled WebService static String updReg(String oppid) { List updList = new List(); List OppItemList = [select id, Id__c, Register_alleffective__c, PricebookEntry.Product2.RegisterNo_ALL__c From OpportunityLineItem Where OpportunityId = :oppid]; for (OpportunityLineItem ol : OppItemList) { ol.Register_alleffective__c = ol.PricebookEntry.Product2.RegisterNo_ALL__c; updList.add(ol); } if (updList.size() > 0) update updList; return 'OK'; } //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start WebService static Boolean judgeIsAssistantAppliedOutTime(String Quoteid) { List PromotionSalesList = [select id,IsAssistantAppliedOutTime__c from PromotionSales__c where Quote__r.Quote_No__c =:Quoteid]; for(PromotionSales__c pro : PromotionSalesList){ if(pro.IsAssistantAppliedOutTime__c){ return false; } } return true; } //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end //贸易合规 20230307 you start //营业拦截提醒 @AuraEnabled WebService static Boolean accSendEmail(String AccDealerBlacklist,String accname,String angency1,String angency2,String ownerids,String ddid,String oppid,String lidongFengId) {//zzm 贸易合规2期 add 20240125 //发送邮件 List sendMails = new List(); List MailsList = new List(); List userIdList = new List(); if(String.isNotBlank(ownerids)){ userIdList.add(ownerids); } if(String.isNotBlank(ddid)){ userIdList.add(ddid); } //zzm 贸易合规2期 add 20240125 if(String.isNotBlank(lidongFengId)){ userIdList.add(lidongFengId); } //zzm 贸易合规2期 add 20240125 //询价所有人,产品担当,发邮件 List UsrList = [SELECT email FROM user WHERE id in :userIdList]; //获取各个用户的email for (User u : UsrList){ MailsList.add(u.email); } MailsList.add('olympus@prec-tech.com'); //zzm 20231218 合规2期 MailsList.add(System.Label.LegalDepartmentEmail); //zzm 20231218 合规2期 system.debug('111===:'+MailsList); if (MailsList!=null&&MailsList.size()>0){ String title = ''; String body = ''; //zzm 20240111 合规2期 start String tmpMsg = '黑名单'; title = ' 【贸易合规】询价医院/经销商涉及'; if(AccDealerBlacklist=='123'){ body += '黑名单的客户为:' + accname+ '
'; body += '黑名单的经销商1为:' + angency1+ '
'; body += '黑名单的经销商2为:' + angency2+ '
'; }else if(AccDealerBlacklist=='12'){ body += '黑名单的客户为:' + accname+ '
'; body += '黑名单的经销商1为:' + angency1+ '
'; }else if(AccDealerBlacklist=='23'){ body += '黑名单的经销商1为:' + angency1+ '
'; body += '黑名单的经销商2为:' + angency2+ '
'; }else if(AccDealerBlacklist=='13'){ body += '黑名单的客户为:' + accname+ '
'; body += '黑名单的经销商2为:' + angency2+ '
'; }else if(AccDealerBlacklist=='1'){ body += '黑名单的客户为:' + accname+ '
'; }else if(AccDealerBlacklist=='2'){ body += '黑名单的经销商1为:' + angency1+ '
'; }else if(AccDealerBlacklist=='3'){ body += '黑名单的经销商2为:' + angency2+ '
'; } if(AccDealerBlacklist=='890'){ tmpMsg = '冻结审核中'; body += '冻结审核中的客户为:' + accname+ '
'; body += '冻结审核中的经销商1为:' + angency1+ '
'; body += '冻结审核中的经销商2为:' + angency2+ '
'; }else if(AccDealerBlacklist=='89'){ tmpMsg = '冻结审核中'; body += '冻结审核中的客户为:' + accname+ '
'; body += '冻结审核中的经销商1为:' + angency1+ '
'; }else if(AccDealerBlacklist=='90'){ tmpMsg = '冻结审核中'; body += '冻结审核中的经销商1为:' + angency1+ '
'; body += '冻结审核中的经销商2为:' + angency2+ '
'; }else if(AccDealerBlacklist=='80'){ tmpMsg = '冻结审核中'; body += '冻结审核中的客户为:' + accname+ '
'; body += '冻结审核中的经销商2为:' + angency2+ '
'; }else if(AccDealerBlacklist=='8'){ tmpMsg = '冻结审核中'; body += '冻结审核中的客户为:' + accname+ '
'; }else if(AccDealerBlacklist=='9'){ tmpMsg = '冻结审核中'; body += '冻结审核中的经销商1为:' + angency1+ '
'; }else if(AccDealerBlacklist=='0'){ tmpMsg = '冻结审核中'; body += '冻结审核中的经销商2为:' + angency2+ '
'; } body += '' + System.Label.Environment_Url+ oppid +'
'; body += '谢谢!'; Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage(); messageNEW.setSubject(title + tmpMsg); //zzm 20240111 合规2期 messageNEW.setHtmlBody(body); messageNEW.setCharset('UTF-8'); messageNEW.setToAddresses(MailsList); //List toCcMailsList = new List(); //toCcMailsList.add('youchang@prec-tech.com'); //messageNEW.setCcAddresses(toCcMailsList); sendMails.add(messageNEW); } boolean rs = true; if (sendMails.size() > 0) { Messaging.Email[] allMails = new Messaging.Email[]{}; for(Integer j = 0; j < sendMails.size(); j++) { allMails.add(sendMails.get(j)); } system.debug('222===:'+allMails); Messaging.SendEmailResult[] results = Messaging.sendEmail(allMails); System.debug('results 结果 :'+results); for (Integer i = 0; i < results.size(); i++) { if (results[i].success == false) { system.debug('=====send mail error:' + results[i].errors[0].message); rs = false; } } } return rs; } //服务拦截提醒 //【新建询价】检查点仅通知合同组 sendalert=Main_Con //【报价Decide】检查点邮件通知人员:合同组、FSE领导、服务助理(标签) sendalert=decide_con @AuraEnabled WebService static Boolean accSendEmailFW(String AccDealerBlacklist,String accname,String angency,String mcid,String sendalert,String[] FSEStr) { //发送邮件 List sendMails = new List(); List MailsList = new List(); List userIdList = new List(); //合同组 List groupmemberList = [SELECT GroupId,Id,UserOrGroupId FROM GroupMember where Group.DeveloperName = 'TradeComplianceGroup']; Set GroupMap = new Set(); List gmInsertList = new List(); if(groupmemberList != null && groupmemberList.size()>0){ for (GroupMember gm : groupmemberList) { GroupMap.add(gm.UserOrGroupId); } } //询价所有人,产品担当,发邮件 List UsrList = [SELECT email FROM user WHERE id in :GroupMap or id in :FSEStr]; //获取各个用户的email for (User u : UsrList){ MailsList.add(u.email); } ////decide 进来服务助理 6个人 //if(sendalert=='decide_con'){ // String toEmailAddress = System.Label.TradeComplianceStatusSendEmailFW; // String[] toAddresses = toEmailAddress.split(','); // for(String toa:toAddresses){ // MailsList.add(toa); // } //} MailsList.add('youchang@prec-tech.com'); MailsList.add('olympus@prec-tech.com'); // WYL 2023/12/13 add MailsList.add(System.Label.LegalDepartmentEmail); system.debug('111===:'+MailsList); if (MailsList!=null&&MailsList.size()>0){ String title = ''; String body = ''; //title = '医院/经销商涉及黑名单'; String accname1 = accname==null ? '' :accname; String angency1 = angency==null ? '' :angency; //if(AccDealerBlacklist=='1' || AccDealerBlacklist=='intercept'){ // body += '黑名单的客户为:' + accname1 + '
'; // body += '黑名单的经销商为:' + angency1 + '
'; //} //wyl 20240111 合规2期 start if(AccDealerBlacklist=='1' || AccDealerBlacklist=='intercept'){ title ='【贸易合规】'+ username(accname1)+'涉及黑名单'; body += '黑名单的客户为:' + username(accname1)+ '
'; }else if(AccDealerBlacklist=='2'){ title = '【贸易合规】'+ username(angency1)+'涉及黑名单'; body += '黑名单的经销商为:' + username(angency1 )+ '
'; }else if(AccDealerBlacklist=='12'){ title = '【贸易合规】'+ username(accname1)+'和'+username(angency1)+'涉及黑名单'; body += '黑名单的客户为:' +username(accname1) + '
'; body += '黑名单的经销商为:' + username(angency1) + '
'; } //wyl 20240111 合规2期 start body += '' + System.Label.Environment_Url+ mcid +'
'; body += '谢谢!'; Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage(); messageNEW.setSubject(title); messageNEW.setHtmlBody(body); messageNEW.setCharset('UTF-8'); messageNEW.setToAddresses(MailsList); sendMails.add(messageNEW); } boolean rs = true; if (sendMails.size() > 0) { Messaging.Email[] allMails = new Messaging.Email[]{}; for(Integer j = 0; j < sendMails.size(); j++) { allMails.add(sendMails.get(j)); } system.debug('222===:'+allMails); Messaging.SendEmailResult[] results = Messaging.sendEmail(allMails); System.debug('results 结果 :'+results); for (Integer i = 0; i < results.size(); i++) { if (results[i].success == false) { system.debug('=====send mail error:' + results[i].errors[0].message); rs = false; } } } return rs; } // 合规一期修改 获取用户名 WYL public static String username(String userId){ System.debug('id打印:'+userId); try { if (userId != null && userId != '') { Account u = [select id,name from Account where id = :userId]; return u.name; } return ''; } catch (Exception e) { return userId; } } //贸易合规 20230307 you end }