using BWP.B3ClientService.BO;
|
|
using BWP.B3ClientService.Utils;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using TSingSoft.WebPluginFramework.TimerTasks;
|
|
|
|
namespace BWP.B3ClientService.Tasks
|
|
{
|
|
public class SyncSegmentInfoToTraceBack : ITimerTask
|
|
{
|
|
public void Execute()
|
|
{
|
|
var url = new B3ClientServiceOnLineConfig().TraceBackUrl.Value;
|
|
if (string.IsNullOrEmpty(url))
|
|
return;
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
Upload(session, url);
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
private void Upload(IDmoSession session, string url)
|
|
{
|
|
var sUrl = url + "SegmentInsert";
|
|
var list = GetTraceBackInfo(session);
|
|
if (!list.Any())
|
|
return;
|
|
var arr = JsonConvert.SerializeObject(list);
|
|
TraceBackInfoUtil.Insert(sUrl, arr);
|
|
foreach (var item in list)
|
|
session.Insert(new SegmentTraceBackLog { SegmentProductionInfo_ID = item.ID });
|
|
}
|
|
|
|
List<SegmentInfo> GetTraceBackInfo(IDmoSession session)
|
|
{
|
|
var list = new List<SegmentInfo>();
|
|
|
|
var main = new JoinAlias(typeof(SegmentProductionInfo));
|
|
var log = new JoinAlias(typeof(SegmentTraceBackLog));
|
|
var goods = new JoinAlias(typeof(Goods));
|
|
var query = new DQueryDom(main);
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(log), DQCondition.EQ(main, "ID", log, "SegmentProductionInfo_ID"));
|
|
query.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(main, "Goods_ID", goods, "ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("BarCode"));
|
|
query.Columns.Add(DQSelectColumn.Field("Name",goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Spec",goods));
|
|
query.Columns.Add(DQSelectColumn.Field("Weight"));
|
|
query.Columns.Add(DQSelectColumn.Field("ProductTime"));
|
|
query.Columns.Add(DQSelectColumn.Field("InStoreTime"));
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Range = SelectRange.Top(500);
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("ProductTime")), DQCondition.IsNotNull(DQExpression.Field("InStoreTime")), DQCondition.IsNull(DQExpression.Field(log, "SegmentProductionInfo_ID"))));
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var info = new SegmentInfo();
|
|
info.Code = (string)reader[0];
|
|
info.Goods_Name = (string)reader[1];
|
|
info.Goods_Spec = (string)reader[2];
|
|
info.Weight = string.Format("{0:#0.######}", reader[3]);
|
|
info.ProductDate = string.Format("{0:yyyyMMdd}", reader[4]);
|
|
info.ButcherDate = ((DateTime)reader[4]).AddDays(-1).ToString("yyyyMMdd");
|
|
info.ProductBatch = info.ProductDate;
|
|
info.InStoreDate = string.Format("{0:yyyyMMdd}", reader[5]);
|
|
info.ID = (long)reader[6];
|
|
info.Farm_Name = "南墅养殖场";
|
|
info.TestingResult = "合格";
|
|
info.TestingMan = "耿建平";
|
|
info.SendCustomer = "青岛福兴祥商品配送有限公司";
|
|
list.Add(info);
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return "抽取分割信息到追溯服务器"; }
|
|
}
|
|
}
|
|
class SegmentInfo
|
|
{
|
|
[JsonIgnore]
|
|
public long ID { get; set; }
|
|
//[LogicName("条码")]
|
|
public string Code { get; set; }
|
|
|
|
//[LogicName("产品名称")]
|
|
public string Goods_Name { get; set; }
|
|
|
|
//[LogicName("规格")]
|
|
public string Goods_Spec { get; set; }
|
|
|
|
//[LogicName("重量")]
|
|
public string Weight { get; set; }
|
|
|
|
//[LogicName("屠宰日期")]
|
|
public string ButcherDate { get; set; }
|
|
|
|
//[LogicName("生产日期")]
|
|
public string ProductDate { get; set; }
|
|
|
|
//[LogicName("养殖场")]
|
|
public string Farm_Name { get; set; }
|
|
|
|
//[LogicName("检验结果")]
|
|
public string TestingResult { get; set; }
|
|
|
|
//[LogicName("检验人员")]
|
|
public string TestingMan { get; set; }
|
|
|
|
//[LogicName("生产批次")]
|
|
public string ProductBatch { get; set; }
|
|
|
|
//[LogicName("入库日期")]
|
|
public string InStoreDate { get; set; }
|
|
|
|
//[LogicName("发货时间")]
|
|
public string SendDate { get; set; }
|
|
|
|
//[LogicName("发货客户")]
|
|
public string SendCustomer { get; set; }
|
|
|
|
//[LogicName("货运车牌")]
|
|
public string CarNo { get; set; }
|
|
}
|
|
}
|