using System;
|
using System.Collections.Generic;
|
using System.Runtime.ConstrainedExecution;
|
using System.Web.Http;
|
|
using HH.WCS.Mobox3.DSZSH.core;
|
using HH.WCS.Mobox3.DSZSH.models;
|
using HH.WCS.Mobox3.DSZSH.util;
|
|
using Newtonsoft.Json;
|
|
using static HH.WCS.Mobox3.DSZSH.api.ApiModel;
|
|
namespace HH.WCS.Mobox3.DSZSH.api {
|
/// <summary>
|
/// 测试用:如果项目中要和设备对接,前期设备无法测试,用接口模拟
|
/// </summary>
|
[RoutePrefix("api")]
|
public class DebugController : ApiController
|
{
|
/// <summary>
|
/// AGV状态一键回报134562
|
/// </summary>
|
/// <param name="model">容器号</param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("AGVSeriesReports")]
|
public ReturnResults AGVSeriesReports(UpdateTaskState model) {
|
var agvTaskState = new AgvTaskState() {
|
task_no = model.TaskID,
|
forklift_no = model.ForkliftNo,
|
state = 1
|
};
|
ReturnResults returnResult = new ReturnResults();
|
returnResult.ResultList = new List<ReturnResult>();
|
|
var temp1 = WCSCore.OperateAgvTaskStatus(agvTaskState);
|
returnResult.ResultList.Add(temp1);
|
|
agvTaskState.state = 3;
|
var temp3 = WCSCore.OperateAgvTaskStatus(agvTaskState);
|
returnResult.ResultList.Add(temp3);
|
|
agvTaskState.state = 4;
|
var temp4 = WCSCore.OperateAgvTaskStatus(agvTaskState);
|
returnResult.ResultList.Add(temp4);
|
|
agvTaskState.state = 5;
|
var temp5 = WCSCore.OperateAgvTaskStatus(agvTaskState);
|
returnResult.ResultList.Add(temp5);
|
|
agvTaskState.state = 6;
|
var temp6 = WCSCore.OperateAgvTaskStatus(agvTaskState);
|
returnResult.ResultList.Add(temp6);
|
|
agvTaskState.state = 2;
|
var temp2 = WCSCore.OperateAgvTaskStatus(agvTaskState);
|
returnResult.ResultList.Add(temp2);
|
|
return returnResult;
|
}
|
|
/// <summary>
|
/// 初始化数据库
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("CreateDatabase")]
|
public string CreateDatabase(FalseOk model) {
|
try {
|
if (model.JumpOut) {
|
return "跳出";
|
}
|
var db = new SqlHelper<object>().GetInstance();
|
|
var entityTypes = new Type[] {
|
//typeof(TN_CAR_IN),
|
//typeof(TN_CG_Detail),
|
//typeof(TN_Container),
|
//typeof(TN_Loc_Container),
|
//typeof(TN_Location),
|
//typeof(TN_Task),
|
//typeof(TN_Task_Action),
|
//typeof(SysHelper.OI_SYS_MAXID),
|
|
//typeof(TN_Inbound_Order),
|
//typeof(TN_Check_Detail),
|
//typeof(TN_Check_Order),
|
//typeof(TN_CNTR_ITEM),
|
//typeof(TN_Outbound_Detail),
|
//typeof(TN_Outbound_Order),
|
//typeof(TN_Shift_Order),
|
//typeof(TN_Shift_Detail)
|
|
//typeof(TN_Container_Item),
|
};
|
|
//var areaNameList = new List<string>();
|
//foreach (var area in Settings.Areas) {
|
// areaNameList.AddRange(area.Codes);
|
//}
|
|
//var locationList = new List<TN_Location>();
|
//foreach (var area in areaNameList) {
|
// int i = 0;
|
// int j = 0;
|
// int k = 0;
|
|
// if (area == "KXHJQ" || area == "MTHJQ" || area == "MXHJQ") {
|
// for (i = 1; i <= 4; i++) {
|
// for (j = 1; j <= 5; j++) {
|
// for (k = 1; k <= 3; k++) {
|
// locationList.Add(new TN_Location() {
|
// N_ROW = i,
|
// N_COL = j,
|
// N_LAYER = k,
|
// S_AREA_CODE = area,
|
// S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}" +
|
// $"-{k.ToString().PadLeft(2, '0')}"
|
// });
|
// }
|
// }
|
// }
|
// continue;
|
// }
|
|
// if (area == "BZQ") {
|
// for (i = 1; i <= 2; i++) {
|
// for (j = 1; j <= 2; j++) {
|
// locationList.Add(new TN_Location() {
|
// N_ROW = i,
|
// N_COL = j,
|
// S_AREA_CODE = area,
|
// S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}"
|
// });
|
// }
|
// }
|
// continue;
|
// }
|
|
// i = 1;
|
// for (j = 1; j <= 5; j++) {
|
// locationList.Add(new TN_Location() {
|
// N_ROW = i,
|
// N_COL = j,
|
// S_AREA_CODE = area,
|
// S_CODE = $"{area}-{i.ToString().PadLeft(2, '0')}-{j.ToString().PadLeft(2, '0')}"
|
// });
|
// }
|
|
|
//}
|
|
|
|
//using (var tran = db.Ado.UseTran()) {
|
// //db.CodeFirst.InitTables(entityTypes);
|
// if (db.Insertable<TN_Location>(locationList).ExecuteCommand() <= 0) {
|
// tran.RollbackTran();
|
// return "失败";
|
// }
|
|
// tran.CommitTran();
|
|
|
//}
|
|
}
|
catch (Exception ex) {
|
LogHelper.Info($"发生了异常");
|
return "初始化数据库错误" + ex.Message;
|
}
|
return "成功";
|
}
|
|
/// <summary>
|
/// DEBUG:插入货位、容器、货品信息
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("InsertLocCntrCg")]
|
public string InsertLocCntrCg(LocCntrCg locCntrCg) {
|
var db = new SqlHelper<object>().GetInstance();
|
|
try {
|
|
|
using (var tran = db.UseTran()) {
|
LogHelper.Info("LogCntrCg:" + JsonConvert.SerializeObject(locCntrCg));
|
if (string.IsNullOrEmpty(locCntrCg.LocCode)) return "";
|
|
var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode);
|
if (loc == null) {
|
var newLoc = new TN_Location {
|
S_CODE = locCntrCg.LocCode,
|
S_AREA_CODE = locCntrCg.LocArea ?? ""
|
};
|
|
if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) {
|
tran.RollbackTran();
|
LogHelper.Info($"插入位置{locCntrCg.LocCode}失败");
|
return "插入失败";
|
}
|
|
loc = newLoc;
|
}
|
|
if (string.IsNullOrEmpty(locCntrCg.CntrCode)) {
|
LogHelper.Info("容器号为空,不再读取后面的数据");
|
return "";
|
}
|
|
var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode
|
&& a.S_CNTR_CODE == locCntrCg.CntrCode);
|
|
if (locCntrRel == null) {
|
var newLocCntrRel = new TN_Loc_Container {
|
S_LOC_CODE = locCntrCg.LocCode,
|
S_CNTR_CODE = locCntrCg.CntrCode,
|
S_CNTR_TYPE = locCntrCg.CntrType ?? ""
|
};
|
|
loc.N_CURRENT_NUM = 1;
|
|
if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0
|
&& db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) {
|
tran.RollbackTran();
|
LogHelper.Info($"插入位置托盘关系{locCntrCg.LocCode}-{locCntrCg.CntrCode}失败");
|
return "插入失败";
|
}
|
}
|
|
if (string.IsNullOrEmpty(locCntrCg.ItemCode)) {
|
LogHelper.Info("物料号为空,不再读取后面的数据");
|
return "";
|
}
|
|
var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode
|
&& a.S_ITEM_CODE == locCntrCg.ItemCode);
|
if (cgDetail == null) {
|
var locList = new List<TN_CG_Detail>();
|
locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" });
|
if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) {
|
tran.RollbackTran();
|
LogHelper.Info($"插入托盘物料关系{locCntrCg.CntrCode}-{locCntrCg}失败");
|
return "插入失败";
|
}
|
}
|
tran.CommitTran();
|
}
|
|
return "插入数据成功";
|
|
}
|
catch (Exception ex) {
|
return $"Error reading CSV file: {ex.Message}";
|
}
|
}
|
|
/// <summary>
|
/// DEBUG:根据容器物料信息表,插入容器物料登记信息表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("InsertContainerItemByCgDetail")]
|
public string InsertContainerItemByCgDetail(FalseOk _) {
|
var db = new SqlHelper<object>().GetInstance();
|
try {
|
var cgDetailList = db.Queryable<TN_CG_Detail>().ToList();
|
var cntrItemList = new List<TN_Container_Item>();
|
foreach (var cgDetail in cgDetailList) {
|
if (db.Queryable<TN_Container_Item>().Where(i => i.S_CNTR_CODE == cgDetail.S_CNTR_CODE).Any()) {
|
continue;
|
}
|
|
cntrItemList.Add(new TN_Container_Item {
|
S_CNTR_CODE = cgDetail.S_CNTR_CODE,
|
S_ITEM_CODE = cgDetail.S_ITEM_CODE,
|
});
|
}
|
|
if (db.Insertable<TN_Container_Item>(cntrItemList).ExecuteCommand() <= 0) {
|
return "插入失败";
|
}
|
|
return "插入成功";
|
}
|
catch (Exception ex) {
|
|
LogHelper.InfoEx(ex);
|
return ex.Message;
|
}
|
}
|
|
/// <summary>
|
/// DEBUG:根据容器物料信息表,插入容器物料登记信息表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("InsertContainerItem")]
|
public string InsertContainerItem(InsertCntrItemInfo cgDetail) {
|
var db = new SqlHelper<object>().GetInstance();
|
try {
|
var cntrItem = new TN_Container_Item {
|
S_CNTR_CODE = cgDetail.Cntr,
|
S_ITEM_CODE = cgDetail.Item,
|
};
|
|
if (db.Insertable<TN_Container_Item>(cntrItem).ExecuteCommand() <= 0) {
|
return "插入失败";
|
}
|
|
return "插入成功";
|
}
|
catch (Exception ex) {
|
|
LogHelper.InfoEx(ex);
|
return ex.Message;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 模拟 AGV 传递信号,用于更改任务状态
|
/// </summary>
|
public class UpdateTaskState {
|
/// <summary>
|
/// 任务ID
|
/// </summary>
|
public string TaskID { set; get; }
|
/// <summary>
|
/// AGV 小车号
|
/// </summary>
|
public string ForkliftNo { set; get; }
|
/// <summary>
|
/// AGV 下一个状态
|
/// </summary>
|
public int NextState { set; get; }
|
}
|
|
public class FalseOk {
|
public bool JumpOut { set; get; } = true;
|
}
|
|
public class InsertCntrItemInfo {
|
public string Cntr { set; get; }
|
public string Item { set; get; }
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public class ReturnResults {
|
public List<ReturnResult> ResultList { set; get; }
|
}
|
|
public class LocCntrCg {
|
public string Note { get; set; } // 仅用于备注
|
|
public string LocCode { get; set; }
|
public string LocArea { get; set; }
|
public string CntrCode { get; set; }
|
public string CntrType { get; set; }
|
public string ItemCode { get; set; }
|
public string BatchNo { get; set; }
|
}
|
}
|