using BWP.B3ClientService.BO;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.JsonRpc;
|
|
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 SegmentProductionRpc
|
|
{
|
|
static string[] ProductInfoFields = new string[] { "ProductTime", "Worker_ID", "WorkUnit_ID", "ProductBatch_ID", "Goods_ID", "Weight" };
|
|
static Type MinDmoType = typeof(SegmentProductionMin);
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int Insert(string json)
|
|
{
|
|
var list = JsonConvert.DeserializeObject<List<SegmentProductionMin>>(json);
|
|
var dmoType = typeof(SegmentProductionInfo);
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
var id = Exist(session, item.BarCode);
|
|
if (id == null)
|
|
{
|
|
var entity = new SegmentProductionInfo();
|
|
entity.BarCode = item.BarCode;
|
|
foreach (var f in ProductInfoFields)
|
|
dmoType.GetProperty(f).SetValue(entity, MinDmoType.GetProperty(f).GetValue(item, null), null);
|
|
session.Insert(entity);
|
|
}
|
|
else
|
|
Update(session, id.Value, item, ProductInfoFields);
|
|
}
|
|
session.Commit();
|
|
}
|
|
return list.Count;
|
|
}
|
|
|
|
private static void Update(IDmoSession session, long id, SegmentProductionMin entity, params string[] fields)
|
|
{
|
|
var update = new DQUpdateDom(typeof(SegmentProductionInfo));
|
|
foreach (var field in fields)
|
|
update.Columns.Add(new DQUpdateColumn(field, DQExpression.Value(MinDmoType.GetProperty(field).GetValue(entity, null))));
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
session.ExecuteNonQuery(update);
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int SetInStoreTime(string json)
|
|
{
|
|
var list = JsonConvert.DeserializeObject<List<SegmentProductionMin>>(json);
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
var id = Exist(session, item.BarCode);
|
|
if (id.HasValue)
|
|
{
|
|
var entity = new SegmentProductionInfo();
|
|
entity.BarCode = item.BarCode;
|
|
entity.InStoreTime = item.InStoreTime;
|
|
session.Insert(entity);
|
|
}
|
|
else
|
|
Update(session, id.Value, item, "InStoreTime");
|
|
}
|
|
session.Commit();
|
|
}
|
|
return list.Count;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
class SegmentProductionMin
|
|
{
|
|
public string BarCode { get; set; }
|
|
public DateTime? ProductTime { get; set; }
|
|
public long? Worker_ID { get; set; }
|
|
public long? WorkUnit_ID { get; set; }
|
|
public long? ProductBatch_ID { get; set; }
|
|
public long? Goods_ID { get; set; }
|
|
public decimal? Weight { get; set; }
|
|
public DateTime? InStoreTime { get; set; }
|
|
|
|
}
|
|
}
|