|
|
|
@ -23,7 +23,7 @@ namespace BWP.B3SheepButcherManage.BL |
|
|
|
[LogicName("羊过磅单")] |
|
|
|
public interface IWeightBillBL : IDepartmentWorkFlowBillBL<WeightBill> |
|
|
|
{ |
|
|
|
void UpdateDetailOtherNumber(long p); |
|
|
|
void UpdateDetailOtherNumber(IEnumerable<long> weightDetailIDs); |
|
|
|
} |
|
|
|
|
|
|
|
public class WeightBillBL : DepartmentWorkFlowBillBL<WeightBill>, IWeightBillBL |
|
|
|
@ -67,7 +67,7 @@ namespace BWP.B3SheepButcherManage.BL |
|
|
|
runner.Global["奖罚依据"] = ""; |
|
|
|
runner.Execute(result.Item3); |
|
|
|
var bType = TypeMarshal.AsString(runner.Global["奖罚依据"]); |
|
|
|
if (bType == "过磅单") |
|
|
|
if (bType == "羊过磅单") |
|
|
|
{ |
|
|
|
runner.Global["单价"] = 0m; |
|
|
|
runner.Execute(result.Item2); |
|
|
|
@ -113,7 +113,7 @@ namespace BWP.B3SheepButcherManage.BL |
|
|
|
|
|
|
|
protected override void doUnCheck(WeightBill dmo) |
|
|
|
{ |
|
|
|
if (dmo.WeighRecords.Any(x => x.PlanNumber > 0 || x.ButcherNumber > 0)) |
|
|
|
if (dmo.WeighRecords.Any(x => x.PlanNumber > 0)) |
|
|
|
throw new ApplicationException("过磅单已经排宰"); |
|
|
|
|
|
|
|
var stayPayBL = BIFactory.Create<IStatPayBL>(Session); |
|
|
|
@ -132,54 +132,92 @@ namespace BWP.B3SheepButcherManage.BL |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 更新屠宰单明细的已计划数量,已屠宰数量,剩余数量
|
|
|
|
/// 更新屠宰单明细的已计划数量,剩余数量
|
|
|
|
/// </summary>
|
|
|
|
public void UpdateDetailOtherNumber(long weighDetailID) |
|
|
|
public void UpdateDetailOtherNumber(IEnumerable<long> weightDetailIDs) |
|
|
|
{ |
|
|
|
if (weighDetailID == 0) |
|
|
|
{ |
|
|
|
if (weightDetailIDs.Count() == 0) |
|
|
|
return; |
|
|
|
var exp = weightDetailIDs.Distinct().Select(x => DQExpression.Value(x)).ToArray(); |
|
|
|
|
|
|
|
var main = new JoinAlias(typeof(Summary)); |
|
|
|
var detail = new JoinAlias(typeof(WeightBill_Record)); |
|
|
|
var query = new DQueryDom(main); |
|
|
|
Summary.Register(query, exp); |
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID", main)); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum(main, "Number")); |
|
|
|
query.Columns.Add(DQSelectColumn.Max(detail, "Number")); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field(main, "ID")); |
|
|
|
|
|
|
|
var list = new List<Tuple<long, int, int>>(); |
|
|
|
using (var reader = Session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
var item1 = (long)reader[0]; |
|
|
|
var item2 = Convert.ToInt32(reader[1] ?? 0); |
|
|
|
var item3 = Convert.ToInt32(reader[2] ?? 0); |
|
|
|
var last = item3 - item2; |
|
|
|
if (last < 0) |
|
|
|
throw new Exception(string.Format("过磅单明细ID{0} 头数{1} 已计划{2} 超出{3}", item1, item3, item2, -last)); |
|
|
|
list.Add(new Tuple<long, int, int>(item1, item2, last)); |
|
|
|
} |
|
|
|
} |
|
|
|
foreach (var item in list) |
|
|
|
UpdateReocrdPlanNumber(item); |
|
|
|
} |
|
|
|
|
|
|
|
private void UpdateReocrdPlanNumber(Tuple<long, int, int> item) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(WeightBill_Record)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("PlanNumber", item.Item2)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("RemainNumber", item.Item3)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", item.Item1)); |
|
|
|
Session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
class Summary |
|
|
|
{ |
|
|
|
public long ID { get; set; } |
|
|
|
|
|
|
|
public int Number { get; set; } |
|
|
|
|
|
|
|
public static void Register(DQueryDom root, IDQExpression[] ids) |
|
|
|
{ |
|
|
|
var q1 = ButcherQuery(ids); |
|
|
|
q1.UnionNext.Select = HurryButcherQuery(ids); |
|
|
|
q1.UnionNext.Type = UnionType.All; |
|
|
|
root.RegisterQueryTable(typeof(Summary), new string[] { "ID", "Number" }, q1); |
|
|
|
} |
|
|
|
|
|
|
|
var butcher = new JoinAlias(typeof(Butcher)); |
|
|
|
var detail = new JoinAlias(typeof(Butcher_Detail)); |
|
|
|
var subQuery = new DQueryDom(detail); |
|
|
|
subQuery.From.AddJoin(JoinType.Left, new DQDmoSource(butcher), DQCondition.EQ(detail, "Butcher_ID", butcher, "ID")); |
|
|
|
subQuery.Where.Conditions.Add(DQCondition.EQ(detail, "Weigh_Detail_ID", weighDetailID)); |
|
|
|
subQuery.Where.Conditions.Add(DQCondition.InEQ(butcher, "BillState", 单据状态.已作废)); |
|
|
|
subQuery.Columns.Add(DQSelectColumn.Count()); |
|
|
|
subQuery.Columns.Add(DQSelectColumn.Create(DQExpression.Sum( |
|
|
|
DQExpression.LogicCase(DQCondition.IsNotNull(DQExpression.Field("Weight")), DQExpression.ConstValue(1), DQExpression.ConstValue(0))), "HasWeight")); |
|
|
|
var tuple = subQuery.EExecuteScalar<long?, int?>(Session); |
|
|
|
var planNumber = tuple.Item1 ?? 0; |
|
|
|
var butcherNumber = tuple.Item2 ?? 0; |
|
|
|
|
|
|
|
var hurryDetail = new JoinAlias(typeof(HurryButcher_Detail)); |
|
|
|
var hurry = new JoinAlias(typeof(HurryButcher)); |
|
|
|
var hurryDom = new DQueryDom(hurryDetail); |
|
|
|
hurryDom.From.AddJoin(JoinType.Left, new DQDmoSource(hurry), DQCondition.EQ(hurryDetail, "HurryButcher_ID", hurry, "ID")); |
|
|
|
hurryDom.Where.Conditions.Add(DQCondition.EQ("Weigh_Detail_ID", weighDetailID)); |
|
|
|
hurryDom.Where.Conditions.Add(DQCondition.Or( |
|
|
|
DQCondition.EQ(hurry, "BillState", 单据状态.已审核), |
|
|
|
DQCondition.EQ(hurry, "BillState", 单据状态.已完毕))); |
|
|
|
hurryDom.Columns.Add(DQSelectColumn.Sum("Number")); |
|
|
|
var hurryNumber = (int?)Session.ExecuteScalar(hurryDom); |
|
|
|
|
|
|
|
butcherNumber = (butcherNumber) + (hurryNumber ?? 0); |
|
|
|
planNumber = (planNumber) + (hurryNumber ?? 0); |
|
|
|
|
|
|
|
var updatedom = new DQUpdateDom(typeof(WeightBill_Record)); |
|
|
|
updatedom.Where.Conditions.Add(DQCondition.EQ("ID", weighDetailID)); |
|
|
|
|
|
|
|
long weightid = InnerBLUtil.GetDmoPropertyByID<long>(Session, typeof(WeightBill_Record), "WeightBill_ID", weighDetailID); |
|
|
|
|
|
|
|
updatedom.Columns.Add(new DQUpdateColumn("PlanNumber", planNumber));//已计划头数
|
|
|
|
updatedom.Columns.Add(new DQUpdateColumn("ButcherNumber", butcherNumber)); //已屠宰
|
|
|
|
updatedom.Columns.Add(new DQUpdateColumn("RemainNumber", DQExpression.Subtract(DQExpression.Field("Number"), DQExpression.Value(planNumber > butcherNumber ? planNumber : butcherNumber)))); |
|
|
|
//剩余头数
|
|
|
|
|
|
|
|
Session.ExecuteNonQuery(updatedom); |
|
|
|
static DQueryDom ButcherQuery(IDQExpression[] ids) |
|
|
|
{ |
|
|
|
var main = new JoinAlias(typeof(Butcher)); |
|
|
|
var detail = new JoinAlias(typeof(Butcher_Detail)); |
|
|
|
var query = new DQueryDom(detail); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(main), DQCondition.EQ(detail, "Butcher_ID", main, "ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "Weigh_Detail_ID"), ids)); |
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Weigh_Detail_ID", detail)); |
|
|
|
query.Columns.Add(DQSelectColumn.Count()); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field(detail, "Weigh_Detail_ID")); |
|
|
|
return query; |
|
|
|
} |
|
|
|
|
|
|
|
static DQueryDom HurryButcherQuery(IDQExpression[] ids) |
|
|
|
{ |
|
|
|
var detail = new JoinAlias(typeof(HurryButcher_Detail)); |
|
|
|
var main = new JoinAlias(typeof(HurryButcher)); |
|
|
|
var query = new DQueryDom(detail); |
|
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(main), DQCondition.EQ(detail, "HurryButcher_ID", main, "ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(detail, "Weigh_Detail_ID"), ids)); |
|
|
|
query.Where.Conditions.Add(DQCondition.InEQ(main, "BillState", 单据状态.已作废)); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Weigh_Detail_ID", detail)); |
|
|
|
query.Columns.Add(DQSelectColumn.Sum("Number")); |
|
|
|
query.GroupBy.Expressions.Add(DQExpression.Field(detail, "Weigh_Detail_ID")); |
|
|
|
return query; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |