using BWP.B3ClientService.BO;
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 状态 入库时间 退库时间
|
|
/// 未入库 空 空
|
|
/// 已入库 有 空
|
|
/// 已退库 有 有
|
|
/// </summary>
|
|
[Rpc]
|
|
public static class SegmentInStoreRpc
|
|
{
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static string GetSegmentProductInfo(string barCode)
|
|
{
|
|
var main = new JoinAlias(typeof(SegmentProductionInfo));
|
|
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.EQ("BarCode", barCode));
|
|
query.Columns.Add(DQSelectColumn.Field("Code", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Name", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Spec", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("ProductTime"));
|
|
query.Columns.Add(DQSelectColumn.Field("Weight"));
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
var entity = new SegmentProductObj();
|
|
entity.Goods_Code = (string)reader[0];
|
|
entity.Goods_Name = (string)reader[1];
|
|
entity.Goods_Spec = (string)reader[2];
|
|
entity.ProductTime = (DateTime?)reader[3];
|
|
entity.Weight = (decimal?)reader[4];
|
|
|
|
return JsonConvert.SerializeObject(entity);
|
|
}
|
|
}
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int UploadSegmentInStoreInfo(string json)
|
|
{
|
|
var list = JsonConvert.DeserializeObject<List<SegmentInStoreObj>>(json);
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
/* BarCode InStoreTime Store_ID BackStoreTime */
|
|
foreach (var item in list)
|
|
{
|
|
var id = Exist(session, item.BarCode);
|
|
if (id == null)
|
|
{
|
|
var entity = new SegmentProductionInfo();
|
|
entity.BarCode = item.BarCode;
|
|
entity.InStoreTime = item.InStoreTime;
|
|
entity.BackTime = item.BackStoreTime;
|
|
entity.Store_ID = item.Store_ID;
|
|
session.Insert(entity);
|
|
}
|
|
else
|
|
Update(session, id.Value, item);
|
|
}
|
|
session.Commit();
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static long? Exist(IDmoSession session, string barCode)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo)));
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode));
|
|
return query.EExecuteScalar<long?>(session);
|
|
}
|
|
|
|
private static void Update(IDmoSession session, long id, SegmentInStoreObj entity)
|
|
{
|
|
var update = new DQUpdateDom(typeof(SegmentProductionInfo));
|
|
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);
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static string GetUnInStoreList()
|
|
{
|
|
var main = new JoinAlias(typeof(SegmentProductionInfo));
|
|
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.IsNull(DQExpression.Field("InStoreTime")));
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode"));
|
|
query.Columns.Add(DQSelectColumn.Field("Code", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Name", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Spec", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("ProductTime"));
|
|
query.Columns.Add(DQSelectColumn.Field("Weight"));
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
|
|
query.Range = SelectRange.Top(50);
|
|
var list = new List<SegmentProductObj>();
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var obj = new SegmentProductObj();
|
|
obj.BarCode = (string)reader[0];
|
|
obj.Goods_Code = (string)reader[1];
|
|
obj.Goods_Name = (string)reader[2];
|
|
obj.Goods_Spec = (string)reader[3];
|
|
obj.ProductTime = (DateTime?)reader[4];
|
|
obj.Weight = (decimal?)reader[5];
|
|
list.Add(obj);
|
|
}
|
|
}
|
|
}
|
|
return JsonConvert.SerializeObject(list);
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static string StockUpScan(string barCode)
|
|
{
|
|
var main = new JoinAlias(typeof(SegmentProductionInfo));
|
|
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.Columns.Add(DQSelectColumn.Field("Code", goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Weight"));
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BarCode", barCode), DQCondition.IsNotNull(DQExpression.Field("InStoreTime")), DQCondition.IsNull(DQExpression.Field("BackTime"))));
|
|
var result = query.EExecuteScalar<string, decimal?>();
|
|
if (result == null)
|
|
return string.Empty;
|
|
return JsonConvert.SerializeObject(new ExtensionObj { StringExt1 = result.Item1, DecimalExt1 = result.Item2 });
|
|
}
|
|
}
|
|
|
|
class SegmentInStoreObj
|
|
{
|
|
public string BarCode { get; set; }
|
|
|
|
public DateTime InStoreTime { get; set; }
|
|
|
|
public long? Store_ID { get; set; }
|
|
|
|
public DateTime? BackStoreTime { get; set; }
|
|
}
|
|
|
|
class SegmentProductObj
|
|
{
|
|
public string BarCode { get; set; }
|
|
public string Goods_Name { get; set; }
|
|
public string Goods_Code { get; set; }
|
|
public string Goods_Spec { get; set; }
|
|
public decimal? Weight { get; set; }
|
|
public DateTime? ProductTime { get; set; }
|
|
}
|
|
}
|