|
|
|
@ -0,0 +1,185 @@ |
|
|
|
using BWP.B3ClientService.BO; |
|
|
|
using BWP.B3ClientService.NamedValueTemplate; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
using Forks.EnterpriseServices.JsonRpc; |
|
|
|
using Forks.EnterpriseServices.SqlDoms; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using TSingSoft.WebPluginFramework; |
|
|
|
|
|
|
|
namespace BWP.B3ClientService.Rpcs |
|
|
|
{ |
|
|
|
[Rpc] |
|
|
|
public static class SectionStoreDetailRpc |
|
|
|
{ |
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int Insert(string json) |
|
|
|
{ |
|
|
|
var arr = JsonConvert.DeserializeObject<List<SectionInfo>>(json); |
|
|
|
if (arr.Count == 0) |
|
|
|
return 0; |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(CarcassFullInfo))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ProductBatch_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("BarCode"), arr.Select(x => DQExpression.Value(x.BarCode)).ToArray())); |
|
|
|
|
|
|
|
var config = GetSectionConfig(session); |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
var entity = new SectionStoreDetail(); |
|
|
|
entity.BarCode = (string)reader[0]; |
|
|
|
var f = arr.First(x => x.BarCode == entity.BarCode); |
|
|
|
entity.InStoreTime = f.InStoreTime; |
|
|
|
entity.ProductBatch_ID = (long?)reader[1]; |
|
|
|
entity.Goods_ID = f.Goods_ID; |
|
|
|
entity.Worker_ID = f.Worker_ID; |
|
|
|
|
|
|
|
var e2 = new SectionStoreDetail(); |
|
|
|
e2.InStoreTime = entity.InStoreTime; |
|
|
|
e2.ProductBatch_ID = entity.ProductBatch_ID; |
|
|
|
var c = config.FirstOrDefault(x => x.Item1 == entity.Goods_ID.Value); |
|
|
|
if (c == null) |
|
|
|
throw new Exception("未配置条段对应关系"); |
|
|
|
e2.Goods_ID = c.Item2; |
|
|
|
e2.Worker_ID = entity.Worker_ID; |
|
|
|
|
|
|
|
session.Insert(entity); |
|
|
|
session.Insert(e2); |
|
|
|
|
|
|
|
SetCarcassTakeOut(session, (long)reader[2], entity.InStoreTime, entity.Worker_ID); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return arr.Count; |
|
|
|
} |
|
|
|
|
|
|
|
static void SetCarcassTakeOut(IDmoSession session, long id, DateTime time, long worker_ID) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(CarcassFullInfo)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("PickWeight", DQExpression.Field("InStoreWeight"))); |
|
|
|
update.Columns.Add(new DQUpdateColumn("PickWorker_ID", worker_ID)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("PickTime", time)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("PickType", 领用类型.条转段)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
static List<Tuple<long, long>> GetSectionConfig(IDmoSession session) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(SectionGoodsConfig))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("RelateGoods_ID")); |
|
|
|
return query.EExecuteList<long, long>(session); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static string GetSectionConfig() |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(SectionGoodsConfig))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Name")); |
|
|
|
var list = query.EExecuteList<long, string>().Select(x => new ExtensionObj { LongExt1 = x.Item1, StringExt1 = x.Item2 }); |
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static int FillWeight(string json) |
|
|
|
{ |
|
|
|
var list = JsonConvert.DeserializeObject<List<CarcassTakeOutObj>>(json); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
foreach (var item in list) |
|
|
|
{ |
|
|
|
var ids = GetIDs(session, item); |
|
|
|
for (var i = 0; i < item.Number; i++) |
|
|
|
{ |
|
|
|
var id = ids.FirstOrDefault(); |
|
|
|
if (id == 0) |
|
|
|
{ |
|
|
|
Insert(session, item); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Update(session, id, item); |
|
|
|
ids.Remove(id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
private static void Insert(IDmoSession session, CarcassTakeOutObj item) |
|
|
|
{ |
|
|
|
var entity = new SectionStoreDetail(); |
|
|
|
entity.BarCode = item.BarCode; |
|
|
|
entity.Goods_ID = item.Goods_ID; |
|
|
|
entity.InStoreTime = item.Time.Value; |
|
|
|
entity.OutStoreTime = entity.InStoreTime; |
|
|
|
entity.PickType = 领用类型.分割领用; |
|
|
|
entity.ProductBatch_ID = item.ProductBatch_ID; |
|
|
|
entity.TakeOutCreate = true; |
|
|
|
entity.Weight = item.Weight; |
|
|
|
entity.Worker_ID = item.Worker_ID; |
|
|
|
session.Insert(entity); |
|
|
|
} |
|
|
|
|
|
|
|
private static void Update(IDmoSession session, long id, CarcassTakeOutObj item) |
|
|
|
{ |
|
|
|
var update = new DQUpdateDom(typeof(SectionStoreDetail)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("Weight", item.Weight)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("OutStoreTime", item.Time)); |
|
|
|
update.Columns.Add(new DQUpdateColumn("PickType", 领用类型.分割领用)); |
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
} |
|
|
|
|
|
|
|
static List<long> GetIDs(IDmoSession session, CarcassTakeOutObj item) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(SectionStoreDetail))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("OutStoreTime"))); |
|
|
|
if (string.IsNullOrEmpty(item.BarCode)) |
|
|
|
{ |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Goods_ID", item.Goods_ID), DQCondition.EQ("ProductBatch_ID", item.ProductBatch_ID))); |
|
|
|
query.Range = SelectRange.Top(item.Number); |
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); |
|
|
|
} |
|
|
|
else |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("BarCode", item.BarCode)); |
|
|
|
return query.EExecuteList<long>(session); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static string GetTestJson() |
|
|
|
{ |
|
|
|
var list = new List<SectionInfo>(); |
|
|
|
list.Add(new SectionInfo { Worker_ID = 5, BarCode = "2609234234234009009", Goods_ID = 45, InStoreTime = DateTime.Now }); |
|
|
|
list.Add(new SectionInfo { Worker_ID = 5, BarCode = "2609234234234011012", Goods_ID = 47, InStoreTime = DateTime.Now }); |
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class SectionInfo |
|
|
|
{ |
|
|
|
public long Worker_ID { get; set; } |
|
|
|
|
|
|
|
public string BarCode { get; set; } |
|
|
|
|
|
|
|
public long Goods_ID { get; set; } |
|
|
|
|
|
|
|
public DateTime InStoreTime { get; set; } |
|
|
|
} |
|
|
|
} |