From 06e0d049fe4cc8754863b7db35e99c17ce41d909 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Tue, 6 Feb 2018 14:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- B3ClientService/B3ClientService.csproj | 3 +- .../ClientGoodsSet_/ClientGoodsSet_Detail.cs | 2 + .../MaterialRequisitionRecord.cs | 42 ++++-- .../Rpcs/BillRpc/ClientGoodsSetRpc.cs | 1 + .../MaterialRequisitionRecordDto.cs | 27 ---- .../MaterialRequisitionRecordRpc.cs | 132 ++++++++++++++---- .../TrunksIousOutInStoreRecordDto.cs | 29 ---- .../TrunksIousOutInStoreRecordRpc.cs | 19 ++- .../Rpcs/RpcBO/Bill/ClientGoodsSetDto.cs | 1 + .../UploadMaterialRequisitionRecord.cs | 64 +++++++++ .../Tasks/UpdateLoad/UploadTest.cs | 1 + 11 files changed, 218 insertions(+), 103 deletions(-) delete mode 100644 B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordDto.cs delete mode 100644 B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordDto.cs create mode 100644 B3ClientService/Tasks/UpdateLoad/UploadMaterialRequisitionRecord.cs diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index f516619..9ec946d 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -139,7 +139,6 @@ - @@ -147,7 +146,6 @@ - @@ -174,6 +172,7 @@ + diff --git a/B3ClientService/BO/ClientGoodsSet_/ClientGoodsSet_Detail.cs b/B3ClientService/BO/ClientGoodsSet_/ClientGoodsSet_Detail.cs index 23a730d..c1c399f 100644 --- a/B3ClientService/BO/ClientGoodsSet_/ClientGoodsSet_Detail.cs +++ b/B3ClientService/BO/ClientGoodsSet_/ClientGoodsSet_Detail.cs @@ -28,6 +28,8 @@ namespace BWP.B3ClientService.BO public string Goods_Spell { get; set; } + public string Goods_MainUnit { get; set; } + [LogicName("主辅换算主单位比例")] public Money? Goods_MainUnitRatio { get; set; } diff --git a/B3ClientService/BO/MaterialRequisitionRecord_/MaterialRequisitionRecord.cs b/B3ClientService/BO/MaterialRequisitionRecord_/MaterialRequisitionRecord.cs index 38fde5e..d5240cd 100644 --- a/B3ClientService/BO/MaterialRequisitionRecord_/MaterialRequisitionRecord.cs +++ b/B3ClientService/BO/MaterialRequisitionRecord_/MaterialRequisitionRecord.cs @@ -11,27 +11,41 @@ namespace BWP.B3ClientService.BO { [Serializable] [DFClass] - public class MaterialRequisitionRecord : Base + public class MaterialRequisitionRecord : SyncBill { - public long? B3_ID { get; set; } - public DateTime? SyncToB3DateTime { get; set; } + public string BarCode { get; set; } + public long? Goods_ID { get; set; } + public string Goods_Name { get; set; } + public string Goods_Code { get; set; } + public string Goods_MainUnit { get; set; } - private DateTime mCreateTime = DateTime.Now; - [DbColumn(DbType = SqlDbType.DateTime)] - public DateTime CreateTime { get { return mCreateTime; } set { mCreateTime = value; } } + private int mNumber = 1; + public int Number + { + get { return mNumber; } + set { mNumber = value; } + } - public string BarCode { get; set; }//条码 + [ReferenceTo(typeof(TrunksIousOutInStoreRecord), "Weight")] + [Join("BarCode", "BarCode")] + public decimal? BeforeWeight { get; set; } - public long Goods_ID { get; set; } + public decimal? Weight { get; set; } - public string Goods_Name { get; set; } - public string Goods_Spec { get; set; } + public bool IsSubmited { get; set; }//界面有2个状态 待提交已提交 , 有条码有重量为已提交 + + public long? WorkShop_ID { get; set; } + + public long? WorkUnit_ID { get; set; } + + public long? Store_ID { get; set; } + + public long? ProductBatch_ID { get; set; } - public decimal Weight { get; set; }//净重 + public string ProductBatch { get; set; } - public string CardBarCode { get; set; }//放产品的车的条码 + public int RowVersion { get; set; } - public string BiaoShi { get; set; }//用来记录那个工作台或者哪台触摸屏做的 - public string CreateUserName { get; set; } + public DateTime? CreateTime { get; set; } } } diff --git a/B3ClientService/Rpcs/BillRpc/ClientGoodsSetRpc.cs b/B3ClientService/Rpcs/BillRpc/ClientGoodsSetRpc.cs index f57dce8..6580619 100644 --- a/B3ClientService/Rpcs/BillRpc/ClientGoodsSetRpc.cs +++ b/B3ClientService/Rpcs/BillRpc/ClientGoodsSetRpc.cs @@ -41,6 +41,7 @@ using TSingSoft.WebPluginFramework; dto.Goods_Name = setDetail.Goods_Name; dto.Goods_Code = setDetail.Goods_Code; dto.Goods_Spec = setDetail.Goods_Spec; + dto.Goods_MainUnit = setDetail.Goods_MainUnit; dto.StandardWeight = setDetail.StandardWeight; dto.StandardWeightUp = setDetail.StandardWeightUp; diff --git a/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordDto.cs b/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordDto.cs deleted file mode 100644 index f652b5a..0000000 --- a/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordDto.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using BWP.B3ClientService.BO; -using Forks.EnterpriseServices.DataForm; - -namespace BWP.B3ClientService.Rpcs.BillRpc -{ - [Serializable, DFClass] - public class MaterialRequisitionRecordDto : ClientSyncBaseDto - { - public string BarCode { get; set; }//条码 - - public long Goods_ID { get; set; } - - public string Goods_Name { get; set; } - public string Goods_Spec { get; set; } - - public decimal Weight { get; set; }//净重 - - public string CardBarCode { get; set; }//放产品的车的条码 - - public string BiaoShi { get; set; }//用来记录那个工作台或者哪台触摸屏做的 - public string CreateUserName { get; set; } - } -} diff --git a/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordRpc.cs b/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordRpc.cs index bbf727e..898f7aa 100644 --- a/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordRpc.cs +++ b/B3ClientService/Rpcs/BillRpc/MaterialRequisitionRecordRpc_/MaterialRequisitionRecordRpc.cs @@ -5,62 +5,136 @@ using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; using Forks.EnterpriseServices.JsonRpc; using Newtonsoft.Json; +using TSingSoft.WebPluginFramework; +using Forks.EnterpriseServices.SqlDoms; +using System.Collections.Generic; +using System.Linq; namespace BWP.B3ClientService.Rpcs.BillRpc { [Rpc] public static class MaterialRequisitionRecordRpc { - private static readonly object _insertObj = new object(); + [Rpc] + public static string GetUnSubmitList() + { + var query = new DQueryDom(new JoinAlias(typeof(MaterialRequisitionRecord))); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("IsSubmited", false))); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); + var list = query.EExecuteDmoList("ID", "BarCode", "Goods_Name", "Goods_Code", "Goods_MainUnit", "Weight"); + return JsonConvert.SerializeObject(list); + } [Rpc] - public static long Insert(string json) + public static string GetSubmitedList() { - lock (_insertObj) - { - var record = JsonConvert.DeserializeObject(json); - record.CreateTime = DateTime.Now; - using (var session = Dmo.NewSession()) - { - session.Insert(record); - session.Commit(); - } - return record.ID; - } + var query = new DQueryDom(new JoinAlias(typeof(MaterialRequisitionRecord))); + query.Where.Conditions.Add(DQCondition.EQ("IsSubmited", true)); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); + query.Range = SelectRange.Top(50); + + var list = query.EExecuteDmoList("ID", "BarCode", "Goods_Name", "Goods_Code", "Goods_MainUnit", "Number", "BeforeWeight", "Weight"); + + return JsonConvert.SerializeObject(list); } - private static readonly object _updateObj = new object(); [Rpc] - public static int Update(string json) + public static string GetCodeStoreInfo(string code) { - lock (_updateObj) + var main = new JoinAlias(typeof(TrunksIousOutInStoreRecord)); + var take = new JoinAlias(typeof(MaterialRequisitionRecord)); + var query = new DQueryDom(main); + query.From.AddJoin(JoinType.Left, new DQDmoSource(take), DQCondition.And(DQCondition.EQ(main, "BarCode", take, "BarCode"), DQCondition.EQ(take, "DeleteState", false))); + query.Columns.Add(DQSelectColumn.Field("ID", main)); + query.Columns.Add(DQSelectColumn.Field("Weight", main)); + query.Columns.Add(DQSelectColumn.Field("Goods_Name", main)); + query.Columns.Add(DQSelectColumn.Field("Store_ID", main)); + query.Columns.Add(DQSelectColumn.Field("Goods_ID", main)); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ(main, "BarCode", code), DQCondition.IsNull(DQExpression.Field(take, "ID")))); + using (var session = Dmo.NewSession()) { - var clientRecord = JsonConvert.DeserializeObject(json); - using (var session = Dmo.NewSession()) + using (var reader = session.ExecuteReader(query)) { - var record = session.Load(new DmoIdentity(typeof(MaterialRequisitionRecord), clientRecord.Service_ID ?? 0)); - if (record == null) + while (reader.Read()) { - return 0; + var r = new MaterialRequisitionRecord(); + r.ID = (long)reader[0]; + r.Weight = (decimal?)reader[1]; + r.Goods_Name = (string)reader[2]; + r.Store_ID = (long?)reader[3]; + r.Goods_ID = (long?)reader[4]; + return JsonConvert.SerializeObject(r); } - DmoUtil.CopyDmoFields(clientRecord, record, "ID", "B3_ID"); - session.Update(record); - session.Commit(); } - return 1; } + return string.Empty; } [Rpc] - public static int Delete(long id) + public static string Insert(string json) { - var delDom = new DQDeleteDom(typeof(MaterialRequisitionRecord)); - delDom.Where.Conditions.Add(DQCondition.EQ("ID", id)); + var record = JsonConvert.DeserializeObject(json); using (var session = Dmo.NewSession()) { - session.ExecuteNonQuery(delDom); + record.CreateTime = record.ModifyTime = DateTime.Now; + FillGoodsInfo(record, session); + session.Insert(record); session.Commit(); } + return JsonConvert.SerializeObject(record); + } + + static void FillGoodsInfo(MaterialRequisitionRecord record, IDmoSession session) + { + var query = new DQueryDom(new JoinAlias(typeof(ClientGoodsSet_Detail))); + query.Where.Conditions.Add(DQCondition.EQ("Goods_ID", record.Goods_ID)); + query.Columns.Add(DQSelectColumn.Field("Goods_Name")); + query.Columns.Add(DQSelectColumn.Field("Goods_MainUnit")); + query.Columns.Add(DQSelectColumn.Field("Goods_Code")); + query.Range = SelectRange.Top(1); + var r = query.EExecuteScalar(session); + if (r != null) + { + record.Goods_Name = r.Item1; + record.Goods_MainUnit = r.Item2; + record.Goods_Code = r.Item3; + } + } + + [Rpc] + public static int FillWeight(long id, decimal weight) + { + var update = new DQUpdateDom(typeof(MaterialRequisitionRecord)); + update.Where.Conditions.Add(DQCondition.EQ("ID", id)); + update.Columns.Add(new DQUpdateColumn("Weight", weight)); + using (var session = Dmo.NewSession()) + { + session.ExecuteNonQuery(update); + session.Commit(); + } + return 1; + } + + [Rpc] + public static int Submit(List arr) + { + var update = new DQUpdateDom(typeof(MaterialRequisitionRecord)); + update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), arr.Select(x => DQExpression.Value(x)).ToArray())); + update.Columns.Add(new DQUpdateColumn("IsSubmited", true)); + using (var session = Dmo.NewSession()) + { + session.ExecuteNonQuery(update); + session.Commit(); + } + return 1; + } + + [Rpc] + public static int Delete(long id) + { + var delete = new DQDeleteDom(typeof(MaterialRequisitionRecord)); + delete.Where.Conditions.Add(DQCondition.EQ("ID", id)); + delete.EExecute(); return 1; } } diff --git a/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordDto.cs b/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordDto.cs deleted file mode 100644 index 5cc3bf6..0000000 --- a/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordDto.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using BWP.B3ClientService.BO; -using Forks.EnterpriseServices.DataForm; - -namespace BWP.B3ClientService.Rpcs.BillRpc.TrunksIousOutInStoreRecord_ -{ - [Serializable,DFClass] - public class TrunksIousOutInStoreRecordDto: ClientSyncBaseDto - { - public string BarCode { get; set; } - public long? Goods_ID { get; set; } - public string Goods_Name { get; set; } - - private int mNumber = 1; - public int Number - { - get { return mNumber; } - set { mNumber = value; } - } - - public decimal? Weight { get; set; } - - public string CarcassStatus { get; set; }// 胴体状态 - - } -} diff --git a/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordRpc.cs b/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordRpc.cs index fba0402..507b3f2 100644 --- a/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordRpc.cs +++ b/B3ClientService/Rpcs/BillRpc/TrunksIousOutInStoreRecord_/TrunksIousOutInStoreRecordRpc.cs @@ -69,13 +69,18 @@ namespace BWP.B3ClientService.Rpcs.BillRpc.TrunksIousOutInStoreRecord_ public static string GetFinalCode(string barCode) { var uri = new Uri(barCode); - return HttpUtility.ParseQueryString(uri.Query)["code"]; + var code = HttpUtility.ParseQueryString(uri.Query)["code"]; + if (!string.IsNullOrEmpty(code)) + CheckCodeRight(code); + return code; } [Rpc] public static long SimpleInsertOrUpdate(long goodsId, string goodsName, string barCode) { - + if (string.IsNullOrEmpty(barCode)) + throw new Exception("条码不能为空"); + CheckCodeRight(barCode); using (var session = Dmo.NewSession()) { var record = GetExist(session, barCode); @@ -114,5 +119,15 @@ namespace BWP.B3ClientService.Rpcs.BillRpc.TrunksIousOutInStoreRecord_ //throw new Exception("存在多条记录,请找管理员"); return null; } + + static void CheckCodeRight(string barCode) + { + var query = new DQueryDom(new JoinAlias(typeof(GradeAndWeight_Detail))); + query.Where.Conditions.Add(DQCondition.EQ("barCode", barCode)); + query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c")); + query.Range = SelectRange.Top(1); + if (query.EExecuteScalar() == null) + throw new Exception("条码不正确"); + } } } diff --git a/B3ClientService/Rpcs/RpcBO/Bill/ClientGoodsSetDto.cs b/B3ClientService/Rpcs/RpcBO/Bill/ClientGoodsSetDto.cs index 0577941..ff51e59 100644 --- a/B3ClientService/Rpcs/RpcBO/Bill/ClientGoodsSetDto.cs +++ b/B3ClientService/Rpcs/RpcBO/Bill/ClientGoodsSetDto.cs @@ -15,6 +15,7 @@ namespace BWP.B3ClientService.Rpcs.RpcBO.Bill public string Goods_Name { get; set; } public string Goods_Code { get; set; } public string Goods_Spec { get; set; } + public string Goods_MainUnit { get; set; } public decimal? StandardWeight { get; set; } public decimal? StandardWeightUp { get; set; } diff --git a/B3ClientService/Tasks/UpdateLoad/UploadMaterialRequisitionRecord.cs b/B3ClientService/Tasks/UpdateLoad/UploadMaterialRequisitionRecord.cs new file mode 100644 index 0000000..88bf4d8 --- /dev/null +++ b/B3ClientService/Tasks/UpdateLoad/UploadMaterialRequisitionRecord.cs @@ -0,0 +1,64 @@ +using BWP.B3ClientService.BO; +using Forks.EnterpriseServices.BusinessInterfaces; +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 System.Threading.Tasks; +using System.Web.Script.Serialization; +using TSingSoft.WebPluginFramework; +using TSingSoft.WebPluginFramework.BWPClients; + +namespace BWP.B3ClientService.Tasks.UpdateLoad +{ + public static class UploadMaterialRequisitionRecord + { + public static void Execute(string uri) + { + //获取所有未上传的数据 + var allBill = GetAllNeedSyncBill(); + foreach (var group in allBill.GroupBy(x => x.Creator)) + { + var bwpClient = new BWPClient(uri, group.Key); + foreach (var item in group) + { + using (var context = new TransactionContext()) + { + var result = bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/ProductTakeOutRpc/InsertOrUpdate", JsonConvert.SerializeObject(item)); + if (result.HasValue) + SetB3ID(context.Session, item.ID, result.Value); + SetSyncd(context.Session, item.ID, item.RowVersion); + context.Commit(); + } + } + } + } + + private static IEnumerable GetAllNeedSyncBill() + { + var query = new DmoQuery(typeof(MaterialRequisitionRecord)); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("IsSubmited", true), DQCondition.EQ("Sync", false))); + return query.EExecuteList().Cast(); + } + + static void SetB3ID(IDmoSession session, long id, long B3ID) + { + var update = new DQUpdateDom(typeof(MaterialRequisitionRecord)); + update.Columns.Add(new DQUpdateColumn("B3ID", B3ID)); + update.Where.Conditions.Add(DQCondition.EQ("ID", id)); + session.ExecuteNonQuery(update); + } + + static void SetSyncd(IDmoSession session, long id, int rowVersion) + { + var update = new DQUpdateDom(typeof(MaterialRequisitionRecord)); + update.Columns.Add(new DQUpdateColumn("Sync", true)); + update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", id), DQCondition.EQ("RowVersion", rowVersion))); + session.ExecuteNonQuery(update); + } + } +} diff --git a/B3ClientService/Tasks/UpdateLoad/UploadTest.cs b/B3ClientService/Tasks/UpdateLoad/UploadTest.cs index f9ea976..de6e57c 100644 --- a/B3ClientService/Tasks/UpdateLoad/UploadTest.cs +++ b/B3ClientService/Tasks/UpdateLoad/UploadTest.cs @@ -27,6 +27,7 @@ namespace BWP.B3ClientService.Tasks UploadSecondOrder.Execute(serverUri); DoCheckBills.Execute(serverUri); UploadTrunksIousOutInStoreRecord.Execute(serverUri); + UploadMaterialRequisitionRecord.Execute(serverUri); } public string Name