diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj
index 0f0129d..156a58a 100644
--- a/B3ClientService/B3ClientService.csproj
+++ b/B3ClientService/B3ClientService.csproj
@@ -114,6 +114,7 @@
+
@@ -191,6 +192,7 @@
+
@@ -203,6 +205,7 @@
+
diff --git a/B3ClientService/BO/Bill/SyncCarcassInStoreLog.cs b/B3ClientService/BO/Bill/SyncCarcassInStoreLog.cs
new file mode 100644
index 0000000..7602cbb
--- /dev/null
+++ b/B3ClientService/BO/Bill/SyncCarcassInStoreLog.cs
@@ -0,0 +1,17 @@
+using BWP.B3Frameworks.BO;
+using Forks.EnterpriseServices.DataForm;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BWP.B3ClientService.BO
+{
+ [DFClass]
+ public class SyncCarcassInStoreLog : Base
+ {
+ public string Code { get; set; }
+
+ public string Date { get; set; }
+ }
+}
diff --git a/B3ClientService/OfflinRpc/CarcassInStoreRpc.cs b/B3ClientService/OfflinRpc/CarcassInStoreRpc.cs
index 34d980c..09b2736 100644
--- a/B3ClientService/OfflinRpc/CarcassInStoreRpc.cs
+++ b/B3ClientService/OfflinRpc/CarcassInStoreRpc.cs
@@ -151,6 +151,8 @@ namespace BWP.B3ClientService.Rpcs
Update(id.Value, item, session);
else
Insert(item, session);
+ var log = new SyncCarcassInStoreLog { Code = item.BarCode, Date = item.InStoreTime.Value.ToString("yyyyMMdd") };
+ session.Insert(log);
}
session.Commit();
}
@@ -221,5 +223,5 @@ namespace BWP.B3ClientService.Rpcs
public long? InStoreGoods_ID { get; set; }
public decimal? InStoreWeight { get; set; }
public DateTime? InStoreTime { get; set; }
- }
+ }
}
diff --git a/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs b/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs
new file mode 100644
index 0000000..2bbb23d
--- /dev/null
+++ b/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs
@@ -0,0 +1,72 @@
+using BWP.B3ClientService.BO;
+using BWP.B3ClientService.Utils;
+using Forks.EnterpriseServices.DomainObjects2;
+using Forks.EnterpriseServices.DomainObjects2.DQuery;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TSingSoft.WebPluginFramework.TimerTasks;
+using TSingSoft.WebPluginFramework;
+
+namespace BWP.B3ClientService.Tasks
+{
+ public class SyncCarcassInStoreToTrackBack : ITimerTask
+ {
+ public void Execute()
+ {
+ var url = ServerHost.GetTraceServerUrl();
+ if (string.IsNullOrEmpty(url))
+ return;
+ url = url + "InsertInStore";
+ using (var session = Dmo.NewSession())
+ {
+ var list = GetUnSyncdInfo(session);
+ if (!list.Any())
+ return;
+ var splitList = TraceBackInfoUtil.SplitList(list, 1000);
+ foreach (var infos in splitList)
+ {
+ var arr = JsonConvert.SerializeObject(infos);
+ TraceBackInfoUtil.Insert(url, arr);
+ }
+ DeleteSyncd(session, list.Min(x => x.ID), list.Max(x => x.ID));
+ session.Commit();
+ }
+ }
+
+ List GetUnSyncdInfo(IDmoSession session)
+ {
+ var query = new DQueryDom(new JoinAlias(typeof(SyncCarcassInStoreLog)));
+ query.Columns.Add(DQSelectColumn.Field("ID"));
+ query.Columns.Add(DQSelectColumn.Field("Code"));
+ query.Columns.Add(DQSelectColumn.Field("Date"));
+ query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
+ var list = query.EExecuteList(session);
+ return list.Select(x => new TraceBackInStoreInfo { ID = x.Item1, Code = x.Item2, InStoreDate = x.Item3 }).ToList();
+ }
+
+ void DeleteSyncd(IDmoSession session, long min, long max)
+ {
+ var delete = new DQDeleteDom(typeof(SyncCarcassInStoreLog));
+ delete.Where.Conditions.Add(DQCondition.Between("ID", min, max));
+ session.ExecuteNonQuery(delete);
+ }
+
+ public string Name
+ {
+ get { return "抽取白条入库信息到追溯服务器"; }
+ }
+ }
+
+ class TraceBackInStoreInfo
+ {
+ [JsonIgnore]
+ public long ID { get; set; }
+ //[LogicName("条码")]
+ public string Code { get; set; }
+
+ public string InStoreDate { get; set; }
+ }
+}
diff --git a/B3ClientService/Utils/TraceBackInfoUtil.cs b/B3ClientService/Utils/TraceBackInfoUtil.cs
new file mode 100644
index 0000000..e4de52c
--- /dev/null
+++ b/B3ClientService/Utils/TraceBackInfoUtil.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+
+namespace BWP.B3ClientService.Utils
+{
+ public class TraceBackInfoUtil
+ {
+ public static void Insert(string serverUrl, string json)
+ {
+ //raw方式使用的是纯字符串的数据上传方式,所以在POST之前,可能需要手工的把一些JSON格式的数据转换成字符串的(加两单引号)
+ //在这里坑了一个上午
+ json = string.Format("'{0}'", json);
+ var request = (HttpWebRequest)WebRequest.Create(serverUrl);
+ request.Method = "POST";
+ request.ContentType = "application/json";
+ request.AllowWriteStreamBuffering = false;
+ request.KeepAlive = true;
+ request.Accept = "*/*";
+ request.UserAgent = "bwptraceback";
+ var buffer = Encoding.UTF8.GetBytes(json);
+ request.ContentLength = buffer.Length;
+ using (var requestStream = request.GetRequestStream())
+ {
+ requestStream.Write(buffer, 0, buffer.Length);
+ }
+
+ var response = request.GetResponse();
+ string backInfo = "";
+ using (var stream = response.GetResponseStream())
+ {
+ using (var reader = new StreamReader(stream, Encoding.UTF8))
+ {
+ backInfo = reader.ReadToEnd();
+ }
+ }
+
+ if (backInfo != "null")
+ {
+ throw new Exception(backInfo);
+ }
+ }
+
+ public static List> SplitList(List list, int size)
+ where T : new()
+ {
+ List> result = new List>();
+ for (int i = 0; i < list.Count() / size; i++)
+ {
+ T[] clist = new T[size];
+ list.CopyTo(i * size, clist, 0, size);
+ result.Add(clist.ToList());
+ }
+
+ int r = list.Count() % size;
+ if (r != 0)
+ {
+ T[] cclist = new T[r];
+ list.CopyTo(list.Count() - r, cclist, 0, r);
+ result.Add(cclist.ToList());
+ }
+ return result;
+ }
+ }
+}