using Admin.NET.Core;
|
using iWareCommon;
|
using iWareCommon.Utils;
|
using iWareSql.MyDbContext;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.Entity;
|
using System.Data.Entity.Migrations;
|
using System.Linq;
|
using System.Net.Http;
|
using System.Threading;
|
|
namespace iWareCC
|
{
|
/// <summary>
|
/// po单收货线程
|
/// </summary>
|
public class ReceivingPoOrderHandler
|
{
|
private static object _lock;
|
public static void Handler()
|
{
|
var errMsg = "";
|
while (true)
|
{
|
try
|
{
|
SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = "循环开始...";
|
if (SystemValue.isAllowRuning_ReceivingPoOrderHandler && SystemValue.isStartedModel)
|
{
|
errMsg = "";//重置
|
try
|
{
|
lock (_lock)
|
{
|
Do(errMsg);
|
if (!string.IsNullOrEmpty(errMsg))
|
{
|
SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = errMsg;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Log4NetHelper.WriteErrorLog(LogType.ReceivingPoOrderHandler, "收货处理的线程=>" + errMsg + ",异常:" + ex.Message, ex);
|
SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = "收货处理的线程=>" + errMsg + ",异常:" + ex.Message;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = "出现异常:" + ex.Message;
|
Log4NetHelper.WriteErrorLog(LogType.ReceivingPoOrderHandler, "PrintHandler 出现异常:" + ex.Message, ex);
|
}
|
Thread.Sleep(1 * 1000);//休眠40秒
|
}
|
}
|
|
|
/// <summary>
|
/// 接收收发货记录
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="Lane"></param>
|
/// <param name="flag"></param>
|
/// <param name="errMsg"></param>
|
private static async void Do(string errMsg)
|
{
|
using (MyDbContext mycontext = new MyDbContext())
|
{
|
|
var inputData = new UpdateAdapterRecordByCCInput();
|
var infoData = new AdapterLogsInfoUpdateInput();
|
var recordAdapterIdList = new List<long>();
|
var query_ErpPushStatus = 2;
|
var receivingList = mycontext.wms_adapter_record.Where(x => (x.IsDelete == false) && x.DealWithStatus == query_ErpPushStatus && x.AdapterMethodName == "PO单收货")
|
.OrderBy(x => x.Id).ToList();
|
if (receivingList.Count > 0)
|
{
|
|
}
|
else
|
{
|
errMsg = $"没有可收货的内容!";
|
return;
|
}
|
foreach (var receiving in receivingList)
|
{
|
recordAdapterIdList.Add(receiving.Id);
|
|
inputData.ErpVoucher = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
}
|
inputData.RecordAdapterIdList = recordAdapterIdList;
|
infoData.RecordAdapterIdList = recordAdapterIdList;
|
|
string jsonData = JsonConvert.SerializeObject(inputData);
|
|
string apiUrl1 = "http://localhost:5005/api/RecordAdapter/UpdateAdapterRecordByCC";
|
string apiUrl2 = "http://localhost:5005/api/RecordAdapter/UpdateAdapterRecordInfo";
|
using (var httpClient = new HttpClient())
|
{
|
try
|
{
|
|
// 创建HttpContent对象,设置为JSON格式
|
var httpContent = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json");
|
|
// 发送POST请求
|
var response = await httpClient.PostAsync(apiUrl1, httpContent);
|
|
//// 检查响应是否成功
|
//response.EnsureSuccessStatusCode();
|
|
//// 读取响应内容
|
//string jsonResponse = await response.Content.ReadAsStringAsync();
|
//infoData.AdapterInputInfo = jsonResponse;
|
//string infoJsonData = JsonConvert.SerializeObject(infoData);
|
//var infoHttpContent = new StringContent(infoJsonData, System.Text.Encoding.UTF8, "application/json");
|
//// 发送POST请求
|
//var response2 = await httpClient.PostAsync(apiUrl2, infoHttpContent);
|
|
|
|
}
|
catch (Exception ex)
|
{
|
// 处理异常情况
|
throw ex;
|
}
|
}
|
|
|
|
|
|
|
}
|
}
|
|
|
|
|
/// <summary>
|
/// 接收收发货记录
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="Lane"></param>
|
/// <param name="flag"></param>
|
/// <param name="errMsg"></param>
|
private static void Do2(ref string errMsg)
|
{
|
using (MyDbContext mycontext = new MyDbContext())
|
{
|
|
var inputData = new UpdateAdapterRecordByCCInput();
|
|
var query_ErpPushStatus = 0;
|
var receivingList = mycontext.wms_adapter_record.Where(x => (x.IsDelete == false) && x.DealWithStatus == query_ErpPushStatus)
|
.OrderBy(x => x.Id).ToList();
|
if (receivingList.Count > 0)
|
{
|
foreach (var item in receivingList)
|
{
|
//判断是否是 PO收货
|
if (1 == 1)
|
{//是PO收货
|
//1、模拟调用SERP
|
//2、模拟调用成功ERP
|
//3、调用成功后- 更新wms_adapter_record的状态
|
item.DealWithStatus = 0;//已处理
|
item.UpdateTime = DateTime.Now;
|
item.UpdateUserName = "调度系统";
|
|
//查询收货记录表 ,更新他的ErpPushStatusEnum值
|
//
|
}
|
}
|
|
}
|
else
|
{
|
errMsg = $"没有可收货的内容!";
|
return;
|
}
|
foreach (var receiving in receivingList)
|
{
|
|
inputData.ErpVoucher = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
}
|
string jsonData = JsonConvert.SerializeObject(inputData);
|
|
string apiUrl = "http://localhost:5005/api/RecordAdapter/UpdateAdapterRecordByCC";
|
using (var httpClient = new HttpClient())
|
{
|
try
|
{
|
// 创建HttpContent对象,设置为JSON格式
|
var httpContent = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json");
|
|
// 发送POST请求
|
var response = httpClient.PostAsync(apiUrl, httpContent);
|
|
|
}
|
catch (Exception ex)
|
{
|
// 处理异常情况
|
Console.WriteLine($"发生异常:{ex.Message}");
|
}
|
}
|
|
|
|
|
|
|
}
|
}
|
|
public class UpdateAdapterRecordByCCInput
|
{
|
public List<long> RecordAdapterIdList { get; set; }
|
|
public string ErpVoucher { get; set; }
|
}
|
|
public class AdapterLogsInfoUpdateInput
|
{
|
public List<long> RecordAdapterIdList { get; set; }
|
|
public string AdapterInputInfo { get; set; }
|
}
|
|
|
|
|
private static bool GetPrintClassifyEnum(wms_record_sncode_print item, MyDbContext mycontext, ref string errMsg, ref PrintClassifyEnum printClassifyEnum)
|
{
|
if (item.PrintType == (int)PrintTypeEnum.看板卡)
|
{
|
printClassifyEnum = PrintClassifyEnum.看板卡;
|
}
|
else
|
{
|
wms_config_sncode_rule rule = null;
|
var ruleList = mycontext.wms_config_sncode_rule.Where(x => (x.RuleName == "ASN一维码" || x.RuleName == "ASN二维码") && x.IsDisabled == false).ToList();
|
if (ruleList != null && ruleList.Count > 1)
|
{
|
errMsg = "条码生成规则配置中,ASN一维码和ASN二维码只能启用其中一个!";
|
return false;
|
}
|
if (ruleList == null || ruleList.Count == 0)
|
{
|
errMsg = "条码生成规则配置中,ASN一维码和ASN二维码两个都没有配置启用!";
|
return false;
|
}
|
rule = ruleList.First();
|
|
printClassifyEnum = default(PrintClassifyEnum);
|
if (rule.RuleName == "ASN一维码")
|
{
|
printClassifyEnum = PrintClassifyEnum.一维跟踪码;
|
}
|
else
|
{
|
printClassifyEnum = PrintClassifyEnum.二维跟踪码;
|
}
|
}
|
|
return true;
|
|
}
|
|
}
|
}
|