|
|
@ -21,419 +21,210 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
static JavaScriptSerializer serializer = new JavaScriptSerializer(); |
|
|
static JavaScriptSerializer serializer = new JavaScriptSerializer(); |
|
|
|
|
|
|
|
|
[Rpc] |
|
|
[Rpc] |
|
|
public static BackRpcObj UploadBill(WeightBill dmo, string recordDetail) |
|
|
|
|
|
|
|
|
public static string GetWeightBillList(DateTime date, long? carID, long? supplierID) |
|
|
{ |
|
|
{ |
|
|
recordDetail = recordDetail.ESerializeDateTime(); |
|
|
|
|
|
var records = serializer.Deserialize<List<WeightDetail>>(recordDetail); |
|
|
|
|
|
var weightDetails = dmo.Details.ToList(); |
|
|
|
|
|
dmo.Details = new WeightBill_DetailCollection(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("SanctionNumber")); |
|
|
|
|
|
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 session = Dmo.NewSession()) |
|
|
{ |
|
|
{ |
|
|
if (dmo.ID == 0) |
|
|
|
|
|
session.Insert(dmo); |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var item in dmo.FarmerDetails) |
|
|
|
|
|
{ |
|
|
|
|
|
if (item.ID == 0) |
|
|
|
|
|
session.Insert(item); |
|
|
|
|
|
else |
|
|
|
|
|
session.Update(item); |
|
|
|
|
|
} |
|
|
|
|
|
dmo.FarmerDetails = new WeightBill_FarmerDetailCollection(); |
|
|
|
|
|
FillServerUpdateFields(session, dmo); |
|
|
|
|
|
session.Update(dmo); |
|
|
|
|
|
} |
|
|
|
|
|
InsertWeightDetails(dmo.ID, weightDetails, records, session); |
|
|
|
|
|
session.Commit(); |
|
|
|
|
|
} |
|
|
|
|
|
var result = new BackRpcObj(); |
|
|
|
|
|
result.ID = dmo.ID; |
|
|
|
|
|
var details = new BackRpcObj() { Flag = "Details" }; |
|
|
|
|
|
foreach (var d in weightDetails) |
|
|
|
|
|
details.DetailBack.Add(new BackRpcObj() { Flag = d.Index.ToString(), ID = d.ID }); |
|
|
|
|
|
result.DetailBack.Add(details); |
|
|
|
|
|
var farmerDetails = new BackRpcObj() { Flag = "FarmerDetails" }; |
|
|
|
|
|
foreach (var d in dmo.FarmerDetails) |
|
|
|
|
|
farmerDetails.DetailBack.Add(new BackRpcObj() { Flag = d.Index.ToString(), ID = d.ID }); |
|
|
|
|
|
result.DetailBack.Add(farmerDetails); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void InsertWeightDetails(long id, List<WeightBill_Detail> details, List<WeightDetail> records, IDmoSession session) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var item in details) |
|
|
|
|
|
{ |
|
|
|
|
|
if (item.ID == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
item.WeightBill_ID = id; |
|
|
|
|
|
session.Insert(item); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
session.Update(item); |
|
|
|
|
|
foreach (var r in records) |
|
|
|
|
|
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
{ |
|
|
{ |
|
|
if (r.Delete) |
|
|
|
|
|
session.Delete(r); |
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
while (reader.Read()) |
|
|
{ |
|
|
{ |
|
|
r.WeightBill_Detail_ID = item.ID; |
|
|
|
|
|
session.Insert(r); |
|
|
|
|
|
|
|
|
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.SanctionNumber = (int?)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); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void FillServerUpdateFields(IDmoSession session, WeightBill dmo) |
|
|
|
|
|
{ |
|
|
|
|
|
var min = InnerBLUtil.GetSingleDmo<WeightBill>(session, "ID", dmo.ID, "B3ID", "DeleteState", "AlreadyHouse", "Inspector_ID", "Inspector_Name", "HouseNames"); |
|
|
|
|
|
dmo.B3ID = min.B3ID; |
|
|
|
|
|
dmo.DeleteState = min.DeleteState; |
|
|
|
|
|
dmo.AlreadyHouse = min.AlreadyHouse; |
|
|
|
|
|
dmo.Inspector_ID = min.Inspector_ID; |
|
|
|
|
|
dmo.Inspector_Name = min.Inspector_Name; |
|
|
|
|
|
dmo.HouseNames = min.HouseNames; |
|
|
|
|
|
dmo.Sync = false; |
|
|
|
|
|
dmo.ModifyTime = DateTime.Now; |
|
|
|
|
|
|
|
|
return serializer.Serialize(list); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc] |
|
|
[Rpc] |
|
|
public static bool DeleteBill(long id) |
|
|
|
|
|
{ |
|
|
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
|
|
{ |
|
|
|
|
|
DeleteEntity<WeightBill>(session, "ID", id); |
|
|
|
|
|
DeleteEntity<WeightBill_Detail>(session, "WeightBill_ID", id); |
|
|
|
|
|
DeleteEntity<WeightBill_FarmerDetail>(session, "WeightBill_ID", id); |
|
|
|
|
|
DeleteEntity<WeightBill_HouseDetail>(session, "WeightBill_ID", id); |
|
|
|
|
|
DeleteEntity<WeightBill_SanctionDetail>(session, "WeightBill_ID", id); |
|
|
|
|
|
session.Commit(); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void DeleteEntity<T>(IDmoSession session, string property, object value) |
|
|
|
|
|
where T : SyncBase |
|
|
|
|
|
{ |
|
|
|
|
|
var update = new DQUpdateDom(typeof(T)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("DeleteState", true)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.EQ(property, value)); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Rpc] |
|
|
|
|
|
public static List<WeightBill> GetWeightBillList(DateTime date, long? carID, long? supplierID) |
|
|
|
|
|
|
|
|
public static string Load(long id) |
|
|
{ |
|
|
{ |
|
|
var query = new DmoQuery(typeof(WeightBill)); |
|
|
var query = new DmoQuery(typeof(WeightBill)); |
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.Between("WeighTime", date.Date, date.Date + new TimeSpan(23, 59, 29)))); |
|
|
|
|
|
if (carID.HasValue) |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Car_ID", carID)); |
|
|
|
|
|
if (supplierID.HasValue) |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Supplier_ID", supplierID)); |
|
|
|
|
|
return query.EExecuteList().Cast<WeightBill>().ToList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
|
|
var entity = query.EExecuteScalar<WeightBill>(); |
|
|
|
|
|
|
|
|
[Rpc] |
|
|
|
|
|
public static List<Tuple<long, long>> SyncBillB3Ids(List<long> ids) |
|
|
|
|
|
{ |
|
|
|
|
|
return GetSyncBaseB3Ids<WeightBill>(ids); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
[Rpc] |
|
|
|
|
|
public static List<Tuple<long, long>> SyncWeightDetailB3Ids(List<long> ids) |
|
|
|
|
|
{ |
|
|
|
|
|
return GetSyncBaseB3Ids<WeightBill_Detail>(ids); |
|
|
|
|
|
|
|
|
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] |
|
|
[Rpc] |
|
|
public static List<Tuple<long, long>> SyncFarmerDetailB3Ids(List<long> ids) |
|
|
|
|
|
{ |
|
|
|
|
|
return GetSyncBaseB3Ids<WeightBill_FarmerDetail>(ids); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static List<Tuple<long, long>> GetSyncBaseB3Ids<T>(List<long> ids) |
|
|
|
|
|
where T : SyncBase |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(T))); |
|
|
|
|
|
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()))); |
|
|
|
|
|
return query.EExecuteList<long, long>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Rpc] |
|
|
|
|
|
public static List<Tuple<long, long, int>> SyncWeightDetailFirstNumber(List<long> detailIds) |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill_Detail))); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("Number")), DQCondition.InList(DQExpression.Field("ID"), detailIds.Select(x => DQExpression.Value(x)).ToArray()))); |
|
|
|
|
|
return query.EExecuteList<long, long, int>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Rpc] |
|
|
|
|
|
public static List<WeightWithHouseDetail> GetNoHouseInfoWeightBills(DateTime date) |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill))); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.Between("WeighTime", date.Date, date.Date + new TimeSpan(23, 59, 29))))); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("Employee_Name")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("AlreadyHouse")); |
|
|
|
|
|
var result = query.EExecuteList<long, long?, string, string, bool>(); |
|
|
|
|
|
var list = new List<WeightWithHouseDetail>(); |
|
|
|
|
|
foreach (var item in result) |
|
|
|
|
|
{ |
|
|
|
|
|
var bill = new WeightWithHouseDetail(); |
|
|
|
|
|
var entity = new WeightBill(); |
|
|
|
|
|
bill.Bill = entity; |
|
|
|
|
|
list.Add(bill); |
|
|
|
|
|
entity.ID = item.Item1; |
|
|
|
|
|
entity.B3ID = item.Item2; |
|
|
|
|
|
entity.Employee_Name = item.Item3; |
|
|
|
|
|
entity.Supplier_Name = item.Item4; |
|
|
|
|
|
entity.AlreadyHouse = item.Item5; |
|
|
|
|
|
entity.FirstWeightNumber = GetWeightDetailFirstNumber(entity.ID); |
|
|
|
|
|
} |
|
|
|
|
|
var details = GetWeightHouseDetail(list.Select(x => x.Bill.ID)); |
|
|
|
|
|
foreach (var item in list) |
|
|
|
|
|
{ |
|
|
|
|
|
var tags = details.Where(x => x.WeightBill_ID == item.Bill.ID); |
|
|
|
|
|
if (tags.Any()) |
|
|
|
|
|
item.Detail = tags.ToArray(); |
|
|
|
|
|
} |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int? GetWeightDetailFirstNumber(long id) |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill_Detail))); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", id))); |
|
|
|
|
|
query.Range = SelectRange.Top(1); |
|
|
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); |
|
|
|
|
|
return query.EExecuteScalar<int?>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static IEnumerable<WeightBill_HouseDetail> GetWeightHouseDetail(IEnumerable<long> billIDs) |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DmoQuery(typeof(WeightBill_HouseDetail)); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.InList(DQExpression.Field("WeightBill_ID"), billIDs.Select(x => DQExpression.Value(x)).ToArray()))); |
|
|
|
|
|
return query.EExecuteList().Cast<WeightBill_HouseDetail>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Rpc] |
|
|
|
|
|
public static int UpdateInsertWeightBillHouseDetail(WeightBill bo) |
|
|
|
|
|
|
|
|
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()) |
|
|
using (var session = Dmo.NewSession()) |
|
|
{ |
|
|
{ |
|
|
//因为传过来的明细是不带ID的。
|
|
|
|
|
|
var houseDetail = GetList<WeightBill_HouseDetail>(new Tuple<string, object>("WeightBill_ID", bo.ID), new Tuple<string, object>("DeleteState", false)); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in bo.HouseDetails) |
|
|
|
|
|
|
|
|
if (dmo.ID != 0) |
|
|
{ |
|
|
{ |
|
|
var first = houseDetail.FirstOrDefault(x => x.LiveColonyHouse_ID == item.LiveColonyHouse_ID); |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
houseDetail.Add(item); |
|
|
|
|
|
else |
|
|
|
|
|
first.Index = item.Index; |
|
|
|
|
|
|
|
|
FillServerUpdateFields(session, dmo); |
|
|
|
|
|
session.Update(dmo); |
|
|
} |
|
|
} |
|
|
var delete = new List<long>(); |
|
|
|
|
|
var houseNames = new List<string>(); |
|
|
|
|
|
foreach (var item in houseDetail) |
|
|
|
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
if (bo.HouseDetails.Any(x => x.LiveColonyHouse_ID == item.LiveColonyHouse_ID)) |
|
|
|
|
|
{ |
|
|
|
|
|
UpdateOrInsertHouseDetail(session, item); |
|
|
|
|
|
houseNames.Add(item.LiveColonyHouse_Name); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
delete.Add(item.LiveColonyHouse_ID ?? 0); |
|
|
|
|
|
|
|
|
dmo.ModifyTime = DateTime.Now; |
|
|
|
|
|
session.Insert(dmo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (delete.Any()) |
|
|
|
|
|
|
|
|
var detailBack = InsertWeightDetails(dmo.ID, dmo.Details, records, session); |
|
|
|
|
|
if (detailBack.Any()) |
|
|
{ |
|
|
{ |
|
|
Delete<WeightBill_HouseDetail>(session, (dom) => |
|
|
|
|
|
{ |
|
|
|
|
|
dom.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", bo.ID))); |
|
|
|
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("LiveColonyHouse_ID"), delete.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
var details = new BackRpcObj() { Flag = "Details" }; |
|
|
|
|
|
details.DetailBack.AddRange(detailBack); |
|
|
|
|
|
result.DetailBack.Add(details); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var sanctionDetail = GetList<WeightBill_SanctionDetail>(new Tuple<string, object>("WeightBill_ID", bo.ID), new Tuple<string, object>("DeleteState", false)); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in bo.SanctionDetails) |
|
|
|
|
|
|
|
|
var farmerDetails = new BackRpcObj() { Flag = "FarmerDetails" }; |
|
|
|
|
|
foreach (var detail in dmo.FarmerDetails) |
|
|
{ |
|
|
{ |
|
|
var first = sanctionDetail.FirstOrDefault(x => x.AbnormalItem_ID == item.AbnormalItem_ID); |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
sanctionDetail.Add(item); |
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
if (detail.ID == 0) |
|
|
{ |
|
|
{ |
|
|
first.Index = item.Index; |
|
|
|
|
|
first.Number = item.Number; |
|
|
|
|
|
|
|
|
detail.WeightBill_ID = dmo.ID; |
|
|
|
|
|
session.Insert(detail); |
|
|
|
|
|
farmerDetails.DetailBack.Add(new BackRpcObj() { Flag = detail.Index.ToString(), ID = detail.ID }); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
delete.Clear(); |
|
|
|
|
|
foreach (var item in sanctionDetail) |
|
|
|
|
|
{ |
|
|
|
|
|
if (bo.SanctionDetails.Any(x => x.AbnormalItem_ID == item.AbnormalItem_ID)) |
|
|
|
|
|
UpdateOrInsertSanctionDetail(session, item); |
|
|
|
|
|
else |
|
|
else |
|
|
delete.Add(item.AbnormalItem_ID ?? 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (delete.Any()) |
|
|
|
|
|
{ |
|
|
|
|
|
Delete<WeightBill_SanctionDetail>(session, (dom) => |
|
|
|
|
|
{ |
|
|
|
|
|
dom.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", bo.ID))); |
|
|
|
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("AbnormalItem_ID"), delete.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
session.Update(detail); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var firstID = GetWeightDetailFirstID(bo.ID); |
|
|
|
|
|
if (firstID.HasValue) |
|
|
|
|
|
{ |
|
|
|
|
|
var dUpdate = new DQUpdateDom(typeof(WeightBill_Detail)); |
|
|
|
|
|
dUpdate.Columns.Add(new DQUpdateColumn("Number", bo.FirstWeightNumber)); |
|
|
|
|
|
dUpdate.Where.Conditions.Add(DQCondition.EQ("ID", firstID)); |
|
|
|
|
|
session.ExecuteNonQuery(dUpdate); |
|
|
|
|
|
} |
|
|
|
|
|
var update = new DQUpdateDom(typeof(WeightBill)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("HogGrade_ID", bo.HogGrade_ID)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("HogGrade_Name", bo.HogGrade_Name)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Inspector_ID", bo.Inspector_ID)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Inspector_Name", bo.Inspector_Name)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("HouseNames", string.Join(",", houseNames))); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("AlreadyHouse", true)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Sync", false)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("ModifyTime", DateTime.Now)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", bo.ID)); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
|
|
|
if (farmerDetails.DetailBack.Any()) |
|
|
|
|
|
result.DetailBack.Add(farmerDetails); |
|
|
session.Commit(); |
|
|
session.Commit(); |
|
|
} |
|
|
} |
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static List<T> GetList<T>(params Tuple<string, object>[] condition) |
|
|
|
|
|
{ |
|
|
|
|
|
var query = new DmoQuery(typeof(T)); |
|
|
|
|
|
if (condition.Any()) |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(condition.Select(x => DQCondition.EQ(x.Item1, x.Item2)))); |
|
|
|
|
|
return query.EExecuteList().Cast<T>().ToList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void Delete<T>(IDmoSession session, Action<DQUpdateDom> conditions) |
|
|
|
|
|
where T : SyncBase |
|
|
|
|
|
{ |
|
|
|
|
|
var delete = new DQUpdateDom(typeof(T)); |
|
|
|
|
|
delete.Columns.Add(new DQUpdateColumn("DeleteState", true)); |
|
|
|
|
|
conditions(delete); |
|
|
|
|
|
session.ExecuteNonQuery(delete); |
|
|
|
|
|
|
|
|
result.ID = dmo.ID; |
|
|
|
|
|
return serializer.Serialize(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void UpdateOrInsertHouseDetail(IDmoSession session, WeightBill_HouseDetail detail) |
|
|
|
|
|
|
|
|
static void FillServerUpdateFields(IDmoSession session, WeightBill dmo) |
|
|
{ |
|
|
{ |
|
|
if (detail.ID == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
session.Insert(detail); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
var update = new DQUpdateDom(typeof(WeightBill_HouseDetail)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Index", detail.Index)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("LiveColonyHouse_ID", detail.LiveColonyHouse_ID))); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
|
|
|
var min = InnerBLUtil.GetSingleDmo<WeightBill>(session, "ID", dmo.ID, "B3ID", "Inspector_ID", "Inspector_Name", "HouseNames", "SanctionNumber"); |
|
|
|
|
|
dmo.B3ID = min.B3ID; |
|
|
|
|
|
dmo.Inspector_ID = min.Inspector_ID; |
|
|
|
|
|
dmo.Inspector_Name = min.Inspector_Name; |
|
|
|
|
|
dmo.HouseNames = min.HouseNames; |
|
|
|
|
|
dmo.SanctionNumber = min.SanctionNumber; |
|
|
|
|
|
dmo.Sync = false; |
|
|
|
|
|
dmo.ModifyTime = DateTime.Now; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void UpdateOrInsertSanctionDetail(IDmoSession session, WeightBill_SanctionDetail detail) |
|
|
|
|
|
|
|
|
static List<BackRpcObj> InsertWeightDetails(long id, List<WeightBill_Detail> details, List<WeightDetail> records, IDmoSession session) |
|
|
{ |
|
|
{ |
|
|
if (detail.ID == 0) |
|
|
|
|
|
|
|
|
var result = new List<BackRpcObj>(); |
|
|
|
|
|
foreach (var item in details) |
|
|
{ |
|
|
{ |
|
|
session.Insert(detail); |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
var update = new DQUpdateDom(typeof(WeightBill_SanctionDetail)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Index", detail.Index)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Number", detail.Number)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("AbnormalItem_ID", detail.AbnormalItem_ID))); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static long? GetWeightDetailFirstID(long id) |
|
|
|
|
|
|
|
|
static void DeleteWeightDetail(IDmoSession session, long detailID) |
|
|
{ |
|
|
{ |
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill_Detail))); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", id))); |
|
|
|
|
|
query.Range = SelectRange.Top(1); |
|
|
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); |
|
|
|
|
|
return query.EExecuteScalar<long?>(); |
|
|
|
|
|
|
|
|
var delete = new DQDeleteDom(typeof(WeightDetail)); |
|
|
|
|
|
delete.Where.Conditions.Add(DQCondition.EQ("WeightBill_Detail_ID", detailID)); |
|
|
|
|
|
session.ExecuteNonQuery(delete); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc] |
|
|
[Rpc] |
|
|
public static int GetDetailTotalNumber(DateTime date) |
|
|
|
|
|
|
|
|
public static string GetWeightRecord(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(main, "ID", detail, "WeightBill_ID")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.And(DQCondition.EQ(detail, "DeleteState", false), DQCondition.EQ("DeleteState", false), DQCondition.Between("WeighTime", date.Date, date.Date + new TimeSpan(23, 59, 29))))); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Sum(detail, "Number")); |
|
|
|
|
|
var result = query.EExecuteScalar(); |
|
|
|
|
|
|
|
|
|
|
|
if (result == null) |
|
|
|
|
|
return 0; |
|
|
|
|
|
return Convert.ToInt32(result); |
|
|
|
|
|
|
|
|
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] |
|
|
[Rpc] |
|
|
public static WeightWithHouseAndSanction GetWeightBillOnHousePage(long id) |
|
|
|
|
|
|
|
|
public static bool DeleteBill(long id) |
|
|
{ |
|
|
{ |
|
|
var result = new WeightWithHouseAndSanction(); |
|
|
|
|
|
using (var session = Dmo.NewSession()) |
|
|
using (var session = Dmo.NewSession()) |
|
|
{ |
|
|
{ |
|
|
var entity = new WeightBill(); |
|
|
|
|
|
entity.HogGrade_ID = InnerBLUtil.GetDmoPropertyByID<long?>(session, typeof(WeightBill), "HogGrade_ID", id); |
|
|
|
|
|
entity.FirstWeightNumber = GetWeightDetailFirstNumber(id); |
|
|
|
|
|
result.Bill = entity; |
|
|
|
|
|
result.Detail = InnerBLUtil.GetPartialFieldsDmoList<WeightBill_HouseDetail>(session, (query) => |
|
|
|
|
|
{ |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("WeightBill_ID", id), DQCondition.EQ("DeleteState", false))); |
|
|
|
|
|
}, "ID", "LiveColonyHouse_ID").ToArray(); |
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
|
result.SanctionDetail = InnerBLUtil.GetPartialFieldsDmoList<WeightBill_SanctionDetail>(session, (query) => |
|
|
|
|
|
{ |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("WeightBill_ID", id), DQCondition.EQ("DeleteState", false))); |
|
|
|
|
|
}, "ID", "AbnormalItem_ID", "Number").ToArray(); |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
session.Commit(); |
|
|
} |
|
|
} |
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc] |
|
|
[Rpc] |
|
|
public static string GetWeightRecord(long id) |
|
|
|
|
|
|
|
|
public static string SyncBillB3Ids(List<long> ids) |
|
|
{ |
|
|
{ |
|
|
var query = new DmoQuery(typeof(WeightDetail)); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("WeightBill_Detail_ID", id)); |
|
|
|
|
|
var result = query.EExecuteList(); |
|
|
|
|
|
return serializer.Serialize(result); |
|
|
|
|
|
|
|
|
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()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[RpcObject] |
|
|
|
|
|
public class WeightWithHouseDetail |
|
|
|
|
|
{ |
|
|
|
|
|
public WeightBill Bill { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public WeightBill_HouseDetail[] Detail { get; set; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[RpcObject] |
|
|
|
|
|
public class WeightWithHouseAndSanction : WeightWithHouseDetail |
|
|
|
|
|
{ |
|
|
|
|
|
public WeightBill_SanctionDetail[] SanctionDetail { get; set; } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |