From 5b5b231841ab3e8b2d48f828294c72ac17c37cb5 Mon Sep 17 00:00:00 2001
From: yibo <361071264@qq.com>
Date: Wed, 13 Sep 2017 09:10:58 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
B3ClientService/B3ClientService.csproj | 5 +
.../BO/Bill/WeightBill/WeightBill.cs | 3 +
.../WeightBill/WeightBill_FarmerDetail.cs | 2 +
B3ClientService/MapBO/WeightBill/WeighBill.cs | 166 +++++++++++++++
.../WeightBill/Weigh_AbnormalRecording.cs | 50 +++++
.../MapBO/WeightBill/Weigh_FarmerDetail.cs | 41 ++++
.../MapBO/WeightBill/Weigh_Record.cs | 91 ++++++++
B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs | 201 +++++++++++++++++-
.../Tasks/UpdateLoad/UpLoadWeightBill.cs | 197 +++++++++++++++++
.../Tasks/UpdateLoad/UploadTest.cs | 132 ++++++------
10 files changed, 811 insertions(+), 77 deletions(-)
create mode 100644 B3ClientService/MapBO/WeightBill/WeighBill.cs
create mode 100644 B3ClientService/MapBO/WeightBill/Weigh_AbnormalRecording.cs
create mode 100644 B3ClientService/MapBO/WeightBill/Weigh_FarmerDetail.cs
create mode 100644 B3ClientService/MapBO/WeightBill/Weigh_Record.cs
create mode 100644 B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs
diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj
index 34ee02b..1535a70 100644
--- a/B3ClientService/B3ClientService.csproj
+++ b/B3ClientService/B3ClientService.csproj
@@ -87,6 +87,10 @@
+
+
+
+
@@ -95,6 +99,7 @@
+
diff --git a/B3ClientService/BO/Bill/WeightBill/WeightBill.cs b/B3ClientService/BO/Bill/WeightBill/WeightBill.cs
index 28ccf1b..8c685bb 100644
--- a/B3ClientService/BO/Bill/WeightBill/WeightBill.cs
+++ b/B3ClientService/BO/Bill/WeightBill/WeightBill.cs
@@ -76,6 +76,9 @@ namespace BWP.B3ClientService.BO
[DbColumn(DefaultValue = 0)]
public bool AlreadyHouse { get; set; }
+ //[NonDmoProperty]
+ public int? FirstWeightNumber { get; set; }
+
private WeightBill_DetailCollection mDetails = new WeightBill_DetailCollection();
[OneToMany(typeof(WeightBill_Detail), "ID")]
[Join("ID", "WeightBill_ID")]
diff --git a/B3ClientService/BO/Bill/WeightBill/WeightBill_FarmerDetail.cs b/B3ClientService/BO/Bill/WeightBill/WeightBill_FarmerDetail.cs
index eb6415e..6062509 100644
--- a/B3ClientService/BO/Bill/WeightBill/WeightBill_FarmerDetail.cs
+++ b/B3ClientService/BO/Bill/WeightBill/WeightBill_FarmerDetail.cs
@@ -19,6 +19,8 @@ namespace BWP.B3ClientService.BO
public string Farmer_Name { get; set; }
public int? Number { get; set; }
+
+ public decimal? Weight { get; set; }
}
[Serializable]
diff --git a/B3ClientService/MapBO/WeightBill/WeighBill.cs b/B3ClientService/MapBO/WeightBill/WeighBill.cs
new file mode 100644
index 0000000..64881b8
--- /dev/null
+++ b/B3ClientService/MapBO/WeightBill/WeighBill.cs
@@ -0,0 +1,166 @@
+using BWP.B3Frameworks;
+using BWP.B3Frameworks.BO;
+using Forks.EnterpriseServices;
+using Forks.EnterpriseServices.DataForm;
+using Forks.EnterpriseServices.DomainObjects2;
+using System;
+using Forks.Utils;
+using TSingSoft.WebControls2;
+using BWP.B3Frameworks.Utils;
+using BWP.B3Frameworks.BO.MoneyTemplate;
+using TSingSoft.WebPluginFramework;
+
+
+namespace BWP.B3ClientService.MapBO
+{
+ [Serializable]
+ [LogicName("过磅单")]
+ [BOClass(Exclude = true)]
+
+ public class WeighBill : DomainBill
+ {
+ [LogicName("会计单位")]
+ public long? AccountingUnit_ID { get; set; }
+
+ [LogicName("来源地")]
+ public long? Zone_ID { get; set; }
+
+ //[ReferenceTo(typeof(Zone1), "Depth")]
+ //[Join("Zone_ID", "ID")]
+ //public int? Zone_Depth { get; set; }
+
+ //[ReferenceTo(typeof(Zone1), "Name")]
+ //[Join("Zone_ID", "ID")]
+ //[LogicName("区域")]
+ //public string Zone_Name { get; set; }
+
+ //[ReferenceTo(typeof(Zone1), "TreeDeep1_Name")]
+ //[Join("Zone_ID", "ID")]
+ //[LogicName("一级区域")]
+ //public string TreeDeep1_Name { get; set; }
+
+ //[ReferenceTo(typeof(Zone1), "TreeDeep2_Name")]
+ //[Join("Zone_ID", "ID")]
+ //[LogicName("二级区域")]
+ //public string TreeDeep2_Name { get; set; }
+
+ //[NonDmoProperty]
+ //[DFPrompt("区域树形名称")]
+ //public string Zone_TreeName
+ //{
+ // get { return TreeUtil.GetTreePrefix(Zone_Depth) + Zone_Name; }
+ //}
+
+ [LogicName("部门")]
+ public long? Department_ID { get; set; }
+
+ [LogicName("供应商")]
+ public long? Supplier_ID { get; set; }
+
+ DateTime dt = DateTime.Now;
+ [LogicName("过磅时间")]
+ public DateTime? WeighTime { get { return dt; } set { dt = (DateTime)value; } }
+
+ //[LogicName("收购头数")]
+ //[DFExtProperty("WebControlType", DFEditControl.StaticText)]
+ //public int? BuyNum { get; set; }
+
+ //[LogicName("收购重量")]
+ //[DFExtProperty("WebControlType", DFEditControl.StaticText)]
+ //public Money? BuyWeigh1 { get; set; }
+
+ [LogicName("棚前单价")]
+ public Money? ShackPrice { get; set; }
+
+ [LogicName("棚前重量")]
+ public Money? ShackWeight { get; set; }
+
+ [LogicName("棚前金额")]
+ //[DFExtProperty("WebControlType", DFEditControl.StaticText)]
+ public Money<金额>? ShackMoney { get; set; }
+
+ [LogicName("收购类型")]
+ public short? PurchaseType { get; set; }
+
+ [LogicName("定价单")]
+ public long? FixedPrice_ID { get; set; }
+
+ [LogicName("车辆")]
+ public long? Car_ID { get; set; }
+
+ [LogicName("验质员")]
+ public long? Inspector_ID { get; set; }
+
+ [LogicName("动检号")]
+ public string AnimalTestNumber { get; set; }
+
+ [LogicName("动检日期")]
+ public DateTime? AnimalTestDate { get; set; }
+
+ [LogicName("动检员")]
+ public string AnimalTestMan { get; set; }
+
+ //[ReferenceTo(typeof(AccountingUnit), "Name")]
+ //[Join("AccountingUnit_ID", "ID")]
+ //[DFPrompt("会计单位")]
+ //public string AccountingUnit_Name { get; set; }
+
+ //[Join("Department_ID", "ID")]
+ //[LogicName("部门名称")]
+ //[ReferenceTo(typeof(Department), "Name")]
+ //public string Department_Name { get; set; }
+
+ //[Join("Supplier_ID", "ID")]
+ //[LogicName("供应商")]
+ //[ReferenceTo(typeof(Supplier), "Name")]
+ //public string Supplier_Name { get; set; }
+
+ //[Join("Supplier_ID", "ID")]
+ //[LogicName("联系方式")]
+ //[ReferenceTo(typeof(Supplier), "Tel")]
+ //public string Supplier_Tel { get; set; }
+
+ [LogicName("车牌号")]
+ public string CarNo { get; set; }
+
+ //[ReferenceTo(typeof(Car), "Name")]
+ //[Join("Car_ID", "ID")]
+ //[DFPrompt("车辆")]
+ //public string Car_Name { get; set; }
+
+ //[Join("Inspector_ID", "ID")]
+ //[LogicName("验质员")]
+ //[ReferenceTo(typeof(Employee), "Name")]
+ //public string Inspector_Name { get; set; }
+
+ private Weigh_RecordCollection mWeighRecord = new Weigh_RecordCollection();
+ [OneToMany(typeof(Weigh_Record), "ID")]
+ [Join("ID", "Weigh_ID")]
+ public Weigh_RecordCollection WeighRecord
+ {
+ get { return mWeighRecord; }
+ set { mWeighRecord = value; }
+ }
+
+ private Weigh_AbnormalRecordingCollection mWeighAbnormalRecording = new Weigh_AbnormalRecordingCollection();
+ [OneToMany(typeof(Weigh_AbnormalRecording), "ID")]
+ [Join("ID", "Weigh_ID")]
+ public Weigh_AbnormalRecordingCollection WeighAbnormalRecording
+ {
+ get { return mWeighAbnormalRecording; }
+ set { mWeighAbnormalRecording = value; }
+ }
+
+ private Weigh_FarmerDetailCollection mFarmerDetails = new Weigh_FarmerDetailCollection();
+ [OneToMany(typeof(Weigh_FarmerDetail), "ID")]
+ [Join("ID", "Weigh_ID")]
+ public Weigh_FarmerDetailCollection FarmerDetails
+ {
+ get { return mFarmerDetails; }
+ set { mFarmerDetails = value; }
+ }
+
+ [LogicName("外部ID")]
+ public long? CID { get; set; }
+ }
+}
diff --git a/B3ClientService/MapBO/WeightBill/Weigh_AbnormalRecording.cs b/B3ClientService/MapBO/WeightBill/Weigh_AbnormalRecording.cs
new file mode 100644
index 0000000..02fd648
--- /dev/null
+++ b/B3ClientService/MapBO/WeightBill/Weigh_AbnormalRecording.cs
@@ -0,0 +1,50 @@
+using BWP.B3Frameworks.BO;
+using Forks.EnterpriseServices;
+using Forks.EnterpriseServices.DataDictionary;
+using Forks.EnterpriseServices.DataForm;
+using Forks.EnterpriseServices.DomainObjects2;
+using Forks.Utils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TSingSoft.WebPluginFramework;
+
+namespace BWP.B3ClientService.MapBO
+{
+
+ [LogicName("过磅记录")]
+ [Serializable]
+ [BOClass(Exclude = true)]
+ public class Weigh_AbnormalRecording : Base
+ {
+ public long? Weigh_ID { get; set; }
+
+ [LogicName("奖罚设置")]
+ public long? Sanction_ID { get; set; }
+
+ [LogicName("头数")]
+ public int Num { get; set; }
+
+ [LogicName("单价")]
+ public Money? UnitPrice { get; set; }
+
+ [LogicName("金额")]
+ public Money? Abnormal_Money { get; set; }
+
+ //[LogicName("异常项目")]
+ //public string Abnormal_Name { get; set; }
+
+ [LogicName("异常项目ID")]
+ public long? AbnormalItem_ID { get; set; }
+
+ [LogicName("外部ID")]
+ public long? CID { get; set; }
+ }
+
+ [Serializable]
+ public class Weigh_AbnormalRecordingCollection : DmoCollection
+ {
+
+ }
+}
diff --git a/B3ClientService/MapBO/WeightBill/Weigh_FarmerDetail.cs b/B3ClientService/MapBO/WeightBill/Weigh_FarmerDetail.cs
new file mode 100644
index 0000000..7090708
--- /dev/null
+++ b/B3ClientService/MapBO/WeightBill/Weigh_FarmerDetail.cs
@@ -0,0 +1,41 @@
+using BWP.B3Frameworks.BO;
+using Forks.EnterpriseServices;
+using Forks.EnterpriseServices.DataDictionary;
+using Forks.EnterpriseServices.DataForm;
+using Forks.EnterpriseServices.DomainObjects2;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TSingSoft.WebPluginFramework;
+
+namespace BWP.B3ClientService.MapBO
+{
+ [LogicName("过磅单_养殖户信息")]
+ [Serializable]
+ [BOClass(Exclude = true)]
+ public class Weigh_FarmerDetail : Base
+ {
+ [LogicName("过磅记录ID")]
+ public long Weigh_ID { get; set; }
+
+ [LogicName("养殖户")]
+ public long? Farmer_ID { get; set; }
+
+ //[LogicName("养殖户")]
+ //public string Farmer_Name { get; set; }
+
+ [LogicName("头数")]
+ public int? Number { get; set; }
+
+ [LogicName("重量")]
+ public decimal? Weight { get; set; }
+
+ [LogicName("外部ID")]
+ public long? CID { get; set; }
+ }
+
+ [Serializable]
+ public class Weigh_FarmerDetailCollection : DmoCollection
+ { }
+}
diff --git a/B3ClientService/MapBO/WeightBill/Weigh_Record.cs b/B3ClientService/MapBO/WeightBill/Weigh_Record.cs
new file mode 100644
index 0000000..829743c
--- /dev/null
+++ b/B3ClientService/MapBO/WeightBill/Weigh_Record.cs
@@ -0,0 +1,91 @@
+using BWP.B3Frameworks.BO;
+using Forks.EnterpriseServices;
+using Forks.EnterpriseServices.DataDictionary;
+using Forks.EnterpriseServices.DataForm;
+using Forks.EnterpriseServices.DomainObjects2;
+using Forks.Utils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using BWP.B3Frameworks.BO.MoneyTemplate;
+using TSingSoft.WebPluginFramework;
+
+namespace BWP.B3ClientService.MapBO
+{
+ [LogicName("过磅记录")]
+ [Serializable]
+ [BOClass(Exclude = true)]
+ public class Weigh_Record : Base
+ {
+ [LogicName("过磅记录ID")]
+ public long Weigh_ID { get; set; }
+
+ [LogicName("活体品种")]
+ public long? LiveVarieties_ID { get; set; }
+
+ //[LogicName("活体品种")]
+ //public string LiveVarieties_Name { get; set; }
+
+ [LogicName("等级")]
+ public long? HogGrade_ID { get; set; }
+
+ //[LogicName("等级")]
+ //public string HogGrade_Name { get; set; }
+
+ [LogicName("活体标识")]
+ public string LiveMark { get; set; }
+
+ [LogicName("头数")]
+ public int Number { get; set; }
+
+ [LogicName("毛重")]
+ public Money? MaoWeight { get; set; }
+
+ [LogicName("皮重")]
+ public Money? PiWeight { get; set; }
+
+ [LogicName("重量")]
+ public Money? Weight { get; set; }
+
+ //[LogicName("均重")]
+ //[NonDmoProperty]
+ //public Money<一位小数>? AvgWeight {
+ // get { return Weight / Number; }
+ //}
+
+ short? nv = 0;
+ [LogicName("建议工艺")]
+ public short? SuggestedProcess1
+ {
+ get { return nv; }
+ set { nv = value; }
+ }
+
+
+ [LogicName("活体圈舍")]
+ public string LiveColonyHouse_Name { get; set; }
+
+ [LogicName("剩余头数")]
+ public int? RemainNumber { get; set; }
+
+ [LogicName("已计划头数")]
+ public int? PlanNumber { get; set; }
+
+ [LogicName("已屠宰头数")]
+ public int? ButcherNumber { get; set; }
+
+ [LogicName("备注")]
+ public string Remark { get; set; }
+
+ [LogicName("外部ID")]
+ public long? CID { get; set; }
+ }
+
+ [Serializable]
+ public class Weigh_RecordCollection : DmoCollection
+ {
+
+ }
+
+}
diff --git a/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs b/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs
index ea9b071..d4d3936 100644
--- a/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs
+++ b/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs
@@ -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(session, "ID", id);
+ DeleteEntity(session, "WeightBill_ID", id);
+ DeleteEntity(session, "WeightBill_ID", id);
+ DeleteEntity(session, "WeightBill_ID", id);
+ DeleteEntity(session, "WeightBill_ID", id);
+ session.Commit();
}
return true;
}
+ static void DeleteEntity(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 GetWeightBillList(DateTime date)
{
@@ -122,6 +134,16 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
return query.EExecuteList();
}
+ [Rpc]
+ public static List> SyncWeightDetailFirstNumber(List 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();
+ }
[Rpc]
public static List 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();
+ }
+
static IEnumerable GetWeightHouseDetail(IEnumerable 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(new Tuple("WeightBill_ID", bo.ID), new Tuple("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();
+ 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(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(new Tuple("WeightBill_ID", bo.ID), new Tuple("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(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 GetList(params Tuple[] 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().ToList();
+ }
+
+ static void Delete(IDmoSession session, Action 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();
+ }
+
[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(session, typeof(WeightBill), "HogGrade_ID", id);
+ entity.FirstWeightNumber = GetWeightDetailFirstNumber(id);
+ result.Bill = entity;
+ result.Detail = InnerBLUtil.GetPartialFieldsDmoList(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(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; }
+ }
}
diff --git a/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs b/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs
new file mode 100644
index 0000000..2930dee
--- /dev/null
+++ b/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs
@@ -0,0 +1,197 @@
+using BWP.B3ClientService.BO;
+using BWP.B3ClientService.MapBO;
+using BWP.B3ClientService.Rpcs;
+using Forks.EnterpriseServices.DomainObjects2;
+using Forks.EnterpriseServices.DomainObjects2.DQuery;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TSingSoft.WebPluginFramework;
+using TSingSoft.WebPluginFramework.BWPClients;
+
+namespace BWP.B3ClientService.Tasks.UpdateLoad
+{
+ public static class UpLoadWeightBill
+ {
+ public static void Execute()
+ {
+ //1、清理垃圾(删除且未上传的)
+ ClearUnUpdateLoadAndDeleteData();
+
+ //2、获取所有未上传的数据
+ var allBill = GetAllNeedSyncBill();
+
+ //3、上传
+ //{
+ // 1、插入(全量)
+
+
+
+ // 2、修改{1、全部修改,2、明细删除} 返回 信息后,明细该删的,要清理,然后改为已同步。
+ // 3、删除的,删除,并清理本地
+
+ // 修改删除注意单据状态。
+ // }
+
+
+ //4、并反馈ID
+
+ //4、改为已上传
+ }
+
+ static void ClearUnUpdateLoadAndDeleteData()
+ {
+ using (var session = Dmo.NewSession())
+ {
+ DeleteEntity(session);
+ DeleteEntity(session);
+ DeleteEntity(session);
+ DeleteEntity(session);
+ DeleteEntity(session);
+ session.Commit();
+ }
+ }
+
+ static void DeleteEntity(IDmoSession session)
+ where T : SyncBase
+ {
+ var delete = new DQDeleteDom(typeof(T));
+ delete.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", true), DQCondition.IsNull(DQExpression.Field("B3ID"))));
+ session.ExecuteNonQuery(delete);
+ }
+
+ static IEnumerable GetAllNeedSyncBill()
+ {
+ var query = new DmoQuery(typeof(WeightBill));
+ query.Where.Conditions.Add(DQCondition.EQ("Sync", false));
+ query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true));
+ return query.EExecuteList().Cast();
+ }
+
+ static BackRpcObj Sync(WeightBill bill, string serverUri)
+ {
+ var bwpClient = new BWPClient(serverUri, bill.Creator);
+ WeighBill dmo = new WeighBill();
+ if (bill.B3ID.HasValue)
+ dmo = bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/Load", bill.B3ID.Value);
+ dmo.AccountingUnit_ID = bill.AccountingUnit_ID;
+ dmo.Department_ID = bill.Department_ID;
+ dmo.Zone_ID = bill.Zone_ID;
+ dmo.Employee_ID = bill.Employee_ID;
+ dmo.Supplier_ID = bill.Supplier_ID;
+ dmo.WeighTime = bill.WeighTime;
+ dmo.ShackPrice = bill.ShackPrice;
+ dmo.ShackWeight = bill.ShackWeight;
+ dmo.ShackMoney = bill.ShackMoney;
+ dmo.PurchaseType = bill.PurchaseType_ID;
+ dmo.Inspector_ID = bill.Inspector_ID;
+ dmo.Car_ID = bill.Car_ID;
+ dmo.AnimalTestNumber = bill.AnimalTestNumber;
+ dmo.AnimalTestDate = bill.AnimalTestDate;
+ dmo.AnimalTestMan = bill.AnimalTestMan;
+ dmo.Remark = bill.Remark;
+ dmo.CID = bill.ID;
+
+ foreach (var bF in bill.FarmerDetails)
+ {
+ //未上传标识为删除的,已经在ClearUnUpdateLoadAndDeleteData里处理了
+ var first = dmo.FarmerDetails.FirstOrDefault(x => x.ID == bF.B3ID);
+ if (bF.DeleteState)
+ {
+ if (first != null)
+ dmo.FarmerDetails.Remove(first);
+ continue;
+ }
+ if (first == null)
+ {
+ first = new Weigh_FarmerDetail();
+ dmo.FarmerDetails.Add(first);
+ first.CID = bF.ID;
+ }
+ first.Farmer_ID = bF.Farmer_ID;
+ first.Number = bF.Number;
+ first.Weigh_ID = dmo.ID;
+ first.Weight = bF.Weight;
+ }
+
+ foreach (var bd in bill.Details)
+ {
+ var first = dmo.WeighRecord.FirstOrDefault(x => x.ID == bd.B3ID);
+ if (bd.DeleteState)
+ {
+ if (first != null)
+ dmo.WeighRecord.Remove(first);
+ continue;
+ }
+ if (first == null)
+ {
+ first = new Weigh_Record();
+ dmo.WeighRecord.Add(first);
+ first.CID = bd.ID;
+ }
+ first.Weigh_ID = dmo.ID;
+ first.LiveVarieties_ID = bill.LiveVarieties_ID;
+ first.HogGrade_ID = bill.HogGrade_ID;
+ first.Number = bd.Number ?? 0;
+ first.MaoWeight = bd.MaoWeight;
+ first.PiWeight = bd.PiWeight;
+ first.Weight = bd.Weight;
+ first.LiveColonyHouse_Name = string.Join(",", bill.HouseDetails.Where(x => !x.DeleteState).Select(x => x.LiveColonyHouse_Name));
+ }
+
+ foreach (var bs in bill.SanctionDetails)
+ {
+ var first = dmo.WeighAbnormalRecording.FirstOrDefault(x => x.ID == bs.B3ID);
+ if (bs.DeleteState)
+ {
+ if (first != null)
+ dmo.WeighAbnormalRecording.Remove(first);
+ continue;
+ }
+ if (first == null)
+ {
+ first = new Weigh_AbnormalRecording();
+ dmo.WeighAbnormalRecording.Add(first);
+ first.CID = bs.ID;
+ }
+ first.Sanction_ID = bs.Sanction_ID;
+ first.AbnormalItem_ID = bs.AbnormalItem_ID;
+ first.Num = bs.Number ?? 0;
+ first.Weigh_ID = dmo.ID;
+ }
+
+
+
+
+ //var farmerDic = new Dictionary();
+ //foreach (var farmerDetail in bill.FarmerDetails)
+ //{
+ // farmerDic.Add("ID", farmerDetail.B3ID);
+ // farmerDic.Add("Weigh_ID", bill.ID);
+ // farmerDic.Add("Farmer_ID", farmerDetail.Farmer_ID);
+ // farmerDic.Add("Number", farmerDetail.Number);
+ // farmerDic.Add("Weight", farmerDetail.Weight);
+ // farmerDic.Add("CID", farmerDetail.ID);
+ //}
+
+ //dic.Add("FarmerDetails", farmerDic);
+
+ //var farmerDic = new Dictionary();
+ //foreach (var farmerDetail in bill.FarmerDetails)
+ //{
+ // farmerDic.Add("ID", farmerDetail.B3ID);
+ // farmerDic.Add("Weigh_ID", bill.ID);
+ // farmerDic.Add("Farmer_ID", farmerDetail.Farmer_ID);
+ // farmerDic.Add("Number", farmerDetail.Number);
+ // farmerDic.Add("Weight", farmerDetail.Weight);
+ // farmerDic.Add("CID", farmerDetail.ID);
+ //}
+
+ //dic.Add("FarmerDetails", farmerDic);
+ return null;
+ }
+
+ }
+}
diff --git a/B3ClientService/Tasks/UpdateLoad/UploadTest.cs b/B3ClientService/Tasks/UpdateLoad/UploadTest.cs
index 294b71a..faecd9c 100644
--- a/B3ClientService/Tasks/UpdateLoad/UploadTest.cs
+++ b/B3ClientService/Tasks/UpdateLoad/UploadTest.cs
@@ -1,72 +1,72 @@
-//using BWP.B3ClientService.BO;
-//using Forks.EnterpriseServices.DomainObjects2.DQuery;
-//using Forks.JsonRpc.Client;
-//using System;
-//using System.Collections.Generic;
-//using System.Linq;
-//using System.Text;
-//using System.Threading.Tasks;
-//using TSingSoft.WebPluginFramework.BWPClients;
-//using TSingSoft.WebPluginFramework.TimerTasks;
-//using TSingSoft.WebPluginFramework;
-//using Forks.JsonRpc.Client.Data;
-//using Forks.EnterpriseServices.DomainObjects2;
+using BWP.B3ClientService.BO;
+using Forks.EnterpriseServices.DomainObjects2.DQuery;
+using Forks.JsonRpc.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TSingSoft.WebPluginFramework.BWPClients;
+using TSingSoft.WebPluginFramework.TimerTasks;
+using TSingSoft.WebPluginFramework;
+using Forks.JsonRpc.Client.Data;
+using Forks.EnterpriseServices.DomainObjects2;
-//namespace BWP.B3ClientService.Tasks
-//{
-// public class UploadTest : ITimerTask
-// {
-// public void Execute()
-// {
-// var serverUri = ServerHost.GetServerUrl();
-// if (string.IsNullOrEmpty(serverUri))
-// throw new Exception("请配置服务器地址");
+namespace BWP.B3ClientService.Tasks
+{
+ public class UploadTest : ITimerTask
+ {
+ public void Execute()
+ {
+ var serverUri = ServerHost.GetServerUrl();
+ if (string.IsNullOrEmpty(serverUri))
+ throw new Exception("请配置服务器地址");
-// var list = GetWeightBill();
-// foreach (var bill in list)
-// {
-// BWPClient bwpClient = new BWPClient(serverUri, bill.CreaterName);
-// var obj = ConvertToRpcObject(bill);
-// var id =bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/TouchScreenUploadRpc/InsertWeighBill", obj);
-// using (var dmo = Dmo.NewSession())
-// {
-
-// }
+ var list = GetWeightBill();
+ foreach (var bill in list)
+ {
+ BWPClient bwpClient = new BWPClient(serverUri, bill.Creator);
+ var obj = ConvertToRpcObject(bill);
+ var id = bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/TouchScreenUploadRpc/InsertWeighBill", obj);
+ using (var dmo = Dmo.NewSession())
+ {
-// }
-// }
+ }
-// IEnumerable GetWeightBill()
-// {
-// var query = new DmoQuery(typeof(WeightBill));
-// query.Where.Conditions.Add(DQCondition.EQ("Sync", false));
-// return query.EExecuteList().Cast();
-// }
+ }
+ }
-// Dictionary ConvertToRpcObject(WeightBill bill)
-// {
-// var dic = new Dictionary();
-// dic.Add("AccountingUnit_ID", 1);
-// dic.Add("Department_ID", 5);
-// dic.Add("Domain_ID", 1);
-// dic.Add("Zone_ID", bill.Zone_ID);
-// dic.Add("Employee_ID", bill.Employee_ID);
-// dic.Add("Supplier_ID", bill.Supplier_ID);
-// dic.Add("WeighTime", bill.WeightTime);
-// dic.Add("ShackPrice", bill.ShackPrice);
-// dic.Add("ShackWeight", bill.ShackWeight);
-// dic.Add("PurchaseType", bill.PurchaseType_ID);
-// dic.Add("Inspector_ID", bill.Inspector_ID);
-// dic.Add("Car_ID", bill.Car_ID);
-// dic.Add("AnimalTestNumber", bill.AnimalTestNumber);
-// dic.Add("AnimalTestDate", bill.AnimalTestDate);
-// dic.Add("AnimalTestMan", bill.AnimalTestMan);
-// return dic;
-// }
+ IEnumerable GetWeightBill()
+ {
+ var query = new DmoQuery(typeof(WeightBill));
+ query.Where.Conditions.Add(DQCondition.EQ("Sync", false));
+ return query.EExecuteList().Cast();
+ }
-// public string Name
-// {
-// get { return "测试上传"; }
-// }
-// }
-//}
+ Dictionary ConvertToRpcObject(WeightBill bill)
+ {
+ var dic = new Dictionary();
+ dic.Add("AccountingUnit_ID", 1);
+ dic.Add("Department_ID", 5);
+ dic.Add("Domain_ID", 1);
+ dic.Add("Zone_ID", bill.Zone_ID);
+ dic.Add("Employee_ID", bill.Employee_ID);
+ dic.Add("Supplier_ID", bill.Supplier_ID);
+ dic.Add("WeighTime", bill.WeighTime);
+ dic.Add("ShackPrice", bill.ShackPrice);
+ dic.Add("ShackWeight", bill.ShackWeight);
+ dic.Add("PurchaseType", bill.PurchaseType_ID);
+ dic.Add("Inspector_ID", bill.Inspector_ID);
+ dic.Add("Car_ID", bill.Car_ID);
+ dic.Add("AnimalTestNumber", bill.AnimalTestNumber);
+ dic.Add("AnimalTestDate", bill.AnimalTestDate);
+ dic.Add("AnimalTestMan", bill.AnimalTestMan);
+ return dic;
+ }
+
+ public string Name
+ {
+ get { return "测试上传"; }
+ }
+ }
+}