Browse Source

销售出库上传到TraceBack

master
yibo 7 years ago
parent
commit
919ac73142
5 changed files with 163 additions and 1 deletions
  1. +3
    -0
      B3ClientService/B3ClientService.csproj
  2. +17
    -0
      B3ClientService/BO/Bill/SyncCarcassInStoreLog.cs
  3. +3
    -1
      B3ClientService/OfflinRpc/CarcassInStoreRpc.cs
  4. +72
    -0
      B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs
  5. +68
    -0
      B3ClientService/Utils/TraceBackInfoUtil.cs

+ 3
- 0
B3ClientService/B3ClientService.csproj View File

@ -114,6 +114,7 @@
<Compile Include="BO\Bill\SaleOutStore_\SaleOutStore.cs" /> <Compile Include="BO\Bill\SaleOutStore_\SaleOutStore.cs" />
<Compile Include="BO\Bill\SecondOrder\SecondOrder.cs" /> <Compile Include="BO\Bill\SecondOrder\SecondOrder.cs" />
<Compile Include="BO\Bill\SecondOrder\SecondOrder_Detail.cs" /> <Compile Include="BO\Bill\SecondOrder\SecondOrder_Detail.cs" />
<Compile Include="BO\Bill\SyncCarcassInStoreLog.cs" />
<Compile Include="BO\Bill\WeightBill\WeightBill.cs" /> <Compile Include="BO\Bill\WeightBill\WeightBill.cs" />
<Compile Include="BO\Bill\WeightBill\WeightBillCheck.cs" /> <Compile Include="BO\Bill\WeightBill\WeightBillCheck.cs" />
<Compile Include="BO\Bill\WeightBill\WeightBillShowRelate.cs" /> <Compile Include="BO\Bill\WeightBill\WeightBillShowRelate.cs" />
@ -191,6 +192,7 @@
<Compile Include="Rpcs\BillRpc\GradeAndWeightRpc.cs" /> <Compile Include="Rpcs\BillRpc\GradeAndWeightRpc.cs" />
<Compile Include="Rpcs\BillRpc\WeightBillRpc.cs" /> <Compile Include="Rpcs\BillRpc\WeightBillRpc.cs" />
<Compile Include="Rpcs\UserInfoRpc.cs" /> <Compile Include="Rpcs\UserInfoRpc.cs" />
<Compile Include="Tasks\SyncCarcassInStoreToTrackBack.cs" />
<Compile Include="Tasks\SyncInfoFromServer.cs" /> <Compile Include="Tasks\SyncInfoFromServer.cs" />
<Compile Include="Tasks\SyncBillFromServer.cs" /> <Compile Include="Tasks\SyncBillFromServer.cs" />
<Compile Include="Tasks\UpdateLoad\DoCheckBills.cs" /> <Compile Include="Tasks\UpdateLoad\DoCheckBills.cs" />
@ -203,6 +205,7 @@
<Compile Include="ClientServiceUtils.cs" /> <Compile Include="ClientServiceUtils.cs" />
<Compile Include="InnerUtils.cs" /> <Compile Include="InnerUtils.cs" />
<Compile Include="Utils\SegmentationByPproductTraceBL.cs" /> <Compile Include="Utils\SegmentationByPproductTraceBL.cs" />
<Compile Include="Utils\TraceBackInfoUtil.cs" />
<Compile Include="WordPair.cs" /> <Compile Include="WordPair.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>


+ 17
- 0
B3ClientService/BO/Bill/SyncCarcassInStoreLog.cs View File

@ -0,0 +1,17 @@
using BWP.B3Frameworks.BO;
using Forks.EnterpriseServices.DataForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BWP.B3ClientService.BO
{
[DFClass]
public class SyncCarcassInStoreLog : Base
{
public string Code { get; set; }
public string Date { get; set; }
}
}

+ 3
- 1
B3ClientService/OfflinRpc/CarcassInStoreRpc.cs View File

