| @ -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<int>(method, JsonConvert.SerializeObject(list)); | |||
| SetAsSyncd(context.Session, list.Select(x => x.ID)); | |||
| context.Commit(); | |||
| } | |||
| } | |||
| private void SetAsSyncd(IDmoSession session, IEnumerable<long> 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<SelfTemp> 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<SelfTemp>(); | |||
| 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; } | |||
| } | |||
| } | |||
| } | |||