using ButcherFactory.BO.Utils; using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; using Forks.JsonRpc.Client; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ButcherFactory.BO.LocalBL { public static class SegmentSaleOutBL { const string RpcPath = @"/MainSystem/B3Sale/Rpcs/"; const string MESPath = @"/MainSystem/B3ClientService/Rpcs/"; public static BindingList GetSaleOutStoreList(DateTime sendDate, long? deliverGoodsLineID, long? customerID, int billState, long? storeID, bool already = false) { return CarcassSaleOutBL.GetSaleOutStoreList(sendDate, deliverGoodsLineID, customerID, billState, storeID, already); } public static BindingList GetSaleOutStoreDetailList(long id) { return CarcassSaleOutBL.GetSaleOutStoreDetailList(id); } public static bool HasNoAssignDetail(long billID) { return CarcassSaleOutBL.HasNoAssignDetail(billID); } public static BindingList GetWeightRecord(long detailID) { var query = new DmoQuery(typeof(SegmentSaleOut_Detail)); query.Where.Conditions.Add(DQCondition.EQ("DetailID", detailID)); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); var list = query.EExecuteList().Cast().ToList(); var idx = list.Count; foreach (var item in list) { item.Idx = idx; idx--; } return new BindingList(list); } public static SegmentSaleOut_Detail Insert(decimal weight) { using (var session = DmoSession.New()) { var detail = new SegmentSaleOut_Detail() { Number = weight, SecondNumber = 1 }; session.Insert(detail); session.Commit(); return detail; } } public static List GetBatchFromEMS() { return CarcassSaleOutBL.GetBatchFromEMS(1); } static void SubmitDetails(IDmoSession session, IEnumerable details, SaleOutStore_Detail detail, int flag) { var arr = details.Select(x => new WeightRecord { Flag = flag, ID = x.ID, WeightTime = x.Time, MainUnitNum = x.Number, SecondNumber = x.SecondNumber, ProductBatch_ID = x.ProductBatch_ID, BarCode = x.BarCode }); var json = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/SaveWeightRecord", JsonConvert.SerializeObject(arr), detail.ID); var back = JsonConvert.DeserializeObject>>(json); foreach (var item in details) { var first = back.Item3.First(x => x.LongExt1 == item.ID); Update(session, item.ID, new Tuple("WeightRecord_ID", first.LongExt2), new Tuple("ScanRecord_ID", first.LongExt3) ); } } static void Update(IDmoSession session, long id, params Tuple[] pops) { var update = new DQUpdateDom(typeof(SegmentSaleOut_Detail)); foreach (var item in pops) update.Columns.Add(new DQUpdateColumn(item.Item1, item.Item2)); update.Where.Conditions.Add(DQCondition.EQ("ID", id)); session.ExecuteNonQuery(update); } public static void SetGoodsFinish(long id) { CarcassSaleOutBL.SetGoodsFinish(id); } public static void SetGoodsUnFinish(long id) { CarcassSaleOutBL.SetGoodsUnFinish(id); } static void Delete(long id) { var delete = new DQDeleteDom(typeof(SegmentSaleOut_Detail)); delete.Where.Conditions.Add(DQCondition.EQ("ID", id)); delete.EExecute(); } public static void AddAndUpdate(SegmentSaleOut_Detail detail) { using (var session = DmoSession.New()) { session.Insert(detail); var arr = new List { new WeightRecord { Flag = 2, ID = detail.ID, WeightTime = detail.Time, MainUnitNum = detail.Number, SecondNumber = detail.SecondNumber } }; var json = RpcFacade.Call(RpcPath + "SaleOutStoreRpc/SaveWeightRecord", JsonConvert.SerializeObject(arr), detail.DetailID); var back = JsonConvert.DeserializeObject>>(json); var first = back.Item3.First(); Update(session, detail.ID, new Tuple("WeightRecord_ID", first.LongExt2), new Tuple("ScanRecord_ID", first.LongExt3) ); session.Commit(); } } public static void DeleteAndUpdate(SegmentSaleOut_Detail tag) { var json = JsonConvert.SerializeObject(new List() { new ExtensionObj { LongExt1 = tag.DetailID, LongExt2 = tag.WeightRecord_ID, LongExt3 = tag.ScanRecord_ID } }); RpcFacade.Call(RpcPath + "SaleOutStoreRpc/DeleteAndUpdate", json); Delete(tag.ID); } public static void InsertByCode(SaleOutStore_Detail orderDetail, SegmentSaleOut_Detail detail) { var json = ButcherFactoryUtil.SecondUrlCall(MESPath + "SegmentSaleOutStoreRpc/GetSegmentInfo", detail.BarCode); var scanInfo = JsonConvert.DeserializeObject(json); if (scanInfo.StringExt1 != orderDetail.Goods_Code) throw new Exception("扫码明细与发货明细 存货不一致!"); detail.BillID = orderDetail.SaleOutStore_ID; detail.DetailID = orderDetail.ID; detail.Goods_ID = orderDetail.Goods_ID; detail.Goods_Code = orderDetail.Goods_Code; detail.Goods_Name = orderDetail.Goods_Name; detail.Number = scanInfo.DecimalExt1.Value; if (orderDetail.Number.HasValue && orderDetail.SecondNumber.HasValue && orderDetail.Number != 0) detail.SecondNumber = decimal.Round(orderDetail.SecondNumber.Value * detail.Number / orderDetail.Number.Value, 2); detail.Operator = "扫码发货"; using (var session = DmoSession.New()) { session.Insert(detail); SubmitDetails(session, new SegmentSaleOut_Detail[] { detail }, orderDetail, 1); session.Commit(); } } public static void InsertReadWeight(SaleOutStore_Detail orderDetail, SegmentSaleOut_Detail detail) { detail.BillID = orderDetail.SaleOutStore_ID; detail.DetailID = orderDetail.ID; detail.Goods_ID = orderDetail.Goods_ID; detail.Goods_Code = orderDetail.Goods_Code; detail.Goods_Name = orderDetail.Goods_Name; if (orderDetail.Number.HasValue && orderDetail.SecondNumber.HasValue && orderDetail.Number != 0) detail.SecondNumber = decimal.Round(orderDetail.SecondNumber.Value * detail.Number / orderDetail.Number.Value, 2); detail.Operator = "读入重量"; using (var session = DmoSession.New()) { session.Insert(detail); SubmitDetails(session, new SegmentSaleOut_Detail[] { detail }, orderDetail, 2); session.Commit(); } } public static bool BarCodeUsed(string barCode) { var query = new DQueryDom(new JoinAlias(typeof(SegmentSaleOut_Detail))); query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode)); query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c")); return query.EExecuteScalar() != null; } } }