|
using HH.WCS.Mobox3.HD.device;
|
using HH.WCS.Mobox3.HD.process;
|
using HH.WCS.Mobox3.HD.util;
|
using HH.WCS.Mobox3.HD.wms;
|
using Newtonsoft.Json;
|
using System;
|
using System.Web.Http;
|
using static HH.WCS.Mobox3.HD.api.ApiHelper;
|
using static HH.WCS.Mobox3.HD.api.ApiModel;
|
using static HH.WCS.Mobox3.HD.api.OtherModel;
|
using static HH.WCS.Mobox3.HD.core.MQTTCore;
|
using static HH.WCS.Mobox3.HD.device.S7Helper;
|
using SqlSugar;
|
using System.Reflection;
|
|
namespace HH.WCS.Mobox3.HD.api {
|
/// <summary>
|
/// 测试用,如果项目中要和设备对接,前期设备无法测试,用接口模拟
|
/// </summary>
|
[RoutePrefix("api")]
|
public class DebugController : System.Web.Http.ApiController {
|
|
|
[HttpPost]
|
[Route("s7SetInt")]
|
public SimpleResult s7SetInt(DBWModel model) {
|
S7Helper.s7SetInt(model);
|
return new SimpleResult();
|
|
}
|
|
[HttpPost]
|
[Route("s7SetDint")]
|
public SimpleResult s7SetDint(DBWModel model)
|
{
|
S7Helper.s7SetDint(model);
|
return new SimpleResult();
|
|
}
|
|
|
[HttpPost]
|
[Route("s7SetBit")]
|
public SimpleResult s7SetBit(DBXModel model) {
|
S7Helper.s7SetBit(model);
|
return new SimpleResult();
|
}
|
|
[HttpPost]
|
[Route("s7SetString")]
|
public SimpleResult s7SetString(DBBModel model) {
|
S7Helper.s7SetStr(model);
|
return new SimpleResult();
|
|
}
|
|
[HttpPost]
|
[Route("mqttsTest")]
|
public SimpleResult mqttsTest(string locCode)
|
{
|
try
|
{
|
Location loc = LocationHelper.GetLoc(locCode);
|
MqttClientService mqttClientService = new MqttClientService();
|
LogHelper.Info("获取MQTT服务......", "MQTTS");
|
mqqtClients.TryGetValue("数字孪生", out mqttClientService);
|
|
LogHelper.Info("mqtts开始推送消息", "MQTTS");
|
mqttClientService.Publish("locationChange", JsonConvert.SerializeObject(new AreaLocStatusData()
|
{
|
areaCode = loc.S_AREA_CODE,
|
locCode = locCode,
|
status = 1
|
}));
|
LogHelper.Info("mqtts推送消息完成", "MQTTS");
|
}
|
catch (Exception e)
|
{
|
Console.WriteLine(e.Message);
|
LogHelper.Info("mqtts测试错误,错误原因:" + e.Message,"MQTTS");
|
}
|
return new SimpleResult();
|
}
|
|
[HttpPost]
|
[Route("ddjTaskTest")]
|
public SimpleResult ddjTaskTest(TaskParam model)
|
{
|
var startLoc = LocationHelper.GetLoc(model.startLoc);
|
var endLoc = LocationHelper.GetLoc(model.endLoc);
|
|
WCSTask wcsTask = new WCSTask
|
{
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = "堆垛机"+ model.taskType + "测试任务",
|
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_CNTR_CODE = model.trayCode,
|
N_CNTR_COUNT = 1,
|
S_SCHEDULE_TYPE = "RB",
|
S_EQ_NO = model.eqCode,
|
};
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
// 对开始货位、接驳货位、终点货位进行加锁
|
LocationHelper.LockLoc(startLoc.S_CODE, 2);
|
LocationHelper.LockLoc(endLoc.S_CODE, 1);
|
}
|
return new SimpleResult();
|
|
}
|
|
[HttpPost]
|
[Route("Test1")]
|
public SimpleResult Test1() {
|
var db = new SqlHelper<object>().GetInstance();
|
var data = db.Queryable<Location>()
|
.LeftJoin<FunctionArea>((a, b) => a.S_CODE == b.S_FA_CODE && b.N_FA_TYPE == 1)
|
.LeftJoin<WCSTask>((a, b, c) => a.S_CODE == c.S_END_LOC && c.N_B_STATE < 3)
|
.Where((a, b, c) => a.S_AREA_CODE == "LTK02-JB" && a.N_ROADWAY == 1 && b.N_TYPE == 11)
|
.GroupBy((a, b, c) => new { a.S_CODE })
|
.Select((a, b, c) => new {
|
count = SqlFunc.AggregateCount(c.S_END_LOC),
|
name = a.S_CODE
|
})
|
.MergeTable()//需要加MergeTable才能排序统计过的列
|
.OrderBy(it => it.count)
|
.ToList();
|
return new SimpleResult() { result = data };
|
}
|
|
[HttpPost]
|
[Route("ExecutionMethod")]
|
public void ExecutionMethod()
|
{
|
// 假设你已经获取到了类名和方法名
|
string className = "HH.WCS.Mobox3.HD.api.DebugController";
|
string methodName = "mqttsTest";
|
string locCode = "11111";
|
|
// 获取类型
|
Type type = Type.GetType(className);
|
if (type == null)
|
{
|
Console.WriteLine("Class not found");
|
return;
|
}
|
|
// 创建实例
|
object instance = Activator.CreateInstance(type);
|
|
// 获取方法信息
|
MethodInfo methodInfo = type.GetMethod(methodName);
|
if (methodInfo == null)
|
{
|
Console.WriteLine("Method not found");
|
return;
|
}
|
|
// 调用方法
|
methodInfo.Invoke(instance, new object[] { locCode });
|
}
|
|
[HttpPost]
|
[Route("DeleteMouldByCntr")]
|
public void DeleteMouldByCntr(string cntrCode)
|
{
|
MouldHelper.deleteMouldByCntr(cntrCode);
|
}
|
|
public class TaskParam{
|
public string taskType { get; set; }
|
public string startLoc { get; set; }
|
public string endLoc { get; set; }
|
public string trayCode { get; set; }
|
public string eqCode { get; set; } // 设备号
|
}
|
}
|
}
|