using HH.WCS.Mobox3.YNJT_PT.device;
|
using HH.WCS.Mobox3.YNJT_PT.models;
|
using HH.WCS.Mobox3.YNJT_PT.process;
|
using HH.WCS.Mobox3.YNJT_PT.util;
|
using HH.WCS.Mobox3.YNJT_PT.wms;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using SqlSugar;
|
using Swashbuckle.Swagger;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Threading;
|
using static HH.WCS.Mobox3.YNJT_PT.api.ApiModel;
|
using static HH.WCS.Mobox3.YNJT_PT.api.OtherModel;
|
using static HH.WCS.Mobox3.YNJT_PT.api.WmsController;
|
using static System.Net.Mime.MediaTypeNames;
|
|
namespace HH.WCS.Mobox3.YNJT_PT.api {
|
/// <summary>
|
/// api接口辅助类
|
/// </summary>
|
public class ApiHelper {
|
static ApiHelper() {
|
|
}
|
|
/// <summary>
|
/// 成型机下线记录
|
/// </summary>
|
/// <param name="model"></param>
|
public static ResponseResult cxjOffLineRecord(OffLineModel model)
|
{
|
ResponseResult response = new ResponseResult();
|
var container = ContainerHelper.GetCntr(model.rfid);
|
var location = LocationHelper.GetLoc(model.loc);
|
if (location != null)
|
{
|
if (container == null)
|
{
|
ContainerHelper.AddCntr(model.rfid);
|
}
|
|
try
|
{
|
OffLineRecord record = new OffLineRecord()
|
{
|
S_RFID = model.rfid,
|
S_LOC = model.loc,
|
N_IS_URGENT = model.isUrgent,
|
T_OFF_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
N_IS_FULL = model.isFull,
|
|
};
|
WMSHelper.addOffLineRecord(record);
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info($"添加成型机下线记录错误,错误原因:{ex.Message}", "WMS");
|
response.code = 500;
|
response.msg = "WMS系统内部错误,请联系开发人员排查问题";
|
}
|
}
|
else
|
{
|
response.code = 1;
|
response.msg = $"货位:{model.loc}不存在";
|
}
|
return response;
|
}
|
|
/// <summary>
|
/// 下线请求
|
/// </summary>
|
/// <returns></returns>
|
public static ResponseResult offLineRequest(NotifyDeviceSignalModel model)
|
{
|
ResponseResult response = new ResponseResult();
|
var startLoc = LocationHelper.GetLoc(model.loc);
|
if (startLoc != null)
|
{
|
List<BarcodeModel> extData = model.extData;
|
int dataCount = extData.Count;
|
if (dataCount > 0)
|
{
|
var rfidExistNull = extData.Where(a => string.IsNullOrEmpty(a.rfid)).Count()>0;
|
if (rfidExistNull)
|
{
|
response.code = 1;
|
response.msg = "rfid不能为空";
|
}
|
else
|
{
|
Dictionary<BarcodeModel, bool> rfidDic = new Dictionary<BarcodeModel, bool>();
|
foreach (var ext in extData)
|
{
|
string rfid = ext.rfid;
|
if (rfid.Contains("ET"))
|
{
|
rfidDic.Add(ext, false);
|
}
|
else
|
{
|
// 1.查询成型机中间表,rfid 是否存在
|
var offLineRecord = WMSHelper.getOffLineRecord(rfid);
|
if (offLineRecord != null)
|
{
|
// 2.查询物料条码信息表,条码信息是否存在
|
var itemBarcodeInfo = WMSHelper.GetGreenTireInformation(ext.barcode);
|
if (itemBarcodeInfo == null)
|
{
|
rfidDic.Add(ext, false);
|
}
|
else
|
{
|
rfidDic.Add(ext, true);
|
}
|
}
|
else
|
{
|
rfidDic.Add(ext, false);
|
}
|
}
|
}
|
|
// 判断是否有异常托盘
|
bool isNormal = rfidDic.Where(a => a.Value == false).Count() == 0;
|
if (isNormal && extData.Count == 2)
|
{
|
// 双托正常料入库
|
Location endLoc = null;
|
var itemBarcodeInfo = WMSHelper.GetGreenTireInformation(extData[0].barcode);
|
string groupNo = WMSHelper.GenerateTaskGroupNo();
|
var endLocList = WMSHelper.getInStockEndLoc(itemBarcodeInfo.ITEMCODE, 2);
|
if (endLocList.Count == 2)
|
{
|
var rfidList = rfidDic.Keys.ToList();
|
for (int i = 0; i < rfidList.Count; i++)
|
{
|
endLoc = endLocList[i];
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = rfidList[i].rfid,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "满料下线入库任务",
|
S_OP_DEF_CODE = model.reqId,
|
S_OP_DEF_NAME = "成型机满料下线入库",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
S_GROUP_NO = groupNo,
|
};
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = wmsTask.S_CNTR_CODE,
|
S_TYPE = wmsTask.S_TYPE,
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
|
// 绑定容器物料信息
|
WMSHelper.bindBarcodeItemInfo(wmsTask.S_CNTR_CODE,itemBarcodeInfo);
|
}
|
}
|
}
|
}
|
else
|
{
|
response.code = 1;
|
response.msg = "库区没有可入的空货位";
|
}
|
}
|
else
|
{
|
// 异常料出库检修 或 单拖物料入库
|
foreach (var dic in rfidDic)
|
{
|
Location middleLoc = null;
|
Location endLoc = null;
|
if (dic.Value)
|
{
|
var itemBarcodeInfo = WMSHelper.GetGreenTireInformation(dic.Key.barcode);
|
var endLocList = WMSHelper.getInStockEndLoc(itemBarcodeInfo.ITEMCODE, 1);
|
if (endLocList.Count == 1)
|
{
|
endLoc = endLocList[0];
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = dic.Key.rfid,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "满料下线入库任务",
|
S_OP_DEF_CODE = model.reqId,
|
S_OP_DEF_NAME = "成型机满料下线入库",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = wmsTask.S_CNTR_CODE,
|
S_TYPE = wmsTask.S_TYPE,
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
|
// 绑定容器物料信息
|
WMSHelper.bindBarcodeItemInfo(wmsTask.S_CNTR_CODE, itemBarcodeInfo);
|
}
|
}
|
}
|
else
|
{
|
response.code = 1;
|
response.msg = "库区没有可入的空货位";
|
}
|
}
|
else
|
{
|
middleLoc = WMSHelper.getMinTaskMiddleLoc(1); // 1.异常排出位
|
endLoc = WMSHelper.getAbnormalAreaEmptyLoc(Settings.abnormalArea);
|
var wmsTask = new WMSTask()
|
{
|
S_CNTR_CODE = dic.Key.rfid,
|
S_CODE = WMSHelper.GenerateTaskNo(),
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = endLoc.S_CODE,
|
S_END_AREA = endLoc.S_AREA_CODE,
|
S_TYPE = "异常托盘出库任务",
|
S_OP_DEF_CODE = model.reqId,
|
S_OP_DEF_NAME = "异常托盘出库检修",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
if (WMSHelper.CreateWmsTask(wmsTask))
|
{
|
// 创建一段入库任务
|
WCSTask wcsTask = new WCSTask()
|
{
|
S_OP_NAME = wmsTask.S_OP_DEF_NAME,
|
S_OP_CODE = wmsTask.S_CODE,
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_CNTR_CODE = wmsTask.S_CNTR_CODE,
|
S_TYPE = wmsTask.S_TYPE,
|
S_START_LOC = startLoc.S_CODE,
|
S_START_AREA = startLoc.S_AREA_CODE,
|
S_END_LOC = middleLoc.S_CODE,
|
S_END_AREA = middleLoc.S_AREA_CODE,
|
S_SCHEDULE_TYPE = "WCS",
|
N_PRIORITY = 1,
|
T_START_TIME = DateTime.Now,
|
};
|
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 起点、接驳点、终点加锁
|
LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
|
LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
|
|
// 更新作业任务状态
|
wmsTask.N_B_STATE = 1;
|
WMSHelper.UpdateTaskState(wmsTask);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
else
|
{
|
response.code = 1;
|
response.msg = "入参缺少托盘和条码信息";
|
}
|
}
|
else
|
{
|
response.code = 1;
|
response.msg = "起点货位不存在";
|
}
|
return response;
|
}
|
|
/// <summary>
|
/// 读码请求
|
/// </summary>
|
public static ResponseResult readCodeRequest(NotifyDeviceSignalModel model)
|
{
|
ResponseResult response = new ResponseResult();
|
readCodeFeedbackResponse readCodeFeedbackResponse = new readCodeFeedbackResponse()
|
{
|
verifyResult = true
|
};
|
var wmsTask = WMSHelper.GetWmsTask(model.taskNo);
|
if (wmsTask != null)
|
{
|
if (wmsTask.S_TYPE != "异常托盘出库任务")
|
{
|
Location endLoc = null;
|
Location middleLoc = null;
|
// 判断rfid是否异常
|
if (model.cntrNo != wmsTask.S_CNTR_CODE)
|
{
|
middleLoc = WMSHelper.getMinTaskMiddleLoc(1); // 1.异常排出位
|
endLoc = WMSHelper.getAbnormalAreaEmptyLoc(Settings.abnormalArea);
|
wmsTask.S_END_LOC = endLoc.S_CODE;
|
wmsTask.S_END_AREA = endLoc.S_AREA_CODE;
|
WMSHelper.UpdateTaskEnd(wmsTask);
|
|
var wcsTask = WCSHelper.GetTaskBySrcNo(wmsTask.S_CODE);
|
if (wcsTask != null)
|
{
|
wcsTask.S_END_LOC = middleLoc.S_CODE;
|
wcsTask.S_END_AREA = middleLoc.S_AREA_CODE;
|
WCSHelper.updateTaskEnd(wcsTask);
|
}
|
|
readCodeFeedbackResponse.verifyResult = false;
|
readCodeFeedbackResponse.endLoc = middleLoc.S_CODE;
|
response.data = readCodeFeedbackResponse;
|
}
|
else
|
{
|
var cntrItemRels = ContainerHelper.GetCntrItemRel(wmsTask.S_CNTR_CODE);
|
if (cntrItemRels.Count > 0)
|
{
|
if (cntrItemRels[0].S_ITEM_STATE != "OK")
|
{
|
middleLoc = WMSHelper.getMinTaskMiddleLoc(1); // 1.异常排出位
|
endLoc = WMSHelper.getAbnormalAreaEmptyLoc(Settings.abnormalArea);
|
wmsTask.S_END_LOC = endLoc.S_CODE;
|
wmsTask.S_END_AREA = endLoc.S_AREA_CODE;
|
WMSHelper.UpdateTaskEnd(wmsTask);
|
|
var wcsTask = WCSHelper.GetTaskBySrcNo(wmsTask.S_CODE);
|
if (wcsTask != null)
|
{
|
wcsTask.S_END_LOC = middleLoc.S_CODE;
|
wcsTask.S_END_AREA = middleLoc.S_AREA_CODE;
|
WCSHelper.updateTaskEnd(wcsTask);
|
}
|
|
readCodeFeedbackResponse.verifyResult = false;
|
readCodeFeedbackResponse.endLoc = middleLoc.S_CODE;
|
response.data = readCodeFeedbackResponse;
|
}
|
}
|
}
|
}
|
}
|
else
|
{
|
response.code = 1;
|
response.msg = $"任务号:{model.taskNo},未查询到执行中的任务";
|
}
|
response.data = readCodeFeedbackResponse;
|
return response;
|
}
|
|
/// <summary>
|
/// 硫化机呼叫胚胎出库
|
/// </summary>
|
/// <param name="model"></param>
|
public static ResponseResult callItemOutStock(CallItemModel model)
|
{
|
ResponseResult response = new ResponseResult();
|
|
return response;
|
}
|
|
public class readCodeFeedbackResponse
|
{
|
public bool verifyResult { get; set; }
|
public string endLoc { get; set; }
|
}
|
|
/// <summary>
|
/// 创建任务
|
/// </summary>
|
/// <param name="model"></param>
|
internal static void AddTask(AddTaskModel model) {
|
if (!WCSHelper.CheckExist(model.No)) {
|
if (LocationHelper.CheckExist(model.From) && LocationHelper.CheckExist(model.To)) {
|
WCSHelper.CreateTask(model.No, model.From, model.To, "搬运", 99, "");
|
}
|
|
}
|
}
|
/// <summary>
|
/// 创建入库单主子表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult Putaway_Order_In(Putaway_Order_In model) {
|
var result = new SimpleResult();
|
//创建入库单主子表
|
var po = WMSHelper.GetPutawayOrder(model.Data.arrival_no);
|
if (po == null) {
|
po = new PutawayOrder { S_NO = model.Data.arrival_no, S_BS_TYPE = model.Data.op_type };
|
po.Details = new List<PutawayDetail>();
|
if (model.Data.items.Count > 0) {
|
model.Data.items.ForEach(a => {
|
po.Details.Add(new PutawayDetail
|
{
|
S_PUTAWAY_NO = model.Data.arrival_no,
|
N_ROW_NO = po.Details.Count + 1,
|
S_ITEM_CODE = a.item_code,
|
F_QTY = a.qty,
|
S_BATCH_NO = a.batch_no,
|
});
|
});
|
WMSHelper.CreatePutawayOrder(po);
|
}
|
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 创建发货单主子表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult OutboundOrder(OutboundOrder model) {
|
var result = new SimpleResult();
|
//创建发货单,人工点确认后生成分拣单,没有缺货的自动更新为失败,有货的更新为执行中
|
//创建出库单主子表
|
var po = WMSHelper.GetShippingOrder(model.Data.out_no);
|
if (po == null) {
|
po = new ShippingOrder { S_NO = model.Data.out_no, S_BS_TYPE = model.Data.op_type };
|
po.Details = new List<ShippingDetail>();
|
if (model.Data.items.Count > 0) {
|
model.Data.items.ForEach(a => {
|
po.Details.Add(new ShippingDetail
|
{
|
S_SHIPPING_NO = model.Data.out_no,
|
N_ROW_NO = po.Details.Count + 1,
|
S_ITEM_CODE = a.item_code,
|
F_QTY = a.qty,
|
S_BATCH_NO = a.batch_no,
|
});
|
});
|
WMSHelper.CreateShippingOrder(po);
|
}
|
|
}
|
return result;
|
}
|
|
public static List<KeyValuePair<string, InstockInfo>> cacheInstockInfos = new List<KeyValuePair<string, InstockInfo>>();
|
|
public static void addKeyValuePair(string ip , InstockInfo instockInfo) {
|
KeyValuePair<string, InstockInfo> pair = new KeyValuePair<string, InstockInfo>(ip,instockInfo);
|
LogHelper.Info("添加缓存信号,缓存信息:" + JsonConvert.SerializeObject(pair), "TSSG");
|
|
// 查找并替换键值对
|
bool replaced = false;
|
for (int i = 0; i < cacheInstockInfos.Count; i++)
|
{
|
if (cacheInstockInfos[i].Key == pair.Key)
|
{
|
cacheInstockInfos[i] = pair;
|
replaced = true;
|
LogHelper.Info("存在相同IP的缓存信号,替换缓存信息:" + JsonConvert.SerializeObject(pair), "TSSG");
|
break; // 如果只需要替换第一个匹配的项,就跳出循环
|
}
|
}
|
// 如果没有找到要替换的项,可以选择添加新的键值对或执行其他操作
|
if (!replaced)
|
{
|
cacheInstockInfos.Add(pair);
|
}
|
}
|
|
internal static CodeInfo GetCodeInfo(string code, string org) {
|
//return new CodeInfo { Fitemid_XK=code, FSourceNo="123456"};
|
CodeInfo result = null;
|
try {
|
var db = new SqlHelper<object>().GetInstance(Settings.SqlServer1);
|
var nameP = new SugarParameter("@FBarCode", code);
|
var orgP = new SugarParameter("@Forg", org);
|
//var ageP = new SugarParameter("@age", null, true);//设置为output
|
//var dt = db.Ado.UseStoredProcedure().GetDataTable("sp_school", nameP, ageP);//返回dt
|
result = db.Ado.UseStoredProcedure().SqlQuery<CodeInfo>("WMS_FBarCode", nameP, orgP).First();//返回List
|
Console.WriteLine($"读存储过程成功,result={result}");
|
}
|
catch (Exception ex) {
|
Console.WriteLine(ex.Message);
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// agv 车辆报警
|
/// </summary>
|
/// <param name="forkliftNo"></param>
|
/// <param name="errCode"></param>
|
/// <param name="errCode2"></param>
|
/// <param name="failCode"></param>
|
public static void agvCarAlarm(string forkliftNo, string errCode , string errCode2 , string failCode) {
|
bool turnLight = false;
|
|
|
}
|
|
public class OffLineModel
|
{
|
public string rfid { get; set; } // 托盘号
|
public string loc { get; set; } // 下线货位
|
public int isUrgent { get; set; } // N_IS_URGENT 是否加急(0.否 1.是)
|
public int isFull { get; set; } // 是否满拖 0.否 1.是
|
}
|
public class AddTaskModel {
|
public string From { get; set; }
|
public string To { get; set; }
|
public string No { get; set; }
|
}
|
public class TN_LocationModel {
|
public string TN_Location { get; set; }
|
}
|
public class CodeInfo {
|
/// <summary>
|
/// 生产订单内码
|
/// </summary>
|
public string FInterID { get; set; }
|
/// <summary>
|
/// 生产订单编号
|
/// </summary>
|
public string FSourceNo { get; set; }
|
/// <summary>
|
/// 批号
|
/// </summary>
|
public string FGMPBatchNo { get; set; }
|
public string FState { get; set; }
|
/// <summary>
|
/// 物料编码(内码就是编码)
|
/// </summary>
|
public string Fitemid_XK { get; set; }
|
/// <summary>
|
/// 分录id
|
/// </summary>
|
public string Fentryid { get; set; }
|
}
|
public class NoteInfo : CodeInfo {
|
public string WmsBillNo { get; set; }
|
}
|
}
|
}
|