屠宰场管理服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0 KiB

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
{
[Rpc]
public static class SegmentSaleOutStoreRpc
{
[Rpc(RpcFlags.SkipAuth)]
public static string GetSegmentInfo(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.IsNull(DQExpression.Field("BackTime")), DQCondition.EQ("BarCode", barCode)));
query.Range = SelectRange.Top(1);
var rst = query.EExecuteScalar<string, decimal?>();
var entity = new ExtensionObj();
if (rst != null)
{
entity.StringExt1 = rst.Item1;
entity.DecimalExt1 = rst.Item2;
}
return JsonConvert.SerializeObject(entity);
}
[Rpc(RpcFlags.SkipAuth)]
public static int UploadSegmentInfo(string json)
{
var list = JsonConvert.DeserializeObject<List<SegmentSaleOutStoreObj>>(json);
using (var session = Dmo.NewSession())
{
foreach (var item in list)
{
var id = GetSegmentID(item.BarCode, session);
if (id == null)
Insert(item, session);
else
Update(id.Value, item, session);
}
session.Commit();
}
return 1;
}
static long? GetSegmentID(string code, IDmoSession session)
{
if (string.IsNullOrEmpty(code))
return null;
var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNull(DQExpression.Field("BackTime")), DQCondition.EQ("BarCode", code)));
return query.EExecuteScalar<long>(session);
}
static void Update(long id, SegmentSaleOutStoreObj obj, IDmoSession session)
{
var update = new DQUpdateDom(typeof(SegmentProductionInfo));
update.Columns.Add(new DQUpdateColumn("PickTime", obj.Time));
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
session.ExecuteNonQuery(update);
}
static void Insert(SegmentSaleOutStoreObj obj, IDmoSession session)
{
var entity = new SegmentProductionInfo();
entity.BarCode = obj.BarCode;
entity.PickTime = obj.Time;
session.Insert(entity);
}
}
class SegmentSaleOutStoreObj
{
public string BarCode { get; set; }
public DateTime? Time { get; set; }
}
}