From af7b716a60d889acea95560abba0e46eee008b8f Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期三, 05 七月 2023 13:54:50 +0800
Subject: [PATCH] backup0705
---
force-app/main/default/classes/Product2Handler.cls | 927 +++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 603 insertions(+), 324 deletions(-)
diff --git a/force-app/main/default/classes/Product2Handler.cls b/force-app/main/default/classes/Product2Handler.cls
index 44e5cc5..cbde78d 100644
--- a/force-app/main/default/classes/Product2Handler.cls
+++ b/force-app/main/default/classes/Product2Handler.cls
@@ -1,337 +1,616 @@
public without sharing class Product2Handler extends Oly_TriggerHandler {
- private Map<Id, Product2> newMap;
- private Map<Id, Product2> oldMap;
- private List<Product2> newList;
- private List<Product2> oldList;
+ private Map<Id, Product2> newMap;
+ private Map<Id, Product2> oldMap;
+ private List<Product2> newList;
+ private List<Product2> oldList;
- public Product2Handler() {
- this.newMap = (Map<Id, Product2>) Trigger.newMap;
- this.oldMap = (Map<Id, Product2>) Trigger.oldMap;
- this.newList = (List<Product2>) Trigger.new;
- this.oldList = (List<Product2>) Trigger.old;
- }
+ public Product2Handler() {
+ this.newMap = (Map<Id, Product2>) Trigger.newMap;
+ this.oldMap = (Map<Id, Product2>) Trigger.oldMap;
+ this.newList = (List<Product2>) Trigger.new;
+ this.oldList = (List<Product2>) Trigger.old;
+ }
- protected override void beforeInsert() {
- beforeSetValue();
- // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 Start
- SetCompetitorCode();
- // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 End
- }
- protected override void beforeUpdate() {
- beforeSetValue();
- //SFDC鍋滄棰勮 lt 20211015 add start
- // FlgStopManufacure(this.newList, this.oldMap);
- //SFDC鍋滄棰勮 lt 20211015 add end
- FlgStopManufacure();
-
- }
-
- //SFDC鍋滄棰勮 lt 20210922 add start
- protected override void afterUpdate(){
- Calculate_AverageMonthSales(this.newList, this.oldMap);
- }
- //SFDC鍋滄棰勮 lt 20210922 add end
-
+ protected override void beforeInsert() {
+ beforeSetValue();
// SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 Start
- private void SetCompetitorCode() {
- Boolean SelctFlg = False;
- list<AggregateResult> proList;
- String strPC = '';
- Integer i = 1;
-
- for (Product2 nObj : newList) {
- if (nObj.Competitor_product_dummy__c) {
- SelctFlg = True;
- }
- }
- if (SelctFlg) {
- proList = [Select Max(ProductCode) PC From Product2 Where ProductCode Like 'SD%'];
- if (proList != null && proList.size() > 0) {
- strPC = String.valueof(proList[0].get('PC'));
- }
- }
- for (Product2 nObj : newList) {
- if (nObj.Competitor_product_dummy__c && strPC.length() == 8
- && proList != null && proList.size() > 0 ) {
- Integer num = Integer.valueOf(strPC.SubString(2,strPC.length())) + i;
- nObj.ProductCode = 'SD' + String.valueOf(num).leftpad(6,'0');
- i++;
- }
- }
- }
+ SetCompetitorCode();
// SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 End
-
- private void beforeSetValue() {
-
- for (Product2 nObj : newList) {
- //CHAN-B8GCBB
- if (nObj.WhiteSpace__c == true) {
- nObj.StorageStatus__c = String.valueOf(nObj.StorageStatusNo__c);
- } else {
- nObj.StorageStatus__c = '';
- }
- //CHAN-B8GCBB
-
- nObj.Fixture_Model_No_T__c = nObj.Fixture_Model_No_F__c;
- // CBPR LHJ
- if (Trigger.isInsert ||
- (Trigger.isUpdate && nObj.SFDA_Status_New__c != oldMap.get(nObj.id).SFDA_Status_New__c)) {
- nObj.SFDA_Status__c = nobj.SFDA_Status_New__c;
- if (nobj.SFDA_Status_New__c == '鏂拌=鍝佺敵璜嬩腑' || nobj.SFDA_Status_New__c == '婧栧倷涓�') {
- nObj.SFDA_Status__c = '鍋滄';
- }
- }
- // CBPR LHJ
-
- // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 Start
- if (Trigger.isInsert) {
-
- }
- // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 End
- }
- }
-
- //SFDC鍋滄棰勮 lt 20210914 add start
- private static void Calculate_AverageMonthSales(List<Product2> newList,Map<Id, Product2> oldMap){
-
- //绗﹀悎鏉′欢鐨� 鏃� 浜у搧List
- List<Id> oproList = new List<Id>();
- //绗﹀悎鏉′欢鐨� 鏂版棫 浜у搧Id List 浣滀负鏉′欢
- List<Id> conList = new List<Id>();
- //Map<鏃х殑锛屾柊鐨�>瀵瑰簲
- Map<String,String> matMap = new Map<String,String>();
-
- //Map<鏃d锛岄璁″仠姝㈡棩>
- Map<String,Date> adateMap = new Map<String,Date>();
-
- //Map<鏃d, x(骞冲潎鏈堥攢閲�)>
- Map<String,Integer> xMap = new Map<String,Integer>();
- //Map<鏃d, z(澶╂暟)>
- Map<String,Integer> zMap = new Map<String,Integer>();
-
- for(Product2 term : newList){
- System.debug('鏍囪瘑'+term.CalMonthSalesFLG__c);
- System.debug('鏂板簱瀛�'+term.StorageStatusNo__c);
- System.debug('鏃у簱瀛�'+oldMap.get(term.Id).StorageStatusNo__c);
- if(term.M_BC_Stop_manufacure__c != null && term.SFDA_Status__c != '鍋滄' && (term.StorageStatusNo__c != oldMap.get(term.Id).StorageStatusNo__c || term.CalMonthSalesFLG__c == true)){
- if(term.Correspond_Code__c != null){
- matMap.put((String)term.Id,(String)term.Correspond_Code__c);
- conList.add(term.Correspond_Code__c);
- }
- conList.add(term.Id);
- oproList.add(term.Id);
-
- adateMap.put(term.Id, term.M_BC_Stop_manufacure__c);
- }
- }
-
- //鍋� 涓�瀵瑰 鐨� Map<String,List<鏈堥攢閲�>>
- Map<String,List<ProductMonthlySales__c>> msMap = new Map<String,List<ProductMonthlySales__c>>();
-
- if(conList.size()>0){
- List<ProductMonthlySales__c> msList = [Select Id, MonthSales__c, CurrentMonth__c, CurrentDate__c,
- CurrentYear__c, ProductM__c, Product2Model__c,
- ProductM__r.StorageStatusNo__c,
- ProductM__r.M_BC_Stop_manufacure__c
- From ProductMonthlySales__c
- Where ProductM__c in: conList
- Order by CurrentDate__c DESC];
- //鍙屽眰寰幆 浜у搧==>鏈堥攢閲�
- for(Id pro : conList){
- for(ProductMonthlySales__c mms : msList){
- if(pro == mms.ProductM__c){
- if(msMap.containsKey(pro)){
- msMap.get(pro).add(mms);
- }else{
- List<ProductMonthlySales__c> pmsaleList = new List<ProductMonthlySales__c>();
- pmsaleList.add(mms);
- msMap.put(pro, pmsaleList);
- }
- }
-
- }
- }
-
- System.debug('鏉′欢List'+conList);
- System.debug('sql鏌ュ埌鐨凩ist'+msList);
- System.debug('浜у搧鏈堥攢閲弇sMap涓�'+msMap);
- System.debug('鏃х殑浜у搧List'+oproList);
-
- if(msMap.size() > 0){
- System.debug('浜у搧鏈堥攢閲弇sMap涓�'+msMap);
- for(Id res : oproList){
-
- //a鏃� 鏈堥攢閲忓拰 ; b鏂� 鏈堥攢閲忓拰 ; c鍟�(骞冲潎鏈堥攢閲�) ; x鍟嗗洓鑸嶄簲鍏� ;
- //y 搴撳瓨/骞冲潎鏈堥攢閲忓ぉ鏁� ; z 澶╂暟 鍥涜垗浜斿叆
- Decimal c = 0, y = 0;
- Integer x = 0, z = 0;
-
- if(msMap.get(res) != null){
- //鏈堥攢閲忓ぇ浜�12涓湀
- if(msMap.get(res).size() >= 12){
- Decimal a = 0 , b = 0;
- Integer i;
- for(i = 0 ; i < 12 ; i++){
- a += msMap.get(res)[i].MonthSales__c;
- }
- if(matMap.get(res) != null){
- if(msMap.get(matMap.get(res)) != null){
- if(msMap.get(matMap.get(res)).size() >= 12){
- for(i = 0 ; i < 12 ; i++){
- b += msMap.get(matMap.get(res))[i].MonthSales__c;
- System.debug('鏂扮殑澶т簬鍗佷簩'+b);
- }
- }
- else{
- for(ProductMonthlySales__c nms : msMap.get(matMap.get(res))){
- b+=nms.MonthSales__c;
- System.debug('鏂扮殑灏忎簬鍗佷簩閬嶅巻鍏ㄩ儴'+b);
- }
-
- }
- }
- }
-
- //鍥涜垗浜斿叆
- c = (a + b) / 12 ;
-
- if(c > 1){
- x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
- xMap.put(res,x);
- }else if(c > 0){
- x = 1;
- xMap.put(res,x);
- }
- //x = Integer.valueOf(c.round(System.RoundingMode.Up));
- //x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
-
- System.debug('鏂�'+b);
- System.debug('鏃�'+a);
- System.debug('闄ゆ硶瓒砪'+c);
- System.debug('鍥涜垗浜斿叆x'+x);
-
- }
- //鏈堥攢閲忎笉瓒�12涓湀
- else{
- Decimal a = 0 , b = 0 ;
- for(ProductMonthlySales__c oms : msMap.get(res)){
- a+=oms.MonthSales__c;
- }
- if(msMap.get(matMap.get(res)) != null){
- for(ProductMonthlySales__c nms : msMap.get(matMap.get(res))){
- b+=nms.MonthSales__c;
- }
- }
- c = (a + b) / msMap.get(res).size();
- //x = Integer.valueOf(c.round(System.RoundingMode.UP));
- //x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
- if(c > 1){
- x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
- xMap.put(res,x);
- }else if(c > 0){
- x = 1;
- xMap.put(res,x);
- }
-
- System.debug('闄ゆ硶涓嶈冻12c'+c);
- System.debug('鍥涜垗浜斿叆x'+x);
- }
-
- if(x != 0){
- for(ProductMonthlySales__c dat : msMap.get(res)){
- Decimal m = 0;
- if(dat.ProductM__r.StorageStatusNo__c != null){
- m = dat.ProductM__r.StorageStatusNo__c;
- }
- y = m / x;
- y = y * 30 ;
- }
- }
- //z = Integer.valueOf(y.round(System.RoundingMode.UP));
- z = Integer.valueOf(y.round(System.RoundingMode.HALF_UP));
- zMap.put(res,z);
- System.debug('澶╂暟y'+y);
- System.debug('鍥涜垗浜斿叆z'+z);
-
- }
- }
- }
-
- List<Product2> finList = new List<Product2>();
- for(Id fin : oproList){
- Product2 fip = new Product2();
- fip.Id = fin;
- fip.CalMonthSalesFLG__c = false;
-
- if(xMap.get(fin) != null){
- fip.Average_MonthSales__c = xMap.get(fin);
- }
-
- //20211020
- if(zMap.get(fin) != null){
- if(zMap.get(fin) != 0){
- fip.Estimated_ConsumptionDueDate__c = Date.today().addDays(zMap.get(fin));
- }else{
- if(adateMap != null){
- Date adate = adateMap.get(fin);
- fip.Estimated_ConsumptionDueDate__c = adate;
- }
- }
- }else{
- if(adateMap != null){
- Date adate = adateMap.get(fin);
- fip.Estimated_ConsumptionDueDate__c = adate;
- }
- }
- //20211020
-
- finList.add(fip);
- }
- update finList;
- }
-
- }
- //SFDC鍋滄棰勮 lt 20210914 add end
-
+ // WLIG-CKKA4M xxf 銆愬鎵樸�戙�愪骇鍝佷富鏁版嵁銆戞敞鍐岃瘉鏇存柊鍚庨儴鍒嗗瓧娈典俊鎭湭鑷姩浠e叆 Start
+ AutomaticallyBringData();
+ // WLIG-CKKA4M xxf 銆愬鎵樸�戙�愪骇鍝佷富鏁版嵁銆戞敞鍐岃瘉鏇存柊鍚庨儴鍒嗗瓧娈典俊鎭湭鑷姩浠e叆 End
+ }
+ protected override void beforeUpdate() {
+ beforeSetValue();
//SFDC鍋滄棰勮 lt 20211015 add start
- //ProductMonthlySalesFlag__c 12鏈堥攢閲忔爣璇� 棰勮鍋滄鏃ユ湡(M_BC_Stop_manufacure__c)鍙樺寲鏃�
- // private static void FlgStopManufacure(List<Product2> newList,Map<Id, Product2> oldMap){
- // if(newList != null){
- // for(Product2 pts : newList){
- // if(oldMap != null){
- // if(pts.M_BC_Stop_manufacure__c != null && oldMap.get(pts.Id).M_BC_Stop_manufacure__c == null){
- // pts.ProductMonthlySalesFlag__c = true;
- // }
- // if(pts.M_BC_Stop_manufacure__c != null && oldMap.get(pts.Id).M_BC_Stop_manufacure__c != null && pts.M_BC_Stop_manufacure__c != oldMap.get(pts.Id).M_BC_Stop_manufacure__c){
- // pts.ProductMonthlySalesFlag__c = true;
- // }
- // if(pts.M_BC_Stop_manufacure__c == null && oldMap.get(pts.Id).M_BC_Stop_manufacure__c != null){
- // pts.ProductMonthlySalesFlag__c = false;
- // pts.Estimated_ConsumptionDueDate__c = null;
- // }
- // }
- // }
- // }
-
- // }
+ // FlgStopManufacure(this.newList, this.oldMap);
//SFDC鍋滄棰勮 lt 20211015 add end
- private void FlgStopManufacure(){
- for(Product2 pts : newList){
+ FlgStopManufacure();
+ }
- Product2 oldPts = oldMap.get(pts.Id);
+ //SFDC鍋滄棰勮 lt 20210922 add start
+ protected override void afterUpdate() {
+ Calculate_AverageMonthSales(this.newList, this.oldMap);
+ AssignmentUltrasonic(this.newList, this.oldMap); //20230506 lt DB202304618804 鍖呭惈瓒呭0 add
+ }
+ //SFDC鍋滄棰勮 lt 20210922 add end
- if(pts.M_BC_Stop_manufacure__c != oldPts.M_BC_Stop_manufacure__c){
- pts.ProductMonthlySalesFlag__c = true;
- if (pts.M_BC_Stop_manufacure__c == null) {
- pts.ProductMonthlySalesFlag__c = false;
- pts.Estimated_ConsumptionDueDate__c = null;
- }
- }
+ // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 Start
+ private void SetCompetitorCode() {
+ Boolean SelctFlg = false;
+ list<AggregateResult> proList;
+ //甯﹂噺閲囪喘淇敼 start fy
+ list<AggregateResult> proListsc;
+ //甯﹂噺閲囪喘淇敼 end fy
+ String strPC = '';
+ //甯﹂噺閲囪喘淇敼 start fy
+ String strPCsc = '';
+ //甯﹂噺閲囪喘淇敼 end fy
+ Integer i = 1;
- if(pts.SFDA_Status__c == '鍋滄' && oldPts.SFDA_Status__c != '鍋滄'){
- pts.Estimated_ConsumptionDueDate__c = null;
- }
+ String ProductRecordTypes = System.Label.ProductRecordTypeID;
+ String[] RecordTypes = String.isNotBlank(ProductRecordTypes)
+ ? ProductRecordTypes.split(',')
+ : null;
+
+ for (Product2 nObj : newList) {
+ //甯﹂噺閲囪喘淇敼 start fy
+ String RecordTypeString = '';
+ if (nObj.RecordTypeId != null) {
+ RecordTypeString = String.valueof(nObj.RecordTypeId).substring(0, 15);
+ }
+ // nObj.Competitor_product_dummy__c=System.Label.ProductRecordTypeID.contains(RecordTypeString);
+ // if (nObj.Competitor_product_dummy__c) {
+ if (System.Label.ProductRecordTypeID.contains(RecordTypeString)) {
+ SelctFlg = true;
+ }
+ //甯﹂噺閲囪喘淇敼 end fy
+ }
+ if (SelctFlg) {
+ proList = [
+ SELECT Max(ProductCode) PC
+ FROM Product2
+ WHERE ProductCode LIKE 'SD%' AND ProductCode != 'SD999999'
+ ];
+ if (proList != null && proList.size() > 0) {
+ strPC = String.valueof(proList[0].get('PC'));
+ }
+ //甯﹂噺閲囪喘 start fy
+ // proListsc = [Select Max(ProductCode) PC From Product2 Where ProductCode Like 'SC%'];
+ // if (proListsc != null && proListsc.size() > 0) {
+ // strPCsc = String.valueof(proListsc[0].get('PC'));
+ // }
+ List<Product2> lastPro = [
+ SELECT Id, ProductCode
+ FROM Product2
+ WHERE ProductCode LIKE 'SC%'
+ ORDER BY ProductCode DESC
+ LIMIT 1
+ ];
+ strPCsc = lastPro != null &&
+ lastPro.size() > 0
+ ? lastPro[0].ProductCode
+ : '';
+ //甯﹂噺閲囪喘 end fy
+ }
+ for (Product2 nObj : newList) {
+ //甯﹂噺閲囪喘 start fy
+ String RecordTypeString = '';
+ if (nObj.RecordTypeId != null) {
+ RecordTypeString = String.valueof(nObj.RecordTypeId).substring(0, 15);
+ }
+ // if (nObj.Competitor_product_dummy__c && strPC.length() == 8
+ // if (System.Label.ProductRecordTypeID.contains(RecordTypeString) && strPC.length() == 8
+ if (System.Label.ProductRecordTypeID.contains(RecordTypeString)) {
+ //甯﹂噺閲囪喘 end fy
+ // && proList != null && proList.size() > 0 ) {
+ // Integer num = Integer.valueOf(strPC.SubString(2,strPC.length())) + i;
+ Integer num = String.isNotBlank(strPC)
+ ? Integer.valueOf(strPC.SubString(2, strPC.length())) + i
+ : i;
+ //甯﹂噺閲囪喘 start fy
+ Integer numsc = String.isNotBlank(strPCsc)
+ ? Integer.valueOf(strPCsc.SubString(2, strPCsc.length())) + i
+ : i;
+ // if(RecordTypeString=='0129D000001NacC'){
+ if (
+ RecordTypes != null &&
+ RecordTypes.size() > 1 &&
+ RecordTypeString == RecordTypes[1]
+ ) {
+ nObj.ProductCode = 'SC' + String.valueOf(numsc).leftpad(8, '0');
+ } else {
+ nObj.ProductCode = 'SD' + String.valueOf(num).leftpad(6, '0');
}
+ //甯﹂噺閲囪喘 end fy
+ // nObj.ProductCode = 'SD' + String.valueOf(num).leftpad(6,'0');
+ i++;
+ }
+ }
+ }
+ // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 End
+
+ //WLIG-CKKA4M xxf 銆愬鎵樸�戙�愪骇鍝佷富鏁版嵁銆戞敞鍐岃瘉鏇存柊鍚庨儴鍒嗗瓧娈典俊鎭湭鑷姩浠e叆 Start
+ private void AutomaticallyBringData() {
+ List<String> noNewList = new List<String>();
+ for (Product2 prd : newList) {
+ if (prd.Asset_Model_No__c != null) {
+ noNewList.add(prd.Asset_Model_No__c);
+ }
+ }
+ if (!noNewList.isEmpty()) {
+ List<Product2> prdList = [
+ SELECT
+ Id,
+ Name,
+ Asset_Model_No__c,
+ MDM_Name__c,
+ Maintenance_Price_Year__c,
+ Extend_new_product_gurantee_MD__c,
+ Extend_Gurantee_Start_MD__c,
+ Extend_Gurantee_End_MD__c,
+ Entend_gurantee_period_MD__c,
+ Extend_new_product_gurantee__c,
+ Extend_Gurantee_Start__c,
+ Extend_Gurantee_End__c,
+ Entend_gurantee_period__c,
+ CanNotCancelledGurantee__c,
+ Service_Category1__c,
+ Service_Category2__c,
+ Service_Category3__c,
+ Service_Category4__c,
+ Service_Category5__c,
+ Service_Category6__c,
+ Service_Category7__c,
+ Can_Repair__c,
+ RepairListPriceLevelA__c,
+ RepairListPriceLevelB__c,
+ RepairListPriceLevelC__c,
+ PartSupplyFinishDate__c,
+ EndSaleDate__c,
+ ProductClass__c,
+ ProductCategory__c,
+ Period_Filter_Classify1__c,
+ Period_Filter_Classify2__c,
+ Period_Filter_Classify3__c,
+ Intra_Trade_Service_RMB_Date1__c,
+ Intra_Trade_Service_RMB_Date2__c,
+ Intra_Trade_Service_RMB_EndDate1__c,
+ Intra_Trade_Service_RMB_EndDate2__c,
+ Intra_Trade_Service_RMB_1__c,
+ Intra_Trade_Service_RMB_2__c
+ FROM Product2
+ WHERE Asset_Model_No__c IN :noNewList
+ ORDER BY CreatedDate DESC
+ ];
+ if (prdList.isEmpty()) {
+ return;
+ }
+ Map<String, Product2> prdMap = new Map<String, Product2>();
+ for (Product2 pro2 : prdList) {
+ if (!prdMap.isEmpty() && prdMap.containskey(pro2.Asset_Model_No__c)) {
+ } else {
+ prdMap.put(pro2.Asset_Model_No__c, pro2);
+ }
+ }
+
+ for (Product2 prd : newList) {
+ if (prdMap.containskey(prd.Asset_Model_No__c)) {
+ prd.Maintenance_Price_Year__c = prdMap.get(prd.Asset_Model_No__c)
+ .Maintenance_Price_Year__c; //缁翠慨鍚堝悓鎶ヤ环
+ prd.CanNotCancelledGurantee__c = prdMap.get(prd.Asset_Model_No__c)
+ .CanNotCancelledGurantee__c; //涓嶅彲鍙栨秷澶氬勾淇濅慨
+ prd.ProductClass__c = prdMap.get(prd.Asset_Model_No__c)
+ .ProductClass__c; //甯傚満浜у搧绫诲埆
+ prd.ProductCategory__c = prdMap.get(prd.Asset_Model_No__c)
+ .ProductCategory__c; //甯傚満鍖哄垎
+ prd.Extend_new_product_gurantee_MD__c = prdMap.get(
+ prd.Asset_Model_No__c
+ )
+ .Extend_new_product_gurantee_MD__c; //甯傚満淇濅慨瀵硅薄
+ prd.Extend_new_product_gurantee__c = prdMap.get(prd.Asset_Model_No__c)
+ .Extend_new_product_gurantee__c; //鏈嶅姟淇濅慨瀵硅薄
+ if (
+ prdMap.get(prd.Asset_Model_No__c)
+ .Extend_new_product_gurantee_MD__c == true
+ ) {
+ //甯傚満淇濅慨瀵硅薄
+ prd.Entend_gurantee_period_MD__c = prdMap.get(prd.Asset_Model_No__c)
+ .Entend_gurantee_period_MD__c; //甯傚満淇濅慨鏈�(骞�)
+ }
+ if (
+ prdMap.get(prd.Asset_Model_No__c).Extend_new_product_gurantee__c ==
+ true
+ ) {
+ //鏈嶅姟淇濅慨瀵硅薄
+ prd.Entend_gurantee_period__c = prdMap.get(prd.Asset_Model_No__c)
+ .Entend_gurantee_period__c; //鏈嶅姟淇濅慨鏈�(骞�)
+ }
+ prd.Extend_Gurantee_Start_MD__c = prdMap.get(prd.Asset_Model_No__c)
+ .Extend_Gurantee_Start_MD__c; //甯傚満淇濅慨寮�濮嬫棩
+ prd.Extend_Gurantee_End_MD__c = prdMap.get(prd.Asset_Model_No__c)
+ .Extend_Gurantee_End_MD__c; //甯傚満淇濅慨缁撴潫鏃�
+ prd.Extend_Gurantee_Start__c = prdMap.get(prd.Asset_Model_No__c)
+ .Extend_Gurantee_Start__c; //鏈嶅姟淇濅慨寮�濮嬫棩
+ prd.Extend_Gurantee_End__c = prdMap.get(prd.Asset_Model_No__c)
+ .Extend_Gurantee_End__c; //鏈嶅姟淇濅慨缁撴潫鏃�
+ prd.Service_Category1__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category1__c; //绗�1鏈嶅姟鍒嗙被
+ prd.Service_Category2__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category2__c;
+ prd.Service_Category3__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category3__c;
+ prd.Service_Category4__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category4__c;
+ prd.Service_Category5__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category5__c;
+ prd.Service_Category6__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category6__c;
+ prd.Service_Category7__c = prdMap.get(prd.Asset_Model_No__c)
+ .Service_Category7__c;
+ prd.Can_Repair__c = prdMap.get(prd.Asset_Model_No__c).Can_Repair__c; //鏄惁鍙淮淇�
+ prd.RepairListPriceLevelA__c = prdMap.get(prd.Asset_Model_No__c)
+ .RepairListPriceLevelA__c; //A锛圵锛夌骇缁翠慨鍙傝�冧环鏍�
+ prd.RepairListPriceLevelB__c = prdMap.get(prd.Asset_Model_No__c)
+ .RepairListPriceLevelB__c;
+ prd.RepairListPriceLevelC__c = prdMap.get(prd.Asset_Model_No__c)
+ .RepairListPriceLevelC__c;
+ prd.PartSupplyFinishDate__c = prdMap.get(prd.Asset_Model_No__c)
+ .PartSupplyFinishDate__c; //闆朵欢鍋滄渚涘簲鏃ユ湡
+ prd.EndSaleDate__c = prdMap.get(prd.Asset_Model_No__c).EndSaleDate__c; //鍋滄閿�鍞棩鏈�
+ prd.Period_Filter_Classify1__c = prdMap.get(prd.Asset_Model_No__c)
+ .Period_Filter_Classify1__c; //钀ヤ笟缁熻鍒嗙被1
+ prd.Period_Filter_Classify2__c = prdMap.get(prd.Asset_Model_No__c)
+ .Period_Filter_Classify2__c; //钀ヤ笟缁熻鍒嗙被2
+ prd.Period_Filter_Classify3__c = prdMap.get(prd.Asset_Model_No__c)
+ .Period_Filter_Classify3__c; //钀ヤ笟缁熻鍒嗙被3
+ prd.Intra_Trade_Service_RMB_Date1__c = prdMap.get(
+ prd.Asset_Model_No__c
+ )
+ .Intra_Trade_Service_RMB_Date1__c; //澶氬勾淇濅环鏍兼湁鏁堝紑濮嬫棩1
+ prd.Intra_Trade_Service_RMB_Date2__c = prdMap.get(
+ prd.Asset_Model_No__c
+ )
+ .Intra_Trade_Service_RMB_Date2__c; //澶氬勾淇濅环鏍兼湁鏁堝紑濮嬫棩2
+ prd.Intra_Trade_Service_RMB_EndDate1__c = prdMap.get(
+ prd.Asset_Model_No__c
+ )
+ .Intra_Trade_Service_RMB_EndDate1__c; //澶氬勾淇濅环鏍兼湁鏁堢粨鏉熸棩1
+ prd.Intra_Trade_Service_RMB_EndDate2__c = prdMap.get(
+ prd.Asset_Model_No__c
+ )
+ .Intra_Trade_Service_RMB_EndDate2__c; //澶氬勾淇濅环鏍兼湁鏁堢粨鏉熸棩2
+ prd.Intra_Trade_Service_RMB_1__c = prdMap.get(prd.Asset_Model_No__c)
+ .Intra_Trade_Service_RMB_1__c; //澶氬勾淇濅环鏍�1
+ prd.Intra_Trade_Service_RMB_2__c = prdMap.get(prd.Asset_Model_No__c)
+ .Intra_Trade_Service_RMB_2__c; //澶氬勾淇濅环鏍�2
+ }
+ }
+ }
+ }
+ // WLIG-CKKA4M xxf 銆愬鎵樸�戙�愪骇鍝佷富鏁版嵁銆戞敞鍐岃瘉鏇存柊鍚庨儴鍒嗗瓧娈典俊鎭湭鑷姩浠e叆 end
+
+ private void beforeSetValue() {
+ for (Product2 nObj : newList) {
+ //CHAN-B8GCBB
+ if (nObj.WhiteSpace__c == true) {
+ nObj.StorageStatus__c = String.valueOf(nObj.StorageStatusNo__c);
+ } else {
+ nObj.StorageStatus__c = '';
+ }
+ //CHAN-B8GCBB
+
+ nObj.Fixture_Model_No_T__c = nObj.Fixture_Model_No_F__c;
+ // CBPR LHJ
+ if (
+ Trigger.isInsert ||
+ (Trigger.isUpdate &&
+ nObj.SFDA_Status_New__c != oldMap.get(nObj.id).SFDA_Status_New__c)
+ ) {
+ nObj.SFDA_Status__c = nobj.SFDA_Status_New__c;
+ if (
+ nobj.SFDA_Status_New__c == '鏂拌=鍝佺敵璜嬩腑' ||
+ nobj.SFDA_Status_New__c == '婧栧倷涓�'
+ ) {
+ nObj.SFDA_Status__c = '鍋滄';
+ }
+ }
+ // CBPR LHJ
+
+ // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 Start
+ if (Trigger.isInsert) {
+ }
+ // SWAG-BHE9GK LHJ 绔炰簤瀵规墜浜у搧鑷姩缂栫爜 End
+ }
+ }
+
+ //SFDC鍋滄棰勮 lt 20210914 add start
+ private static void Calculate_AverageMonthSales(
+ List<Product2> newList,
+ Map<Id, Product2> oldMap
+ ) {
+ //绗﹀悎鏉′欢鐨� 鏃� 浜у搧List
+ List<Id> oproList = new List<Id>();
+ //绗﹀悎鏉′欢鐨� 鏂版棫 浜у搧Id List 浣滀负鏉′欢
+ List<Id> conList = new List<Id>();
+ //Map<鏃х殑锛屾柊鐨�>瀵瑰簲
+ Map<String, String> matMap = new Map<String, String>();
+
+ //Map<鏃d锛岄璁″仠姝㈡棩>
+ Map<String, Date> adateMap = new Map<String, Date>();
+
+ //Map<鏃d, x(骞冲潎鏈堥攢閲�)>
+ Map<String, Integer> xMap = new Map<String, Integer>();
+ //Map<鏃d, z(澶╂暟)>
+ Map<String, Integer> zMap = new Map<String, Integer>();
+
+ for (Product2 term : newList) {
+ System.debug('鏍囪瘑' + term.CalMonthSalesFLG__c);
+ System.debug('鏂板簱瀛�' + term.StorageStatusNo__c);
+ System.debug('鏃у簱瀛�' + oldMap.get(term.Id).StorageStatusNo__c);
+ if (
+ term.M_BC_Stop_manufacure__c != null &&
+ term.SFDA_Status__c != '鍋滄' &&
+ (term.StorageStatusNo__c != oldMap.get(term.Id).StorageStatusNo__c ||
+ term.CalMonthSalesFLG__c == true)
+ ) {
+ if (term.Correspond_Code__c != null) {
+ matMap.put((String) term.Id, (String) term.Correspond_Code__c);
+ conList.add(term.Correspond_Code__c);
+ }
+ conList.add(term.Id);
+ oproList.add(term.Id);
+
+ adateMap.put(term.Id, term.M_BC_Stop_manufacure__c);
+ }
}
-}
\ No newline at end of file
+ //鍋� 涓�瀵瑰 鐨� Map<String,List<鏈堥攢閲�>>
+ Map<String, List<ProductMonthlySales__c>> msMap = new Map<String, List<ProductMonthlySales__c>>();
+
+ if (conList.size() > 0) {
+ List<ProductMonthlySales__c> msList = [
+ SELECT
+ Id,
+ MonthSales__c,
+ CurrentMonth__c,
+ CurrentDate__c,
+ CurrentYear__c,
+ ProductM__c,
+ Product2Model__c,
+ ProductM__r.StorageStatusNo__c,
+ ProductM__r.M_BC_Stop_manufacure__c
+ FROM ProductMonthlySales__c
+ WHERE ProductM__c IN :conList
+ ORDER BY CurrentDate__c DESC
+ ];
+ //鍙屽眰寰幆 浜у搧==>鏈堥攢閲�
+ for (Id pro : conList) {
+ for (ProductMonthlySales__c mms : msList) {
+ if (pro == mms.ProductM__c) {
+ if (msMap.containsKey(pro)) {
+ msMap.get(pro).add(mms);
+ } else {
+ List<ProductMonthlySales__c> pmsaleList = new List<ProductMonthlySales__c>();
+ pmsaleList.add(mms);
+ msMap.put(pro, pmsaleList);
+ }
+ }
+ }
+ }
+
+ System.debug('鏉′欢List' + conList);
+ System.debug('sql鏌ュ埌鐨凩ist' + msList);
+ System.debug('浜у搧鏈堥攢閲弇sMap涓�' + msMap);
+ System.debug('鏃х殑浜у搧List' + oproList);
+
+ if (msMap.size() > 0) {
+ System.debug('浜у搧鏈堥攢閲弇sMap涓�' + msMap);
+ for (Id res : oproList) {
+ //a鏃� 鏈堥攢閲忓拰 ; b鏂� 鏈堥攢閲忓拰 ; c鍟�(骞冲潎鏈堥攢閲�) ; x鍟嗗洓鑸嶄簲鍏� ;
+ //y 搴撳瓨/骞冲潎鏈堥攢閲忓ぉ鏁� ; z 澶╂暟 鍥涜垗浜斿叆
+ Decimal c = 0, y = 0;
+ Integer x = 0, z = 0;
+
+ if (msMap.get(res) != null) {
+ //鏈堥攢閲忓ぇ浜�12涓湀
+ if (msMap.get(res).size() >= 12) {
+ Decimal a = 0, b = 0;
+ Integer i;
+ for (i = 0; i < 12; i++) {
+ a += msMap.get(res)[i].MonthSales__c;
+ }
+ if (matMap.get(res) != null) {
+ if (msMap.get(matMap.get(res)) != null) {
+ if (msMap.get(matMap.get(res)).size() >= 12) {
+ for (i = 0; i < 12; i++) {
+ b += msMap.get(matMap.get(res))[i].MonthSales__c;
+ System.debug('鏂扮殑澶т簬鍗佷簩' + b);
+ }
+ } else {
+ for (
+ ProductMonthlySales__c nms : msMap.get(matMap.get(res))
+ ) {
+ b += nms.MonthSales__c;
+ System.debug('鏂扮殑灏忎簬鍗佷簩閬嶅巻鍏ㄩ儴' + b);
+ }
+ }
+ }
+ }
+
+ //鍥涜垗浜斿叆
+ c = (a + b) / 12;
+
+ if (c > 1) {
+ x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
+ xMap.put(res, x);
+ } else if (c > 0) {
+ x = 1;
+ xMap.put(res, x);
+ }
+ //x = Integer.valueOf(c.round(System.RoundingMode.Up));
+ //x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
+
+ System.debug('鏂�' + b);
+ System.debug('鏃�' + a);
+ System.debug('闄ゆ硶瓒砪' + c);
+ System.debug('鍥涜垗浜斿叆x' + x);
+ }
+ //鏈堥攢閲忎笉瓒�12涓湀
+ else {
+ Decimal a = 0, b = 0;
+ for (ProductMonthlySales__c oms : msMap.get(res)) {
+ a += oms.MonthSales__c;
+ }
+ if (msMap.get(matMap.get(res)) != null) {
+ for (ProductMonthlySales__c nms : msMap.get(matMap.get(res))) {
+ b += nms.MonthSales__c;
+ }
+ }
+ c = (a + b) / msMap.get(res).size();
+ //x = Integer.valueOf(c.round(System.RoundingMode.UP));
+ //x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
+ if (c > 1) {
+ x = Integer.valueOf(c.round(System.RoundingMode.HALF_UP));
+ xMap.put(res, x);
+ } else if (c > 0) {
+ x = 1;
+ xMap.put(res, x);
+ }
+
+ System.debug('闄ゆ硶涓嶈冻12c' + c);
+ System.debug('鍥涜垗浜斿叆x' + x);
+ }
+
+ if (x != 0) {
+ for (ProductMonthlySales__c dat : msMap.get(res)) {
+ Decimal m = 0;
+ if (dat.ProductM__r.StorageStatusNo__c != null) {
+ m = dat.ProductM__r.StorageStatusNo__c;
+ }
+ y = m / x;
+ y = y * 30;
+ }
+ }
+ //z = Integer.valueOf(y.round(System.RoundingMode.UP));
+ z = Integer.valueOf(y.round(System.RoundingMode.HALF_UP));
+ zMap.put(res, z);
+ System.debug('澶╂暟y' + y);
+ System.debug('鍥涜垗浜斿叆z' + z);
+ }
+ }
+ }
+
+ List<Product2> finList = new List<Product2>();
+ for (Id fin : oproList) {
+ Product2 fip = new Product2();
+ fip.Id = fin;
+ fip.CalMonthSalesFLG__c = false;
+
+ if (xMap.get(fin) != null) {
+ fip.Average_MonthSales__c = xMap.get(fin);
+ }
+
+ //20211020
+ if (zMap.get(fin) != null) {
+ if (zMap.get(fin) != 0) {
+ fip.Estimated_ConsumptionDueDate__c = Date.today()
+ .addDays(zMap.get(fin));
+ } else {
+ if (adateMap != null) {
+ Date adate = adateMap.get(fin);
+ fip.Estimated_ConsumptionDueDate__c = adate;
+ }
+ }
+ } else {
+ if (adateMap != null) {
+ Date adate = adateMap.get(fin);
+ fip.Estimated_ConsumptionDueDate__c = adate;
+ }
+ }
+ //20211020
+
+ finList.add(fip);
+ }
+ update finList;
+ }
+ }
+ //SFDC鍋滄棰勮 lt 20210914 add end
+
+ //SFDC鍋滄棰勮 lt 20211015 add start
+ //ProductMonthlySalesFlag__c 12鏈堥攢閲忔爣璇� 棰勮鍋滄鏃ユ湡(M_BC_Stop_manufacure__c)鍙樺寲鏃�
+ // private static void FlgStopManufacure(List<Product2> newList,Map<Id, Product2> oldMap){
+ // if(newList != null){
+ // for(Product2 pts : newList){
+ // if(oldMap != null){
+ // if(pts.M_BC_Stop_manufacure__c != null && oldMap.get(pts.Id).M_BC_Stop_manufacure__c == null){
+ // pts.ProductMonthlySalesFlag__c = true;
+ // }
+ // if(pts.M_BC_Stop_manufacure__c != null && oldMap.get(pts.Id).M_BC_Stop_manufacure__c != null && pts.M_BC_Stop_manufacure__c != oldMap.get(pts.Id).M_BC_Stop_manufacure__c){
+ // pts.ProductMonthlySalesFlag__c = true;
+ // }
+ // if(pts.M_BC_Stop_manufacure__c == null && oldMap.get(pts.Id).M_BC_Stop_manufacure__c != null){
+ // pts.ProductMonthlySalesFlag__c = false;
+ // pts.Estimated_ConsumptionDueDate__c = null;
+ // }
+ // }
+ // }
+ // }
+
+ // }
+ //SFDC鍋滄棰勮 lt 20211015 add end
+ private void FlgStopManufacure() {
+ for (Product2 pts : newList) {
+ Product2 oldPts = oldMap.get(pts.Id);
+
+ if (pts.M_BC_Stop_manufacure__c != oldPts.M_BC_Stop_manufacure__c) {
+ pts.ProductMonthlySalesFlag__c = true;
+ if (pts.M_BC_Stop_manufacure__c == null) {
+ pts.ProductMonthlySalesFlag__c = false;
+ pts.Estimated_ConsumptionDueDate__c = null;
+ }
+ }
+
+ if (pts.SFDA_Status__c == '鍋滄' && oldPts.SFDA_Status__c != '鍋滄') {
+ pts.Estimated_ConsumptionDueDate__c = null;
+ }
+ }
+ }
+
+ //20230506 lt DB202304618804 鍖呭惈瓒呭0 start
+ private static void AssignmentUltrasonic(
+ List<Product2> newList,
+ Map<Id, Product2> oldMap
+ ) {
+ List<String> proIdList = new List<String>();
+ List<PCLLostProduct__c> updateplpList = new List<PCLLostProduct__c>();
+
+ for (Product2 pro : newList) {
+ if (
+ pro.RecordTypeId == System.Label.Pro_RecordType &&
+ (pro.Lost_Product_Differ__c !=
+ oldMap.get(pro.Id).Lost_Product_Differ__c ||
+ pro.Lost_Product_Category__c !=
+ oldMap.get(pro.Id).Lost_Product_Category__c)
+ ) {
+ proIdList.add(pro.Id);
+ }
+ }
+
+ List<PCLLostProduct__c> plpList = [
+ SELECT Id, LostProduct__c, ProductClass__c, ProductCategory__c
+ FROM PCLLostProduct__c
+ WHERE LostProduct__c IN :proIdList
+ ];
+ if (plpList.size() > 0) {
+ for (PCLLostProduct__c plp : plpList) {
+ plp.ProductClass__c = '涓绘満';
+ plp.ProductCategory__c = '瓒呭0涓绘満';
+ updateplpList.add(plp);
+ }
+ }
+
+ update updateplpList;
+ }
+ //20230506 lt DB202304618804 鍖呭惈瓒呭0 end
+}
--
Gitblit v1.9.1