| @ -0,0 +1,36 @@ | |||||
| using BWP.B3Frameworks.BO; | |||||
| using Forks.EnterpriseServices.DataForm; | |||||
| using Forks.EnterpriseServices.DomainObjects2; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| namespace BWP.B3ClientService.BO | |||||
| { | |||||
| [DFClass, Serializable] | |||||
| public class ProductInStoreCombine : Base | |||||
| { | |||||
| public string CombineCode { get; set; } | |||||
| public long OutStore_ID { get; set; } | |||||
| [ReferenceTo(typeof(Store), "Code")] | |||||
| [Join("OutStore_ID", "ID")] | |||||
| public string OutStore_Code { get; set; } | |||||
| public long InStore_ID { get; set; } | |||||
| [ReferenceTo(typeof(Store), "Code")] | |||||
| [Join("InStore_ID", "ID")] | |||||
| public string InStore_Code { get; set; } | |||||
| public DateTime CombineTime { get; set; } | |||||
| public bool IsCreated { get; set; } | |||||
| private readonly List<string> mBarCodes = new List<string>(); | |||||
| [NonDmoProperty] | |||||
| public List<string> BarCodes { get { return mBarCodes; } } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,82 @@ | |||||
| using BWP.B3ClientService.BO; | |||||
| using Forks.EnterpriseServices.DomainObjects2; | |||||
| using Forks.EnterpriseServices.DomainObjects2.DQuery; | |||||
| using Forks.EnterpriseServices.JsonRpc; | |||||
| using Forks.EnterpriseServices.SqlDoms; | |||||
| 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 ProductInStoreCombineRpc | |||||
| { | |||||
| [Rpc(RpcFlags.SkipAuth)] | |||||
| public static string ScanBarCode(string barCode) | |||||
| { | |||||
| var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); | |||||
| query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BarCode", barCode), DQCondition.EQ("Delete", false), DQCondition.IsNotNull(DQExpression.Field("Weight")))); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_Name")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_Spec")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Weight")); | |||||
| query.Columns.Add(DQSelectColumn.Field("InStoreTime")); | |||||
| query.Range = SelectRange.Top(1); | |||||
| using (var session = Dmo.NewSession()) | |||||
| { | |||||
| using (var reader = session.ExecuteReader(query)) | |||||
| { | |||||
| if (reader.Read()) | |||||
| { | |||||
| var obj = new | |||||
| { | |||||
| Goods_Name = (string)reader[0], | |||||
| Goods_Spec = (string)reader[1], | |||||
| Weight = (decimal)reader[2], | |||||
| InStoreTime = (DateTime?)reader[3] | |||||
| }; | |||||
| return JsonConvert.SerializeObject(obj); | |||||
| } | |||||
| } | |||||
| } | |||||
| return JsonConvert.SerializeObject(new { }); | |||||
| } | |||||
| [Rpc(RpcFlags.SkipAuth)] | |||||
| public static int InsertCombine(string json) | |||||
| { | |||||
| var list = JsonConvert.DeserializeObject<List<ProductInStoreCombine>>(json); | |||||
| using (var session = Dmo.NewSession()) | |||||
| { | |||||
| foreach (var item in list) | |||||
| { | |||||
| if ((Exist(session, item.CombineCode))) | |||||
| continue; | |||||
| session.Insert(item); | |||||
| UpdateProductInfo(session, item); | |||||
| } | |||||
| session.Commit(); | |||||
| } | |||||
| return 1; | |||||
| } | |||||
| static bool Exist(IDmoSession session, string code) | |||||
| { | |||||
| var query = new DQueryDom(new JoinAlias(typeof(ProductInStoreCombine))); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("CombineCode", code)); | |||||
| return query.EExists(session); | |||||
| } | |||||
| static void UpdateProductInfo(IDmoSession session, ProductInStoreCombine item) | |||||
| { | |||||
| var update = new DQUpdateDom(typeof(SegmentProductionInfo)); | |||||
| update.Columns.Add(new DQUpdateColumn("InStoreCombine_ID", item.ID)); | |||||
| update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("BarCode"), item.BarCodes.Select(x => DQExpression.Value(x)).ToArray())); | |||||
| session.ExecuteNonQuery(update); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,123 @@ | |||||
| 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 InStoreCombineCreateB3Bills : 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/InStoreCombineRpc/CreateInOutStore"; | |||||
| private void DoExecute() | |||||
| { | |||||
| using (var context = new TransactionContext()) | |||||
| { | |||||
| List<long> ids; | |||||
| var list = GetUnSyncdList(context.Session, out ids); | |||||
| if (list.Count == 0) | |||||
| return; | |||||
| RpcFacade.Call<int>(method, JsonConvert.SerializeObject(list)); | |||||
| SetAsSyncd(context.Session, ids); | |||||
| context.Commit(); | |||||
| } | |||||
| } | |||||
| private void SetAsSyncd(IDmoSession session, List<long> ids) | |||||
| { | |||||
| var update = new DQUpdateDom(typeof(ProductInStoreCombine)); | |||||
| update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); | |||||
| update.Columns.Add(new DQUpdateColumn("IsCreated", true)); | |||||
| session.ExecuteNonQuery(update); | |||||
| } | |||||
| private List<object> GetUnSyncdList(IDmoSession session, out List<long> ids) | |||||
| { | |||||
| var main = new JoinAlias(typeof(ProductInStoreCombine)); | |||||
| var detail = new JoinAlias(typeof(SegmentProductionInfo)); | |||||
| var query = new DQueryDom(main); | |||||
| query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "InStoreCombine_ID")); | |||||
| query.Columns.Add(DQSelectColumn.Field("ID")); | |||||
| query.Columns.Add(DQSelectColumn.Field("CombineTime")); | |||||
| query.Columns.Add(DQSelectColumn.Field("OutStore_Code")); | |||||
| query.Columns.Add(DQSelectColumn.Field("InStore_Code")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_Code", detail)); | |||||
| foreach (var c in query.Columns) | |||||
| query.GroupBy.Expressions.Add(c.Expression); | |||||
| query.Columns.Add(DQSelectColumn.Sum("Weight")); | |||||
| query.Columns.Add(DQSelectColumn.Count("C")); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("IsCreated", false)); | |||||
| query.Range = SelectRange.Top(100); | |||||
| var list = new List<object>(); | |||||
| ids = new List<long>(); | |||||
| using (var reader = session.ExecuteReader(query)) | |||||
| { | |||||
| while (reader.Read()) | |||||
| { | |||||
| var id = (long)reader[0]; | |||||
| ids.Add(id); | |||||
| list.Add(new | |||||
| { | |||||
| ID = id, | |||||
| CombineTime = (DateTime)reader[1], | |||||
| OutStore_Code = (string)reader[2], | |||||
| InStore_Code = (string)reader[3], | |||||
| Goods_Code = (string)reader[4], | |||||
| Weight = (decimal)reader[5], | |||||
| Count = Convert.ToInt32(reader[6]) | |||||
| }); | |||||
| } | |||||
| } | |||||
| return list; | |||||
| } | |||||
| public string Name | |||||
| { | |||||
| get { return "成品入库创建产出入库单"; } | |||||
| } | |||||
| } | |||||
| } | |||||