|
|
|
@ -79,13 +79,25 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(WeightBill)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("DeleteState", true)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
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) |
|
|
|
{ |
|
|
|
@ -122,6 +134,16 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
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) |
|
|
|
@ -144,6 +166,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
entity.B3ID = item.Item2; |
|
|
|
entity.Supplier_Name = item.Item3; |
|
|
|
entity.AlreadyHouse = item.Item4; |
|
|
|
entity.FirstWeightNumber = GetWeightDetailFirstNumber(entity.ID); |
|
|
|
} |
|
|
|
var details = GetWeightHouseDetail(list.Select(x => x.Bill.ID)); |
|
|
|
foreach (var item in list) |
|
|
|
@ -155,6 +178,16 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
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)); |
|
|
|
@ -163,15 +196,79 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int InsertWeightBillHouseDetail(WeightBill bo) |
|
|
|
public static int UpdateInsertWeightBillHouseDetail(WeightBill bo) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
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) |
|
|
|
session.Insert(item); |
|
|
|
{ |
|
|
|
var first = houseDetail.FirstOrDefault(x => x.LiveColonyHouse_ID == item.LiveColonyHouse_ID); |
|
|
|
if (first == null) |
|
|
|
houseDetail.Add(item); |
|
|
|
else |
|
|
|
first.Index = item.Index; |
|
|
|
} |
|
|
|
var delete = new List<long>(); |
|
|
|
foreach (var item in houseDetail) |
|
|
|
{ |
|
|
|
if (bo.HouseDetails.Any(x => x.LiveColonyHouse_ID == item.LiveColonyHouse_ID)) |
|
|
|
UpdateOrInsertHouseDetail(session, item); |
|
|
|
else |
|
|
|
delete.Add(item.LiveColonyHouse_ID ?? 0); |
|
|
|
} |
|
|
|
|
|
|
|
if (delete.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 sanctionDetail = GetList<WeightBill_SanctionDetail>(new Tuple<string, object>("WeightBill_ID", bo.ID), new Tuple<string, object>("DeleteState", false)); |
|
|
|
|
|
|
|
foreach (var item in bo.SanctionDetails) |
|
|
|
session.Insert(item); |
|
|
|
{ |
|
|
|
var first = sanctionDetail.FirstOrDefault(x => x.AbnormalItem_ID == item.AbnormalItem_ID); |
|
|
|
if (first == null) |
|
|
|
sanctionDetail.Add(item); |
|
|
|
else |
|
|
|
{ |
|
|
|
first.Index = item.Index; |
|
|
|
first.Number = item.Number; |
|
|
|
} |
|
|
|
} |
|
|
|
delete.Clear(); |
|
|
|
foreach (var item in sanctionDetail) |
|
|
|
{ |
|
|
|
if (bo.SanctionDetails.Any(x => x.AbnormalItem_ID == item.AbnormalItem_ID)) |
|
|
|
UpdateOrInsertSanctionDetail(session, item); |
|
|
|
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())); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
@ -187,14 +284,68 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
static void UpdateOrInsertHouseDetail(IDmoSession session, WeightBill_HouseDetail detail) |
|
|
|
{ |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
static void UpdateOrInsertSanctionDetail(IDmoSession session, WeightBill_SanctionDetail detail) |
|
|
|
{ |
|
|
|
if (detail.ID == 0) |
|
|
|
{ |
|
|
|
session.Insert(detail); |
|
|
|
return; |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
static long? GetWeightDetailFirstID(long id) |
|
|
|
{ |
|
|
|
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?>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetHouseDetailTotalNumber(DateTime date) |
|
|
|
public static int GetDetailTotalNumber(DateTime date) |
|
|
|
{ |
|
|
|
var main = new JoinAlias(typeof(WeightBill)); |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_HouseDetail)); |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail)); |
|
|
|
var query = new DQueryDom(main); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.And(DQCondition.EQ(main, "ID", detail, "WeightBill_ID"), DQCondition.EQ(detail, "DeleteState", false))); |
|
|
|
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.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(); |
|
|
|
|
|
|
|
@ -202,6 +353,29 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
return 0; |
|
|
|
return Convert.ToInt32(result); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static WeightWithHouseAndSanction GetWeightBillOnHousePage(long id) |
|
|
|
{ |
|
|
|
var result = new WeightWithHouseAndSanction(); |
|
|
|
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(); |
|
|
|
|
|
|
|
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(); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[RpcObject] |
|
|
|
@ -209,7 +383,12 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
{ |
|
|
|
public WeightBill Bill { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public WeightBill_HouseDetail[] Detail { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
[RpcObject] |
|
|
|
public class WeightWithHouseAndSanction : WeightWithHouseDetail |
|
|
|
{ |
|
|
|
public WeightBill_SanctionDetail[] SanctionDetail { get; set; } |
|
|
|
} |
|
|
|
} |