|
|
using BWP.B3ClientService.BO;
|
|
|
using BWP.B3ClientService.Tasks.UpdateLoad;
|
|
|
using BWP.B3Frameworks.Utils;
|
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
|
using Forks.EnterpriseServices.JsonRpc;
|
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
|
using Forks.JsonRpc.Client.Data;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Web.Script.Serialization;
|
|
|
using TSingSoft.WebPluginFramework;
|
|
|
|
|
|
namespace BWP.B3ClientService.Rpcs.BillRpc
|
|
|
{
|
|
|
[Rpc]
|
|
|
public static class WeightBillRpc
|
|
|
{
|
|
|
static JavaScriptSerializer serializer = new JavaScriptSerializer();
|
|
|
|
|
|
[Rpc]
|
|
|
public static string GetWeightBillList(DateTime date, long? carID, long? supplierID)
|
|
|
{
|
|
|
var main = new JoinAlias(typeof(WeightBill));
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail));
|
|
|
var query = new DQueryDom(main);
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.And(DQCondition.EQ(detail, "DeleteState", false), DQCondition.EQ(main, "ID", detail, "WeightBill_ID")));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Car_Name"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Employee_Name"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("PurchaseType_Name"));//5
|
|
|
query.Columns.Add(DQSelectColumn.Field("HouseNames"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("SanctionMoney"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Remark"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Weight", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Create(DQExpression.LogicCase(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field(detail, "PiWeight")), DQCondition.IsNotNull(DQExpression.Field(detail, "MaoWeight"))), DQExpression.Value(1), DQExpression.Value(0)), "FinishWeight"));
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.Between("WeighTime", date, date + new TimeSpan(23, 59, 29)), DQCondition.EQ("DeleteState", false)));
|
|
|
if (carID.HasValue)
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Car_ID", carID));
|
|
|
if (supplierID.HasValue)
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Supplier_ID", supplierID));
|
|
|
var list = new List<WeightBillList>();
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
using (var reader = session.ExecuteReader(query))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
var entity = new WeightBillList();
|
|
|
entity.ID = (long)reader[0];
|
|
|
entity.B3ID = (long?)reader[1];
|
|
|
entity.Car_Name = (string)reader[2];
|
|
|
entity.Supplier_Name = (string)reader[3];
|
|
|
entity.Employee_Name = (string)reader[4];
|
|
|
entity.PurchaseType_Name = (string)reader[5];
|
|
|
entity.HouseNames = (string)reader[6];
|
|
|
entity.SanctionMoney = (decimal?)reader[7];
|
|
|
entity.Remark = (string)reader[8];
|
|
|
entity.Number = (int?)reader[9];
|
|
|
entity.Weight = (decimal?)reader[10];
|
|
|
entity.FinishWeight = Convert.ToBoolean(reader[11]);
|
|
|
list.Add(entity);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return serializer.Serialize(list);
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static string Load(long id)
|
|
|
{
|
|
|
var query = new DmoQuery(typeof(WeightBill));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
|
var entity = query.EExecuteScalar<WeightBill>();
|
|
|
|
|
|
var dQuery = new DmoQuery(typeof(WeightBill_Detail));
|
|
|
dQuery.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", id)));
|
|
|
entity.Details = dQuery.EExecuteList().Cast<WeightBill_Detail>().ToList();
|
|
|
|
|
|
var fQuery = new DmoQuery(typeof(WeightBill_FarmerDetail));
|
|
|
fQuery.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", id)));
|
|
|
entity.FarmerDetails = fQuery.EExecuteList().Cast<WeightBill_FarmerDetail>().ToList();
|
|
|
return serializer.Serialize(entity);
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static string UpdateOrInsert(string json, string recordDetail)
|
|
|
{
|
|
|
json = json.ESerializeDateTime();
|
|
|
var dmo = serializer.Deserialize<WeightBill>(json);
|
|
|
recordDetail = recordDetail.ESerializeDateTime();
|
|
|
var records = serializer.Deserialize<List<WeightDetail>>(recordDetail);
|
|
|
var result = new BackRpcObj();
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
if (dmo.ID != 0)
|
|
|
{
|
|
|
bool same = ClientServiceUtils.RowVersionSame<WeightBill>(dmo.RowVersion, dmo.ID);
|
|
|
if (!same)
|
|
|
throw new Exception("数据已被更改,请重新打开");
|
|
|
FillServerUpdateFields(session, dmo);
|
|
|
dmo.RowVersion += 1;
|
|
|
session.Update(dmo);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dmo.ModifyTime = DateTime.Now;
|
|
|
dmo.RowVersion += 1;
|
|
|
session.Insert(dmo);
|
|
|
}
|
|
|
|
|
|
var detailBack = InsertWeightDetails(dmo.ID, dmo.Details, records, session);
|
|
|
if (detailBack.Any())
|
|
|
{
|
|
|
var details = new BackRpcObj() { Flag = "Details" };
|
|
|
details.DetailBack.AddRange(detailBack);
|
|
|
result.DetailBack.Add(details);
|
|
|
}
|
|
|
|
|
|
var farmerDetails = new BackRpcObj() { Flag = "FarmerDetails" };
|
|
|
foreach (var detail in dmo.FarmerDetails)
|
|
|
{
|
|
|
if (detail.ID == 0)
|
|
|
{
|
|
|
detail.WeightBill_ID = dmo.ID;
|
|
|
session.Insert(detail);
|
|
|
farmerDetails.DetailBack.Add(new BackRpcObj() { Flag = detail.Index.ToString(), ID = detail.ID });
|
|
|
}
|
|
|
else
|
|
|
session.Update(detail);
|
|
|
}
|
|
|
if (farmerDetails.DetailBack.Any())
|
|
|
result.DetailBack.Add(farmerDetails);
|
|
|
session.Commit();
|
|
|
}
|
|
|
result.ID = dmo.ID;
|
|
|
return serializer.Serialize(result);
|
|
|
}
|
|
|
|
|
|
static void FillServerUpdateFields(IDmoSession session, WeightBill dmo)
|
|
|
{
|
|
|
var min = InnerBLUtil.GetSingleDmo<WeightBill>(session, "ID", dmo.ID, "B3ID", "DeleteState", "Inspector_ID", "Inspector_Name", "HouseNames", "SanctionMoney");
|
|
|
dmo.B3ID = min.B3ID;
|
|
|
dmo.DeleteState = min.DeleteState;
|
|
|
dmo.Inspector_ID = min.Inspector_ID;
|
|
|
dmo.Inspector_Name = min.Inspector_Name;
|
|
|
dmo.HouseNames = min.HouseNames;
|
|
|
dmo.SanctionMoney = min.SanctionMoney;
|
|
|
dmo.Sync = false;
|
|
|
dmo.ModifyTime = DateTime.Now;
|
|
|
}
|
|
|
|
|
|
static List<BackRpcObj> InsertWeightDetails(long id, List<WeightBill_Detail> details, List<WeightDetail> records, IDmoSession session)
|
|
|
{
|
|
|
var result = new List<BackRpcObj>();
|
|
|
foreach (var item in details)
|
|
|
{
|
|
|
if (item.ID == 0)
|
|
|
{
|
|
|
item.WeightBill_ID = id;
|
|
|
session.Insert(item);
|
|
|
result.Add(new BackRpcObj() { Flag = item.Index.ToString(), ID = item.ID });
|
|
|
}
|
|
|
else
|
|
|
session.Update(item);
|
|
|
if (item.DeleteState)
|
|
|
DeleteWeightDetail(session, item.ID);
|
|
|
else
|
|
|
{
|
|
|
foreach (var r in records)
|
|
|
{
|
|
|
if (r.Delete)
|
|
|
session.Delete(r);
|
|
|
else
|
|
|
{
|
|
|
r.WeightBill_Detail_ID = item.ID;
|
|
|
session.Insert(r);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
static void DeleteWeightDetail(IDmoSession session, long detailID)
|
|
|
{
|
|
|
var delete = new DQDeleteDom(typeof(WeightDetail));
|
|
|
delete.Where.Conditions.Add(DQCondition.EQ("WeightBill_Detail_ID", detailID));
|
|
|
session.ExecuteNonQuery(delete);
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static string GetWeightRecord(long id)
|
|
|
{
|
|
|
var query = new DmoQuery(typeof(WeightDetail));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("WeightBill_Detail_ID", id));
|
|
|
var result = query.EExecuteList();
|
|
|
return serializer.Serialize(result);
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static bool DeleteBill(long id)
|
|
|
{
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
var detailID = InnerBLUtil.GetDmoProperty<long?>(session, typeof(WeightBill_Detail), "ID", new Tuple<string, object>("WeightBill_ID", id), new Tuple<string, object>("DeleteState", false));
|
|
|
if (detailID.HasValue)
|
|
|
DeleteWeightDetail(session, detailID.Value);
|
|
|
|
|
|
var b3ID = InnerBLUtil.GetDmoPropertyByID<long?>(session, typeof(WeightBill), "B3ID", id);
|
|
|
if (b3ID == null)
|
|
|
{
|
|
|
UpLoadWeightBill.Delete(id, session);
|
|
|
session.Commit();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
var update = new DQUpdateDom(typeof(WeightBill));
|
|
|
update.Columns.Add(new DQUpdateColumn("DeleteState", true));
|
|
|
update.Columns.Add(new DQUpdateColumn("Sync", false));
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
|
session.ExecuteNonQuery(update);
|
|
|
|
|
|
var delete = new DQDeleteDom(typeof(WeightBillCheck));
|
|
|
delete.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
|
session.ExecuteNonQuery(delete);
|
|
|
session.Commit();
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static string SyncBillB3Ids(List<long> ids)
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill)));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID"));
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("B3ID")), DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())));
|
|
|
var result = query.EExecuteList<long, long>().Select(x => new CTuple<long, long>(x.Item1, x.Item2));
|
|
|
return serializer.Serialize(result.ToList());
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static string SyncBillB3IdsAndSanctionMoney(DateTime date)
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill)));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("SanctionMoney"));
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.Between("WeighTime", date, date + new TimeSpan(23, 59, 29))));
|
|
|
var result = query.EExecuteList<long, long?, decimal?>().Select(x => new CTuple<long, long?, decimal?>(x.Item1, x.Item2, x.Item3));
|
|
|
return serializer.Serialize(result.ToList());
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static string GetPrintWeightBill(long id)
|
|
|
{
|
|
|
var main = new JoinAlias(typeof(WeightBill));
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail));
|
|
|
var query = new DQueryDom(main);
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(detail, "WeightBill_ID", id));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeighTime"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Creator"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Employee_Name"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Inspector_Name"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Weight", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("HogGrade_Name"));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ(main, "ID", id));
|
|
|
var entity = new PrintWeightBill();
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
using (var reader = session.ExecuteReader(query))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
entity.Supplier_Name = (string)reader[0];
|
|
|
entity.WeighTime = (DateTime?)reader[1];
|
|
|
entity.Creator = (string)reader[2];
|
|
|
entity.Employee_Name = (string)reader[3];
|
|
|
entity.Inspector_Name = (string)reader[4];
|
|
|
entity.Weight = (decimal?)reader[5];
|
|
|
entity.Number = (int?)reader[6];
|
|
|
entity.ID = (long?)reader[7];
|
|
|
entity.HogGrade_Name = (string)reader[8];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var sanction = new DQueryDom(new JoinAlias(typeof(WeightBill_SanctionDetail)));
|
|
|
sanction.Where.Conditions.Add(DQCondition.EQ("WeightBill_ID", id));
|
|
|
sanction.Columns.Add(DQSelectColumn.Field("AbnormalItem_Name"));
|
|
|
sanction.Columns.Add(DQSelectColumn.Field("Number"));
|
|
|
sanction.Columns.Add(DQSelectColumn.Field("Money"));
|
|
|
var s = sanction.EExecuteList<string, int?, decimal?>();
|
|
|
entity.Details = s.Select(x => new PWeightBill_SanctionDetail { AbnormalItem_Name = x.Item1, Number = x.Item2, Money = x.Item3 }).ToList();
|
|
|
return serializer.Serialize(entity);
|
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
|
public static int DoCheck(long id, string creator)
|
|
|
{
|
|
|
WeightBillCheck.Insert(id, creator);
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
}
|