@ -151,6 +151,8 @@ namespace BWP.B3ClientService.Rpcs
Update(id.Value, item, session); Update(id.Value, item, session);
else else
Insert(item, session); Insert(item, session);
var log = new SyncCarcassInStoreLog { Code = item.BarCode, Date = item.InStoreTime.Value.ToString("yyyyMMdd") };
session.Insert(log);
} }
session.Commit(); session.Commit();
} }
@ -221,5 +223,5 @@ namespace BWP.B3ClientService.Rpcs
public long? InStoreGoods_ID { get; set; } public long? InStoreGoods_ID { get; set; }
public decimal? InStoreWeight { get; set; } public decimal? InStoreWeight { get; set; }
public DateTime? InStoreTime { get; set; } public DateTime? InStoreTime { get; set; }
}
}
} }

+ 72
- 0
B3ClientService/Tasks/SyncCarcassInStoreToTrackBack.cs View File

@ -0,0 +1,72 @@
using BWP.B3ClientService.BO;
using BWP.B3ClientService.Utils;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebPluginFramework.TimerTasks;
using TSingSoft.WebPluginFramework;
namespace BWP.B3ClientService.Tasks
{
public class SyncCarcassInStoreToTrackBack : ITimerTask
{
public void Execute()
{
var url = ServerHost.GetTraceServerUrl();
if (string.IsNullOrEmpty(url))
return;
url = url + "InsertInStore";
using (var session = Dmo.NewSession())
{
var list = GetUnSyncdInfo(session);
if (!list.Any())
return;
var splitList = TraceBackInfoUtil.SplitList(list, 1000);
foreach (var infos in splitList)
{
var arr = JsonConvert.SerializeObject(infos);
TraceBackInfoUtil.Insert(url, arr);
}
DeleteSyncd(session, list.Min(x => x.ID), list.Max(x => x.ID));
session.Commit();
}
}
List<TraceBackInStoreInfo> GetUnSyncdInfo(IDmoSession session)
{
var query = new DQueryDom(new JoinAlias(typeof(SyncCarcassInStoreLog)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Columns.Add(DQSelectColumn.Field("Code"));
query.Columns.Add(DQSelectColumn.Field("Date"));
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID"));
var list = query.EExecuteList<long, string, string>(session);
return list.Select(x => new TraceBackInStoreInfo { ID = x.Item1, Code = x.Item2, InStoreDate = x.Item3 }).ToList();
}
void DeleteSyncd(IDmoSession session, long min, long max)
{
var delete = new DQDeleteDom(typeof(SyncCarcassInStoreLog));
delete.Where.Conditions.Add(DQCondition.Between("ID", min, max));
session.ExecuteNonQuery(delete);
}
public string Name
{
get { return "抽取白条入库信息到追溯服务器"; }
}
}
class TraceBackInStoreInfo
{
[JsonIgnore]
public long ID { get; set; }
//[LogicName("条码")]
public string Code { get; set; }
public string InStoreDate { get; set; }
}
}

+ 68
- 0
B3ClientService/Utils/TraceBackInfoUtil.cs View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace BWP.B3ClientService.Utils
{
public class TraceBackInfoUtil
{
public static void Insert(string serverUrl, string json)
{
//raw方式使用的是纯字符串的数据上传方式,所以在POST之前,可能需要手工的把一些JSON格式的数据转换成字符串的(加两单引号)
//在这里坑了一个上午
json = string.Format("'{0}'", json);
var request = (HttpWebRequest)WebRequest.Create(serverUrl);
request.Method = "POST";
request.ContentType = "application/json";
request.AllowWriteStreamBuffering = false;
request.KeepAlive = true;
request.Accept = "*/*";
request.UserAgent = "bwptraceback";
var buffer = Encoding.UTF8.GetBytes(json);
request.ContentLength = buffer.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(buffer, 0, buffer.Length);
}
var response = request.GetResponse();
string backInfo = "";
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
backInfo = reader.ReadToEnd();
}
}
if (backInfo != "null")
{
throw new Exception(backInfo);
}
}
public static List<List<T>> SplitList<T>(List<T> list, int size)
where T : new()
{
List<List<T>> result = new List<List<T>>();
for (int i = 0; i < list.Count() / size; i++)
{
T[] clist = new T[size];
list.CopyTo(i * size, clist, 0, size);
result.Add(clist.ToList());
}
int r = list.Count() % size;
if (r != 0)
{
T[] cclist = new T[r];
list.CopyTo(list.Count() - r, cclist, 0, r);
result.Add(cclist.ToList());
}
return result;
}
}
}

Loading…
Cancel
Save