修改云端数据 代码改为异步,导入成功提示
This commit is contained in:
1 parent
de9cd4ae65
commit
4fdcc94a91
5 files changed
+176
-70
No files matched your search
+83
-7
@@ -1250,13 +1250,89 @@ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
public static async Task<string> PostUtf8Async(string url, string postData, string contentType = "", int? timeOut = null)
|
||||||
/// post 数据
|
{
|
||||||
/// </summary>
|
|
||||||
/// <param name="url"></param>
|
bool isError = false;
|
||||||
/// <param name="byteData"></param>
|
string[] l = UserAgent.Split('\n');
|
||||||
/// <returns></returns>
|
reTry:
|
||||||
public static string PostUtf8(string url, byte[] byteData)
|
try
|
||||||
|
{
|
||||||
|
string codeType = "utf-8";
|
||||||
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
|
request.UserAgent = l[new Random(Guid.NewGuid().GetHashCode()).Next(l.Length)].Trim();
|
||||||
|
byte[] byteData = Encoding.GetEncoding(codeType).GetBytes(postData);
|
||||||
|
request.Method = "POST";
|
||||||
|
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
||||||
|
request.Timeout = BaseClass.TimeOut * 1000;
|
||||||
|
request.ReadWriteTimeout = BaseClass.TimeOut * 1000;
|
||||||
|
if (timeOut != null)
|
||||||
|
{
|
||||||
|
request.Timeout = timeOut.Value * 1000;
|
||||||
|
request.ReadWriteTimeout = timeOut.Value * 1000;
|
||||||
|
}
|
||||||
|
request.Proxy = null;
|
||||||
|
request.ContentType = "application/x-www-form-urlencoded; charset=" + codeType;
|
||||||
|
//if(BaseClass.SaLevel > 0)
|
||||||
|
{
|
||||||
|
//260306 采用GZip/deflate压缩
|
||||||
|
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd");
|
||||||
|
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||||
|
}
|
||||||
|
if (url.StartsWith("https://openapi.jinritemai.com/"))
|
||||||
|
{
|
||||||
|
request.Headers.Add("X-USE-BOE", "1");
|
||||||
|
request.Headers.Add("Origin-From", "djt_prod");
|
||||||
|
request.Headers.Add("djt_prod", "boe_time_sku");
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(contentType))
|
||||||
|
{
|
||||||
|
request.ContentType = contentType;
|
||||||
|
}
|
||||||
|
request.ContentLength = byteData.Length;
|
||||||
|
request.Referer = url;
|
||||||
|
request.CookieContainer = new CookieContainer();
|
||||||
|
request.AllowAutoRedirect = false;
|
||||||
|
using (Stream requestStream = await request.GetRequestStreamAsync())
|
||||||
|
{
|
||||||
|
requestStream.Write(byteData, 0, byteData.Length);
|
||||||
|
}
|
||||||
|
HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync();
|
||||||
|
|
||||||
|
Stream receiveStream = response.GetResponseStream();
|
||||||
|
StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding(codeType));
|
||||||
|
|
||||||
|
//if (BaseClass.SaLevel == 0)
|
||||||
|
//{
|
||||||
|
// return readStream.ReadToEnd().Trim();
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
{
|
||||||
|
//260306 超管采用GZip/deflate压缩
|
||||||
|
//Thread.Sleep(50);
|
||||||
|
return GetProxyHtml.ReadResponse(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LogSave.Add(e.ToString());
|
||||||
|
//if (!isError)
|
||||||
|
//{
|
||||||
|
// isError = true;
|
||||||
|
// goto reTry;
|
||||||
|
//}
|
||||||
|
Thread.Sleep(50);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// post 数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <param name="byteData"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string PostUtf8(string url, byte[] byteData)
|
||||||
{
|
{
|
||||||
WebClientx webClient = new WebClientx();
|
WebClientx webClient = new WebClientx();
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -49,13 +49,21 @@ namespace TemuKJD.PDDForms.ProductSelectForms
|
|||||||
ucSplitPage1.PageChange += UcSplitPage1_PageChange;
|
ucSplitPage1.PageChange += UcSplitPage1_PageChange;
|
||||||
InitCategory();
|
InitCategory();
|
||||||
InitBindingDataGridView();
|
InitBindingDataGridView();
|
||||||
txt_title.Text = "连衣裙";
|
|
||||||
|
|
||||||
num_minsold.Value = 0;
|
num_minsold.Value = 0;
|
||||||
num_maxsold.Value = 999;
|
num_maxsold.Value = 999;
|
||||||
num_minprice.Value = 0;
|
num_minprice.Value = 0;
|
||||||
num_maxprice.Value = 999;
|
num_maxprice.Value = 999;
|
||||||
|
|
||||||
cb_Platform.SelectedIndex = 0;
|
cb_Platform.SelectedIndex = 0;
|
||||||
ucSplitPage1.TotalCount = 0;
|
ucSplitPage1.TotalCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (EnvironmentHelper.IsDevelopment)
|
||||||
|
{
|
||||||
|
txt_title.Text = "连衣裙";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -301,33 +309,48 @@ namespace TemuKJD.PDDForms.ProductSelectForms
|
|||||||
{
|
{
|
||||||
btnSearch_Click(obj, null);
|
btnSearch_Click(obj, null);
|
||||||
}
|
}
|
||||||
private void btnSearch_Click(object sender, EventArgs e)
|
private async void btnSearch_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
GoodsSearchRequest search = new GoodsSearchRequest();
|
try
|
||||||
|
|
||||||
search.Platform = cb_Platform.SelectedIndex == 1 ? PlatformType.PDD : cb_Platform.SelectedIndex == 2 ? PlatformType.WX : PlatformType.None;
|
|
||||||
search.Title = txt_title.Text;
|
|
||||||
search.MinSoldQuantity = (int)num_minsold.Value;
|
|
||||||
search.MaxSoldQuantity = (int)num_maxsold.Value;
|
|
||||||
search.MinPrice = (long)num_minprice.Value * 100;
|
|
||||||
search.MaxPrice = (long)num_maxprice.Value * 100;
|
|
||||||
if (cmbCatSelect1.SelectedItem is PddCatInfo cat1)
|
|
||||||
{
|
{
|
||||||
search.CatId1 = (int)(cat1.cat_id);
|
this.pbLoading.Visible = true;
|
||||||
search.CatId1 = search.CatId1 == 0 ? null : search.CatId1;
|
btnSearch.Enabled = false;
|
||||||
|
|
||||||
|
GoodsSearchRequest search = new GoodsSearchRequest();
|
||||||
|
|
||||||
|
search.Platform = cb_Platform.SelectedIndex == 1 ? PlatformType.PDD : cb_Platform.SelectedIndex == 2 ? PlatformType.WX : PlatformType.None;
|
||||||
|
search.Title = txt_title.Text;
|
||||||
|
search.MinSoldQuantity = (int)num_minsold.Value;
|
||||||
|
search.MaxSoldQuantity = (int)num_maxsold.Value;
|
||||||
|
search.MinPrice = (long)num_minprice.Value * 100;
|
||||||
|
search.MaxPrice = (long)num_maxprice.Value * 100;
|
||||||
|
if (cmbCatSelect1.SelectedItem is PddCatInfo cat1)
|
||||||
|
{
|
||||||
|
search.CatId1 = (int)(cat1.cat_id);
|
||||||
|
search.CatId1 = search.CatId1 == 0 ? null : search.CatId1;
|
||||||
|
}
|
||||||
|
if (cmbCatSelect2.SelectedItem is PddCatInfo cat2)
|
||||||
|
search.CatId2 = (int)(cat2.cat_id);
|
||||||
|
if (cmbCatSelect3.SelectedItem is PddCatInfo cat3)
|
||||||
|
search.CatId3 = (int)(cat3.cat_id);
|
||||||
|
if (cmbCatSelect4.SelectedItem is PddCatInfo cat4)
|
||||||
|
search.CatId4 = (int)(cat4.cat_id);
|
||||||
|
search.PageIndex = ucSplitPage1.CurrentPage;
|
||||||
|
search.PageSize = ucSplitPage1.PageSize;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GetGoods(search);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
BaseMsgForm.ShowError($"查询失败:{ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.pbLoading.Visible = false;
|
||||||
|
btnSearch.Enabled = true;
|
||||||
}
|
}
|
||||||
if (cmbCatSelect2.SelectedItem is PddCatInfo cat2)
|
|
||||||
search.CatId2 = (int)(cat2.cat_id);
|
|
||||||
if (cmbCatSelect3.SelectedItem is PddCatInfo cat3)
|
|
||||||
search.CatId3 = (int)(cat3.cat_id);
|
|
||||||
if (cmbCatSelect4.SelectedItem is PddCatInfo cat4)
|
|
||||||
search.CatId4 = (int)(cat4.cat_id);
|
|
||||||
search.PageIndex = ucSplitPage1.CurrentPage;
|
|
||||||
search.PageSize = ucSplitPage1.PageSize;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GetGoods(search);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -346,24 +369,20 @@ namespace TemuKJD.PDDForms.ProductSelectForms
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void GetGoods(GoodsSearchRequest request)
|
public async void GetGoods(GoodsSearchRequest request)
|
||||||
{
|
{
|
||||||
this.pbLoading.Visible = true;
|
|
||||||
dataList.Clear();
|
dataList.Clear();
|
||||||
|
|
||||||
Task.Run(() =>
|
PageData<CloudGoods> ret = await CloudGoodsService.GetGoods(request);
|
||||||
|
Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
PageData<CloudGoods> ret = CloudGoodsService.GetGoods(request);
|
ret.List.ForEach(a => dataList.Add(a));
|
||||||
Invoke(new Action(() =>
|
ucSplitPage1.TotalPage = Math.Max(1, ret.TotalPages);
|
||||||
{
|
ucSplitPage1.TotalCount = ret.Total;
|
||||||
ret.List.ForEach(a => dataList.Add(a));
|
this.pbLoading.Visible = false;
|
||||||
ucSplitPage1.TotalPage = Math.Max(1, ret.TotalPages);
|
// 异步加载商品缩略图(Column1 绑定 ThumbUrl)
|
||||||
ucSplitPage1.TotalCount = ret.Total;
|
ShowDgvImg();
|
||||||
this.pbLoading.Visible = false;
|
}));
|
||||||
// 异步加载商品缩略图(Column1 绑定 ThumbUrl)
|
|
||||||
ShowDgvImg();
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,32 +396,43 @@ namespace TemuKJD.PDDForms.ProductSelectForms
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void bt_importUploadList_Click(object sender, EventArgs e)
|
private void bt_importUploadList_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
int succ = 0;
|
||||||
|
int err = 0;
|
||||||
foreach (var item in dataList)
|
foreach (var item in dataList)
|
||||||
{
|
{
|
||||||
if (item.IsSelected == false) continue;
|
try
|
||||||
string catName = "";
|
|
||||||
if (item.CatId4.HasValue)
|
|
||||||
{
|
{
|
||||||
catName = GlobalConfig.PddCatList.FirstOrDefault(a => a.cat_id == item.CatId4)?.cat_name ?? "";
|
if (item.IsSelected == false) continue;
|
||||||
|
string catName = "";
|
||||||
|
if (item.CatId4.HasValue)
|
||||||
|
{
|
||||||
|
catName = GlobalConfig.PddCatList.FirstOrDefault(a => a.cat_id == item.CatId4)?.cat_name ?? "";
|
||||||
|
}
|
||||||
|
else if (item.CatId3.HasValue)
|
||||||
|
{
|
||||||
|
catName = GlobalConfig.PddCatList.FirstOrDefault(a => a.cat_id == item.CatId3)?.cat_name ?? "";
|
||||||
|
}
|
||||||
|
else if (item.CatId2.HasValue)
|
||||||
|
{
|
||||||
|
catName = GlobalConfig.PddCatList.FirstOrDefault(a => a.cat_id == item.CatId2)?.cat_name ?? "";
|
||||||
|
}
|
||||||
|
WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Add(new TemuDBProductSelect
|
||||||
|
{
|
||||||
|
out_product_Id = item.GoodsId.ToString(),
|
||||||
|
spu_id = item.GoodsId.ToString(),
|
||||||
|
main_img = item.ThumbUrl,
|
||||||
|
product_name = item.Title,
|
||||||
|
cat_name = catName,
|
||||||
|
});
|
||||||
|
succ++;
|
||||||
}
|
}
|
||||||
else if (item.CatId3.HasValue)
|
catch
|
||||||
{
|
{
|
||||||
catName = GlobalConfig.PddCatList.FirstOrDefault(a => a.cat_id == item.CatId3)?.cat_name ?? "";
|
err++;
|
||||||
}
|
}
|
||||||
else if (item.CatId2.HasValue)
|
|
||||||
{
|
|
||||||
catName = GlobalConfig.PddCatList.FirstOrDefault(a => a.cat_id == item.CatId2)?.cat_name ?? "";
|
|
||||||
}
|
|
||||||
WXDBProdUploadForm.Instance.lstTemuDBProductSelect.Add(new TemuDBProductSelect
|
|
||||||
{
|
|
||||||
out_product_Id = item.GoodsId.ToString(),
|
|
||||||
spu_id = item.GoodsId.ToString(),
|
|
||||||
main_img = item.ThumbUrl,
|
|
||||||
product_name = item.Title,
|
|
||||||
cat_name = catName,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", WXDBProdUploadForm.Instance.lstTemuDBProductSelect);
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", WXDBProdUploadForm.Instance.lstTemuDBProductSelect);
|
||||||
|
BaseMsgForm.ShowInfo($"导入完成!{succ} 成功 {err} 失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -29,7 +29,7 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("选品上传");
|
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("选品上传");
|
||||||
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("云仓数据");
|
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("云端数据");
|
||||||
System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("我的商品库");
|
System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("我的商品库");
|
||||||
System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("商品预售/下架");
|
System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("商品预售/下架");
|
||||||
System.Windows.Forms.TreeNode treeNode5 = new System.Windows.Forms.TreeNode("云仓退货地址");
|
System.Windows.Forms.TreeNode treeNode5 = new System.Windows.Forms.TreeNode("云仓退货地址");
|
||||||
@@ -149,8 +149,8 @@
|
|||||||
this.tv.Name = "tv";
|
this.tv.Name = "tv";
|
||||||
treeNode1.Name = "选品上传";
|
treeNode1.Name = "选品上传";
|
||||||
treeNode1.Text = "选品上传";
|
treeNode1.Text = "选品上传";
|
||||||
treeNode2.Name = "云仓数据";
|
treeNode2.Name = "云端数据";
|
||||||
treeNode2.Text = "云仓数据";
|
treeNode2.Text = "云端数据";
|
||||||
treeNode3.Name = "我的商品库";
|
treeNode3.Name = "我的商品库";
|
||||||
treeNode3.Text = "我的商品库";
|
treeNode3.Text = "我的商品库";
|
||||||
treeNode4.Name = "商品预售/下架";
|
treeNode4.Name = "商品预售/下架";
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
case "选品上传":
|
case "选品上传":
|
||||||
SetForm(userSelectDbProductForm.Value);
|
SetForm(userSelectDbProductForm.Value);
|
||||||
break;
|
break;
|
||||||
case "云仓数据":
|
case "云端数据":
|
||||||
SetForm(cloudgoodsForm.Value);
|
SetForm(cloudgoodsForm.Value);
|
||||||
break;
|
break;
|
||||||
case "我的商品库":
|
case "我的商品库":
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ namespace Work.Services
|
|||||||
public class CloudGoodsService
|
public class CloudGoodsService
|
||||||
{
|
{
|
||||||
private const string ServerUrl = "http://119.45.4.202:14312";
|
private const string ServerUrl = "http://119.45.4.202:14312";
|
||||||
public static PageData<CloudGoods> GetGoods(GoodsSearchRequest request)
|
public static async Task<PageData<CloudGoods>> GetGoods(GoodsSearchRequest request)
|
||||||
{
|
{
|
||||||
string data = JsonHelper.SerializeObject(request);
|
string data = JsonHelper.SerializeObject(request);
|
||||||
var html = GetHtml.PostUtf8(ServerUrl + "/Goods/SearchGoods", data, "application/json");
|
var html = await GetHtml.PostUtf8Async(ServerUrl + "/Goods/SearchGoods", data, "application/json");
|
||||||
|
|
||||||
var ret = JsonConvert.DeserializeObject<Result<PageData<CloudGoods>>>(html);
|
var ret = JsonConvert.DeserializeObject<Result<PageData<CloudGoods>>>(html);
|
||||||
if (ret.Code != 200)
|
if (ret.Code != 200)
|
||||||
|
|||||||
Reference in new issue
Block a user