|
|
@ -16,45 +16,58 @@ namespace BWP.B3ClientService.Rpcs |
|
|
public static class SyncBaseInfoRpc |
|
|
public static class SyncBaseInfoRpc |
|
|
{ |
|
|
{ |
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
public static string SyncWorkUnit() |
|
|
|
|
|
|
|
|
public static string SyncWorkUnit(string par) |
|
|
{ |
|
|
{ |
|
|
return GetBaseInfoJosn<WorkUnit>(); |
|
|
|
|
|
|
|
|
return GetBaseInfoJosn<WorkUnit>(par); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
public static string SyncProductBatch() |
|
|
|
|
|
|
|
|
public static string SyncStore(string par) |
|
|
{ |
|
|
{ |
|
|
return SyncProductBatchByType(0); |
|
|
|
|
|
|
|
|
return GetBaseInfoJosn<Store>(par); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
|
|
public static string SyncProductBatchByType(int type) |
|
|
|
|
|
|
|
|
static string GetBaseInfoJosn<T>(string par) |
|
|
|
|
|
where T : B3Frameworks.BO.BaseInfo, new() |
|
|
{ |
|
|
{ |
|
|
var query = new DQueryDom(new JoinAlias(typeof(ProductBatch))); |
|
|
|
|
|
|
|
|
var local = JsonConvert.DeserializeObject<List<Tuple<long, int>>>(par); |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(T))); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Date")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BatchType", type), DQCondition.EQ("IsLocked", false), DQCondition.EQ("Stopped", false))); |
|
|
|
|
|
var list = query.EExecuteList<long, string, DateTime?>().Select(x => new MinProductBatch { ID = x.Item1, Name = x.Item2, Date = x.Item3 }); |
|
|
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("RowVersion")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Stopped", false)); |
|
|
|
|
|
var server = query.EExecuteList<long, string, int>(); |
|
|
|
|
|
var insert = server.Where(x => !local.Any(y => y.Item1 == x.Item1)).Select(x => new { ID = x.Item1, Name = x.Item2, RowVersion = x.Item3 }); |
|
|
|
|
|
var update = server.Where(x => local.Any(y => y.Item1 == x.Item1 && y.Item2 != x.Item3)).Select(x => new { ID = x.Item1, Name = x.Item2, RowVersion = x.Item3 }); |
|
|
|
|
|
var delete = local.Where(x => !server.Any(y => y.Item1 == x.Item1)).Select(x => x.Item1); |
|
|
|
|
|
|
|
|
|
|
|
return JsonConvert.SerializeObject(new Tuple<IEnumerable<object>, IEnumerable<object>, IEnumerable<long>>(insert, update, delete)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static string GetBaseInfoJosn<T>(IDQExpression withCondition = null) |
|
|
|
|
|
where T : B3Frameworks.BO.BaseInfo, new() |
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
|
|
public static string SyncProductBatchByType(int type, string par) |
|
|
{ |
|
|
{ |
|
|
var query = new DQueryDom(new JoinAlias(typeof(T))); |
|
|
|
|
|
|
|
|
var local = JsonConvert.DeserializeObject<List<Tuple<long, int>>>(par); |
|
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(ProductBatch))); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Where.Conditions.Add(DQCondition.EQ("Stopped", false)); |
|
|
|
|
|
if (withCondition != null) |
|
|
|
|
|
query.Where.Conditions.Add(withCondition); |
|
|
|
|
|
var list = query.EExecuteList<long, string>().Select(x => new MinBaseInfo { ID = x.Item1, Name = x.Item2 }); |
|
|
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("Date")); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("RowVersion")); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BatchType", type), DQCondition.EQ("Stopped", false), DQCondition.GreaterThanOrEqual("Date", DateTime.Today.AddDays(-1)))); |
|
|
|
|
|
var server = query.EExecuteList<long, string, DateTime, int>(); |
|
|
|
|
|
var insert = server.Where(x => !local.Any(y => y.Item1 == x.Item1)).Select(x => new { ID = x.Item1, Name = x.Item2, Date = x.Item3, RowVersion = x.Item4 }); |
|
|
|
|
|
var update = server.Where(x => local.Any(y => y.Item1 == x.Item1 && y.Item2 != x.Item4)).Select(x => new { ID = x.Item1, Name = x.Item2, Date = x.Item3, RowVersion = x.Item4 }); |
|
|
|
|
|
var delete = local.Where(x => !server.Any(y => y.Item1 == x.Item1)).Select(x => x.Item1); |
|
|
|
|
|
|
|
|
|
|
|
return JsonConvert.SerializeObject(new Tuple<IEnumerable<object>, IEnumerable<object>, IEnumerable<long>>(insert, update, delete)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
public static string SyncClientGoodsSetByClient(short type) |
|
|
|
|
|
|
|
|
public static string SyncClientGoodsSetByClient(short type, string par, string p2) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var local = JsonConvert.DeserializeObject<List<Tuple<long, int>>>(par); |
|
|
|
|
|
var g2 = JsonConvert.DeserializeObject<List<Tuple<long, int>>>(p2); |
|
|
|
|
|
|
|
|
var main = new JoinAlias(typeof(ClientGoodsSet)); |
|
|
var main = new JoinAlias(typeof(ClientGoodsSet)); |
|
|
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail)); |
|
|
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail)); |
|
|
var goods = new JoinAlias(typeof(Goods)); |
|
|
var goods = new JoinAlias(typeof(Goods)); |
|
|
@ -62,9 +75,10 @@ namespace BWP.B3ClientService.Rpcs |
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID")); |
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID")); |
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(detail, "Goods_ID", goods, "ID")); |
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(detail, "Goods_ID", goods, "ID")); |
|
|
query.Where.Conditions.Add(DQCondition.EQ("ApplyClient", type)); |
|
|
query.Where.Conditions.Add(DQCondition.EQ("ApplyClient", type)); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Stopped", false)); |
|
|
|
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Stopped")); |
|
|
|
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("RowVersion")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID", detail)); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID", detail)); |
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail)); |
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail)); |
|
|
@ -75,9 +89,15 @@ namespace BWP.B3ClientService.Rpcs |
|
|
query.Columns.Add(DQSelectColumn.Field("Code", goods)); |
|
|
query.Columns.Add(DQSelectColumn.Field("Code", goods)); |
|
|
query.Columns.Add(DQSelectColumn.Field("Spec", goods)); |
|
|
query.Columns.Add(DQSelectColumn.Field("Spec", goods)); |
|
|
query.Columns.Add(DQSelectColumn.Field("MainUnit", goods)); |
|
|
query.Columns.Add(DQSelectColumn.Field("MainUnit", goods)); |
|
|
|
|
|
query.Columns.Add(DQSelectColumn.Field("RowVersion", goods)); |
|
|
|
|
|
|
|
|
var list = new List<MinClientGoodsSet>(); |
|
|
|
|
|
var goodsList = new List<MinGoods>(); |
|
|
|
|
|
|
|
|
var insert = new List<MinClientGoodsSet>(); |
|
|
|
|
|
var update = new List<MinClientGoodsSet>(); |
|
|
|
|
|
var serverIDs = new List<long>(); |
|
|
|
|
|
|
|
|
|
|
|
var gInsert = new List<MinGoods>(); |
|
|
|
|
|
var gUpdate = new List<MinGoods>(); |
|
|
|
|
|
var gsID = new List<long>(); |
|
|
using (var session = Dmo.NewSession()) |
|
|
using (var session = Dmo.NewSession()) |
|
|
{ |
|
|
{ |
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
@ -85,69 +105,105 @@ namespace BWP.B3ClientService.Rpcs |
|
|
while (reader.Read()) |
|
|
while (reader.Read()) |
|
|
{ |
|
|
{ |
|
|
var id = (long)reader[0]; |
|
|
var id = (long)reader[0]; |
|
|
var first = list.FirstOrDefault(x => x.ID == id); |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
|
|
|
var rowVersion = (int)reader[1]; |
|
|
|
|
|
if (!serverIDs.Contains(id)) |
|
|
|
|
|
serverIDs.Add(id); |
|
|
|
|
|
|
|
|
|
|
|
MinClientGoodsSet first = null; |
|
|
|
|
|
if (!local.Any(x => x.Item1 == id))//insert
|
|
|
|
|
|
{ |
|
|
|
|
|
first = insert.FirstOrDefault(x => x.ID == id); |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
{ |
|
|
|
|
|
first = new MinClientGoodsSet(); |
|
|
|
|
|
insert.Add(first); |
|
|
|
|
|
first.ID = id; |
|
|
|
|
|
first.RowVersion = rowVersion; |
|
|
|
|
|
first.Name = (string)reader[2]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (local.Any(x => x.Item1 == id && x.Item2 != rowVersion))//upate
|
|
|
|
|
|
{ |
|
|
|
|
|
first = update.FirstOrDefault(x => x.ID == id); |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
{ |
|
|
|
|
|
first = new MinClientGoodsSet(); |
|
|
|
|
|
update.Add(first); |
|
|
|
|
|
first.ID = id; |
|
|
|
|
|
first.RowVersion = rowVersion; |
|
|
|
|
|
first.Name = (string)reader[2]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
var goodsID = (long)reader[4]; |
|
|
|
|
|
if (first != null) |
|
|
|
|
|
{ |
|
|
|
|
|
var d = new ClientGoodsSet_Detail(); |
|
|
|
|
|
first.Details.Add(d); |
|
|
|
|
|
d.ClientGoodsSet_ID = id; |
|
|
|
|
|
d.ID = (long)reader[3]; |
|
|
|
|
|
d.Goods_ID = goodsID; |
|
|
|
|
|
d.StandardWeight = (decimal?)reader[5]; |
|
|
|
|
|
d.StandardWeightUp = (decimal?)reader[6]; |
|
|
|
|
|
d.StandardWeightLow = (decimal?)reader[7]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!gsID.Contains(goodsID)) |
|
|
|
|
|
gsID.Add(goodsID); |
|
|
|
|
|
|
|
|
|
|
|
var gVersion = (int)reader[12]; |
|
|
|
|
|
if (!g2.Any(x => x.Item1 == goodsID))//insert
|
|
|
{ |
|
|
{ |
|
|
first = new MinClientGoodsSet(); |
|
|
|
|
|
list.Add(first); |
|
|
|
|
|
first.ID = id; |
|
|
|
|
|
first.Stopped = (bool)reader[1]; |
|
|
|
|
|
if (first.Stopped) |
|
|
|
|
|
continue; |
|
|
|
|
|
first.Name = (string)reader[2]; |
|
|
|
|
|
|
|
|
if (!gInsert.Any(x => x.ID == goodsID)) |
|
|
|
|
|
{ |
|
|
|
|
|
gInsert.Add(new MinGoods |
|
|
|
|
|
{ |
|
|
|
|
|
ID = goodsID, |
|
|
|
|
|
Name = (string)reader[8], |
|
|
|
|
|
Code = (string)reader[9], |
|
|
|
|
|
Spec = (string)reader[10], |
|
|
|
|
|
MainUnit = (string)reader[11], |
|
|
|
|
|
RowVersion = gVersion |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
var d = new ClientGoodsSet_Detail(); |
|
|
|
|
|
first.Details.Add(d); |
|
|
|
|
|
d.ClientGoodsSet_ID = id; |
|
|
|
|
|
d.ID = (long)reader[3]; |
|
|
|
|
|
d.Goods_ID = (long)reader[4]; |
|
|
|
|
|
d.StandardWeight = (decimal?)reader[5]; |
|
|
|
|
|
d.StandardWeightUp = (decimal?)reader[6]; |
|
|
|
|
|
d.StandardWeightLow = (decimal?)reader[7]; |
|
|
|
|
|
if (goodsList.Any(x => x.ID == d.Goods_ID)) |
|
|
|
|
|
continue; |
|
|
|
|
|
goodsList.Add(new MinGoods |
|
|
|
|
|
|
|
|
else if (g2.Any(x => x.Item1 == goodsID && x.Item2 != gVersion))//upate
|
|
|
{ |
|
|
{ |
|
|
ID = d.Goods_ID, |
|
|
|
|
|
Name = (string)reader[8], |
|
|
|
|
|
Code = (string)reader[9], |
|
|
|
|
|
Spec = (string)reader[10], |
|
|
|
|
|
MainUnit = (string)reader[11] |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
if (!gUpdate.Any(x => x.ID == goodsID)) |
|
|
|
|
|
{ |
|
|
|
|
|
gUpdate.Add(new MinGoods |
|
|
|
|
|
{ |
|
|
|
|
|
ID = goodsID, |
|
|
|
|
|
Name = (string)reader[8], |
|
|
|
|
|
Code = (string)reader[9], |
|
|
|
|
|
Spec = (string)reader[10], |
|
|
|
|
|
MainUnit = (string)reader[11], |
|
|
|
|
|
RowVersion = gVersion |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
var eFirst = list.FirstOrDefault(x => !x.Stopped); |
|
|
|
|
|
if (eFirst != null) |
|
|
|
|
|
eFirst.Goods.AddRange(goodsList); |
|
|
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
|
|
public static string GetProductBatch(int range) |
|
|
|
|
|
{ |
|
|
|
|
|
return GetProductBatchByType(range, 0); |
|
|
|
|
|
|
|
|
var delete = local.Where(x => !serverIDs.Any(y => y == x.Item1)).Select(x => x.Item1); |
|
|
|
|
|
var gDelete = g2.Where(x => !gsID.Any(y => y == x.Item1)).Select(x => x.Item1); |
|
|
|
|
|
|
|
|
|
|
|
var result = new Tuple<List<MinClientGoodsSet>, List<MinClientGoodsSet>, IEnumerable<long>, List<MinGoods>, List<MinGoods>, IEnumerable<long>>(insert, update, delete, gInsert, gUpdate, gDelete); |
|
|
|
|
|
return JsonConvert.SerializeObject(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
public static string GetProductBatchByType(int range, int type) |
|
|
|
|
|
|
|
|
public static string GetProductBatchByType(int top, short type) |
|
|
{ |
|
|
{ |
|
|
var query = new DQueryDom(new JoinAlias(typeof(ProductBatch))); |
|
|
var query = new DQueryDom(new JoinAlias(typeof(ProductBatch))); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Name")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Date")); |
|
|
query.Columns.Add(DQSelectColumn.Field("Date")); |
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BatchType", type), DQCondition.EQ("IsLocked", false), DQCondition.EQ("Stopped", false))); |
|
|
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); |
|
|
|
|
|
query.Range = SelectRange.Top(range); |
|
|
|
|
|
var list = query.EExecuteList<long, string, DateTime?>().Select(x => new MinProductBatch { ID = x.Item1, Name = x.Item2, Date = x.Item3 }); |
|
|
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
|
|
public static string SyncStore() |
|
|
|
|
|
{ |
|
|
|
|
|
return GetBaseInfoJosn<Store>(); |
|
|
|
|
|
|
|
|
query.Range = SelectRange.Top(top); |
|
|
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("Date", true)); |
|
|
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BatchType", type), DQCondition.EQ("Stopped", false))); |
|
|
|
|
|
var result= query.EExecuteList<long, string, DateTime?>().Select(x => new { ID = x.Item1, Name = x.Item2, Date = x.Item3 }); |
|
|
|
|
|
return JsonConvert.SerializeObject(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
@ -167,12 +223,14 @@ namespace BWP.B3ClientService.Rpcs |
|
|
class MinBaseInfo |
|
|
class MinBaseInfo |
|
|
{ |
|
|
{ |
|
|
public long ID { get; set; } |
|
|
public long ID { get; set; } |
|
|
|
|
|
|
|
|
public string Name { get; set; } |
|
|
public string Name { get; set; } |
|
|
|
|
|
public int RowVersion { get; set; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class MinProductBatch : MinBaseInfo |
|
|
|
|
|
|
|
|
class MinProductBatch |
|
|
{ |
|
|
{ |
|
|
|
|
|
public long ID { get; set; } |
|
|
|
|
|
public string Name { get; set; } |
|
|
public DateTime? Date { get; set; } |
|
|
public DateTime? Date { get; set; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -183,25 +241,13 @@ namespace BWP.B3ClientService.Rpcs |
|
|
public string MainUnit { get; set; } |
|
|
public string MainUnit { get; set; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class MinClientGoodsSet |
|
|
|
|
|
|
|
|
class MinClientGoodsSet : MinBaseInfo |
|
|
{ |
|
|
{ |
|
|
public long ID { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public bool Stopped { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
List<ClientGoodsSet_Detail> _details = new List<ClientGoodsSet_Detail>(); |
|
|
List<ClientGoodsSet_Detail> _details = new List<ClientGoodsSet_Detail>(); |
|
|
public List<ClientGoodsSet_Detail> Details |
|
|
public List<ClientGoodsSet_Detail> Details |
|
|
{ |
|
|
{ |
|
|
get { return _details; } |
|
|
get { return _details; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<MinGoods> _goods = new List<MinGoods>(); |
|
|
|
|
|
public List<MinGoods> Goods |
|
|
|
|
|
{ |
|
|
|
|
|
get { return _goods; } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |