Browse Source

更新经营默哀hi同步

liangku_skuoptimazation
shanji 1 year ago
parent
commit
ba381ca072
  1. 6
      BBWYB.PurchaserCapture/MainWindow.xaml
  2. 56
      BBWYB.PurchaserCapture/MainWindow.xaml.cs
  3. 12
      BBWYB.PurchaserCapture/Model/Db/Purchaser.cs
  4. 5
      BBWYB.Server.Model/Db/Purchaser/Purchaser.cs

6
BBWYB.PurchaserCapture/MainWindow.xaml

@ -10,8 +10,10 @@
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<TextBlock x:Name="txtInfo" Text="" Grid.Row="1" VerticalAlignment="Center" Margin="5,0,0,0" HorizontalAlignment="Left"/>
<Button x:Name="btn_start" Grid.Row="1" Width="80" Content="开始" Height="25" Click="btn_start_Click"/>
<TextBox x:Name="txt_url" Grid.Row="1" Height="30" Margin="5,0" VerticalContentAlignment="Center"/>
<TextBlock x:Name="txtInfo" Text="" Grid.Row="2" VerticalAlignment="Center" Margin="5,0,0,0" HorizontalAlignment="Left"/>
<Button x:Name="btn_start" Grid.Row="2" Width="80" Content="开始" Height="25" Click="btn_start_Click"/>
</Grid>
</Window>

56
BBWYB.PurchaserCapture/MainWindow.xaml.cs

@ -3,6 +3,8 @@ using BBWYB.Server.Model.Db;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using System.IO;
using System.Reflection.Metadata;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using io = System.IO;
@ -16,6 +18,8 @@ namespace BBWYB.PurchaserCapture
{
private IFreeSql fsql;
private WebView2 wb2;
private string purchaserId;
private string purchaserMemberId;
public MainWindow()
{
@ -35,6 +39,16 @@ namespace BBWYB.PurchaserCapture
wb2.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
wb2.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceived;
wb2.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
wb2.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted;
}
private void CoreWebView2_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
{
var scriptBuilder = new StringBuilder();
scriptBuilder.AppendLine("var divElement = document.querySelector('div[style=\"position: relative; display: flex; flex-direction: row;\"]');");
scriptBuilder.AppendLine("var mouseeoverEvent = new MouseEvent('mouseover', {'view': window,'bubbles': true,'cancelable': false});");
scriptBuilder.AppendLine("divElement.dispatchEvent(mouseeoverEvent);");
wb2.CoreWebView2.ExecuteScriptAsync(scriptBuilder.ToString());
}
private async void CoreWebView2_WebResourceResponseReceived(object? sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
@ -55,7 +69,7 @@ namespace BBWYB.PurchaserCapture
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
sr.Dispose();
var match = Regex.Match(content, "\"bizTypeName\":\\s?\"(.+)\",");
var match = Regex.Match(content, "\"bizTypeName\":\\s?\"(.*)\",\"isShili");
if (!match.Success)
{
Console.WriteLine($"bizTypeName解析失败,已忽略 {e.Request.Uri}");
@ -63,12 +77,25 @@ namespace BBWYB.PurchaserCapture
}
var bizTypeName = match.Groups[1].Value;
Console.WriteLine(bizTypeName);
if (!string.IsNullOrEmpty(purchaserId))
{
if (!string.IsNullOrEmpty(purchaserMemberId))
{
if (!content.Contains(purchaserMemberId))
{
Console.WriteLine($"memberId验证失败,已忽略 {e.Request.Uri}");
return;
}
}
Console.WriteLine($"更新采购商{purchaserId}");
fsql.Update<Purchaser>(purchaserId).Set(p => p.ManagmentModeText, bizTypeName).ExecuteAffrows();
}
}
private void CoreWebView2_WebResourceRequested(object? sender, CoreWebView2WebResourceRequestedEventArgs e)
{
}
private void Wb2_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
@ -83,7 +110,11 @@ namespace BBWYB.PurchaserCapture
private void Navigate(string url)
{
this.Dispatcher.Invoke(() => wb2.CoreWebView2.Navigate(url));
this.Dispatcher.Invoke(() =>
{
txt_url.Text = url;
wb2.CoreWebView2.Navigate(url);
});
}
private void btn_start_Click(object sender, RoutedEventArgs e)
@ -94,21 +125,28 @@ namespace BBWYB.PurchaserCapture
//var sk = "consign";
var pspList = fsql.Select<PurchaseSchemeProduct, Purchaser>()
.InnerJoin((psp2, p) => psp2.PurchaserId == p.Id)
.Where((psp2, p) => string.IsNullOrEmpty(p.ManagmentMode))
.GroupBy((psp2, p) => psp2.PurchaserId)
.WithTempQuery(g => new { MaxId = g.Max(g.Value.Item1.Id), PurchaserId = g.Key })
.Where((psp2, p) => string.IsNullOrEmpty(p.ManagmentModeText))
.GroupBy((psp2, p) => new { p.Id, p.MemberId })
.WithTempQuery(g => new { MaxId = g.Max(g.Value.Item1.Id), PurchaserId = g.Key.Id, MemberId = g.Key.MemberId })
.From<PurchaseSchemeProduct>()
.InnerJoin((psp2, psp1) => psp2.MaxId == psp1.Id)
.OrderByDescending((psp2, psp1) => psp1.Id)
.ToList((psp2, psp1) => psp1);
.ToList((psp2, psp1) => new
{
psp1.PurchaserId,
psp2.MemberId,
psp1.PurchaseProductId
});
for (var i = 0; i < pspList.Count; i++)
{
SetInfo($"{i + 1}/{pspList.Count}");
purchaserId = pspList[i].PurchaserId;
purchaserMemberId = pspList[i].MemberId;
var url = $"https://detail.1688.com/offer/{pspList[i].PurchaseProductId}.html?clickid={Guid.NewGuid().ToString().Md5Encrypt()}&sessionid={Guid.NewGuid().ToString().Md5Encrypt()}&sk={sk}";
Navigate(url);
Thread.Sleep(60000);
Thread.Sleep(10000);
}
});
}

12
BBWYB.PurchaserCapture/Model/Db/Purchaser.cs

@ -28,11 +28,17 @@ namespace BBWYB.Server.Model.Db
[Column(StringLength = 50)]
public string Location { get; set; }
/// <summary>
/// 经营模式
/// 经营模式 0贸易 1厂家
/// </summary>
[Column(StringLength = 50)]
public string ManagmentMode { get; set; }
[Column(DbType = "int", MapType = typeof(int))]
public Enums.ManagmentMode? ManagmentMode { get; set; }
/// <summary>
/// 经营模式(文本)
/// </summary>
public string ManagmentModeText { get; set; }
[Column(StringLength = 50)]
public string MemberId { get; set; }

5
BBWYB.Server.Model/Db/Purchaser/Purchaser.cs

@ -34,6 +34,11 @@ namespace BBWYB.Server.Model.Db
[Column(DbType = "int", MapType = typeof(int))]
public Enums.ManagmentMode? ManagmentMode { get; set; }
/// <summary>
/// 经营模式(文本)
/// </summary>
public string ManagmentModeText { get; set; }
[Column(StringLength = 50)]
public string MemberId { get; set; }

Loading…
Cancel
Save