using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Runtime.ConstrainedExecution;
|
using System.Web.Http;
|
|
using HH.WCS.Mobox3.DSZSH.core;
|
using HH.WCS.Mobox3.DSZSH.device;
|
using HH.WCS.Mobox3.DSZSH.models;
|
using HH.WCS.Mobox3.DSZSH.util;
|
using HH.WCS.Mobox3.DSZSH.wms;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using static HH.WCS.Mobox3.DSZSH.api.ApiModel;
|
using static HH.WCS.Mobox3.DSZSH.api.OtherModel;
|
using static HH.WCS.Mobox3.DSZSH.Config;
|
using static HH.WCS.Mobox3.DSZSH.core.Monitor;
|
|
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) {
|
ReturnResults returnResult = new ReturnResults();
|
returnResult.ResultList = new List<ReturnResult>();
|
|
var agvTaskState = new AgvTaskState() {
|
task_no = model.TaskID,
|
forklift_no = model.ForkliftNo,
|
};
|
|
agvTaskState.state = 1;
|
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() {
|
try {
|
var db = new SqlHelper<object>().GetInstance();
|
|
var entityTypes = new Type[] { };
|
|
//db.CodeFirst.InitTables(entityTypes);
|
}
|
catch (Exception ex) {
|
LogHelper.Info($"发生了异常");
|
return "初始化数据库错误" + ex.Message;
|
}
|
return "成功";
|
}
|
|
/// <summary>
|
/// DEBUG:模拟输送线产线满托盘下线流程
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("AddInboundTask")]
|
public string AddInboundTask(AddInboundTaskInfo model) {
|
return WCSCore.CreateInboundTask(model.StartLoc, model.CntrCode).Content;
|
}
|
|
/// <summary>
|
/// DEBUG:模拟人工将料箱搬运到产线上线口 (直接修改数据库)
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("GoodpackToProdLine")]
|
public string GoodpackToProdLine(GoodpackToProdLineInfo model) {
|
|
var db = new SqlHelper<object>().GetInstance();
|
try {
|
// 查询起点货位:数量=0
|
var startLoc = db.Queryable<TN_Location>().LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE)
|
.Where((l,c) => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntrCode).First();
|
if (startLoc == null) {
|
return $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无',当前容器数量=1";
|
}
|
|
// 查询终点货位
|
// Order:按货位层数,从小到大排列
|
var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.N_CURRENT_NUM == 0).First();
|
if (endLoc == null) {
|
return $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0";
|
}
|
|
var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == model.CntrCode).First() ;
|
if (locCntrRel == null) {
|
return $"该容器不存在绑定的货位!";
|
}
|
|
locCntrRel.S_LOC_CODE = model.StartLoc;
|
startLoc.N_CURRENT_NUM = 0;
|
endLoc.N_CURRENT_NUM = 1;
|
|
using (var tran = db.Ado.UseTran()) {
|
if (db.Updateable(startLoc).ExecuteCommand() <= 0 &&
|
db.Updateable(endLoc).ExecuteCommand() <= 0 &&
|
db.Updateable(locCntrRel).ExecuteCommand() <= 0) {
|
|
tran.RollbackTran();
|
return "数据库操作失败!";
|
}
|
|
tran.CommitTran() ;
|
return "数据库操作成功";
|
}
|
}
|
catch (Exception ex) {
|
|
return ex.Message;
|
}
|
}
|
|
/// <summary>
|
/// DEBUG:模拟Erp下发出库计划单
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("TestErpSendOutboundPlan")]
|
public ErpResult TestErpSendOutboundPlan(TestErpSendOutboundPlanInfo model) {
|
var apiName = "ERP下发出库计划单";
|
//LogHelper.InfoApi(apiName, model);
|
|
var erpModel = new ErpSendOutboundPlanInfo();
|
erpModel.jhdh = model.PlanNo;
|
erpModel.cpdm = model.ItemCode;
|
erpModel.pzjs = model.ItemNum;
|
|
LogHelper.InfoApi(apiName, erpModel);
|
|
return ApiHelper.ErpSendOutboundPlan(erpModel);
|
}
|
|
/// <summary>
|
/// (内部方法请勿调用) 模拟取货完成反馈Erp回报结果 (默认为success)
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("PickUpReturn")]
|
public TestErpResult PickUpReturn(PickUpReturnErpInfo model) {
|
if (model.sfjs == 0) {
|
return new TestErpResult {
|
code = 1,
|
message = "实发件数未确定"
|
};
|
}
|
|
return new TestErpResult {
|
code = 0,
|
message = "success"
|
};
|
}
|
|
/// <summary>
|
/// (内部方法请勿调用) 模拟任务创建完成反馈Erp回报结果 (默认为success)
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("CreateTaskReturn")]
|
public TestErpResult CreateTaskReturn(CreateTaskReturnErpInfo model) {
|
if (model.hw == "") {
|
return new TestErpResult {
|
code = 1,
|
message = "货位信息未提供"
|
};
|
}
|
|
return new TestErpResult {
|
code = 0,
|
message = "success"
|
};
|
}
|
}
|
|
public class GoodpackToProdLineInfo {
|
public string CntrCode { get; set; }
|
public string StartLoc { get; set; }
|
public string EndLoc { get; set; }
|
}
|
|
public class TestErpSendOutboundPlanInfo {
|
/// <summary>
|
/// 出库计划单号 (计划单号 jhdh)
|
/// </summary>
|
public string PlanNo { get; set; } = string.Empty;
|
/// <summary>
|
/// 物料编码 (产品代码 cpdm)
|
/// </summary>
|
public string ItemCode { get; set; } = string.Empty;
|
/// <summary>
|
/// 物料数量 (派装件数 pzjs)
|
/// </summary>
|
public float ItemNum { get; set; } = 0;
|
}
|
|
public class TestErpResult {
|
public int code { get; set; }
|
public string message { get; set; }
|
}
|
|
public class AddInboundTaskInfo {
|
/// <summary>
|
/// 物料编码 (暂时没用)
|
/// </summary>
|
public string ItemCode { get; set; }
|
/// <summary>
|
/// 批次号 (暂时没用)
|
/// </summary>
|
public string BatchNo { get; set; }
|
/// <summary>
|
/// 容器编码
|
/// </summary>
|
public string CntrCode { get; set; }
|
/// <summary>
|
/// 起始货位
|
/// </summary>
|
public string StartLoc { get; set; }
|
}
|
|
/// <summary>
|
/// 模拟 AGV 传递信号,用于更改任务状态
|
/// </summary>
|
public class UpdateTaskState {
|
/// <summary>
|
/// 任务ID
|
/// </summary>
|
public string TaskID { set; get; }
|
/// <summary>
|
/// AGV 小车号
|
/// </summary>
|
public string ForkliftNo { set; get; }
|
}
|
|
public class AgvReportsInfo {
|
/// <summary>
|
/// 任务号
|
/// </summary>
|
public string TaskId { set; get; }
|
/// <summary>
|
/// AGV 小车号
|
/// </summary>
|
public string ForkliftNo { get; set; }
|
/// <summary>
|
/// AGV 下一状态 (任务回报号)
|
/// </summary>
|
public int NextState { set; get; } = 0;
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
public class ReturnResults {
|
public List<ReturnResult> ResultList { set; get; }
|
}
|
|
}
|