DROP PROCEDURE IF EXISTS `GetPRODUCTCHECKPRICEfromVEI`; CREATE PROCEDURE GetPRODUCTCHECKPRICEfromVEI(IN paramEnterCode varchar(30),out paramSyncNo VARCHAR(50),in paramSyncAmount int) BEGIN

 DECLARE psyncTime date;-- PricingCategory.id  DECLARE plastupdatetime date;

set @BranchId=1;set @BranchCode='1000001';set @BranchName='好快省'; set @BranchidParam=1; select syncTime as syncTime from ScheduleLog where webservicename = 'GetPRODUCTCHECKPRICEfromVEI' and srcsysname = 'VEIHMS' and srcwebservicename = 'GetPRODUCTCHECKPRICE' and tagbillname = 'sparepart' into psyncTime; insert into enterprisepartscost_u(suppliercode,suppliername,productcode,checkprice,partstype) SELECT  a.supplieid as suppliernumber,b.name as suppliername,a.materialcode as itemcode,a.price as itemprice, 2 as partstype  FROM `hks-tj_test`. epc_suppliers_goods a inner join `hks-tj_test`.epc_suppliers b on a.supplieid=b.supplieid AND b.stype=48 AND b.supplieid != 100000 and b.supplieid<>100018 and b.branchcode='1000002' left join enterprisepartscost c on a.supplieid = c.SupplierCode and a.materialcode = c.ProductCode and a.price = c.CheckPrice where c.ProductCode is null  AND A.lastupdatetime >=psyncTime order by A.lastupdatetime  limit 500;

insert into enterprisepartscost(suppliercode,suppliername,productcode,productname,checkprice,partstype) SELECT  a.supplieid as suppliernumber,b.name as suppliername,a.materialcode as itemcode,d.productname ,a.price as itemprice, 2 as partstype  FROM `hks-tj_test`.epc_suppliers_goods a inner join `hks-tj_test`.epc_suppliers b on a.supplieid=b.supplieid AND b.stype=48 AND b.supplieid != 100000 and b.supplieid<>100018 and b.branchcode='1000003' left join enterprisepartscost c on a.supplieid = c.SupplierCode and a.materialcode = c.ProductCode and a.price = c.CheckPrice left join sparepart d on d.productcode = a.materialcode where c.ProductCode is null  AND A.lastupdatetime >=psyncTime order by A.lastupdatetime  limit 500;

SELECT  MAX( a.lastupdatetime)  FROM `hks-tj_test`. epc_suppliers_goods a inner join `hks-tj_test`.epc_suppliers b on a.supplieid=b.supplieid AND b.stype=48 AND b.supplieid != 100000 and b.supplieid<>100018 and b.branchcode='1000004' left join enterprisepartscost c on a.supplieid = c.SupplierCode and a.materialcode = c.ProductCode and a.price = c.CheckPrice where c.ProductCode is null  AND A.lastupdatetime >=psyncTime order by A.lastupdatetime  limit 1 into plastupdatetime; if(plastupdatetime is not null ) then update ScheduleLog set syncTime=plastupdatetime where webservicename = 'GetPRODUCTCHECKPRICEfromVEI' ; end if;   CREATE TEMPORARY TABLE IF NOT EXISTS  saleprice_tmp(                  PartsCode VARCHAR(36),          Code VARCHAR(50),          CheckPrice DECIMAL(11,4),          PartsType int(2),          SupplierCode VARCHAR(50),          suppliername VARCHAR(50)      ) ENGINE = MEMORY; -- 需要更新的动态备件表1      TRUNCATE TABLE saleprice_tmp;

  CREATE TEMPORARY TABLE IF NOT EXISTS  provincesaleprice_tmp(                  PartsCode VARCHAR(36),          Code VARCHAR(50),          CheckPrice DECIMAL(11,4),          PartsType int(2),          SupplierCode VARCHAR(50),          suppliername VARCHAR(50)      ) ENGINE = MEMORY; -- 需要更新的动态备件表2      TRUNCATE TABLE provincesaleprice_tmp;  CREATE TEMPORARY TABLE IF NOT EXISTS  pricecategory_tmp(          PartsCode VARCHAR(36),          Code VARCHAR(50),          corpCode VARCHAR(50),          corpName VARCHAR(50),          SalePriceColumn VARCHAR(50),          PriceCategoryColumn VARCHAR(50),          PriceMethods int(9),          SalePrice DECIMAL(11,4),          CheckPrice DECIMAL(11,4),          `PRECISION` int(9),          Retentionway int(9),          SupplierCode VARCHAR(50),          suppliername VARCHAR(50),          PartsType int(2)      ) ENGINE = MEMORY; -- 需要更新的动态备件表3      TRUNCATE TABLE saleprice_tmp;

insert into saleprice_tmp select a.ProductCode as partscode,case when pcg1.`Code` is not null then pcg1.`Code`  when pcg2.code is not null then pcg2.code when pcgfz1.code is not null then pcgfz1.code else null END  as Code, epp.CheckPrice,epp.PartsType,epp.SupplierCode,epp.suppliername from sparepart a inner join customertype ct on 1=1 inner join enterprisepartscost_u epp on epp.ProductCode = a.ProductCode and epp.partstype = 2 inner join partsgroup fz1 on a.GroupCode = fz1.GroupCode and fz1.Category = 1  /*最下一层的分组*/ inner join partsgroup pp on a.SpareBrandCode = pp.GroupCode and pp.ParentCode=fz1.`Code` and pp.Category= 2 /*品牌层*/ /*配件定价原则*/ left join pricingcategory pcg1 on pcg1.GroupCode = a.ProductCode and pcg1.`Status` = 2 and pcg1.PricingCategoryID =1 and pcg1.corpcode = '1000' and pcg1.grouptype =3 and pcg1.CustomerTypeId = ct.Id /*配件品牌定价原则*/ left join pricingcategory pcg2 on pcg2.GroupCode = pp.`Code` and pcg2.`Status` = 2 and pcg2.PricingCategoryID =1 and pcg2.corpcode = '1000' and pcg2.grouptype =2 and pcg2.CustomerTypeId = ct.Id  /*配件分组定价原则*/ left join pricingcategory pcgfz1 on pcgfz1.GroupCode =fz1.`Code` and pcgfz1.`Status` = 2 and pcgfz1.PricingCategoryID =1 and pcgfz1.corpcode = '1000' and pcgfz1.grouptype =1 and pcgfz1.CustomerTypeId = ct.Id

where pcg1.code is not null or pcg2.code is not null or pcgfz1.code is not null;

insert into pricecategory_tmp select distinct tmp.partscode as partscode, pcg.`Code` as code, pcg.CorpCode as corpcode, pcg.CorpName as CorpName, (select PartsSalePrice from salepricefieldmap where TypeCode = ct.TypeCode) as SalePriceColumn, (select PriceCategoryCode from salepricefieldmap where TypeCode = ct.TypeCode) as PriceCategoryColumn, pcg.PriceMethods, case pcg.PriceMethods when 1 then tmp.CheckPrice*(1+pcg.SalePrice/100) when 2 then pcg.SalePrice when 3 then tmp.CheckPrice+pcg.SalePrice  END  as SalePrice,  tmp.CheckPrice, pcg.`Precision`, pcg.Retentionway, tmp.SupplierCode, tmp.SupplierName,tmp.PartsType from pricecategory_tmp tmp inner join pricingcategory pcg on pcg.`Code` = tmp.`Code` inner join customertype ct on ct.id = pcg.customertypeid;

update pricecategory_tmp  categorytmp set categorytmp.SalePrice= (case categorytmp.Retentionway when 1 then  ROUND( CEILING(SalePrice),(`PRECISION`-1)) when 2 then  ROUND( FLOOR(SalePrice),(`PRECISION`-1)) when 3 then  ROUND( SalePrice,(`PRECISION`-1))  when 4 then  ROUND((CEILING(SalePrice/5))*5,(`PRECISION`-1)) end);

