schangxiang@126.com
2024-11-22 0b417bdc320a980cef619d9a88ce3cb0511b498b
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
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DBModel;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
using XiGang.Core.Model;
 
namespace iWareSql.DataAccess
{
    public class MesService
    {
        public static string xiGang_WMSApi = ConfigHelper.GetConfigString("XiGang_WMSApi");
        public static string xiGang_WMSApi_OutStoreToMes = ConfigHelper.GetConfigString("XiGang_WMSApi_OutStoreToMes");
 
 
        /// <summary>
        /// MES上线接口
        /// </summary>
        /// <param name="analyzeMaterialPostParam"></param>
        /// <returns></returns>
        public static void UpdateIsNeedOnLineForMainTask(Task_Main mainTask)
        {
 
            try
            {
                if ((mainTask.TaskType == (int)MainTaskTypeEnum.手动出库 || mainTask.TaskType == (int)MainTaskTypeEnum.自动出库)
                    && mainTask.MaterialType == (int)MaterialTypeEnum.一般物料)
                {//不管是本体机还是改制机,都要给MES推送出库
 
                    mainTask.IsNeedOnLine = true;
                }
                else
                {
                    mainTask.IsNeedOnLine = false;
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteErrorLog(LogType.MesService, "UpdateIsNeedOnLineForMainTask出现异常:" + ex.Message, ex);
                throw;
            }
        }
 
        /// <summary>
        /// MES上线接口
        /// </summary>
        /// <param name="analyzeMaterialPostParam"></param>
        /// <returns></returns>
        public static MesRetModel<string> updateOnlineStatus(Task_Main mainTask)
        {
            //Task.Run(() =>
            //{
            return updateOnlineStatusWithNoTask(mainTask);
            //});
        }
 
        /// <summary>
        /// MES上线接口
        /// </summary>
        /// <param name="analyzeMaterialPostParam"></param>
        /// <returns></returns>
        public static MesRetModel<string> updateOnlineStatusWithNoTask(Task_Main mainTask)
        {
            MesRetModel<string> retModel = null;
            try
            {
                if ((mainTask.TaskType == (int)MainTaskTypeEnum.手动出库 || mainTask.TaskType == (int)MainTaskTypeEnum.自动出库)
                    && mainTask.MaterialType == (int)MaterialTypeEnum.一般物料)
                {//不管是本体机还是改制机,都要给MES推送出库   
                    HTTPService service = new HTTPService(xiGang_WMSApi);
                    var res = service.postContentForString(xiGang_WMSApi_OutStoreToMes + "?mainId=" + mainTask.Id, "", "");
 
 
                    if (!string.IsNullOrEmpty(res))
                    {
                        Log4NetHelper.WriteInfoLog(LogType.MesService, "MES上线接口updateOnlineStatus,传递参数:mainId=" + mainTask.Id + ",接收的返回值res:" + res);
                        retModel = JsonConvert.DeserializeObject<MesRetModel<string>>(res);
                    }
                    if (retModel != null)
                    {
                    }
                    else
                    {
                        retModel = new MesRetModel<string>()
                        {
                            code = 400,
                            msg = "MES返回为NULL"
                        };
                    }
                }
                else
                {
                    retModel = new MesRetModel<string>()
                    {
                        code = 400,
                        msg = "任务类型不是出库类型,不允许下发给MES上线"
                    };
                }
                return retModel;
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteErrorLog(LogType.MesService, "updateOnlineStatus出现异常:" + ex.Message, ex);
                retModel = new MesRetModel<string>()
                {
                    code = 400,
                    msg = "出现异常:" + ex.Message
                };
                return retModel;
            }
        }
    }
}