屠宰场管理服务
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.

125 lines
3.9 KiB

using BWP.B3ClientService.BO;
using Forks.EnterpriseServices.BusinessInterfaces;
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;
using TSingSoft.WebPluginFramework.TimerTasks;
namespace BWP.B3ClientService.Tasks
{
public class InStoreCombineCreateB3Bills : ITimerTask
{
private static volatile object _lockObj = new object();
public void Execute()
{
if (!Monitor.TryEnter(_lockObj))
{
throw new SameTaskNotFinishException(this);
}
var serverUri = ServerHost.GetServerUrl();
if (string.IsNullOrEmpty(serverUri))
throw new Exception("请配置服务器地址");
try
{
RpcFacade.Init(serverUri, "B3ClientServer");
}
catch (Exception ex)
{
if (ex.Message != "Can only start once")
throw;
}
try
{
DoExecute();
}
catch (Exception e)
{
throw new ApplicationException(e.ToString());
}
finally
{
Monitor.Exit(_lockObj);
}
}
string method = "/MainSystem/B3ButcherManage/Rpcs/InStoreCombineRpc/CreateInOutStore";
private void DoExecute()
{
using (var context = new TransactionContext())
{
List<long> ids;
var list = GetUnSyncdList(context.Session, out ids);
if (list.Count == 0)
return;
RpcFacade.Call<int>(method, JsonConvert.SerializeObject(list));
SetAsSyncd(context.Session, ids);
context.Commit();
}
}
private void SetAsSyncd(IDmoSession session, List<long> ids)
{
var update = new DQUpdateDom(typeof(ProductInStoreCombine));
update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray()));
update.Columns.Add(new DQUpdateColumn("IsCreated", true));
session.ExecuteNonQuery(update);
}
private List<object> GetUnSyncdList(IDmoSession session, out List<long> ids)
{
var main = new JoinAlias(typeof(ProductInStoreCombine));
var detail = new JoinAlias(typeof(SegmentProductionInfo));
var query = new DQueryDom(main);
query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "InStoreCombine_ID"));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Columns.Add(DQSelectColumn.Field("CombineTime"));
query.Columns.Add(DQSelectColumn.Field("OutStore_Code"));
query.Columns.Add(DQSelectColumn.Field("InStore_Code"));
query.Columns.Add(DQSelectColumn.Field("Goods_Code", detail));
query.Columns.Add(DQSelectColumn.Field("Worker_Name"));
foreach (var c in query.Columns)
query.GroupBy.Expressions.Add(c.Expression);
query.Columns.Add(DQSelectColumn.Sum(detail, "Weight"));
query.Columns.Add(DQSelectColumn.Count("C"));
query.Where.Conditions.Add(DQCondition.EQ("IsCreated", false));
query.Range = SelectRange.Top(100);
var list = new List<object>();
ids = new List<long>();
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
{
var id = (long)reader[0];
ids.Add(id);
list.Add(new
{
ID = id,
CombineTime = (DateTime)reader[1],
OutStore_Code = (string)reader[2],
InStore_Code = (string)reader[3],
Goods_Code = (string)reader[4],
Worker_Name = (string)reader[5],
Weight = (decimal)reader[6],
Count = Convert.ToInt32(reader[7])
});
}
}
return list;
}
public string Name
{
get { return "成品入库创建产出入库单"; }
}
}
}