diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index 36e5a0a..ca27539 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -157,6 +157,8 @@ + + @@ -202,6 +204,7 @@ + @@ -245,6 +248,7 @@ + diff --git a/B3ClientService/BO/Bill/SegmentProductionInfo.cs b/B3ClientService/BO/Bill/SegmentProductionInfo.cs new file mode 100644 index 0000000..764487d --- /dev/null +++ b/B3ClientService/BO/Bill/SegmentProductionInfo.cs @@ -0,0 +1,62 @@ +using BWP.B3Frameworks.BO; +using Forks.EnterpriseServices; +using Forks.EnterpriseServices.DataDictionary; +using Forks.EnterpriseServices.DataForm; +using Forks.EnterpriseServices.DomainObjects2; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; + +namespace BWP.B3ClientService.BO +{ + [DBIndex("IDX_B3ClientService_SegmentProductionInfo_Clustered", "BarCode", false, 0)] + [DBIndexType("IDX_B3ClientService_SegmentProductionInfo_Clustered", IndexType.Normal)] + [DFClass] + [LogicName("分割品数据表")] + public class SegmentProductionInfo : Base + { + public SegmentProductionInfo() + { + CreateTime = DateTime.Now; + } + + [DbColumn(DbType = SqlDbType.DateTime)] + [LogicName("创建时间")] + public DateTime CreateTime { get; set; } + + [LogicName("条码")] + public string BarCode { get; set; } + + #region 生产信息 + [LogicName("生产时间")] + [DbColumn(DbType = SqlDbType.DateTime)] + public DateTime? ProductTime { get; set; } + + [LogicName("生产员")] + public long? Worker_ID { get; set; } + + [LogicName("工作单元")] + public long? WorkUnit_ID { get; set; } + + [LogicName("生产批次")] + public long? ProductBatch_ID { get; set; } + + [LogicName("存货")] + public long? Goods_ID { get; set; } + + [LogicName("重量")] + public decimal? Weight { get; set; } + #endregion + + #region 入库信息 + [LogicName("入库时间")] + [DbColumn(DbType = SqlDbType.DateTime)] + public DateTime? InStoreTime { get; set; } + #endregion + + #region 领用信息 + #endregion + } +} diff --git a/B3ClientService/BO/Bill/SegmentTraceBackLog.cs b/B3ClientService/BO/Bill/SegmentTraceBackLog.cs new file mode 100644 index 0000000..1a49ea7 --- /dev/null +++ b/B3ClientService/BO/Bill/SegmentTraceBackLog.cs @@ -0,0 +1,16 @@ +using BWP.B3Frameworks.BO; +using Forks.EnterpriseServices.DataForm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TSingSoft.WebPluginFramework; + +namespace BWP.B3ClientService.BO +{ + [BOClass] + public class SegmentTraceBackLog + { + public long SegmentProductionInfo_ID { get; set; } + } +} diff --git a/B3ClientService/OfflinRpc/SegmentProductionRpc.cs b/B3ClientService/OfflinRpc/SegmentProductionRpc.cs new file mode 100644 index 0000000..2d0cbc9 --- /dev/null +++ b/B3ClientService/OfflinRpc/SegmentProductionRpc.cs @@ -0,0 +1,102 @@ +using BWP.B3ClientService.BO; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.JsonRpc; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TSingSoft.WebPluginFramework; + +namespace BWP.B3ClientService.Rpcs +{ + [Rpc] + public static class SegmentProductionRpc + { + static string[] ProductInfoFields = new string[] { "ProductTime", "Worker_ID", "WorkUnit_ID", "ProductBatch_ID", "Goods_ID", "Weight" }; + static Type MinDmoType = typeof(SegmentProductionMin); + + [Rpc(RpcFlags.SkipAuth)] + public static int Insert(string json) + { + var list = JsonConvert.DeserializeObject>(json); + var dmoType = typeof(SegmentProductionInfo); + using (var session = Dmo.NewSession()) + { + foreach (var item in list) + { + var id = Exist(session, item.BarCode); + if (id == null) + { + var entity = new SegmentProductionInfo(); + entity.BarCode = item.BarCode; + foreach (var f in ProductInfoFields) + dmoType.GetProperty(f).SetValue(entity, MinDmoType.GetProperty(f).GetValue(item, null), null); + //还没做入库客户端,先这么搞 + entity.InStoreTime = entity.ProductTime; + session.Insert(entity); + } + else + Update(session, id.Value, item, ProductInfoFields); + } + session.Commit(); + } + return list.Count; + } + + private static void Update(IDmoSession session, long id, SegmentProductionMin entity, params string[] fields) + { + var update = new DQUpdateDom(typeof(SegmentProductionInfo)); + foreach (var field in fields) + update.Columns.Add(new DQUpdateColumn(field, DQExpression.Value(MinDmoType.GetProperty(field).GetValue(entity, null)))); + update.Where.Conditions.Add(DQCondition.EQ("ID", id)); + session.ExecuteNonQuery(update); + } + + [Rpc(RpcFlags.SkipAuth)] + public static int SetInStoreTime(string json) + { + var list = JsonConvert.DeserializeObject>(json); + using (var session = Dmo.NewSession()) + { + foreach (var item in list) + { + var id = Exist(session, item.BarCode); + if (id.HasValue) + { + var entity = new SegmentProductionInfo(); + entity.BarCode = item.BarCode; + entity.InStoreTime = item.InStoreTime; + session.Insert(entity); + } + else + Update(session, id.Value, item, "InStoreTime"); + } + session.Commit(); + } + return list.Count; + } + + static long? Exist(IDmoSession session, string barCode) + { + var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode)); + return query.EExecuteScalar(session); + } + } + + class SegmentProductionMin + { + public string BarCode { get; set; } + public DateTime? ProductTime { get; set; } + public long? Worker_ID { get; set; } + public long? WorkUnit_ID { get; set; } + public long? ProductBatch_ID { get; set; } + public long? Goods_ID { get; set; } + public decimal? Weight { get; set; } + public DateTime? InStoreTime { get; set; } + + } +} diff --git a/B3ClientService/Tasks/SyncSegmentInfoToTraceBack.cs b/B3ClientService/Tasks/SyncSegmentInfoToTraceBack.cs new file mode 100644 index 0000000..a9d9964 --- /dev/null +++ b/B3ClientService/Tasks/SyncSegmentInfoToTraceBack.cs @@ -0,0 +1,131 @@ +using BWP.B3ClientService.BO; +using BWP.B3ClientService.Utils; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TSingSoft.WebPluginFramework.TimerTasks; + +namespace BWP.B3ClientService.Tasks +{ + public class SyncSegmentInfoToTraceBack : ITimerTask + { + public void Execute() + { + var url = new B3ClientServiceOnLineConfig().TraceBackUrl.Value; + if (string.IsNullOrEmpty(url)) + return; + using (var session = Dmo.NewSession()) + { + Upload(session, url); + session.Commit(); + } + } + + private void Upload(IDmoSession session, string url) + { + var sUrl = url + "SegmentInsert"; + var list = GetTraceBackInfo(session); + if (!list.Any()) + return; + var arr = JsonConvert.SerializeObject(list); + TraceBackInfoUtil.Insert(sUrl, arr); + foreach (var item in list) + session.Insert(new SegmentTraceBackLog { SegmentProductionInfo_ID = item.ID }); + } + + List GetTraceBackInfo(IDmoSession session) + { + var list = new List(); + + var main = new JoinAlias(typeof(SegmentProductionInfo)); + var log = new JoinAlias(typeof(SegmentTraceBackLog)); + var goods = new JoinAlias(typeof(Goods)); + var query = new DQueryDom(main); + query.From.AddJoin(JoinType.Left, new DQDmoSource(log), DQCondition.EQ(main, "ID", log, "SegmentProductionInfo_ID")); + query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID")); + query.Columns.Add(DQSelectColumn.Field("BarCode")); + query.Columns.Add(DQSelectColumn.Field("Name",goods)); + query.Columns.Add(DQSelectColumn.Field("Spec",goods)); + query.Columns.Add(DQSelectColumn.Field("Weight")); + query.Columns.Add(DQSelectColumn.Field("ProductTime")); + query.Columns.Add(DQSelectColumn.Field("InStoreTime")); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Range = SelectRange.Top(500); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("ProductTime")), DQCondition.IsNotNull(DQExpression.Field("InStoreTime")), DQCondition.IsNull(DQExpression.Field(log, "SegmentProductionInfo_ID")))); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var info = new SegmentInfo(); + info.Code = (string)reader[0]; + info.Goods_Name = (string)reader[1]; + info.Goods_Spec = (string)reader[2]; + info.Weight = string.Format("{0:#0.######}", reader[3]); + info.ProductDate = string.Format("{0:yyyyMMdd}", reader[4]); + info.ProductBatch = info.ProductDate; + info.InStoreDate = string.Format("{0:yyyyMMdd}", reader[5]); + info.ID = (long)reader[6]; + info.Farm_Name = "自属备案养殖场"; + info.TestingResult = "合格"; + list.Add(info); + } + } + + return list; + } + + public string Name + { + get { return "抽取分割信息到追溯服务器"; } + } + } + class SegmentInfo + { + [JsonIgnore] + public long ID { get; set; } + //[LogicName("条码")] + public string Code { get; set; } + + //[LogicName("产品名称")] + public string Goods_Name { get; set; } + + //[LogicName("规格")] + public string Goods_Spec { get; set; } + + //[LogicName("重量")] + public string Weight { get; set; } + + //[LogicName("生产日期")] + public string ProductDate { get; set; } + + //[LogicName("养殖场")] + public string Farm_Name { get; set; } + + //[LogicName("检验结果")] + public string TestingResult { get; set; } + + //[LogicName("检验人员")] + public string TestingMan { get; set; } + + //[LogicName("生产批次")] + public string ProductBatch { get; set; } + + //[LogicName("入库日期")] + public string InStoreDate { get; set; } + + //[LogicName("发货时间")] + public string SendDate { get; set; } + + //[LogicName("发货客户")] + public string SendCustomer { get; set; } + + //[LogicName("货运车牌")] + public string CarNo { get; set; } + } +}