using BO.BO; using Forks.JsonRpc.Client; using Forks.JsonRpc.Client.Data; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BO.Utils.BillRpc { public static class WeightBillRpc { public static bool Send(WeightBill bo) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/UploadBill"; var obj = new RpcObject("/MainSystem/B3ClientService/BO/WeightBill"); if (bo.ID == 0) { bo.Creator = ButcherAppContext.Context.UserConfig.UserName; bo.AccountingUnit_ID = ButcherAppContext.Context.UserConfig.AccountingUnit_ID; bo.Department_ID = ButcherAppContext.Context.UserConfig.Department_ID; } obj.Set("Creator", bo.Creator); obj.Set("AccountingUnit_ID", bo.AccountingUnit_ID); obj.Set("Department_ID", bo.Department_ID); //base obj.Set("ID", bo.ID); //bill obj.Set("FinishCreate", bo.FinishCreate); obj.Set("ModifyTime", DateTime.Now); //bill obj.Set("Employee_ID", bo.Employee_ID); obj.Set("Employee_Name", bo.Employee_Name); obj.Set("WeighTime", bo.WeighTime); obj.Set("Supplier_ID", bo.Supplier_ID); obj.Set("Supplier_Name", bo.Supplier_Name); obj.Set("Zone_ID", bo.Zone_ID); obj.Set("Zone_Name", bo.Zone_Name); obj.Set("PurchaseType_ID", bo.PurchaseType_ID); obj.Set("PurchaseType_Name", bo.PurchaseType_Name); obj.Set("Car_ID", bo.Car_ID); obj.Set("Car_Name", bo.Car_Name); obj.Set("LiveVarieties_ID", bo.LiveVarieties_ID); obj.Set("LiveVarieties_Name", bo.LiveVarieties_Name); obj.Set("HogGrade_ID", bo.HogGrade_ID); obj.Set("HogGrade_Name", bo.HogGrade_Name); obj.Set("ShackWeight", bo.ShackWeight); obj.Set("ShackPrice", bo.ShackPrice); obj.Set("AnimalTestNumber", bo.AnimalTestNumber); obj.Set("AnimalTestDate", bo.AnimalTestDate); obj.Set("AnimalTestMan", bo.AnimalTestMan); obj.Set("Remark", bo.Remark); //obj.Set("Inspector_ID", bo.Inspector_ID); //obj.Set("Inspector_Name", bo.Inspector_Name); const string detailErtPath = "/MainSystem/B3ClientService/BO/WeightBill_Detail"; var details = new ManyList(detailErtPath); foreach (var detail in bo.Details) { var objDetail = new RpcObject(detailErtPath); objDetail.Set("ID", detail.ID); objDetail.Set("B3ID", detail.B3ID); objDetail.Set("DeleteState", detail.DeleteState); objDetail.Set("WeightBill_ID", detail.WeightBill_ID); objDetail.Set("Index", detail.Index); objDetail.Set("MaoWeight", detail.MaoWeight); objDetail.Set("PiWeight", detail.PiWeight); objDetail.Set("Weight", detail.Weight); objDetail.Set("Number", detail.Number); details.Add(objDetail); } obj.Set("Details", details); const string farmerDetailErtPath = "/MainSystem/B3ClientService/BO/WeightBill_FarmerDetail"; var farmerDetils = new ManyList(farmerDetailErtPath); foreach (var detail in bo.FarmerDetails) { var objDetail = new RpcObject(farmerDetailErtPath); objDetail.Set("ID", detail.ID); objDetail.Set("B3ID", detail.B3ID); objDetail.Set("DeleteState", detail.DeleteState); objDetail.Set("WeightBill_ID", detail.WeightBill_ID); objDetail.Set("Index", detail.Index); objDetail.Set("Farmer_ID", detail.Farmer_ID); objDetail.Set("Farmer_Name", detail.Farmer_Name); objDetail.Set("Number", detail.Number); farmerDetils.Add(objDetail); } obj.Set("FarmerDetails", farmerDetils); var result = RpcFacade.Call(method, obj); if (bo.ID == 0) bo.ID = result.Get("ID"); var detailReturns = result.Get>("DetailBack"); foreach (var d in detailReturns) { var dFlag = d.Get("Flag"); switch (dFlag) { case "Details": var rdetails = d.Get>("DetailBack"); foreach (var rd in rdetails) { var idx = Convert.ToInt32(rd.Get("Flag")); var first = bo.Details.First(x => x.Index == idx); if (first.ID == 0) { first.ID = rd.Get("ID"); first.WeightBill_ID = bo.ID; } } break; case "FarmerDetails": var rfarmerDetails = d.Get>("DetailBack"); foreach (var rd in rfarmerDetails) { var idx = Convert.ToInt32(rd.Get("Flag")); var first = bo.FarmerDetails.First(x => x.Index == idx); if (first.ID == 0) { first.ID = rd.Get("ID"); first.WeightBill_ID = bo.ID; } } break; } } return true; } public static bool Delete(long id) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/DeleteBill"; return RpcFacade.Call(method, id); } public static List GetWeightBillList(long? carID, long? supplierID) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/GetWeightBillList"; var list = RpcFacade.Call>(method, DateTime.Today, carID, supplierID); var result = new List(); foreach (var obj in list) { var entity = new WeightBill(); result.Add(entity); entity.Creator = obj.Get("Creator"); entity.AccountingUnit_ID = obj.Get("AccountingUnit_ID"); entity.Department_ID = obj.Get("Department_ID"); entity.ID = obj.Get("ID"); entity.B3ID = obj.Get("B3ID"); entity.DeleteState = false; entity.FinishCreate = obj.Get("FinishCreate"); entity.Employee_ID = obj.Get("Employee_ID"); entity.Employee_Name = obj.Get("Employee_Name"); entity.WeighTime = obj.Get("WeighTime"); entity.Supplier_ID = obj.Get("Supplier_ID"); entity.Supplier_Name = obj.Get("Supplier_Name"); entity.Zone_ID = obj.Get("Zone_ID"); entity.Zone_Name = obj.Get("Zone_Name"); entity.PurchaseType_ID = obj.Get("PurchaseType_ID"); entity.PurchaseType_Name = obj.Get("PurchaseType_Name"); entity.Car_ID = obj.Get("Car_ID"); entity.Car_Name = obj.Get("Car_Name"); entity.LiveVarieties_ID = obj.Get("LiveVarieties_ID"); entity.LiveVarieties_Name = obj.Get("LiveVarieties_Name"); entity.HogGrade_ID = obj.Get("HogGrade_ID"); entity.HogGrade_Name = obj.Get("HogGrade_Name"); entity.ShackWeight = obj.Get("ShackWeight"); entity.ShackPrice = obj.Get("ShackPrice"); entity.AnimalTestNumber = obj.Get("AnimalTestNumber"); entity.AnimalTestDate = obj.Get("AnimalTestDate"); entity.AnimalTestMan = obj.Get("AnimalTestMan"); entity.Remark = obj.Get("Remark"); entity.Inspector_ID = obj.Get("Inspector_ID"); entity.Inspector_Name = obj.Get("Inspector_Name"); var details = obj.Get("Details"); foreach (var detail in details) { var d = new WeightBill_Detail(); d.DeleteState = detail.Get("DeleteState"); if (d.DeleteState) continue; entity.Details.Add(d); d.ID = detail.Get("ID"); d.B3ID = detail.Get("B3ID"); d.Index = detail.Get("Index"); d.MaoWeight = detail.Get("MaoWeight"); d.PiWeight = detail.Get("PiWeight"); d.Number = detail.Get("Number"); d.Weight = detail.Get("Weight"); d.WeightBill_ID = detail.Get("WeightBill_ID"); } var farmers = obj.Get("FarmerDetails"); foreach (var detail in farmers) { var d = new WeightBill_FarmerDetail(); d.DeleteState = detail.Get("DeleteState"); if (d.DeleteState) continue; entity.FarmerDetails.Add(d); d.ID = detail.Get("ID"); d.B3ID = detail.Get("B3ID"); d.Index = detail.Get("Index"); d.Farmer_ID = detail.Get("Farmer_ID"); d.Farmer_Name = detail.Get("Farmer_Name"); d.Number = detail.Get("Number"); d.WeightBill_ID = detail.Get("WeightBill_ID"); } } return result; } public static List GetUnHousedBill(DateTime date) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/GetNoHouseInfoWeightBills"; var list = RpcFacade.Call>(method, date); var result = new List(); foreach (var obj in list) { var entity = new WeightBill(); result.Add(entity); var bill = obj.Get("Bill"); entity.ID = bill.Get("ID"); entity.B3ID = bill.Get("B3ID"); entity.Supplier_Name = bill.Get("Supplier_Name"); entity.AlreadyHouse = bill.Get("AlreadyHouse"); entity.FirstWeightNumber = bill.Get("FirstWeightNumber"); var details = obj.Get>("Detail"); //明细接收的数据不全,所以不能全量保存. foreach (var detail in details) { var d = new WeightBill_HouseDetail(); entity.HouseDetails.Add(d); d.LiveColonyHouse_Name = detail.Get("LiveColonyHouse_Name"); } } return result; } public static int UpdateInsertHouseAndSanctionInfo(WeightBill bo) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/UpdateInsertWeightBillHouseDetail"; var obj = new RpcObject("/MainSystem/B3ClientService/BO/WeightBill"); obj.Set("ID", bo.ID); obj.Set("HogGrade_ID", bo.HogGrade_ID); obj.Set("HogGrade_Name", bo.HogGrade_Name); obj.Set("AlreadyHouse", bo.AlreadyHouse); obj.Set("FirstWeightNumber", bo.FirstWeightNumber); obj.Set("Inspector_ID", ButcherAppContext.Context.UserConfig.Employee_ID); obj.Set("Inspector_Name", ButcherAppContext.Context.UserConfig.Employee_Name); const string houseErtPath = "/MainSystem/B3ClientService/BO/WeightBill_HouseDetail"; var houseDetails = new ManyList(houseErtPath); foreach (var detail in bo.HouseDetails) { var objDetail = new RpcObject(houseErtPath); objDetail.Set("WeightBill_ID", detail.WeightBill_ID); objDetail.Set("Index", detail.Index); objDetail.Set("LiveColonyHouse_ID", detail.LiveColonyHouse_ID); objDetail.Set("LiveColonyHouse_Name", detail.LiveColonyHouse_Name); objDetail.Set("Number", detail.Number); houseDetails.Add(objDetail); } obj.Set("HouseDetails", houseDetails); const string sanctionsErtPath = "/MainSystem/B3ClientService/BO/WeightBill_SanctionDetail"; var sanctionDetails = new ManyList(sanctionsErtPath); foreach (var detail in bo.SanctionDetails) { var objDetail = new RpcObject(sanctionsErtPath); objDetail.Set("WeightBill_ID", detail.WeightBill_ID); objDetail.Set("Index", detail.Index); objDetail.Set("Sanction_ID", detail.Sanction_ID); objDetail.Set("AbnormalItem_ID", detail.AbnormalItem_ID); objDetail.Set("AbnormalItem_Name", detail.AbnormalItem_Name); objDetail.Set("Number", detail.Number); sanctionDetails.Add(objDetail); } obj.Set("SanctionDetails", sanctionDetails); return RpcFacade.Call(method, obj); } public static int GetDetailTotalNumber(DateTime date) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/GetDetailTotalNumber"; return RpcFacade.Call(method, date); } public static List> SyncBillB3Ids(List ids) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/SyncBillB3Ids"; return RpcFacade.Call>>(method, ids.ToArray()); } public static List> SyncWeightDetailB3Ids(List ids) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/SyncWeightDetailB3Ids"; return RpcFacade.Call>>(method, ids); } public static List> SyncFarmerDetailB3Ids(List ids) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/SyncFarmerDetailB3Ids"; return RpcFacade.Call>>(method, ids); } public static List> SyncWeightDetailFirstNumber(List ids) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/SyncWeightDetailFirstNumber"; return RpcFacade.Call>>(method, ids); } public static WeightBill GetWeightBillOnHousePage(long id) { const string method = "/MainSystem/B3ClientService/Rpcs/BillRpc/WeightBillRpc/GetWeightBillOnHousePage"; var obj = RpcFacade.Call(method, id); var entity = new WeightBill(); var bill = obj.Get("Bill"); entity.FirstWeightNumber = bill.Get("FirstWeightNumber"); entity.HogGrade_ID = bill.Get("HogGrade_ID"); var details = obj.Get>("Detail"); //明细接收的数据不全,所以不能全量保存. foreach (var detail in details) { var d = new WeightBill_HouseDetail(); entity.HouseDetails.Add(d); d.ID = detail.Get("ID"); d.LiveColonyHouse_ID = detail.Get("LiveColonyHouse_ID"); } var sanctionDetail = obj.Get>("SanctionDetail"); //明细接收的数据不全,所以不能全量保存. foreach (var detail in sanctionDetail) { var d = new WeightBill_SanctionDetail(); entity.SanctionDetails.Add(d); d.ID = detail.Get("ID"); d.AbnormalItem_ID = detail.Get("AbnormalItem_ID"); d.Number = detail.Get("Number"); } return entity; } } }