|
|
|
@ -0,0 +1,239 @@ |
|
|
|
using BWP.B3ClientService.BO; |
|
|
|
using BWP.B3ClientService.RpcBO; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
using Forks.EnterpriseServices.JsonRpc; |
|
|
|
using Forks.EnterpriseServices.SqlDoms; |
|
|
|
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 OrderDetailRpc |
|
|
|
{ |
|
|
|
static JavaScriptSerializer serializer = new JavaScriptSerializer(); |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static string GetNeedOrderWeightBill(DateTime date) |
|
|
|
{ |
|
|
|
var main = new JoinAlias(typeof(WeightBill)); |
|
|
|
var query = new DQueryDom(main); |
|
|
|
var detail = WeightDetailTemp.Register(query, main); |
|
|
|
var already = OrderDetailTemp.Register(query, main); |
|
|
|
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)); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeighTime")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3ID")); |
|
|
|
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)))); |
|
|
|
var result = new List<NeedOrderEntity>(); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
var item = new NeedOrderEntity(); |
|
|
|
item.WeightBill_ID = (long)reader[0]; |
|
|
|
item.Supplier_Name = (string)reader[1]; |
|
|
|
item.HouseNames = (string)reader[2]; |
|
|
|
var v = reader[3]; |
|
|
|
if (v != null) |
|
|
|
item.Number = Convert.ToInt32(v); |
|
|
|
v = reader[4]; |
|
|
|
if (v != null) |
|
|
|
item.AlreadyNumber = Convert.ToInt32(v); |
|
|
|
item.WeighTime = (DateTime)reader[5]; |
|
|
|
item.B3ID = (long?)reader[6]; |
|
|
|
result.Add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return serializer.Serialize(result); |
|
|
|
} |
|
|
|
|
|
|
|
class WeightDetailTemp |
|
|
|
{ |
|
|
|
public long WeightBill_ID { get; set; } |
|
|
|
|
|
|
|
public int? Number { get; set; } |
|
|
|
|
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill_Detail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("Number")); |
|
|
|
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.From.AddJoin(JoinType.Left, new DQDmoSource(alias), DQCondition.EQ(rootAlias, "ID", alias, "WeightBill_ID")); |
|
|
|
return alias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class OrderDetailTemp |
|
|
|
{ |
|
|
|
public long WeightBill_ID { get; set; } |
|
|
|
|
|
|
|
public int? Number { get; set; } |
|
|
|
|
|
|
|
public static JoinAlias Register(DQueryDom rootQuery, JoinAlias rootAlias) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID")); |
|
|
|
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(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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static string GetBackWeightBillInfo(long weightID, long backId) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Supplier_Name")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("HouseNames")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("WeighTime")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("ID", weightID)); |
|
|
|
var result = query.EExecuteScalar<string, string, DateTime>(); |
|
|
|
var entity = new NeedOrderEntity(); |
|
|
|
entity.WeightBill_ID = weightID; |
|
|
|
entity.Supplier_Name = result.Item1; |
|
|
|
entity.HouseNames = result.Item2; |
|
|
|
entity.WeighTime = result.Item3; |
|
|
|
entity.Number = GetWeightNumber(weightID); |
|
|
|
entity.AlreadyNumber = GetAlreadyNumberWithoutBack(weightID, backId); |
|
|
|
|
|
|
|
return serializer.Serialize(entity); |
|
|
|
} |
|
|
|
|
|
|
|
static int GetWeightNumber(long wid) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(WeightBill_Detail))); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", wid))); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("Number")); |
|
|
|
var rst = query.EExecuteScalar(); |
|
|
|
if (rst != null) |
|
|
|
return Convert.ToInt32(rst); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
static int GetAlreadyNumberWithoutBack(long wid, long bid) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", false), DQCondition.EQ("WeightBill_ID", wid), DQCondition.InEQ("ID", bid))); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("PlanNumber")); |
|
|
|
var rst = query.EExecuteScalar(); |
|
|
|
if (rst != null) |
|
|
|
return Convert.ToInt32(rst); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
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("LiveColonyHouse_Name")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("IsHurryButcher")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("B3WeighBill_ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", date), DQCondition.EQ("DeleteState", false), DQCondition.EQ("SecondarySplit", false))); |
|
|
|
var list = new List<OrderDetail>(); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
var entity = new OrderDetail(); |
|
|
|
entity.ID = (long)reader[0]; |
|
|
|
entity.WeightBill_ID = (long)reader[1]; |
|
|
|
entity.Order = (int)reader[2]; |
|
|
|
entity.PlanNumber = (int)reader[3]; |
|
|
|
entity.LiveColonyHouse_Name = (string)reader[4]; |
|
|
|
entity.IsHurryButcher = (bool)reader[5]; |
|
|
|
entity.B3WeighBill_ID = (long?)reader[6]; |
|
|
|
list.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return serializer.Serialize(list); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int GetMaxOrder(DateTime date) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Max("Order")); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.Between("Date", date.Date, date.Date + new TimeSpan(23, 59, 29)), DQCondition.EQ("DeleteState", false))); |
|
|
|
return query.EExecuteScalar<int?>() ?? 1; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static long Insert(string update, string insert) |
|
|
|
{ |
|
|
|
var list = serializer.Deserialize<List<CTuple<long, int>>>(update); |
|
|
|
var entity = serializer.Deserialize<OrderDetail>(insert); |
|
|
|
entity.ModifyTime = DateTime.Now; |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
foreach (var item in list) |
|
|
|
UpdateOrderDetailPartial(session, item.Item1, "Order", item.Item2); |
|
|
|
session.Insert(entity); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return entity.ID; |
|
|
|
} |
|
|
|
|
|
|
|
static void UpdateOrderDetailPartial(IDmoSession session, long id, string property, object value) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(OrderDetail)); |
|
|
|
update.Columns.Add(new DQUpdateColumn(property, value)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int UpdateOrderProperty(long id, string property, object value) |
|
|
|
{ |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
UpdateOrderDetailPartial(session, id, property, value); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc] |
|
|
|
public static int Delete(string update, long id) |
|
|
|
{ |
|
|
|
var list = serializer.Deserialize<List<CTuple<long, int>>>(update); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
foreach (var item in list) |
|
|
|
UpdateOrderDetailPartial(session, item.Item1, "Order", item.Item2); |
|
|
|
UpdateOrderDetailPartial(session, id, "DeleteState", true); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |