From 1ff23f1b47be94a4089c938028be3ef5cb26e424 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Mon, 4 Jun 2018 20:21:56 +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 + .../BO/MiniProgram/SendPigRecord.cs | 45 ++++ B3ClientService/BO/MiniProgram/WeiUserBind.cs | 15 ++ B3ClientService/OfflinRpc/MiniProgramRpc.cs | 223 ++++++++++++++++++ .../Tasks/SyncCarcassInStoreToTrackBack.cs | 16 +- 5 files changed, 299 insertions(+), 3 deletions(-) create mode 100644 B3ClientService/BO/MiniProgram/SendPigRecord.cs create mode 100644 B3ClientService/BO/MiniProgram/WeiUserBind.cs create mode 100644 B3ClientService/OfflinRpc/MiniProgramRpc.cs diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index 0b1f49b..4fde668 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -175,6 +175,8 @@ + + @@ -205,6 +207,7 @@ + diff --git a/B3ClientService/BO/MiniProgram/SendPigRecord.cs b/B3ClientService/BO/MiniProgram/SendPigRecord.cs new file mode 100644 index 0000000..ee7cfe1 --- /dev/null +++ b/B3ClientService/BO/MiniProgram/SendPigRecord.cs @@ -0,0 +1,45 @@ +using BWP.B3Frameworks.BO; +using Forks.EnterpriseServices.DomainObjects2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BWP.B3ClientService.BO +{ + public class SendPigRecord : Base + { + public long userID { get; set; } + public string date { get; set; } + public string time { get; set; } + public int bType { get; set; } + public string carNum { get; set; } + public string carIDCard { get; set; } + public string supplier { get; set; } + public string supplierIDCard { get; set; } + public string receive { get; set; } + public string bank { get; set; } + public string bankNum { get; set; } + public int num { get; set; } + public decimal weight { get; set; } + public decimal price { get; set; } + public decimal money { get; set; } + public decimal? pweight { get; set; } + public decimal? pprice { get; set; } + public decimal? pmoney { get; set; } + public decimal? jjf { get; set; } + + [NonDmoProperty] + public FarmerRecord[] farmers { get; set; } + } + + public class FarmerRecord : Base + { + public long SendPigRecord_ID { get; set; } + public int fidx { get; set; } + public string fName { get; set; } + public string fTel { get; set; } + public string fAddress { get; set; } + public string fIDCard { get; set; } + } +} diff --git a/B3ClientService/BO/MiniProgram/WeiUserBind.cs b/B3ClientService/BO/MiniProgram/WeiUserBind.cs new file mode 100644 index 0000000..b80f0c9 --- /dev/null +++ b/B3ClientService/BO/MiniProgram/WeiUserBind.cs @@ -0,0 +1,15 @@ +using BWP.B3Frameworks.BO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BWP.B3ClientService.BO +{ + public class WeiUserBind : Base + { + public string WeiID { get; set; } + + public string Name { get; set; } + } +} diff --git a/B3ClientService/OfflinRpc/MiniProgramRpc.cs b/B3ClientService/OfflinRpc/MiniProgramRpc.cs new file mode 100644 index 0000000..8ac8c5f --- /dev/null +++ b/B3ClientService/OfflinRpc/MiniProgramRpc.cs @@ -0,0 +1,223 @@ +using BWP.B3ClientService.BO; +using BWP.B3Frameworks.Utils; +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.IO; +using System.Linq; +using System.Net; +using System.Text; +using TSingSoft.WebPluginFramework; + +namespace BWP.B3ClientService.Rpcs +{ + [Rpc] + public static class MiniProgramRpc + { + [Rpc(RpcFlags.SkipAuth)] + public static WeiUserBind GetBindID(string code) + { + var url = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&grant_type=authorization_code&js_code={2}"; + var request = (HttpWebRequest)WebRequest.Create(string.Format(url, "wx106e1fc979e5fad5", "57883555a451434569cbcb58d2047aac", code)); + var response = request.GetResponse(); + using (var stream = response.GetResponseStream()) + { + using (var reader = new StreamReader(stream, Encoding.UTF8)) + { + var weiID = JsonConvert.DeserializeObject(reader.ReadToEnd()).openid; + var user = GetBindWeiUser(weiID); + if (user == null) + user = new WeiUserBind { WeiID = weiID }; + return user; + } + } + } + + [Rpc(RpcFlags.SkipAuth)] + public static long InsertBind(string json) + { + var entity = JsonConvert.DeserializeObject(json); + using (var session = Dmo.NewSession()) + { + session.Insert(entity); + session.Commit(); + } + return entity.ID; + } + + static WeiUserBind GetBindWeiUser(string weiID) + { + var query = new DmoQuery(typeof(WeiUserBind)); + query.Where.Conditions.Add(DQCondition.EQ("WeiID", weiID)); + return query.EExecuteScalar(); + } + + [Rpc(RpcFlags.SkipAuth)] + public static string GetLastInfo(long id) + { + var query = new DQueryDom(new JoinAlias(typeof(SendPigRecord))); + query.Columns.Add(DQSelectColumn.Field("bType")); + query.Columns.Add(DQSelectColumn.Field("carNum")); + query.Columns.Add(DQSelectColumn.Field("carIDCard")); + query.Columns.Add(DQSelectColumn.Field("supplier")); + query.Columns.Add(DQSelectColumn.Field("supplierIDCard")); + query.Columns.Add(DQSelectColumn.Field("receive")); + query.Columns.Add(DQSelectColumn.Field("bank")); + query.Columns.Add(DQSelectColumn.Field("bankNum")); + query.Where.Conditions.Add(DQCondition.EQ("userID", id)); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); + query.Range = SelectRange.Top(1); + var entity = new MinDmo() { bType = 0 }; + using (var session = Dmo.NewSession()) + { + using (var reader = session.ExecuteReader(query)) + { + if (reader.Read()) + { + entity.bType = (int)reader[0]; + entity.carNum = (string)reader[1]; + entity.carIDCard = (string)reader[2]; + entity.supplier = (string)reader[3]; + entity.supplierIDCard = (string)reader[4]; + entity.receive = (string)reader[5]; + entity.bank = (string)reader[6]; + entity.bankNum = (string)reader[7]; + } + } + } + return JsonConvert.SerializeObject(entity); + } + + [Rpc(RpcFlags.SkipAuth)] + public static long Submit(string json) + { + var entity = JsonConvert.DeserializeObject(json); + using (var session = Dmo.NewSession()) + { + session.Insert(entity); + foreach (var item in entity.farmers) + { + item.SendPigRecord_ID = entity.ID; + session.Insert(item); + } + session.Commit(); + } + + return entity.ID; + } + + [Rpc(RpcFlags.SkipAuth)] + public static string GetHistoryList(int type, long userID) + { + var query = new DQueryDom(new JoinAlias(typeof(SendPigRecord))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("date")); + query.Columns.Add(DQSelectColumn.Field("supplier")); + query.Columns.Add(DQSelectColumn.Field("carNum")); + query.Where.Conditions.Add(DQCondition.EQ("userID", userID)); + var list = new List(); + using (var session = Dmo.NewSession()) + { + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var entity = new HistoryObj(); + entity.ID = (long)reader[0]; + entity.Date = (string)reader[1]; + entity.Supplier = (string)reader[2]; + entity.Car = (string)reader[3]; + list.Add(entity); + } + } + } + return JsonConvert.SerializeObject(list); + } + + [Rpc(RpcFlags.SkipAuth)] + public static string GetRecord(long id, long userID) + { + var query = new DmoQuery(typeof(SendPigRecord)); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", id), DQCondition.EQ("userID", userID))); + var entity = query.EExecuteScalar(); + var detail = new DmoQuery(typeof(FarmerRecord)); + detail.Where.Conditions.Add(DQCondition.EQ("SendPigRecord_ID", id)); + var list = detail.EExecuteList().Cast(); + entity.farmers = list.ToArray(); + return JsonConvert.SerializeObject(entity); + } + + [Rpc(RpcFlags.SkipAuth)] + public static long Save(string json) + { + var entity = JsonConvert.DeserializeObject(json); + using (var session = Dmo.NewSession()) + { + var dids = entity.farmers.Select(x => x.ID).Where(x => x > 0); + Delete(session, entity.ID, dids); + session.Update(entity); + foreach (var item in entity.farmers) + { + if (item.ID == 0) + { + item.SendPigRecord_ID = entity.ID; + session.Insert(item); + } + else + session.Update(item); + } + session.Commit(); + } + + return entity.ID; + } + + static void Delete(IDmoSession session, long id, IEnumerable exist) + { + var delete = new DQDeleteDom(typeof(FarmerRecord)); + delete.Where.Conditions.Add(DQCondition.EQ("SendPigRecord_ID", id)); + if (exist.Any()) + delete.Where.Conditions.Add(DQCondition.NotInList(DQExpression.Field("ID"), exist.Select(x => DQExpression.Value(x)).ToArray())); + session.ExecuteNonQuery(delete); + } + } + + class HistoryObj + { + public long ID { get; set; } + + public string Date { get; set; } + + public string Supplier { get; set; } + + public string Car { get; set; } + } + + class MinDmo + { + public int bType { get; set; } + + public string carNum { get; set; } + + public string carIDCard { get; set; } + + public string supplier { get; set; } + + public string supplierIDCard { get; set; } + + public string receive { get; set; } + + public string bank { get; set; } + + public string bankNum { get; set; } + } + + class WeiSer + { + public string openid { get; set; } + } +} diff --git a/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs b/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs index 9e31931..6ef54a9 100644 --- a/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs +++ b/B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs @@ -40,7 +40,7 @@ namespace BWP.B3ClientService.Tasks var arr = JsonConvert.SerializeObject(infos); TraceBackInfoUtil.Insert(sUrl, arr); } - DeleteSyncd (session, list.Min(x => x.ID), list.Max(x => x.ID),"ID"); + DeleteSyncd(session, list.Min(x => x.ID), list.Max(x => x.ID), "ID"); } List GetUnSyncdInfo(IDmoSession session) @@ -54,10 +54,12 @@ namespace BWP.B3ClientService.Tasks return list.Select(x => new TraceBackInStoreInfo { ID = x.Item1, Code = x.Item2, InStoreDate = x.Item3 }).ToList(); } - void DeleteSyncd(IDmoSession session, long min, long max,string idF) + void DeleteSyncd(IDmoSession session, long min, long max, string idF, IDQExpression condition = null) { var delete = new DQDeleteDom(typeof(T)); delete.Where.Conditions.Add(DQCondition.Between(idF, min, max)); + if (condition != null) + delete.Where.Conditions.Add(condition); session.ExecuteNonQuery(delete); } @@ -69,17 +71,25 @@ namespace BWP.B3ClientService.Tasks return; var arr = JsonConvert.SerializeObject(list); TraceBackInfoUtil.Insert(sUrl, arr); - DeleteSyncd(session, list.Min(x => x.GID), list.Max(x => x.GID), "GID"); + DeleteSyncd(session, list.Min(x => x.GID), list.Max(x => x.GID), "GID", DQCondition.IsNotNull(DQExpression.Field("Farmer"))); } IEnumerable GetTraceBackInfo(IDmoSession session) { + FillNoFarmerInfo(session); var query = new DmoQuery(typeof(ButcherTraceBackInfo)); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("GID")); + query.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field("Farmer"))); query.Range = SelectRange.Top(500); return session.ExecuteList(query).Cast(); } + void FillNoFarmerInfo(IDmoSession session) + { + var sql = "update main set main.Farmer=f.Name,main.PigFarmAddress=f.Address,main.TestingMan=wb.AnimalTestMan,main.TestingNo =wb.AnimalTestNumber from B3ClientService_ButcherTraceBackInfo main left outer join B3ClientService_GradeAndWeight_Detail gaw on main.GID=gaw.ID left outer join B3ClientService_OrderDetail od on gaw.OrderDetail_ID = od.ID left outer join B3ClientService_WeightBill wb on od.WeightBill_ID=wb.ID left outer join B3ClientService_WeightBill_FarmerDetail wbf on wb.ID=wbf.WeightBill_ID left outer join B3ClientService_Farmer f on wbf.Farmer_ID=f.ID where main.Farmer is null and f.Name is not null"; + session.ExecuteSqlNonQuery(sql); + } + public string Name { get { return "抽取白条信息到追溯服务器"; }