diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index 5716ca9..75324ca 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -260,6 +260,7 @@ + diff --git a/B3ClientService/BO/Bill/CarcassFullInfo.cs b/B3ClientService/BO/Bill/CarcassFullInfo.cs index 7ac065e..a585aca 100644 --- a/B3ClientService/BO/Bill/CarcassFullInfo.cs +++ b/B3ClientService/BO/Bill/CarcassFullInfo.cs @@ -80,6 +80,9 @@ namespace BWP.B3ClientService.BO [DbColumn(DbType = SqlDbType.DateTime)] public DateTime? InStoreTime { get; set; } + [DbColumn(DefaultValue = 0)] + public bool InStoreIsCreate { get; set; } + #endregion #region 领用信息 @@ -109,6 +112,9 @@ namespace BWP.B3ClientService.BO [LogicName("领用组标识")] public long? PickGroupID { get; set; } + [LogicName("领用仓库")] + public long? PickStore_ID { get; set; } + #endregion } } diff --git a/B3ClientService/Tasks/CreateB3InStoreTask.cs b/B3ClientService/Tasks/CreateB3InStoreTask.cs new file mode 100644 index 0000000..bb1a8f7 --- /dev/null +++ b/B3ClientService/Tasks/CreateB3InStoreTask.cs @@ -0,0 +1,134 @@ +using BWP.B3ClientService.BO; +using Forks.EnterpriseServices.BusinessInterfaces; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; +using Forks.JsonRpc.Client; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using TSingSoft.WebPluginFramework.TimerTasks; + +namespace BWP.B3ClientService.Tasks +{ + public class CreateB3InStoreTask : ITimerTask + { + private static volatile object _lockObj = new object(); + public void Execute() + { + if (!Monitor.TryEnter(_lockObj)) + { + throw new SameTaskNotFinishException(this); + } + var serverUri = ServerHost.GetServerUrl(); + if (string.IsNullOrEmpty(serverUri)) + throw new Exception("请配置服务器地址"); + try + { + RpcFacade.Init(serverUri, "B3ClientServer"); + } + catch (Exception ex) + { + if (ex.Message != "Can only start once") + throw; + } + + try + { + DoExecute(); + } + catch (Exception e) + { + throw new ApplicationException(e.ToString()); + } + finally + { + Monitor.Exit(_lockObj); + } + } + + string method = "/MainSystem/B3ButcherManage/Rpcs/ProductInStoreRpc/InsertCarcassInstore"; + private void DoExecute() + { + using (var context = new TransactionContext()) + { + var list = GetUnSyncdList(context.Session); + if (list.Count == 0) + return; + RpcFacade.Call(method, JsonConvert.SerializeObject(list)); + SetAsSyncd(context.Session, list.Select(x => x.ID)); + context.Commit(); + } + } + + private void SetAsSyncd(IDmoSession session, IEnumerable ids) + { + var update = new DQUpdateDom(typeof(CarcassFullInfo)); + update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); + update.Columns.Add(new DQUpdateColumn("InStoreIsCreate", true)); + session.ExecuteNonQuery(update); + } + + private List GetUnSyncdList(IDmoSession session) + { + var main = new JoinAlias(typeof(CarcassFullInfo)); + var goods = new JoinAlias(typeof(Goods)); + var batch = new JoinAlias(typeof(ProductBatch)); + var worker = new JoinAlias(typeof(Worker)); + var query = new DQueryDom(main); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(goods), DQCondition.EQ(main, "InStoreGoods_ID", goods, "ID")); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(batch), DQCondition.EQ(main, "ProductBatch_ID", batch, "ID")); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(worker), DQCondition.EQ(main, "InStoreWorker_ID", worker, "ID")); + + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("Code", goods)); + query.Columns.Add(DQSelectColumn.Field("Name", batch)); + query.Columns.Add(DQSelectColumn.Field("Date", batch)); + query.Columns.Add(DQSelectColumn.Field("Name", worker)); + query.Columns.Add(DQSelectColumn.Field("InStoreWeight")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("InStoreGoods_ID")), DQCondition.EQ("InStoreIsCreate", false))); + query.Where.Conditions.Add(DQCondition.GreaterThan("InStoreTime", new DateTime(2018, 12, 24))); + query.Range = SelectRange.Top(100); + var list = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var entity = new SelfTemp(); + entity.ID = (long)reader[0]; + entity.Goods_Code = (string)reader[1]; + entity.ProductBatch_Name = (string)reader[2]; + entity.BatchDate = (DateTime)reader[3]; + entity.Worker_Name = (string)reader[4]; + entity.Weight = (decimal)reader[5]; + + list.Add(entity); + } + } + return list; + } + + public string Name + { + get { return "白条入库生成成品入库"; } + } + + class SelfTemp + { + public long ID { get; set; } + + public string Goods_Code { get; set; } + + public string ProductBatch_Name { get; set; } + + public DateTime BatchDate { get; set; } + + public string Worker_Name { get; set; } + + public decimal Weight { get; set; } + } + } +}