jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
using HH.WMS.Common;
using HH.WMS.Entitys.Common;
using HH.WMS.Entitys.External;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace HH.WMS.BLL.External
{
    class InfRequest
    {
        #region 发送AMS指令
        /// <summary>
        /// 发送AMS指令
        /// </summary>
        /// <param name="objs"></param>
        /// <param name="from"></param>
        /// <returns></returns>
        public SqlExecuteResult SendTask(List<JObject> objs, string from)
        {
            SqlExecuteResult msg = new SqlExecuteResult();
 
            try
            {
                var content = JsonConvert.SerializeObject(objs);
                string result = WebApiManager.HttpAms_Post("api/HHAms/AddTask", content);
 
                Log.Info("调用AMS接口下达任务", "发送内容:" + content + ", 接收结果:" + result);
 
                if (!string.IsNullOrEmpty(result))
                {
                    AmsReturnResultEntity amsre = JsonHelper.ParseFormJson<AmsReturnResultEntity>(result);
                    if (amsre.success)
                    {
                        msg.Success = true;
                        return msg;
                    }
                    else
                    {
                        //失败
                        msg.Exception = new Exception(amsre.errMsg);
                        msg.Success = true;//为了当AMS执行失败时,WMS可以继续作业
                        return msg;
                    }
                }
                else
                {
                    msg.Exception = new Exception("失败");
                }
            }
            catch (Exception ex)
            {
                msg.Success = false;
                msg.Exception = ex;
                return msg;
            }
            finally
            {
 
            }
            msg.Success = true;
            return msg;
 
        }
        #endregion
 
        #region 转运任务下达AMS指令
        /// <summary>
        /// 下达转运任务给AMS
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        /// <History>[Hanhe(DBS)] 2018-5-23</History>
        public SqlExecuteResult SendTask(List<TN_WM_TRANSPORT_TASKEntity> taskList)
        {
            try
            {
                List<JObject> sendParams = new List<JObject>();
                foreach (TN_WM_TRANSPORT_TASKEntity m in taskList)
                {
                    JObject sendParam = new JObject();
                    sendParam.Add("businessType", "转运");
                    sendParam.Add("whNoFrom", m.CN_S_STOCK_CODE);
                    sendParam.Add("whNoTo", m.CN_S_STOCK_CODE);
                    sendParam.Add("sysName", "WMS");
                    sendParam.Add("deviceName", "WMS");
                    sendParam.Add("taskNo", m.CN_S_TASK_NO);
                    sendParam.Add("locationFrom", m.CN_S_START_BIT);
                    sendParam.Add("locationTo", m.CN_S_END_BIT);
                    sendParam.Add("priority", m.CN_N_PRIORITY);
                    sendParam.Add("areaTo", (m.END_AREAS == null || m.END_AREAS.Count == 0) ? null : JsonConvert.SerializeObject(m.END_AREAS));
                    sendParams.Add(sendParam);
                }
                return new InfRequest().SendTask(sendParams, "");
            }
            catch (Exception ex)
            {
 
                return new SqlExecuteResult() { Exception = ex };
            }
        }
        #endregion
    }
}