|
|
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 CarcassInStoreRpc
|
|
|
{
|
|
|
#region 手持机端调用
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static string ScarBarCode(string url)
|
|
|
{
|
|
|
if (url.Contains("?"))
|
|
|
{
|
|
|
var arr = url.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
if (arr.Length > 1)
|
|
|
{
|
|
|
var list = arr[1].Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
var l = item.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
if (l.Length == 2 && l[0].ToUpper() == "CODE")
|
|
|
return l[1].Trim();
|
|
|
}
|
|
|
return string.Empty;
|
|
|
}
|
|
|
return string.Empty;
|
|
|
}
|
|
|
return url.Trim();
|
|
|
}
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static long PadInsert(long goodsID, string barCode)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(barCode))
|
|
|
throw new Exception("编码为空");
|
|
|
if (barCode.Length != 23)
|
|
|
throw new Exception("条码格式不正确");
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
var id = CheckExist(barCode, session);
|
|
|
if (id == null)
|
|
|
{
|
|
|
var entity = new PadCarcassInStore();
|
|
|
entity.Goods_ID = goodsID;
|
|
|
entity.BarCode = barCode;
|
|
|
session.Insert(entity);
|
|
|
id = entity.ID;
|
|
|
}
|
|
|
else
|
|
|
Update(id.Value, goodsID, session);
|
|
|
session.Commit();
|
|
|
return id.Value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static long? CheckExist(string barCode, IDmoSession session)
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(PadCarcassInStore)));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
|
return query.EExecuteScalar<long?>(session);
|
|
|
}
|
|
|
|
|
|
static void Update(long id, long goodsID, IDmoSession session)
|
|
|
{
|
|
|
var update = new DQUpdateDom(typeof(PadCarcassInStore));
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
|
update.Columns.Add(new DQUpdateColumn("Goods_ID", goodsID));
|
|
|
update.Columns.Add(new DQUpdateColumn("Sync", false));
|
|
|
update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
|
|
|
session.ExecuteNonQuery(update);
|
|
|
}
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static string PadGetGoodsList()
|
|
|
{
|
|
|
var main = new JoinAlias(typeof(ClientGoodsSet));
|
|
|
var detail = new JoinAlias(typeof(ClientGoodsSet_Detail));
|
|
|
var query = new DQueryDom(main);
|
|
|
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "ClientGoodsSet_ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID", detail));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_Name", detail));
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Stopped", false), DQCondition.EQ("ApplyClient", 适用客户端.白条出入库)));
|
|
|
var list = query.EExecuteList<long, string>();
|
|
|
return JsonConvert.SerializeObject(list.Select(x => new MinGoodsObj { Goods_ID = x.Item1, Goods_Name = x.Item2 }));
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 客户端处理手持机数据
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static string GetUnSyncPadData()
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(PadCarcassInStore)));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("Goods_ID"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("RowVersion"));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("Sync", false));
|
|
|
var r = query.EExecuteList<long, string, long, int>();
|
|
|
var list = r.Select(x => new PadCarcassInStore { ID = x.Item1, BarCode = x.Item2, Goods_ID = x.Item3, RowVersion = x.Item4 });
|
|
|
return JsonConvert.SerializeObject(list);
|
|
|
}
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static int SetPadDataSync(string backInfo)
|
|
|
{
|
|
|
var arr = JsonConvert.DeserializeObject<List<ExtensionObj>>(backInfo);
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
foreach (var item in arr)
|
|
|
UpdateSynced(item, session);
|
|
|
session.Commit();
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
static void UpdateSynced(ExtensionObj info, IDmoSession session)
|
|
|
{
|
|
|
var update = new DQUpdateDom(typeof(PadCarcassInStore));
|
|
|
update.Columns.Add(new DQUpdateColumn("Sync", true));
|
|
|
update.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", info.LongExt1), DQCondition.EQ("RowVersion", info.DecimalExt1)));
|
|
|
session.ExecuteNonQuery(update);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static int UploadCarcassInfo(string json)
|
|
|
{
|
|
|
var list = JsonConvert.DeserializeObject<List<CarcassInStoreObj>>(json);
|
|
|
using (var session = Dmo.NewSession())
|
|
|
{
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
var id = GetID(item.BarCode, session);
|
|
|
if (id.HasValue)
|
|
|
Update(id.Value, item, session);
|
|
|
else
|
|
|
Insert(item, session);
|
|
|
}
|
|
|
session.Commit();
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
static long? GetID(string code, IDmoSession session)
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(CarcassFullInfo)));
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("BarCode", code));
|
|
|
return query.EExecuteScalar<long?>(session);
|
|
|
}
|
|
|
|
|
|
static void Update(long id, CarcassInStoreObj obj, IDmoSession session)
|
|
|
{
|
|
|
var update = new DQUpdateDom(typeof(CarcassFullInfo));
|
|
|
update.Columns.Add(new DQUpdateColumn("InStoreWorker_ID", obj.InStoreWorker_ID));
|
|
|
update.Columns.Add(new DQUpdateColumn("WorkUnit_ID", obj.WorkUnit_ID));
|
|
|
update.Columns.Add(new DQUpdateColumn("ProductBatch_ID", obj.ProductBatch_ID));
|
|
|
update.Columns.Add(new DQUpdateColumn("InStoreGoods_ID", obj.InStoreGoods_ID));
|
|
|
update.Columns.Add(new DQUpdateColumn("InStoreWeight", obj.InStoreWeight));
|
|
|
update.Columns.Add(new DQUpdateColumn("InStoreTime", obj.InStoreTime));
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
|
session.ExecuteNonQuery(update);
|
|
|
}
|
|
|
|
|
|
static void Insert(CarcassInStoreObj obj, IDmoSession session)
|
|
|
{
|
|
|
var entity = new CarcassFullInfo();
|
|
|
entity.BarCode = obj.BarCode;
|
|
|
entity.InStoreWorker_ID = obj.InStoreWorker_ID;
|
|
|
entity.WorkUnit_ID = obj.WorkUnit_ID;
|
|
|
entity.ProductBatch_ID = obj.ProductBatch_ID;
|
|
|
entity.InStoreGoods_ID = obj.InStoreGoods_ID;
|
|
|
entity.InStoreWeight = obj.InStoreWeight;
|
|
|
entity.InStoreTime = obj.InStoreTime;
|
|
|
session.Insert(entity);
|
|
|
}
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
|
public static string GetWeightInfo(List<string> codeList)
|
|
|
{
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(CarcassFullInfo)));
|
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode"));
|
|
|
query.Columns.Add(DQSelectColumn.Field("GradeWeight"));
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("GradeWeight")), DQCondition.InList(DQExpression.Field("BarCode"), codeList.Select(x => DQExpression.Value(x)).ToArray())));
|
|
|
var result = query.EExecuteList<string, decimal?>();
|
|
|
var back = result.Select(x => new ExtensionObj { StringExt1 = x.Item1, DecimalExt1 = x.Item2 });
|
|
|
return JsonConvert.SerializeObject(back);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class MinGoodsObj
|
|
|
{
|
|
|
public long Goods_ID { get; set; }
|
|
|
public string Goods_Name { get; set; }
|
|
|
}
|
|
|
|
|
|
class CarcassInStoreObj
|
|
|
{
|
|
|
public string BarCode { get; set; }
|
|
|
public long? InStoreWorker_ID { get; set; }
|
|
|
public long? WorkUnit_ID { get; set; }
|
|
|
public long? ProductBatch_ID { get; set; }
|
|
|
public long? InStoreGoods_ID { get; set; }
|
|
|
public decimal? InStoreWeight { get; set; }
|
|
|
public DateTime? InStoreTime { get; set; }
|
|
|
}
|
|
|
}
|