using ButcherFactory.BO.Utils;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
using Forks.JsonRpc.Client;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ButcherFactory.BO.LocalBL
|
|
{
|
|
public static class SegmentStockUpBL
|
|
{
|
|
const string RpcPath = @"/MainSystem/B3Sale/Rpcs/";
|
|
const string MESPath = @"/MainSystem/B3ClientService/Rpcs/";
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="code"></param>
|
|
/// <returns>GoodsCode:StringExt1,Weight:DecimalExt1</returns>
|
|
public static ExtensionObj StockUpScan(string code)
|
|
{
|
|
var json = ButcherFactoryUtil.SecondUrlCall<string>(MESPath + "SegmentInStoreRpc/StockUpScan", code);
|
|
return JsonConvert.DeserializeObject<ExtensionObj>(json);
|
|
}
|
|
|
|
public static List<SaleOutStoreInfo> GetSaleOutStoreList(DateTime date)
|
|
{
|
|
var json = RpcFacade.Call<string>(RpcPath + "SaleOutStoreRpc/GetSaleOutStoreByDate", date);
|
|
var list = JsonConvert.DeserializeObject<List<SaleOutStoreInfo>>(json);
|
|
foreach (var item in list)
|
|
item.Date = date;
|
|
return list;
|
|
}
|
|
|
|
public static List<SegmentStockUp> GetLocalList(DateTime date)
|
|
{
|
|
var query = new DmoQuery(typeof(SegmentStockUp));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Date", date));
|
|
return query.EExecuteList().Cast<SegmentStockUp>().ToList();
|
|
}
|
|
|
|
public static void DeleteOld()
|
|
{
|
|
var delete = new DQDeleteDom(typeof(SegmentStockUp));
|
|
delete.Where.Conditions.Add(DQCondition.And(DQCondition.LessThan("Date", DateTime.Today.AddDays(-2)), DQCondition.EQ("Sync", true)));
|
|
delete.EExecute();
|
|
}
|
|
|
|
public static void SyncToServer()
|
|
{
|
|
try
|
|
{
|
|
using (var session = DmoSession.New())
|
|
{
|
|
var list = GetUnSyncList(session);
|
|
if (list.Count == 0)
|
|
return;
|
|
var arr = JsonConvert.SerializeObject(list.Select(x => new { DetailID = x.DetailID, BarCode = x.BarCode, SecondNumber=x.SecondNumber,UnitNumber=x.UnitNumber }));
|
|
RpcFacade.Call<int>(RpcPath + "SaleOutStoreRpc/InsertStockUpDetail", arr);
|
|
SetLocalSync(session, list.First().ID, list.Last().ID);
|
|
session.Commit();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
#if DEBUG
|
|
throw;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
static List<SegmentStockUp> GetUnSyncList(IDmoSession session)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(SegmentStockUp)));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Sync", false));
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("DetailID"));
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode"));
|
|
query.Columns.Add(DQSelectColumn.Field("SecondNumber"));
|
|
query.Columns.Add(DQSelectColumn.Field("UnitNumber"));
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
|
|
query.Range = SelectRange.Top(50);
|
|
var list = new List<SegmentStockUp>();
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var entity = new SegmentStockUp();
|
|
entity.ID = (long)reader[0];
|
|
entity.DetailID = (long)reader[1];
|
|
entity.BarCode = (string)reader[2];
|
|
entity.SecondNumber = (decimal?)reader[3];
|
|
entity.UnitNumber = (decimal?)reader[4];
|
|
list.Add(entity);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
static void SetLocalSync(IDmoSession session, long min, long max)
|
|
{
|
|
var update = new DQUpdateDom(typeof(SegmentStockUp));
|
|
update.Columns.Add(new DQUpdateColumn("Sync", true));
|
|
update.Where.Conditions.Add(DQCondition.Between("ID", min, max));
|
|
session.ExecuteNonQuery(update);
|
|
}
|
|
|
|
public static void Insert(SegmentStockUp detail)
|
|
{
|
|
using (var session = DmoSession.New())
|
|
{
|
|
session.Insert(detail);
|
|
session.Commit();
|
|
}
|
|
}
|
|
}
|
|
}
|