zhao
2021-07-07 2fdf959ac739edd6de84aa8053b8b9683dce8e8b
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 
using HH.AutoBom.Core;
using HH.WMS.Common;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Sys;
using HH.WMS.WebUI.Controllers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net.Sockets;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
 
namespace HH.WMS.WebUI.Areas.Sys.Controllers
{
    [AllowAnonymous]
    [MvcMenuFilter(false)]
    public class SysSetController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult SysConfig()
        {
            ViewData["CN_S_WMS_API"] = Constants.SysConfig.WMS_API;
            return View();
        }
 
        public string GetWebConfig()
        {
            return HttpWMS_Get("api/Strategy/GetWebConfig");
        }
 
        public string TestDb(string dbUrl, string dbType)
        {
            dbUrl = HttpUtility.UrlEncode(dbUrl, System.Text.Encoding.UTF8).Replace("+", "%20");
            return HttpWMS_Get("api/Strategy/TestDb?dbUrl=" + dbUrl + "&dbType=" + dbType);
        }
        public string TestWmsApi(string ipPort)
        {
            TcpClient client = new TcpClient();
            try
            {
                var ar = client.BeginConnect(ipPort.Split(':')[0], Convert.ToInt32(ipPort.Split(':')[1]), null, null);
                ar.AsyncWaitHandle.WaitOne(2000);
                if (client.Connected)
                {
 
                    Constants.SysConfig.WMS_API=ipPort;
                    //SetAppSettingsSection("wms_ipAddress", ipPort);
 
                    return JsonConvert.SerializeObject(OperateResult.Succeed());
                }
                else
                    return JsonConvert.SerializeObject(OperateResult.Error());
            }
            catch (Exception e)
            {
                return JsonConvert.SerializeObject(OperateResult.Error());
            }
            finally
            {
                client.Close();
            }
        }
 
        public string TestIpPort(string ipPort)
        {
            return HttpWMS_Get("api/Strategy/TestIpPort?ipPort=" + ipPort);
        }
        public string SaveWebConfig(SysConfigParamEntity model)
        {
            var loginer = FormsAuth.GetUserData<LoginerBase>();
            model.TokenId = loginer.Extend1;
            SetAppSettingsSection("RedisPath", model.REDIS);
            SetAppSettingsSection("DefaultDb", model.REDIS_DB);
 
            string result = HttpWMS_Post("Api/Strategy/SaveWebConfig", JsonConvert.SerializeObject(model));
 
            Constants.SysConfig = model;
             
            return result;
        }
 
        Configuration config;
 
        public void SetAppSettingsSection(string key, string value)
        {
            config = WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
            AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
            if (appSettings.Settings[key] != null)
            {
                if (appSettings.Settings[key].Value != value)
                {
                    appSettings.Settings[key].Value = value;
                    config.Save();
                }
            }
            else
            {
                appSettings.Settings.Add(key, value);
                config.Save();
            }
        }
 
        #region 获取策略项目
        /// <summary>
        /// 获取策略项目
        /// </summary>
        /// <returns></returns>
        /// <History>[Hanhe(DBS)] created by 2018/12/04</History>
        public string GetSetOption()
        {
            return HttpWMS_Get("api/Strategy/GetSysSetList");
        }
        #endregion
        #region 获取策略值
        /// <summary>
        /// 获取策略值
        /// </summary>
        /// <param name="stockCode">仓库号</param>
        /// <returns></returns>
        /// <History>[Hanhe(DBS)] created by 2018/12/04</History>
        public string GetOptionValue(string stockCode)
        {
            return HttpWMS_Get("api/Strategy/GetOptionValue?stockCode=" + stockCode);
        }
        #endregion
 
        #region 策略保存
        /// <summary>
        /// 策略保存
        /// </summary>
        /// <param name="stockCode">仓库号</param>
        /// <param name="ChangedItems">变更项</param>
        /// <returns></returns>
        /// <History>[Hanhe(DBS)] created by 2018/12/04</History>
        public string Save(string stockCode, string ChangedItems)
        {
            return HttpWMS_Get("api/Strategy/Save?stockCode=" + stockCode + "&ChangedItems=" + ChangedItems);
        }
        #endregion
 
        #region 打单配置
 
        public ActionResult WaveSet()
        {
            return View();
        }
 
        public string GetAutoAreas()
        {
            return HttpWMS_Get("api/WaveSet/GetAutoAreas");
        }
 
        public string GetWaveStrategy(string stockCode)
        {
            return HttpWMS_Get("api/WaveSet/GetWaveStrategy?stockCode=" + stockCode);
        }
 
        public string UpdateWaveStrategy(string stockCode, string startTime, string endTime, string severalMaxCreateWave, string lessMinute)
        {
            List<TN_WM_B_STRATEGY_VALUEEntity> strategyValues = new List<TN_WM_B_STRATEGY_VALUEEntity>();
            strategyValues.Add(new TN_WM_B_STRATEGY_VALUEEntity
            {
                CN_S_STOCK_CODE = stockCode,
                CN_S_CODE = Constants.Strategy_StartTime,
                CN_S_VALUE = startTime
            });
            strategyValues.Add(new TN_WM_B_STRATEGY_VALUEEntity
            {
                CN_S_STOCK_CODE = stockCode,
                CN_S_CODE = Constants.Strategy_EndTime,
                CN_S_VALUE = endTime
            });
            strategyValues.Add(new TN_WM_B_STRATEGY_VALUEEntity
            {
                CN_S_STOCK_CODE = stockCode,
                CN_S_CODE = Constants.Strategy_SeveralMaxCreateWave,
                CN_S_VALUE = severalMaxCreateWave
            });
            strategyValues.Add(new TN_WM_B_STRATEGY_VALUEEntity
            {
                CN_S_STOCK_CODE = stockCode,
                CN_S_CODE = Constants.Strategy_LessMinute,
                CN_S_VALUE = lessMinute
            });
            var postEntity = new
            {
                TokenId = ViewConstants.TokenId,
                PostData = strategyValues
            };
            return HttpWMS_Post("api/WaveSet/UpdateWaveStrategy", JsonConvert.SerializeObject(postEntity));
        }
 
        public string SetServiceMode(string areaCode, string serviceMode)
        {
            return HttpWMS_Get("api/WaveSet/SetServiceMode?areaCode=" + areaCode + "&serviceMode=" + serviceMode);
        }
        #endregion
    }
}