| | |
| | | List<String> HospitalId = new List<String>(); |
| | | List<String> provinceList = new List<String>();//省 |
| | | List<String> cityList = new List<String>();//市 |
| | | List<String> inchargeStaff = new List<String>();//市 |
| | | for (Repair__c nObj : newList) { |
| | | //医院的CSM管理省(文本) 值不为空,并且收货地址不为空 |
| | | if(nObj.Hospital__c != null && nObj.address_Contacts__c == null && nObj.address_Telephone__c == null && nObj.address_Contacts_Name__c == null && nObj.address_City__c == null && nObj.Detailed_Address__c == null){ |
| | | HospitalId.add(nObj.Hospital__C); |
| | | } |
| | | inchargeStaff.add(nObj.Incharge_Staff__c); |
| | | } |
| | | // gzw DB202212270703 20230301 备品地址导入改造 start |
| | | Map<String,user> profileAndRoleMap = new Map<String,user>(); |
| | | for(user re :[select id,Profile.name,Branch__c,UserRole.name from user where id in :inchargeStaff]){ |
| | | profileAndRoleMap.put(re.id, re); |
| | | } |
| | | // gzw DB202212270703 20230301 备品地址导入改造 start |
| | | if(HospitalId != null && HospitalId.size() > 0){ |
| | | String HospitalSQl = 'SELECT id,OCM_man_province_txt__c,FieldCity_Master_Name__c from Account where id in :HospitalId'; |
| | | List<Account> accountList = Database.query(HospitalSQl); |
| | |
| | | for(Account ac : accountList){ |
| | | if(nObj.Hospital__c == ac.id){ |
| | | String provinceAndCity = ''; |
| | | if('山东' == ac.OCM_man_province_txt__c){ |
| | | if('烟台市' == ac.FieldCity_Master_Name__c || '威海市' == ac.FieldCity_Master_Name__c || '日照市' == ac.FieldCity_Master_Name__c |
| | | || '青岛市' == ac.FieldCity_Master_Name__c || '潍坊市' == ac.FieldCity_Master_Name__c){ |
| | | provinceAndCity = matchupMap.get('山东,青岛市'); |
| | | }else{ |
| | | provinceAndCity = matchupMap.get('山东,济南市'); |
| | | } |
| | | //DB202303246427 LY 20230329 start |
| | | // if('山东' == ac.OCM_man_province_txt__c){ |
| | | // if('烟台市' == ac.FieldCity_Master_Name__c || '威海市' == ac.FieldCity_Master_Name__c || '日照市' == ac.FieldCity_Master_Name__c |
| | | // || '青岛市' == ac.FieldCity_Master_Name__c || '潍坊市' == ac.FieldCity_Master_Name__c){ |
| | | // provinceAndCity = matchupMap.get('山东,青岛市'); |
| | | // }else{ |
| | | // provinceAndCity = matchupMap.get('山东,济南市'); |
| | | // } |
| | | if('青岛' == ac.OCM_man_province_txt__c){ |
| | | provinceAndCity = matchupMap.get('山东,青岛市'); |
| | | }else if ('山东' == ac.OCM_man_province_txt__c) { |
| | | provinceAndCity = matchupMap.get('山东,济南市'); |
| | | //DB202303246427 LY 20230329 end |
| | | }else{ |
| | | provinceAndCity = matchupMap.get(ac.OCM_man_province_txt__c); |
| | | } |
| | |
| | | system.debug('cityList='+cityList); |
| | | system.debug('provinceList='+provinceList); |
| | | if(falg && provinceList != null && cityList != null && provinceList.size() > 0 && cityList.size() > 0){ |
| | | String addressSQl = 'SELECT ID,Customer__c,Customer_Name__c,Contacts__c,Contacts_Name__c,Telephone__c,Province__c,Province_Name__c,City__c,City_Name__c,Detailed_Address__c,ZipCode__c' |
| | | //+ ',Contacts__r.LastName_Encrypted__c,ZipCode_Encrypted__c,Detailed_Address_Encrypted__c,Telephone_Encrypted__c' // PI改造 By Bright 20220407 zhj MEBG新方案改造 2022-11-29 |
| | | // gzw DB202212270703 20230301 备品地址导入改造 start |
| | | // String addressSQl = 'SELECT ID,Customer__c,Customer_Name__c,Contacts__c,Contacts_Name__c,Telephone__c,Province__c,Province_Name__c,City__c,City_Name__c,Detailed_Address__c,ZipCode__c' |
| | | // //+ ',Contacts__r.LastName_Encrypted__c,ZipCode_Encrypted__c,Detailed_Address_Encrypted__c,Telephone_Encrypted__c' // PI改造 By Bright 20220407 zhj MEBG新方案改造 2022-11-29 |
| | | // + ' from Address__c ' |
| | | // + ' where Address_Classification__c = \'办事处\' and Province_Name__c in :provinceList and City_Name__c in :cityList ' |
| | | // + ' order by Using_Datetime__c desc NULLS LAST '; |
| | | |
| | | |
| | | String addressSQl = 'SELECT ID,Customer__c,Customer_Name__c,Contacts__c,Contacts_Name__c,Telephone__c,Province__c,Province_Name__c,City__c,City_Name__c,Detailed_Address__c,ZipCode__c ' |
| | | + ' ,Address_Classification__c,Beipin_Center__c ' |
| | | //+ ',Contacts__r.LastName_Encrypted__c,ZipCode_Encrypted__c,Detailed_Address_Encrypted__c,Telephone_Encrypted__c' // PI改造 By Bright 20220407 zhj MEBG新方案改造 2022-11-29 |
| | | + ' from Address__c ' |
| | | + ' where Address_Classification__c = \'办事处\' and Province_Name__c in :provinceList and City_Name__c in :cityList ' |
| | | + ' where ( Address_Classification__c = \'办事处\' and Province_Name__c in :provinceList and City_Name__c in :cityList )' |
| | | + ' or Address_Classification__c = \'备品\'' |
| | | + ' order by Using_Datetime__c desc NULLS LAST '; |
| | | |
| | | // gzw DB202212270703 20230301 备品地址导入改造 end |
| | | system.debug('addressSQl='+addressSQl); |
| | | List<Address__c> addressList = Database.query(addressSQl); |
| | | |
| | | if(addressList != null && addressList.size() > 0){ |
| | | system.debug(addressList[0]); |
| | | List<Address__c> addressList = new List<Address__c>(); |
| | | Map<String,Address__c> beipinMap = new Map<String,Address__c>(); |
| | | List<Address__c> addressTempList = Database.query(addressSQl); |
| | | for (Address__c ad :addressTempList) { |
| | | if (ad.Address_Classification__c == '备品') { |
| | | beipinMap.put(ad.Beipin_Center__c,ad); |
| | | }else{ |
| | | addressList.add(ad); |
| | | } |
| | | } |
| | | //List<Address__c> addressList = Database.query(addressSQl); |
| | | |
| | | System.debug('进入备品+++++addressTempList ' + addressTempList.size()); |
| | | // if(addressList != null && addressList.size() > 0){ |
| | | if(addressTempList != null && addressTempList.size() > 0){ |
| | | for (Repair__c nObj : newList) { |
| | | if(nObj.Hospital__c != null && nObj.address_Contacts__c == null && nObj.address_Telephone__c == null && nObj.address_Contacts_Name__c == null && nObj.address_City__c == null && nObj.Detailed_Address__c == null){ |
| | | //由于为了减少select ,所以获取我们配置好的map,根据保有设备上医院的 OCSM管理省(文本) 的值,获取对应的地址上的省和市 |
| | | for(Account ac : accountList){ |
| | | if(nObj.Hospital__c == ac.id){ |
| | | String provinceAndCity = ''; |
| | | matchupMap.get(ac.OCM_man_province_txt__c); |
| | | if('山东' == ac.OCM_man_province_txt__c){ |
| | | if('烟台市' == ac.FieldCity_Master_Name__c || '威海市' == ac.FieldCity_Master_Name__c || '日照市' == ac.FieldCity_Master_Name__c |
| | | || '青岛市' == ac.FieldCity_Master_Name__c || '潍坊市' == ac.FieldCity_Master_Name__c){ |
| | | System.debug('进入备品+++++ '); |
| | | if (nObj.Returns_Product_way__c == '备品中心') { |
| | | user re = profileAndRoleMap.get(nObj.Incharge_Staff__c); |
| | | if (re == null) return; |
| | | String beipCenter = ''; |
| | | if (re.Profile.name.startsWith('2B3')) { |
| | | beipCenter = '北京备品中心'; |
| | | }else if (re.Profile.name.startsWith('2B2')) { |
| | | if (re.Branch__c == '北京') { |
| | | beipCenter = '北京备品中心'; |
| | | }else if (re.Branch__c == '上海') { |
| | | beipCenter = '华东备品中心'; |
| | | }else if (re.Branch__c == '广州') { |
| | | beipCenter = '广州备品中心'; |
| | | } |
| | | }else if (re.UserRole.name == 'CTEC教育本部') { |
| | | if (re.Branch__c == '北京') { |
| | | beipCenter = '北京C-TEC'; |
| | | }else if (re.Branch__c == '上海') { |
| | | beipCenter = '上海C-TEC'; |
| | | }else if (re.Branch__c == '广州') { |
| | | beipCenter = '广州C-TEC'; |
| | | } |
| | | } |
| | | System.debug('进入备品+++++ beipCenter' + beipCenter); |
| | | |
| | | if(String.isNotBlank(beipCenter)){ |
| | | Address__c addressbeip = beipinMap.get(beipCenter); |
| | | System.debug('进入备品+++++ addressbeip' + addressbeip.id); |
| | | //联系人 |
| | | String contactsName = ''; |
| | | String contactsNameEncrypt = ''; |
| | | if(!String.isBlank(addressbeip.Contacts__c)){ |
| | | contactsName = addressbeip.Contacts_Name__c; |
| | | } |
| | | //省+市 |
| | | String address = addressbeip.Detailed_Address__c.trim(); |
| | | String cityName = addressbeip.City_Name__c.trim(); |
| | | String ProvinceCity = addressbeip.Province_Name__c.trim()+cityName; |
| | | //防止详细地址里面带着省份和市 |
| | | if(!address.contains(ProvinceCity)){ |
| | | address = ProvinceCity + address; |
| | | } |
| | | //联系人 |
| | | String ContactPerson = ''; |
| | | if(!String.isBlank(addressbeip.Customer__c)){ |
| | | ContactPerson = addressbeip.Customer_Name__c; |
| | | } |
| | | nObj.address_Contacts__c=contactsName; |
| | | nObj.address_ZipCode__c = addressbeip.ZipCode__c; |
| | | nObj.address_City__c = cityName; |
| | | nObj.address_Contacts_Name__c = ContactPerson; |
| | | nObj.address_Telephone__c=addressbeip.Telephone__c; |
| | | nObj.Detailed_Address__c=address; |
| | | nObj.Encrypt_Update_Flag__c=true; |
| | | system.debug('nObj assign and Encrypt_Update_Flag__c set true'); |
| | | |
| | | } |
| | | }else{ |
| | | if(nObj.Hospital__c != null && nObj.address_Contacts__c == null && nObj.address_Telephone__c == null && nObj.address_Contacts_Name__c == null && nObj.address_City__c == null && nObj.Detailed_Address__c == null){ |
| | | //由于为了减少select ,所以获取我们配置好的map,根据保有设备上医院的 OCSM管理省(文本) 的值,获取对应的地址上的省和市 |
| | | for(Account ac : accountList){ |
| | | if(nObj.Hospital__c == ac.id){ |
| | | String provinceAndCity = ''; |
| | | matchupMap.get(ac.OCM_man_province_txt__c); |
| | | //DB202303246427 LY 20230329 start |
| | | // if('山东' == ac.OCM_man_province_txt__c){ |
| | | // if('烟台市' == ac.FieldCity_Master_Name__c || '威海市' == ac.FieldCity_Master_Name__c || '日照市' == ac.FieldCity_Master_Name__c |
| | | // || '青岛市' == ac.FieldCity_Master_Name__c || '潍坊市' == ac.FieldCity_Master_Name__c){ |
| | | // provinceAndCity = matchupMap.get('山东,青岛市'); |
| | | // }else{ |
| | | // provinceAndCity = matchupMap.get('山东,济南市'); |
| | | // } |
| | | if ('青岛' == ac.OCM_man_province_txt__c) { |
| | | provinceAndCity = matchupMap.get('山东,青岛市'); |
| | | }else{ |
| | | }else if ('山东' == ac.OCM_man_province_txt__c) { |
| | | provinceAndCity = matchupMap.get('山东,济南市'); |
| | | //DB202303246427 LY 20230329 end |
| | | }else{ |
| | | provinceAndCity = matchupMap.get(ac.OCM_man_province_txt__c); |
| | | } |
| | | }else{ |
| | | provinceAndCity = matchupMap.get(ac.OCM_man_province_txt__c); |
| | | } |
| | | system.debug('provinceAndCity='+provinceAndCity); |
| | | if(provinceAndCity != null){//不能为空 |
| | | //地址表上省和市不能为空 |
| | | if(addressList[0].Province_Name__c != null && addressList[0].City_Name__c!= null){ |
| | | //拼接一个字符串方便对比 |
| | | String pAc = addressList[0].Province_Name__c + ',' + addressList[0].City_Name__c; |
| | | if(provinceAndCity.equals(pAc)){ |
| | | //联系人 |
| | | String contactsName = ''; |
| | | String contactsNameEncrypt = '';// 20220407 PI改造 By Bright |
| | | if(!String.isBlank(addressList[0].Contacts__c)){ |
| | | contactsName = addressList[0].Contacts_Name__c; |
| | | //contactsNameEncrypt = addressList[0].Contacts__r.LastName_Encrypted__c;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | system.debug('provinceAndCity='+provinceAndCity); |
| | | if(provinceAndCity != null){//不能为空 |
| | | //地址表上省和市不能为空 |
| | | if(addressList[0].Province_Name__c != null && addressList[0].City_Name__c!= null){ |
| | | //拼接一个字符串方便对比 |
| | | String pAc = addressList[0].Province_Name__c + ',' + addressList[0].City_Name__c; |
| | | if(provinceAndCity.equals(pAc)){ |
| | | //联系人 |
| | | String contactsName = ''; |
| | | String contactsNameEncrypt = '';// 20220407 PI改造 By Bright |
| | | if(!String.isBlank(addressList[0].Contacts__c)){ |
| | | contactsName = addressList[0].Contacts_Name__c; |
| | | //contactsNameEncrypt = addressList[0].Contacts__r.LastName_Encrypted__c;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | } |
| | | //省+市 |
| | | String address = addressList[0].Detailed_Address__c.trim(); |
| | | //String addressEncrypt = addressList[0].Detailed_Address_Encrypted__c; zhj MEBG新方案改造 2022-11-29 |
| | | String cityName = addressList[0].City_Name__c.trim(); |
| | | String ProvinceCity = addressList[0].Province_Name__c.trim()+cityName; |
| | | //防止详细地址里面带着省份和市 |
| | | if(!address.contains(ProvinceCity)){ |
| | | address = ProvinceCity + address; |
| | | } |
| | | //联系人 |
| | | String ContactPerson = ''; |
| | | if(!String.isBlank(addressList[0].Customer__c)){ |
| | | ContactPerson = addressList[0].Customer_Name__c; |
| | | } |
| | | nObj.address_Contacts__c=contactsName; |
| | | //nObj.address_Contacts_Encrypt__c=contactsNameEncrypt;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.address_ZipCode__c = addressList[0].ZipCode__c; |
| | | //nObj.address_ZipCode_Encrypt__c = addressList[0].ZipCode_Encrypted__c;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.address_City__c = cityName; |
| | | nObj.address_Contacts_Name__c = ContactPerson; |
| | | nObj.address_Telephone__c=addressList[0].Telephone__c; |
| | | //nObj.address_Telephone_Encrypt__c=addressList[0].Telephone_Encrypted__c;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.Detailed_Address__c=address; |
| | | //nObj.Detailed_Address_Encrypt__c=addressEncrypt;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.Encrypt_Update_Flag__c=true;// 20220411 PI改造 By Bright |
| | | system.debug('nObj assign and Encrypt_Update_Flag__c set true'); |
| | | } |
| | | //省+市 |
| | | String address = addressList[0].Detailed_Address__c.trim(); |
| | | //String addressEncrypt = addressList[0].Detailed_Address_Encrypted__c; zhj MEBG新方案改造 2022-11-29 |
| | | String cityName = addressList[0].City_Name__c.trim(); |
| | | String ProvinceCity = addressList[0].Province_Name__c.trim()+cityName; |
| | | //防止详细地址里面带着省份和市 |
| | | if(!address.contains(ProvinceCity)){ |
| | | address = ProvinceCity + address; |
| | | } |
| | | //联系人 |
| | | String ContactPerson = ''; |
| | | if(!String.isBlank(addressList[0].Customer__c)){ |
| | | ContactPerson = addressList[0].Customer_Name__c; |
| | | } |
| | | nObj.address_Contacts__c=contactsName; |
| | | //nObj.address_Contacts_Encrypt__c=contactsNameEncrypt;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.address_ZipCode__c = addressList[0].ZipCode__c; |
| | | //nObj.address_ZipCode_Encrypt__c = addressList[0].ZipCode_Encrypted__c;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.address_City__c = cityName; |
| | | nObj.address_Contacts_Name__c = ContactPerson; |
| | | nObj.address_Telephone__c=addressList[0].Telephone__c; |
| | | //nObj.address_Telephone_Encrypt__c=addressList[0].Telephone_Encrypted__c;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.Detailed_Address__c=address; |
| | | //nObj.Detailed_Address_Encrypt__c=addressEncrypt;// 20220407 PI改造 By Bright zhj MEBG新方案改造 2022-11-29 |
| | | nObj.Encrypt_Update_Flag__c=true;// 20220411 PI改造 By Bright |
| | | system.debug('nObj assign and Encrypt_Update_Flag__c set true'); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |