@ -1,10 +1,13 @@
using BBWY.Common.Http ;
using BBWY.Common.Http ;
using BBWY.Common.Models ;
using BBWY.Common.Models ;
using BBWY.Server.Model ;
using BBWY.Server.Model ;
using BBWY.Server.Model.Db ;
using BBWY.Server.Model.Db.Mds ;
using BBWY.Server.Model.Db.Mds ;
using FreeSql ;
using FreeSql ;
using Microsoft.Extensions.Options ;
using Microsoft.Extensions.Options ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.IO ;
namespace BBWY.Server.Business
namespace BBWY.Server.Business
{
{
@ -12,13 +15,15 @@ namespace BBWY.Server.Business
{
{
private FreeSqlMultiDBManager freeSqlMultiDBManager ;
private FreeSqlMultiDBManager freeSqlMultiDBManager ;
private VenderBusiness venderBusiness ;
private VenderBusiness venderBusiness ;
private IFreeSql fsql ;
public TestBusiness ( RestApiService restApiService ,
public TestBusiness ( RestApiService restApiService ,
IOptions < GlobalConfig > options ,
IOptions < GlobalConfig > options ,
FreeSqlMultiDBManager freeSqlMultiDBManager ,
FreeSqlMultiDBManager freeSqlMultiDBManager ,
VenderBusiness venderBusiness , YunDingBusiness yunDingBusiness ) : base ( restApiService , options , yunDingBusiness )
VenderBusiness venderBusiness , YunDingBusiness yunDingBusiness , IFreeSql fsql ) : base ( restApiService , options , yunDingBusiness )
{
{
this . freeSqlMultiDBManager = freeSqlMultiDBManager ;
this . freeSqlMultiDBManager = freeSqlMultiDBManager ;
this . venderBusiness = venderBusiness ;
this . venderBusiness = venderBusiness ;
this . fsql = fsql ;
}
}
public void SyncVenderId ( )
public void SyncVenderId ( )
@ -28,8 +33,8 @@ namespace BBWY.Server.Business
foreach ( var noVenderShop in noVenderShops )
foreach ( var noVenderShop in noVenderShops )
{
{
if ( string . IsNullOrEmpty ( noVenderShop . AppKey ) )
if ( string . IsNullOrEmpty ( noVenderShop . AppKey ) )
{
{
}
}
var venderResponse = venderBusiness . GetVenderInfo ( new Model . Dto . PlatformRequest ( )
var venderResponse = venderBusiness . GetVenderInfo ( new Model . Dto . PlatformRequest ( )
{
{
@ -42,5 +47,52 @@ namespace BBWY.Server.Business
freeSqlMultiDBManager . MDSfsql . Update < Shops > ( noVenderShop . Id ) . Set ( s = > s . VenderId , venderResponse . VenderId ) . ExecuteAffrows ( ) ;
freeSqlMultiDBManager . MDSfsql . Update < Shops > ( noVenderShop . Id ) . Set ( s = > s . VenderId , venderResponse . VenderId ) . ExecuteAffrows ( ) ;
}
}
}
}
public void StatisticsProduct ( )
{
var shopList = venderBusiness . GetShopList ( platform : Enums . Platform . 京 东 ) ;
var list = new List < string > ( ) ;
foreach ( var shop in shopList )
{
long shopId = long . Parse ( shop . ShopId ) ;
var productCount = fsql . Select < Product > ( ) . Where ( p = > p . ShopId = = shopId )
. Where ( p = > p . State = = 8 )
. Count ( ) ;
var productSkuCount = fsql . Select < ProductSku > ( ) . Where ( p = > p . ShopId = = shopId )
. Where ( p = > p . State = = 1 )
. Count ( ) ;
var jpspu_sql = $"select count(1) as Count,t.ShopId from (select max(osku1.Id) as oskuId,max(osku1.CreateTime) as maxTime,osku1.ProductId,o.ShopId from OrderSku osku1 inner join `Order` o on osku1.OrderId=o.Id where o.OrderState !=6 and o.IsGift=0 and o.StartTime>='2022-05-01' and o.ShopId='{shopId}' Group By osku1.ProductId,o.ShopId order by maxTime desc,osku1.ProductId desc,o.ShopId desc) as t inner join orderSku osku on t.oskuId=osku.Id inner join `order` o on osku.OrderId=o.Id inner join product p on t.ProductId = p.Id where o.StorageType=0 and p.state=8 group by t.ShopId" ;
//京配spu数
var jpspu = fsql . Ado . QuerySingle < JPCount > ( jpspu_sql ) ;
var jpsku_sql = $"select count(1) as Count,t.ShopId from (select max(osku1.Id) as oskuId,max(osku1.CreateTime) as maxTime,osku1.SkuId,o.ShopId from OrderSku osku1 inner join `Order` o on osku1.OrderId=o.Id where o.OrderState !=6 and o.IsGift=0 and o.StartTime>='2022-05-01' and o.ShopId='{shopId}' Group By osku1.SkuId,o.ShopId order by maxTime desc,osku1.SkuId desc,o.ShopId desc) as t inner join orderSku osku on t.oskuId=osku.Id inner join `order` o on osku.OrderId=o.Id inner join productsku psku on t.SkuId = psku.Id where o.StorageType=0 and psku.State=1 group by t.ShopId" ;
var jpsku = fsql . Ado . QuerySingle < JPCount > ( jpsku_sql ) ;
//list.Add($"{shop.ShopName},{productCount},{productSkuCount},{productSkuCount}/{productCount},{jpspu?.Count ?? 0},{jpsku?.Count ?? 0},{(productCount == 0 ? 0 : Math.Round(1.0 * jpspu?.Count ?? 0 / productCount * 100, 2))}%,{(productSkuCount == 0 ? 0 : Math.Round(1.0 * jpsku?.Count ?? 0 / productSkuCount * 100, 2))}%");
var jpspuCount = jpspu ? . Count ? ? 0 ;
var jpskuCount = jpsku ? . Count ? ? 0 ;
var jpspuPercent = productCount = = 0 ? 0 : Math . Round ( 1.0 * jpspuCount / productCount * 1 0 0 , 2 ) ;
var jpskuPercent = productSkuCount = = 0 ? 0 : Math . Round ( 1.0 * jpskuCount / productSkuCount * 1 0 0 , 2 ) ;
list . Add ( $"{shop.ShopName},{productCount},{productSkuCount},{productSkuCount}/{productCount},{jpspuCount},{jpskuCount},{jpspuPercent}%,{jpskuPercent}%" ) ;
}
list . Insert ( 0 , "店铺,SPU数,SKU数,SKU/SPU,京配SPU数,京配SKU数,京配SPU占比,京配SKU占比" ) ;
var filePath = Path . Combine ( AppContext . BaseDirectory , "result.csv" ) ;
File . WriteAllLines ( filePath , list , System . Text . Encoding . UTF8 ) ;
}
}
}
public class JPCount
{
public int Count { get ; set ; }
public long ShopId { get ; set ; }
}
}
}