|
|
|
@ -20,25 +20,29 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
{ |
|
|
|
static JavaScriptSerializer serializer = new JavaScriptSerializer(); |
|
|
|
|
|
|
|
#region 排宰
|
|
|
|
[Rpc] |
|
|
|
public static string GetNeedOrderWeightBill(DateTime date, bool? showType) |
|
|
|
{ |
|
|
|
var main = new JoinAlias(typeof(WeightBill)); |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail)); |
|
|
|
var relate = new JoinAlias(typeof(WeightBillShowRelate)); |
|
|
|
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.From.AddJoin(JoinType.Left, new DQDmoSource(relate), DQCondition.EQ(main, "ID", relate, "WeightBill_ID")); |
|
|
|
var detail = WeightDetailTemp.Register(query, main); |
|
|
|
var already = OrderDetailTemp.Register(query, main); |
|
|
|
var hurry = HurryOrderTemp.Register(query, main, true); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("HouseNames")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", detail)); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", already)); |
|
|
|
var alreadyNumber = DQExpression.Add(DQExpression.IfNull(DQExpression.Field(already, "Number"), DQExpression.Value(0)), DQExpression.IfNull(DQExpression.Field(hurry, "Number"), DQExpression.Value(0))); |
|
|
|
query.Columns.Add(DQSelectColumn.Create(alreadyNumber, "Already")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeighTime")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Show", relate)); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.Between("WeighTime", date.Date, date.Date + new TimeSpan(23, 59, 29)), DQCondition.InEQ("HouseNames", ""))); |
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ(DQExpression.IfNull(DQExpression.Field(detail, "Number"), DQExpression.Value(0)), DQExpression.IfNull(DQExpression.Field(already, "Number"), DQExpression.Value(0)))); |
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ(DQExpression.IfNull(DQExpression.Field(detail, "Number"), DQExpression.Value(0)), alreadyNumber)); |
|
|
|
if (showType == true) |
|
|
|
query.Where.Conditions.Add(DQCondition.Or(DQCondition.IsNull(DQExpression.Field(relate, "Show")), DQCondition.EQ(relate, "Show", true))); |
|
|
|
else if (showType == false) |
|
|
|
@ -70,7 +74,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
return serializer.Serialize(result); |
|
|
|
} |
|
|
|
|
|
|
|
class WeightDetailTemp |
|
|
|
class OrderDetailTemp |
|
|
|
{ |
|
|
|
public long WeightBill_ID { get; set; } |
|
|
|
|
|
|
|
@ -78,35 +82,35 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
|
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill_Detail))); |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("Number")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("PlanNumber")); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field("WeightBill_ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("DeleteState", false)); |
|
|
|
rootQuery.RegisterQueryTable(typeof(WeightDetailTemp), new string[] { "WeightBill_ID", "Number" }, query); |
|
|
|
|
|
|
|
var alias = new JoinAlias(typeof(WeightDetailTemp)); |
|
|
|
rootQuery.RegisterQueryTable(typeof(OrderDetailTemp), new string[] { "WeightBill_ID", "Number" }, query); |
|
|
|
var alias = new JoinAlias(typeof(OrderDetailTemp)); |
|
|
|
rootQuery.From.AddJoin(JoinType.Left, new DQDmoSource(alias), DQCondition.EQ(rootAlias, "ID", alias, "WeightBill_ID")); |
|
|
|
return alias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class OrderDetailTemp |
|
|
|
class HurryOrderTemp |
|
|
|
{ |
|
|
|
public long WeightBill_ID { get; set; } |
|
|
|
|
|
|
|
public int? Number { get; set; } |
|
|
|
|
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias) |
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias, bool unOrder, string joinField = "ID") |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(HurryRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("PlanNumber")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("HurryNumber")); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field("WeightBill_ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("DeleteState", false)); |
|
|
|
rootQuery.RegisterQueryTable(typeof(OrderDetailTemp), new string[] { "WeightBill_ID", "Number" }, query); |
|
|
|
var alias = new JoinAlias(typeof(OrderDetailTemp)); |
|
|
|
rootQuery.From.AddJoin(JoinType.Left, new DQDmoSource(alias), DQCondition.EQ(rootAlias, "ID", alias, "WeightBill_ID")); |
|
|
|
if (unOrder) |
|
|
|
query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("ToOrderDetail_ID"))); |
|
|
|
rootQuery.RegisterQueryTable(typeof(HurryOrderTemp), new string[] { "WeightBill_ID", "Number" }, query); |
|
|
|
var alias = new JoinAlias(typeof(HurryOrderTemp)); |
|
|
|
rootQuery.From.AddJoin(JoinType.Left, new DQDmoSource(alias), DQCondition.EQ(rootAlias, joinField, alias, "WeightBill_ID")); |
|
|
|
return alias; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -117,7 +121,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
var totalNumber = GetWeightNumber(weightID); |
|
|
|
var alreadyNumber = GetAlreadyNumberWithoutBack(weightID, backId); |
|
|
|
|
|
|
|
return totalNumber - alreadyNumber; |
|
|
|
return totalNumber - alreadyNumber - HurryRecordUnOrderNumber(weightID); |
|
|
|
} |
|
|
|
|
|
|
|
static int GetWeightNumber(long wid) |
|
|
|
@ -142,27 +146,33 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
static int HurryRecordUnOrderNumber(long wid) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(HurryRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("HurryNumber")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("WeightBill_ID", wid), DQCondition.IsNull(DQExpression.Field("ToOrderDetail_ID")))); |
|
|
|
var rst = query.EExecuteScalar(); |
|
|
|
if (rst != null) |
|
|
|
return Convert.ToInt32(rst); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static string GetOrderDetail(DateTime date, bool onlyNormal) |
|
|
|
public static string GetOrderDetail(DateTime date) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Order")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("PlanNumber")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("PlanNumber")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("LiveColonyHouse_Name")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("IsHurryButcher")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3WeighBill_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("SecondarySplit")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("OrderState")); |
|
|
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", date), DQCondition.EQ("DeleteState", false))); |
|
|
|
if (onlyNormal) |
|
|
|
{ |
|
|
|
var record = HurryRecordTemp.Register(query, query.From.RootSource.Alias); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", record)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("IsHurryButcher", false)); |
|
|
|
} |
|
|
|
var list = new List<OrderDetail>(); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
@ -180,11 +190,8 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
entity.B3WeighBill_ID = (long?)reader[6]; |
|
|
|
entity.SecondarySplit = (bool)reader[7]; |
|
|
|
entity.Supplier_Name = (string)reader[8]; |
|
|
|
if (onlyNormal) |
|
|
|
{ |
|
|
|
entity.HurryNumber = Convert.ToInt32(reader[9] ?? 0); |
|
|
|
entity.PlanNumber += entity.HurryNumber; |
|
|
|
} |
|
|
|
entity.OrderState = (int)reader[9]; |
|
|
|
entity.Date = date; |
|
|
|
list.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -192,26 +199,6 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
return serializer.Serialize(list); |
|
|
|
} |
|
|
|
|
|
|
|
class HurryRecordTemp |
|
|
|
{ |
|
|
|
public long OrderDetail_ID { get; set; } |
|
|
|
|
|
|
|
public int? Number { get; set; } |
|
|
|
|
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(HurryRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("FromOrderDetail_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("HurryNumber")); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field("FromOrderDetail_ID")); |
|
|
|
rootQuery.RegisterQueryTable(typeof(HurryRecordTemp), new string[] { "OrderDetail_ID", "Number" }, query); |
|
|
|
|
|
|
|
var alias = new JoinAlias(typeof(HurryRecordTemp)); |
|
|
|
rootQuery.From.AddJoin(JoinType.Left, new DQDmoSource(alias), DQCondition.EQ(rootAlias, "ID", alias, "OrderDetail_ID")); |
|
|
|
return alias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetMaxOrder(DateTime date) |
|
|
|
{ |
|
|
|
@ -223,11 +210,22 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetCurrentOrder(long id) |
|
|
|
{ |
|
|
|
return GetOrderDetailProperty<int>(id, "Order"); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetCurrentOrderPlanNumber(long id) |
|
|
|
{ |
|
|
|
return GetOrderDetailProperty<int>(id, "PlanNumber"); |
|
|
|
} |
|
|
|
|
|
|
|
static T GetOrderDetailProperty<T>(long id, string property) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Order")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field(property)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
return query.EExecuteScalar<int>(); |
|
|
|
return (T)query.EExecuteScalar(); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
@ -237,7 +235,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
var entity = serializer.Deserialize<OrderDetail>(insert); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
//CheckCanInsert(session, entity.Order, entity.Date.Value);
|
|
|
|
CheckCanInsert(session, entity.Order, entity.Date.Value); |
|
|
|
entity.ModifyTime = DateTime.Now; |
|
|
|
UpdateOrder(session, entity.Order - 1, 1, entity.Date); |
|
|
|
session.Insert(entity); |
|
|
|
@ -251,7 +249,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Range = SelectRange.Top(1); |
|
|
|
query.Columns.Add(DQSelectColumn.Create(DQExpression.Value(1), "c")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", date), DQCondition.EQ("DeleteState", false), DQCondition.EQ("SecondarySplit", true), DQCondition.GreaterThanOrEqual("Order", order))); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", date), DQCondition.EQ("DeleteState", false), DQCondition.GreaterThanOrEqual("OrderState", 10), DQCondition.GreaterThanOrEqual("Order", order))); |
|
|
|
if (query.EExecuteScalar(session) != null) |
|
|
|
throw new Exception("不允许插入到已进行烫毛计数顺序之前"); |
|
|
|
} |
|
|
|
@ -285,11 +283,12 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var entity = InnerBLUtil.GetSingleDmo<OrderDetail>(session, "ID", id, "Order", "Date", "SecondarySplit"); |
|
|
|
//if (entity.SecondarySplit)
|
|
|
|
// throw new Exception("已进行烫毛计数,不能修改");
|
|
|
|
var entity = InnerBLUtil.GetSingleDmo<OrderDetail>(session, "ID", id, "Order", "Date", "OrderState"); |
|
|
|
if (entity.OrderState != 0) |
|
|
|
throw new Exception("已开始宰杀,不能修改"); |
|
|
|
UpdateOrder(session, entity.Order, -1, entity.Date); |
|
|
|
UpdateOrderDetailPartial(session, id, "DeleteState", true); |
|
|
|
ClearHurryRecordToOrderID(session, id); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
@ -319,46 +318,58 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region hurryButcher
|
|
|
|
[Rpc] |
|
|
|
public static string GetHurryRecords(long orderId) |
|
|
|
public static string GetHurryRecordList(long weightId) |
|
|
|
{ |
|
|
|
var query = new DmoQuery(typeof(HurryRecord)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("FromOrderDetail_ID", orderId)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("WeightBill_ID", weightId)); |
|
|
|
return serializer.Serialize(query.EExecuteList().Cast<HurryRecord>().ToList()); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int DeleteHurryRecord(long id) |
|
|
|
public static long? DeleteHurryRecord(long id) |
|
|
|
{ |
|
|
|
long? orderID; |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var hurryNumber = InnerBLUtil.GetDmoPropertyByID<int>(session, typeof(HurryRecord), "HurryNumber", id); |
|
|
|
var entity = InnerBLUtil.GetSingleDmo<HurryRecord>(session, "ID", id, "HurryNumber", "WeightBill_ID"); |
|
|
|
orderID = GetOrderID(entity.WeightBill_ID); |
|
|
|
var delete = new DQDeleteDom(typeof(HurryRecord)); |
|
|
|
delete.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
session.ExecuteNonQuery(delete); |
|
|
|
AddOrderNumber(session, id, hurryNumber); |
|
|
|
if (orderID > 0) |
|
|
|
AddOrderNumber(session, orderID.Value, entity.HurryNumber); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
return orderID; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int InsertHurryRecord(string detail) |
|
|
|
public static string InsertHurryRecord(string detail) |
|
|
|
{ |
|
|
|
detail = detail.ESerializeDateTime(); |
|
|
|
var entity = serializer.Deserialize<HurryRecord>(detail); |
|
|
|
long? orderID = GetOrderID(entity.WeightBill_ID); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
session.Insert(entity); |
|
|
|
AddOrderNumber(session, entity.ID, -entity.HurryNumber); |
|
|
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(HurryRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("HurryNumber")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("FromOrderDetail_ID", entity.FromOrderDetail_ID)); |
|
|
|
var r= Convert.ToInt32(query.EExecuteScalar(session) ?? 0); |
|
|
|
if (orderID > 0) |
|
|
|
AddOrderNumber(session, orderID.Value, -entity.HurryNumber); |
|
|
|
session.Commit(); |
|
|
|
return r; |
|
|
|
} |
|
|
|
return string.Format("{0}|{1}", orderID, entity.ID); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetHurryRecordNumber(long weightId) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(HurryRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("HurryNumber")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("WeightBill_ID", weightId)); |
|
|
|
return Convert.ToInt32(query.EExecuteScalar() ?? 0); |
|
|
|
} |
|
|
|
|
|
|
|
static void AddOrderNumber(IDmoSession session, long ID, int subNumber) |
|
|
|
@ -369,5 +380,160 @@ namespace BWP.B3ClientService.Rpcs.BillRpc |
|
|
|
update.Columns.Add(new DQUpdateColumn("PlanNumber", DQExpression.Add(DQExpression.Field("PlanNumber"), DQExpression.Value(subNumber)))); |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
static long? GetOrderID(long weightBillId) |
|
|
|
{ |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail)); |
|
|
|
var order = new JoinAlias(typeof(OrderDetail)); |
|
|
|
var query = new DQueryDom(detail); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(order), DQCondition.EQ(order, "WeightBill_ID", weightBillId)); |
|
|
|
var hurry = GetHurryRecordNumber(weightBillId); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID", order)); |
|
|
|
query.Columns.Add(DQSelectColumn.Create(DQExpression.Subtract(DQExpression.IfNull(DQExpression.Field(detail, "Number"), DQExpression.Value(0)), DQExpression.IfNull(DQExpression.Field(order, "PlanNumber"), DQExpression.Value(0))), "last")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ(detail, "DeleteState", false), DQCondition.EQ(order, "DeleteState", false), DQCondition.EQ(order, "IsHurryButcher", false), DQCondition.EQ(detail, "WeightBill_ID", weightBillId))); |
|
|
|
long? id = null; |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
if (id.HasValue || Convert.ToInt32(reader[1]) - hurry != 0) |
|
|
|
return -1; |
|
|
|
id = (long)reader[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return id; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static string GetHurryRecord(long id) |
|
|
|
{ |
|
|
|
var query = new DmoQuery(typeof(HurryRecord)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
var entity = query.EExecuteScalar<HurryRecord>(); |
|
|
|
if (entity == null) |
|
|
|
throw new Exception(string.Format("急宰单No.{0} 已被删除", id)); |
|
|
|
return serializer.Serialize(entity); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static string GetSelectHurryList(DateTime butcherDate) |
|
|
|
{ |
|
|
|
var bill = new JoinAlias(typeof(WeightBill)); |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail)); |
|
|
|
var query = new DQueryDom(bill); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.And(DQCondition.EQ(bill, "ID", detail, "WeightBill_ID"), DQCondition.EQ(detail, "DeleteState", false))); |
|
|
|
var hurry = HurryOrderTemp.Register(query, bill, false); |
|
|
|
var start = StartOrderTemp.Register(query, bill, butcherDate); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("HouseNames")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", detail)); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Number", hurry)); |
|
|
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.InEQ("HouseNames", ""))); |
|
|
|
|
|
|
|
var list = new List<SelectHurryList>(); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
var entity = new SelectHurryList(); |
|
|
|
entity.WeightBill_ID = (long)reader[0]; |
|
|
|
entity.B3WeighBill_ID = (long?)reader[1]; |
|
|
|
entity.Supplier_Name = (string)reader[2]; |
|
|
|
entity.LiveColonyHouse_Name = (string)reader[3]; |
|
|
|
entity.WeightNumber = (int?)reader[4] ?? 0; |
|
|
|
entity.HurryNumber = Convert.ToInt32(reader[5] ?? 0); |
|
|
|
list.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return serializer.Serialize(list); |
|
|
|
} |
|
|
|
|
|
|
|
class StartOrderTemp |
|
|
|
{ |
|
|
|
public long WeightBill_ID { get; set; } |
|
|
|
|
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias, DateTime date) |
|
|
|
{ |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Detail)); |
|
|
|
var order = new JoinAlias(typeof(OrderDetail)); |
|
|
|
var query = new DQueryDom(detail); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(order), DQCondition.And(DQCondition.EQ(detail, "WeightBill_ID", order, "WeightBill_ID"), DQCondition.EQ(order, "DeleteState", false))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID", detail)); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field(detail, "WeightBill_ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.Or(DQCondition.IsNull(DQExpression.Field(order, "ID")), DQCondition.EQ(order, "Date", date)), DQCondition.EQ(detail, "DeleteState", false))); |
|
|
|
|
|
|
|
rootQuery.RegisterQueryTable(typeof(StartOrderTemp), new string[] { "WeightBill_ID" }, query); |
|
|
|
var alias = new JoinAlias(typeof(StartOrderTemp)); |
|
|
|
rootQuery.From.AddJoin(JoinType.Inner, new DQDmoSource(alias), DQCondition.EQ(rootAlias, "ID", alias, "WeightBill_ID")); |
|
|
|
return alias; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region orderConfirm
|
|
|
|
[Rpc] |
|
|
|
public static int SetOrderState(long id, int state) |
|
|
|
{ |
|
|
|
if (!(state == 0 || state == 10 || state == 20)) |
|
|
|
throw new Exception(string.Format("错误的状态输入 {0}", state)); |
|
|
|
var update = new DQUpdateDom(typeof(OrderDetail)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("OrderState", state)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
update.EExecute(); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static long InsertByHurryRecord(string insert, long hurryID) |
|
|
|
{ |
|
|
|
insert = insert.ESerializeDateTime(); |
|
|
|
var entity = serializer.Deserialize<OrderDetail>(insert); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
CheckCanInsert(session, entity.Order, entity.Date.Value); |
|
|
|
entity.ModifyTime = DateTime.Now; |
|
|
|
UpdateOrder(session, entity.Order - 1, 1, entity.Date); |
|
|
|
session.Insert(entity); |
|
|
|
SetHurryRecordToOrderID(session, entity.ID, hurryID); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return entity.ID; |
|
|
|
} |
|
|
|
|
|
|
|
static void SetHurryRecordToOrderID(IDmoSession session, long orderID, long hurryID) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(HurryRecord)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", hurryID)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("ToOrderDetail_ID", orderID)); |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
static void ClearHurryRecordToOrderID(IDmoSession session, long orderID) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(HurryRecord)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ToOrderDetail_ID", orderID)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("ToOrderDetail_ID", DQExpression.NULL)); |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetFinishNumbers(DateTime date) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("PlanNumber")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("Date", date), DQCondition.EQ("OrderState", 20))); |
|
|
|
return query.EExecuteScalar<int?>() ?? 0; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |