diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj
index c5b131a..750e969 100644
--- a/B3ClientService/B3ClientService.csproj
+++ b/B3ClientService/B3ClientService.csproj
@@ -264,6 +264,7 @@
+
diff --git a/B3ClientService/BO/Bill/SegmentProductionInfo.cs b/B3ClientService/BO/Bill/SegmentProductionInfo.cs
index 3c92305..52f581e 100644
--- a/B3ClientService/BO/Bill/SegmentProductionInfo.cs
+++ b/B3ClientService/BO/Bill/SegmentProductionInfo.cs
@@ -15,6 +15,12 @@ namespace BWP.B3ClientService.BO
[DBIndexType("IDX_B3ClientService_SegmentProductionInfo_Clustered", IndexType.Normal)]
[DFClass]
[LogicName("分割品数据表")]
+ ///
+ /// 状态 入库时间 退库时间
+ /// 未入库 空 空
+ /// 已入库 有 空
+ /// 已退库 有 有
+ ///
public class SegmentProductionInfo : Base
{
public SegmentProductionInfo()
@@ -60,12 +66,11 @@ namespace BWP.B3ClientService.BO
#endregion
#region 退库信息
+
[LogicName("退库时间")]
[DbColumn(DbType = SqlDbType.DateTime)]
public DateTime? BackTime { get; set; }
- [LogicName("退库")]
- public bool IsDelete { get; set; }
#endregion
#region 销售时间
diff --git a/B3ClientService/OfflinRpc/SegmentInStoreRpc.cs b/B3ClientService/OfflinRpc/SegmentInStoreRpc.cs
index 94a8705..22f9021 100644
--- a/B3ClientService/OfflinRpc/SegmentInStoreRpc.cs
+++ b/B3ClientService/OfflinRpc/SegmentInStoreRpc.cs
@@ -12,6 +12,12 @@ using TSingSoft.WebPluginFramework;
namespace BWP.B3ClientService.Rpcs
{
+ ///
+ /// 状态 入库时间 退库时间
+ /// 未入库 空 空
+ /// 已入库 有 空
+ /// 已退库 有 有
+ ///
[Rpc]
public static class SegmentInStoreRpc
{
@@ -54,28 +60,17 @@ namespace BWP.B3ClientService.Rpcs
var list = JsonConvert.DeserializeObject>(json);
using (var session = Dmo.NewSession())
{
- /* BarCode InStoreTime Store_ID State */
+ /* BarCode InStoreTime Store_ID BackStoreTime */
foreach (var item in list)
{
var id = Exist(session, item.BarCode);
if (id == null)
{
- if (item.Delete)
- continue;
var entity = new SegmentProductionInfo();
entity.BarCode = item.BarCode;
- if (item.State == 2)
- {
- entity.InStoreTime = item.InStoreTime;
- entity.BackTime = item.BackStoreTime;
- entity.Store_ID = item.Store_ID;
- entity.IsDelete = true;
- }
- else
- {
- entity.InStoreTime = item.InStoreTime;
- entity.Store_ID = item.Store_ID;
- }
+ entity.InStoreTime = item.InStoreTime;
+ entity.BackTime = item.BackStoreTime;
+ entity.Store_ID = item.Store_ID;
session.Insert(entity);
}
else
@@ -97,25 +92,11 @@ namespace BWP.B3ClientService.Rpcs
private static void Update(IDmoSession session, long id, SegmentInStoreObj entity)
{
var update = new DQUpdateDom(typeof(SegmentProductionInfo));
- if (entity.Delete || entity.State == 2)
- {
- if (entity.Delete)
- {
- update.Columns.Add(new DQUpdateColumn("InStoreTime", DQExpression.NULL));
- update.Columns.Add(new DQUpdateColumn("Store_ID", DQExpression.NULL));
- }
- else
- {
- update.Columns.Add(new DQUpdateColumn("BackTime", entity.BackStoreTime));
- update.Columns.Add(new DQUpdateColumn("IsDelete", true));
- }
- }
- else
- {
- update.Columns.Add(new DQUpdateColumn("InStoreTime", entity.InStoreTime));
- update.Columns.Add(new DQUpdateColumn("Store_ID", entity.Store_ID));
- }
+ update.Columns.Add(new DQUpdateColumn("InStoreTime", entity.InStoreTime));
+ update.Columns.Add(new DQUpdateColumn("Store_ID", entity.Store_ID));
+ update.Columns.Add(new DQUpdateColumn("BackTime", DQExpression.Value(entity.BackStoreTime)));
update.Columns.Add(new DQUpdateColumn("IsSync", false));
+ update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
session.ExecuteNonQuery(update);
}
@@ -127,7 +108,7 @@ namespace BWP.B3ClientService.Rpcs
var goods = new JoinAlias(typeof(Goods));
var query = new DQueryDom(main);
query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID"));
- query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNull(DQExpression.Field("InStoreTime")), DQCondition.EQ("IsDelete", false)));
+ query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("InStoreTime")));
query.Columns.Add(DQSelectColumn.Field("BarCode"));
query.Columns.Add(DQSelectColumn.Field("Code", goods));
query.Columns.Add(DQSelectColumn.Field("Name", goods));
@@ -165,7 +146,7 @@ namespace BWP.B3ClientService.Rpcs
query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID"));
query.Columns.Add(DQSelectColumn.Field("Code", goods));
query.Columns.Add(DQSelectColumn.Field("Weight"));
- query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BarCode", barCode), DQCondition.EQ("IsDelete", false)));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BarCode", barCode), DQCondition.IsNotNull(DQExpression.Field("InStoreTime")), DQCondition.IsNull(DQExpression.Field("BackTime"))));
var result = query.EExecuteScalar();
if (result == null)
return string.Empty;
@@ -181,11 +162,6 @@ namespace BWP.B3ClientService.Rpcs
public long? Store_ID { get; set; }
- //0入库 2退库
- public int State { get; set; }
-
- public bool Delete { get; set; }
-
public DateTime? BackStoreTime { get; set; }
}
diff --git a/B3ClientService/OfflinRpc/SegmentSaleOutStoreRpc.cs b/B3ClientService/OfflinRpc/SegmentSaleOutStoreRpc.cs
index 70584ca..d0de1ed 100644
--- a/B3ClientService/OfflinRpc/SegmentSaleOutStoreRpc.cs
+++ b/B3ClientService/OfflinRpc/SegmentSaleOutStoreRpc.cs
@@ -24,7 +24,7 @@ namespace BWP.B3ClientService.Rpcs
query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID"));
query.Columns.Add(DQSelectColumn.Field("Code", goods));
query.Columns.Add(DQSelectColumn.Field("Weight"));
- query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("IsDelete", false), DQCondition.EQ("BarCode", barCode)));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNull(DQExpression.Field("BackTime")), DQCondition.EQ("BarCode", barCode)));
query.Range = SelectRange.Top(1);
var rst = query.EExecuteScalar();
var entity = new ExtensionObj();
@@ -61,7 +61,7 @@ namespace BWP.B3ClientService.Rpcs
return null;
var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo)));
query.Columns.Add(DQSelectColumn.Field("ID"));
- query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("IsDelete", false), DQCondition.EQ("BarCode", code)));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNull(DQExpression.Field("BackTime")), DQCondition.EQ("BarCode", code)));
return query.EExecuteScalar(session);
}
diff --git a/B3ClientService/Tasks/UpdateLoad/UploadProductInStore.cs b/B3ClientService/Tasks/UpdateLoad/UploadProductInStore.cs
new file mode 100644
index 0000000..eb8e4d7
--- /dev/null
+++ b/B3ClientService/Tasks/UpdateLoad/UploadProductInStore.cs
@@ -0,0 +1,150 @@
+using BWP.B3ClientService.BO;
+using Forks.EnterpriseServices.DomainObjects2;
+using Forks.EnterpriseServices.DomainObjects2.DQuery;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using TSingSoft.WebPluginFramework.TimerTasks;
+using TSingSoft.WebPluginFramework;
+using Forks.EnterpriseServices.BusinessInterfaces;
+using Forks.EnterpriseServices.SqlDoms;
+using Newtonsoft.Json;
+using Forks.JsonRpc.Client;
+
+namespace BWP.B3ClientService.Tasks
+{
+ public class UploadProductInStore : ITimerTask
+ {
+ void InitRpc(string uri)
+ {
+ try
+ {
+ RpcFacade.Init(uri, "B3ClientServer");
+ }
+ catch (Exception ex)
+ {
+ if (ex.Message != "Can only start once")
+ throw;
+ }
+ }
+
+ public void Execute()
+ {
+ var serverUri = ServerHost.GetServerUrl();
+ if (string.IsNullOrEmpty(serverUri))
+ throw new Exception("请配置服务器地址");
+ var need = GetNeedUploadBatchStore();
+ if (need.Count == 0)
+ return;
+
+ InitRpc(serverUri);
+
+ var method = "/MainSystem/B3ButcherManage/Rpcs/ProductInStoreRpc/InsertInstore";
+ foreach (var item in need)
+ {
+ using (var context = new TransactionContext())
+ {
+ var arr = GetArrList(item.Item1, item.Item2);
+ var summary = new List();
+ foreach (var g in arr.GroupBy(x => new { x.ProductBatch, x.StoreCode, x.Goods_Code }))
+ {
+ var detail = new ProductInStoreJson();
+ detail.ProductBatch = g.Key.ProductBatch;
+ detail.StoreCode = g.Key.StoreCode;
+ detail.Goods_Code = g.Key.Goods_Code;
+ detail.Number = g.Sum(x => x.Number ?? 0);
+ detail.SecondNumber = g.Sum(x => x.SecondNumber ?? 0);
+ summary.Add(detail);
+ }
+ RpcFacade.Call(method, JsonConvert.SerializeObject(summary));
+ foreach (var sy in arr)
+ UpdateAsSync(context.Session, sy);
+ context.Commit();
+ }
+ }
+ }
+
+ List> GetNeedUploadBatchStore()
+ {
+ var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo)));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("ProductBatch_ID")), DQCondition.IsNotNull(DQExpression.Field("Store_ID")), DQCondition.IsNotNull(DQExpression.Field("InStoreTime")), DQCondition.EQ("IsSync", false)));
+ query.Columns.Add(DQSelectColumn.Field("ProductBatch_ID"));
+ query.Columns.Add(DQSelectColumn.Field("Store_ID"));
+ query.GroupBy.Expressions.Add(DQExpression.Field("ProductBatch_ID"));
+ query.GroupBy.Expressions.Add(DQExpression.Field("Store_ID"));
+ return query.EExecuteList();
+ }
+
+ List GetArrList(long batchID, long storeID)
+ {
+ var main = new JoinAlias(typeof(SegmentProductionInfo));
+ var batch = new JoinAlias(typeof(ProductBatch));
+ var store = new JoinAlias(typeof(Store));
+ var goods = new JoinAlias(typeof(Goods));
+ var query = new DQueryDom(main);
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(batch), DQCondition.EQ(main, "ProductBatch_ID", batch, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(store), DQCondition.EQ(main, "Store_ID", store, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID"));
+ query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ProductBatch_ID", batchID), DQCondition.EQ("Store_ID", storeID), DQCondition.IsNotNull(DQExpression.Field("InStoreTime"))));
+ query.Columns.Add(DQSelectColumn.Field("Name", batch));
+ query.Columns.Add(DQSelectColumn.Field("Code", store));
+ query.Columns.Add(DQSelectColumn.Field("Code", goods));
+ query.Columns.Add(DQSelectColumn.Field("Weight"));
+ query.Columns.Add(DQSelectColumn.Field("RowVersion"));
+ query.Columns.Add(DQSelectColumn.Field("ID"));
+ var list = new List();
+ using (var session = Dmo.NewSession())
+ {
+ using (var reader = session.ExecuteReader(query))
+ {
+ while (reader.Read())
+ {
+ var detail = new ProductInStoreJson();
+ detail.ProductBatch = (string)reader[0];
+ detail.StoreCode = (string)reader[1];
+ detail.Goods_Code = (string)reader[2];
+ detail.Number = (decimal?)reader[3];
+ detail.SecondNumber = 1;
+ detail.RowVersion = (int)reader[4];
+ detail.ID = (long)reader[5];
+ list.Add(detail);
+ }
+ }
+ }
+ return list;
+ }
+
+ void UpdateAsSync(IDmoSession session, ProductInStoreJson item)
+ {
+ var update = new DQUpdateDom(typeof(ProductInStoreJson));
+ update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", item.ID), DQCondition.EQ("RowVersion", item.RowVersion)));
+ update.Columns.Add(new DQUpdateColumn("IsSync", true));
+ session.ExecuteNonQuery(update);
+ }
+
+ public string Name
+ {
+ get { return "上传成品入库"; }
+ }
+
+ class ProductInStoreJson
+ {
+ public string ProductBatch { get; set; }
+
+ public string StoreCode { get; set; }
+
+ public string Goods_Code { get; set; }
+
+ public decimal? Number { get; set; }
+
+ public decimal? SecondNumber { get; set; }
+
+ [JsonIgnore]
+ public int RowVersion { get; set; }
+
+ [JsonIgnore]
+ public long ID { get; set; }
+ }
+ }
+}