杨前锦
2025-07-07 c8f338feee0b6003d8f069b1d37fd9b90dd1b7f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
 
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; } // 设备号
        }
    }
}