|
|
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 CarcassSaleOutBL
|
|
|
{
|
|
|
const string RpcPath = @"/MainSystem/B3Sale/Rpcs/";
|
|
|
const string MESPath = @"/MainSystem/B3ClientService/Rpcs/";
|
|
|
|
|
|
public static BindingList<SaleOutStore> GetSaleOutStoreList(DateTime sendDate, long? deliverGoodsLineID, long? customerID, int billState, long? storeID, bool already = false)
|
|
|
{
|
|
|
var json = RpcFacade.Call<string>(RpcPath + "SaleOutStoreRpc/GetSaleOutStoreList", sendDate, billState, deliverGoodsLineID, customerID, storeID, already);
|
|
|
var list = JsonConvert.DeserializeObject<List<SaleOutStore>>(json);
|
|
|
return new BindingList<SaleOutStore>(list);
|
|
|
}
|
|
|
|
|
|
public static BindingList<SaleOutStore_Detail> GetSaleOutStoreDetailList(long id)
|
|
|
{
|
|
|
var json = RpcFacade.Call<string>(RpcPath + "SaleOutStoreRpc/GetSaleOutStoreDetailList", id);
|
|
|
var list = JsonConvert.DeserializeObject<List<SaleOutStore_Detail>>(json);
|
|
|
return new BindingList<SaleOutStore_Detail>(list);
|
|
|
}
|
|
|
|
|
|
public static BindingList<CarcassSaleOut_Detail> GetWeightRecord(long detailID)
|
|
|
{
|
|
|
var query = new DmoQuery(typeof(CarcassSaleOut_Detail));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("DetailID", detailID));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true));
|
|
|
var list = query.EExecuteList().Cast<CarcassSaleOut_Detail>().ToList();
|
|
|
var idx = list.Count;
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
item.Idx = idx;
|
|
|
idx--;
|
|
|
}
|
|
|
return new BindingList<CarcassSaleOut_Detail>(list);
|
|
|
}
|
|
|
|
|
|
public static CarcassSaleOut_Detail Insert(decimal weight)
|
|
|
{
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
var detail = new CarcassSaleOut_Detail() { Weight = weight, Number = 1 };
|
|
|
session.Insert(detail);
|
|
|
session.Commit();
|
|
|
return detail;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static BindingList<CarcassSaleOut_Detail> GetUnSubmitWeightRecord()
|
|
|
{
|
|
|
var query = new DmoQuery(typeof(CarcassSaleOut_Detail));
|
|
|
query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("DetailID")));
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true));
|
|
|
var list = query.EExecuteList().Cast<CarcassSaleOut_Detail>().ToList();
|
|
|
var idx = list.Count;
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
item.Idx = idx;
|
|
|
idx--;
|
|
|
}
|
|
|
return new BindingList<CarcassSaleOut_Detail>(list);
|
|
|
}
|
|
|
|
|
|
public static void FillDetail(CarcassSaleOut_Detail first, string barCode, long? batchID)
|
|
|
{
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
var list = new List<Tuple<string, object>>();
|
|
|
if (barCode.StartsWith("G"))
|
|
|
{
|
|
|
var arr = barCode.TrimStart('G').Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
var gid = long.Parse(arr[0]);
|
|
|
var gInfo = GetGoodsInfo(gid);
|
|
|
first.Goods_ID = gid;
|
|
|
first.Goods_Name = gInfo.Item1;
|
|
|
first.Goods_Code = gInfo.Item2;
|
|
|
first.ProductBatch_ID = batchID;
|
|
|
if (arr.Length == 2)
|
|
|
{
|
|
|
first.Number = 0.5m;
|
|
|
list.Add(new Tuple<string, object>("Number", first.Number));
|
|
|
}
|
|
|
list.Add(new Tuple<string, object>("ProductBatch_ID", first.ProductBatch_ID));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var json = ButcherFactoryUtil.SimpleMESCall<string>(MESPath + "CarcassSaleOutStoreRpc/GetCarcassInstoreInfo", barCode);
|
|
|
var mesInfo = JsonConvert.DeserializeObject<SaleOutCarcassObj>(json);
|
|
|
if (!string.IsNullOrEmpty(mesInfo.Goods_Code))
|
|
|
{
|
|
|
if (mesInfo.Goods_Code == "X002")
|
|
|
mesInfo.Goods_Code = "0001";
|
|
|
var gInfo = GetGoodsInfo(mesInfo.Goods_Code);
|
|
|
first.Goods_Code = mesInfo.Goods_Code;
|
|
|
first.InStoreWeight = mesInfo.InStoreWeight;
|
|
|
first.Goods_ID = gInfo.Item1;
|
|
|
first.Goods_Name = gInfo.Item2;
|
|
|
}
|
|
|
first.BarCode = barCode;
|
|
|
list.Add(new Tuple<string, object>("BarCode", first.BarCode));
|
|
|
list.Add(new Tuple<string, object>("InStoreWeight", first.InStoreWeight));
|
|
|
}
|
|
|
first.Filled = true;
|
|
|
list.Add(new Tuple<string, object>("Goods_ID", first.Goods_ID));
|
|
|
list.Add(new Tuple<string, object>("Goods_Name", first.Goods_Name));
|
|
|
list.Add(new Tuple<string, object>("Goods_Code", first.Goods_Code));
|
|
|
list.Add(new Tuple<string, object>("Filled", first.Filled));
|
|
|
Update(session, first.ID, list.ToArray());
|
|
|
session.Commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void UpdateWeightNumber(long id, decimal number)
|
|
|
{
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
Update(session, id, new Tuple<string, object>("Number", number));
|
|
|
session.Commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void Update(IDmoSession session, long id, params Tuple<string, object>[] pops)
|
|
|
{
|
|
|
var update = new DQUpdateDom(typeof(CarcassSaleOut_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);
|
|
|
}
|
|
|
|
|
|
static Dictionary<long, Tuple<string, string>> goodsIdInfo = new Dictionary<long, Tuple<string, string>>();
|
|
|
static Tuple<string, string> GetGoodsInfo(long id)
|
|
|
{
|
|
|
if (!goodsIdInfo.ContainsKey(id))
|
|
|
{
|
|
|
var json = RpcFacade.Call<string>(RpcPath + "BaseInfoSelectRpc/GetGoodsInfo", "ID", id);
|
|
|
var g = JsonConvert.DeserializeObject<ExtensionObj>(json);
|
|
|
if (g.LongExt1 == null)
|
|
|
throw new Exception("没有找到存货No." + id);
|
|
|
goodsIdInfo.Add(id, new Tuple<string, string>(g.StringExt1, g.StringExt2));
|
|
|
}
|
|
|
return goodsIdInfo[id];
|
|
|
}
|
|
|
|
|
|
static Dictionary<string, Tuple<long, string>> goodsCodeInfo = new Dictionary<string, Tuple<long, string>>();
|
|
|
public static Tuple<long, string> GetGoodsInfo(string code)
|
|
|
{
|
|
|
if (!goodsCodeInfo.ContainsKey(code))
|
|
|
{
|
|
|
var json = RpcFacade.Call<string>(RpcPath + "BaseInfoSelectRpc/GetGoodsInfo", "Code", code);
|
|
|
var g = JsonConvert.DeserializeObject<ExtensionObj>(json);
|
|
|
if (g.LongExt1 == null)
|
|
|
throw new Exception("没有找到存货编码 " + code);
|
|
|
goodsCodeInfo.Add(code, new Tuple<long, string>(g.LongExt1.Value, g.StringExt1));
|
|
|
}
|
|
|
return goodsCodeInfo[code];
|
|
|
}
|
|
|
|
|
|
public static List<ProductBatch> GetBatchFromEMS()
|
|
|
{
|
|
|
var json = ButcherFactoryUtil.SimpleMESCall<string>(MESPath + "SyncBaseInfoRpc/GetProductBatch", 9);
|
|
|
return JsonConvert.DeserializeObject<List<ProductBatch>>(json);
|
|
|
}
|
|
|
|
|
|
public static void SubmitDetails(IEnumerable<CarcassSaleOut_Detail> details, SaleOutStore_Detail detail)
|
|
|
{
|
|
|
var arr = details.Select(x => new WeightRecord { ID = x.ID, WeightTime = x.Time, MainUnitNum = x.Weight, SecondNumber = x.Number, ProductBatch_ID = x.ProductBatch_ID, BarCode = x.BarCode });
|
|
|
var json = RpcFacade.Call<string>(RpcPath + "SaleOutStoreRpc/SaveWeightRecord", JsonConvert.SerializeObject(arr), detail.ID);
|
|
|
var back = JsonConvert.DeserializeObject<List<ExtensionObj>>(json);
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
foreach (var item in details)
|
|
|
{
|
|
|
var first = back.First(x => x.LongExt1 == item.ID);
|
|
|
|
|
|
Update(session, item.ID, new Tuple<string, object>("BillID", detail.SaleOutStore_ID),
|
|
|
new Tuple<string, object>("DetailID", detail.ID),
|
|
|
new Tuple<string, object>("WeightRecord_ID", first.LongExt2),
|
|
|
new Tuple<string, object>("ScanRecord_ID", first.LongExt3)
|
|
|
);
|
|
|
}
|
|
|
session.Commit();
|
|
|
}
|
|
|
detail.SNumber = (detail.SNumber ?? 0) + details.Sum(x => x.Weight);
|
|
|
detail.SSecondNumber = (detail.SSecondNumber ?? 0) + details.Sum(x => x.Number);
|
|
|
}
|
|
|
|
|
|
public static void SaveAssignNum(long id, decimal number)
|
|
|
{
|
|
|
RpcFacade.Call<int>(RpcPath + "SaleOutStoreRpc/SaveAssignNum", id, number);
|
|
|
}
|
|
|
|
|
|
public static void SetGoodsFinish(long id)
|
|
|
{
|
|
|
RpcFacade.Call<int>(RpcPath + "SaleOutStoreRpc/SetFinishAssignState", id, true);
|
|
|
}
|
|
|
|
|
|
public static void SetGoodsUnFinish(long id)
|
|
|
{
|
|
|
RpcFacade.Call<int>(RpcPath + "SaleOutStoreRpc/SetFinishAssignState", id, false);
|
|
|
}
|
|
|
|
|
|
public static void Delete(long id)
|
|
|
{
|
|
|
var delete = new DQDeleteDom(typeof(CarcassSaleOut_Detail));
|
|
|
delete.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
|
delete.EExecute();
|
|
|
}
|
|
|
|
|
|
public static void AddAndUpdate(CarcassSaleOut_Detail detail)
|
|
|
{
|
|
|
using (var session = DmoSession.New())
|
|
|
{
|
|
|
session.Insert(detail);
|
|
|
var arr = new List<WeightRecord> { new WeightRecord { ID = detail.ID, WeightTime = detail.Time, MainUnitNum = detail.Weight, SecondNumber = detail.Number } };
|
|
|
var json = RpcFacade.Call<string>(RpcPath + "SaleOutStoreRpc/SaveWeightRecord", JsonConvert.SerializeObject(arr), detail.DetailID);
|
|
|
var back = JsonConvert.DeserializeObject<List<ExtensionObj>>(json);
|
|
|
|
|
|
var first = back.First();
|
|
|
|
|
|
Update(session, detail.ID, new Tuple<string, object>("WeightRecord_ID", first.LongExt2),
|
|
|
new Tuple<string, object>("ScanRecord_ID", first.LongExt3)
|
|
|
);
|
|
|
|
|
|
session.Commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void DeleteAndUpdate(CarcassSaleOut_Detail tag)
|
|
|
{
|
|
|
var json = JsonConvert.SerializeObject(new ExtensionObj { LongExt1 = tag.DetailID, LongExt2 = tag.WeightRecord_ID, LongExt3 = tag.ScanRecord_ID });
|
|
|
RpcFacade.Call<int>(RpcPath + "SaleOutStoreRpc/DeleteAndUpdate", json);
|
|
|
Delete(tag.ID);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class SaleOutCarcassObj
|
|
|
{
|
|
|
public string Goods_Code { get; set; }
|
|
|
|
|
|
public decimal? InStoreWeight { get; set; }
|
|
|
}
|
|
|
|
|
|
class WeightRecord
|
|
|
{
|
|
|
public long ID { get; set; }
|
|
|
public string BarCode { get; set; }
|
|
|
public long? ProductBatch_ID { get; set; }
|
|
|
public DateTime WeightTime { get; set; }
|
|
|
public decimal? MainUnitNum { get; set; }
|
|
|
public decimal? SecondNumber { get; set; }
|
|
|
}
|
|
|
}
|