SET @SalePricesql=CONCAT('update PartsSalePrice price join pricecategory_tmp categorytmp on price.productcode= pricecategory_tmp.PartsCode and price.suppliercode=categorytmp.suppliercode  and  categorytmp.branchcode =?                           set price.CheckPrice=cost.CheckPrice,price.ModifyTime=now(), price.',categorytmp.SalePriceColumn,'=',categorytmp.SalePrice,',' ,categorytmp.PriceCategoryColumn,'=  ', categorytmp.Code);          PREPARE stmp FROM @SalePricesql;          EXECUTE stmp  using @BranchCode;     SET @SalePriceInsertsql= CONCAT('insert into PartsSalePrice(productid,productcode,productname,suppliercode,suppliername,checkprice,modifytime,branchid,branchcode,branchname,',categorytmp.SalePriceColumn,',',categorytmp.PriceCategoryColumn,')          select part.ProductId,part.ProductCode,cost.ProductName,cost.SupplierCode,cost.SupplierName,cost.CheckPrice,now(),?,?,?,',categorytmp.SalePrice,',',categorytmp.Code ,' from  pricecategory_tmp categorytmp           LEFT join  PartsSalePrice  price on categorytmp.ProductCode =price.productcode  and  categorytmp.SupplierCode =price.SupplierCode  and price.branchid=?           where price.productcode is null;');     PREPARE stmpin FROM @SalePriceInsertsql;     EXECUTE stmpin USING @BranchId,@BranchCode,@BranchName,  @BranchidParam;

insert into provincesaleprice_tmp select a.ProductCode as partscode, case  when pcg1.isforced = 1 then pcg1.code when pcg2.isforced =1 then pcg2.code when pcgfz1.isforced = 1 then pcgfz1.code else case when pcg1.`Code` is not null then pcg1.`Code` when pcg2.code is not null then pcg2.code when pcgfz1.code is not null then pcgfz1.code else null end  END  as Code, epp.CheckPrice,epp.PartsType,epp.SupplierCode,epp.SupplierName from sparepart a inner join customertype ct on 1=1 inner join vcompany vc on 1=1 and vc.id>1 and vc.status = 3 inner join enterprisepartscost_u epp on epp.ProductCode = a.ProductCode /*如果有重复数据会取到多条*/ inner join partsgroup fz1 on a.GroupCode = fz1.GroupCode and fz1.Category = 1  /*最下一层的分组*/ inner join partsgroup pp on a.SpareBrandCode = pp.GroupCode and pp.ParentCode=fz1.`Code` and pp.Category= 2  /*品牌层*/ /*配件定价原则*/ left join ProvincePricingCategory pcg1 on pcg1.GroupCode = a.ProductCode and pcg1.`Status` = 2 and pcg1.PricingCategoryID =1  and pcg1.grouptype =3 and pcg1.CorpCode=vc.`Code` and pcg1.CustomerTypeId = ct.Id /*配件品牌定价原则*/ left join ProvincePricingCategory pcg2 on pcg2.GroupCode = pp.`Code` and pcg2.`Status` = 2 and pcg2.PricingCategoryID =1 and pcg2.grouptype =2  and pcg2.CorpCode=vc.`Code` and pcg2.CustomerTypeId = ct.Id /*配件分组定价原则*/ left join ProvincePricingCategory pcgfz1 on pcgfz1.GroupCode =fz1.`Code` and pcgfz1.`Status` = 2 and pcgfz1.PricingCategoryID =1  and pcgfz1.grouptype =1  and pcgfz1.CorpCode=vc.`Code` and pcgfz1.CustomerTypeId = ct.Id where pcg1.code is not null or pcg2.code is not null or pcgfz1.code is not null;

-- update provincesaleprice_tmp   categorytmp set SalePrice= -- (case categorytmp.Retentionway when 1 then  ROUND( CEILING(SalePrice),(`PRECISION`-1)) when 2 then  ROUND( FLOOR(SalePrice),(`PRECISION`-1)) when 3 then  ROUND( SalePrice,(`PRECISION`-1))  when 4 then  ROUND(((CEILING(SalePrice/5))*5,(`PRECISION`-1))  );

select distinct tmp.partscode as partscode, pcg.`Code` as code, pcg.CorpCode as corpcode, pcg.CorpName as CorpName, (select PartsSalePrice from salepricefieldmap where TypeCode = ct.TypeCode) as SalePriceColumn, (select PriceCategoryCode from salepricefieldmap where TypeCode = ct.TypeCode) as PriceCategoryCodeColumn, pcg.PriceMethods, case pcg.IsForced when 0 then case  pcg.modifypriceway when 1 then case pricemethods  when 1 then tmp.CheckPrice*(1+(pcg.SalePrice+pcg.provincesaleprice)/100) when 2 then pcg.SalePrice+pcg.ProvinceSalePrice when 3 then

tmp.CheckPrice+pcg.SalePrice+pcg.ProvinceSalePrice end when 2 then case pricemethods when 1 then tmp.CheckPrice*(1+(pcg.SalePrice-pcg.provincesaleprice)/100) when 2 then pcg.SalePrice-pcg.ProvinceSalePrice when 3 then

tmp.CheckPrice+pcg.SalePrice-pcg.ProvinceSalePrice end when 3 then case pricemethods when 1 then tmp.CheckPrice*(1+pcg.provincesaleprice/100) when 2 then pcg.ProvinceSalePrice when 3 then tmp.CheckPrice

+pcg.ProvinceSalePrice end when 4 then pcg.ProvinceSalePrice end when 1 then case pcg.PriceMethods when 1 then tmp.CheckPrice*(1+pcg.SalePrice/100) when 2 then pcg.SalePrice when 3 then (tmp.CheckPrice+pcg.SalePrice) end end as SalePrice, pcg.thresholdvalue as Xvalue, case  pcg.modifypriceway when 1 then case pricemethods when 1 then ((pcg.SalePrice+pcg.provincesaleprice)/100) when 2 then 0 when 3 then pcg.SalePrice+pcg.ProvinceSalePrice end when 2 then case pricemethods when 1 then ((pcg.SalePrice-pcg.provincesaleprice)/100) when 2 then 0 when 3 then pcg.SalePrice-pcg.ProvinceSalePrice end when 3 then case pricemethods when 1 then (pcg.provincesaleprice)/100 when 2 then 0 when 3 then pcg.ProvinceSalePrice end when 4 then 0 end  as Mvalue, pcg.`Precision`, pcg.Retentionway,tmp.SupplierCode,tmp.SupplierName,tmp.PartsType,tmp.CheckPrice from provincesaleprice_tmp  tmp inner join ProvincePricingCategory pcg on pcg.`Code` = tmp.`Code` inner join customertype ct on ct.id = pcg.customertypeid

 

SET @SalePricesql1=CONCAT('update jgzx.',CompanyName,' price join enterprisepartscost cost on cost.productcode= price.productcode and cost.suppliercode=price.suppliercode              set  price.CheckPrice=cost.CheckPrice,price.modifytime=now(), price.',MapSalePrice,'=',NotSalePriceFormat,',' ,MapCategoryCode,'= ? ',' where price.branchid=? and price.productcode =cost.productcode and price.productcode= ? ;');             PREPARE stmp FROM @SalePricesql1;              EXECUTE stmp USING  @pricecode,@BranchidParam,@pricegroupcode;

             SET @SalePriceInsertsql2= CONCAT('insert into jgzx.',CompanyName,'(productid,productcode,productname,suppliercode,suppliername,checkprice,modifytime,branchid,branchcode,branchname,',MapSalePrice,',',MapCategoryCode,')            select part.ProductId,part.ProductCode,cost.ProductName,cost.SupplierCode,cost.SupplierName,cost.CheckPrice,now(),?,?,?,',NotSalePriceFormat,',',' ? from  sparepart part              join  enterprisepartscost cost on  part.Productcode=cost.Productcode              LEFT join  jgzx.',CompanyName,'  price on part.ProductCode =price.productcode  and  cost.SupplierCode =price.SupplierCode  and price.branchid=?              where  part.productcode= ? and price.productcode is null ;');                 PREPARE stmpin FROM @SalePriceInsertsql2;       EXECUTE stmpin USING  @BranchId,@BranchCode,@BranchName,@pricecode,@BranchidParam,@pricegroupcode;

 

END

select * from schedulelog

call GetPRODUCTCHECKPRICEfromVEI('123',@nn,0) select * from enterprisepartscost select * from enterprisecost_u

select * from pricingcategory  LIMIT 1

select retentionway ,case retentionway when 1 then CEILING(X)    when 2 then CEILING(X)  end as price from pricingcategory  LIMIT 1

 

posted on 2016-06-13 18:38  梁娜  阅读(164)  评论(0编辑  收藏  举报