mengjie лет назад: 6
Родитель
Сommit
e6ffca3290

+ 203 - 0
SmsPlatform/BLL/T_Sys_UserAccount.cs

@@ -0,0 +1,203 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using System.Data;
6
+using System.Collections.Generic;
7
+
8
+namespace SmsPlatform.BLL
9
+{
10
+    /// <summary>
11
+	/// T_Sys_UserAccount
12
+	/// </summary>
13
+	public partial class T_Sys_UserAccount
14
+    {
15
+        private readonly DAL.T_Sys_UserAccount dal = new DAL.T_Sys_UserAccount();
16
+        public T_Sys_UserAccount()
17
+        { }
18
+        #region  BasicMethod
19
+
20
+        /// <summary>
21
+        /// 得到最大ID
22
+        /// </summary>
23
+        public int GetMaxId()
24
+        {
25
+            return dal.GetMaxId();
26
+        }
27
+
28
+        /// <summary>
29
+        /// 是否存在该记录
30
+        /// </summary>
31
+        public bool Exists(int F_UserId)
32
+        {
33
+            return dal.Exists(F_UserId);
34
+        }
35
+
36
+        /// <summary>
37
+        /// 增加一条数据
38
+        /// </summary>
39
+        public int Add(Model.T_Sys_UserAccount model)
40
+        {
41
+            return dal.Add(model);
42
+        }
43
+
44
+        /// <summary>
45
+        /// 更新一条数据
46
+        /// </summary>
47
+        public bool Update(Model.T_Sys_UserAccount model)
48
+        {
49
+            return dal.Update(model);
50
+        }
51
+
52
+        /// <summary>
53
+        /// 删除一条数据
54
+        /// </summary>
55
+        public bool Delete(int F_UserId)
56
+        {
57
+
58
+            return dal.Delete(F_UserId);
59
+        }
60
+        /// <summary>
61
+        /// 删除一条数据
62
+        /// </summary>
63
+        public bool DeleteList(string F_UserIdlist)
64
+        {
65
+            return dal.DeleteList(F_UserIdlist);
66
+        }
67
+
68
+        /// <summary>
69
+        /// 得到一个对象实体
70
+        /// </summary>
71
+        public Model.T_Sys_UserAccount GetModel(int F_UserId)
72
+        {
73
+
74
+            return dal.GetModel(F_UserId);
75
+        }
76
+
77
+        ///// <summary>
78
+        ///// 得到一个对象实体,从缓存中
79
+        ///// </summary>
80
+        //public HySoft.XKPCallCenter.Model.T_Sys_UserAccount GetModelByCache(int F_UserId)
81
+        //{
82
+
83
+        //    string CacheKey = "T_Sys_UserAccountModel-" + F_UserId;
84
+        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
85
+        //    if (objModel == null)
86
+        //    {
87
+        //        try
88
+        //        {
89
+        //            objModel = dal.GetModel(F_UserId);
90
+        //            if (objModel != null)
91
+        //            {
92
+        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
93
+        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
94
+        //            }
95
+        //        }
96
+        //        catch{}
97
+        //    }
98
+        //    return (HySoft.XKPCallCenter.Model.T_Sys_UserAccount)objModel;
99
+        //}
100
+
101
+        /// <summary>
102
+        /// 获得数据列表
103
+        /// </summary>
104
+        public DataSet GetList(string strWhere)
105
+        {
106
+            return dal.GetList(strWhere);
107
+        }
108
+        public DataSet GetListView(string strWhere)
109
+        {
110
+            return dal.GetListView(strWhere);
111
+        }
112
+        /// <summary>
113
+        /// 获得前几行数据
114
+        /// </summary>
115
+        public DataSet GetList(int Top, string strWhere, string filedOrder)
116
+        {
117
+            return dal.GetList(Top, strWhere, filedOrder);
118
+        }
119
+        /// <summary>
120
+        /// 获得数据列表
121
+        /// </summary>
122
+        public List<Model.T_Sys_UserAccount> GetModelList(string strWhere)
123
+        {
124
+            DataSet ds = dal.GetList(strWhere);
125
+            return DataTableToList(ds.Tables[0]);
126
+        }
127
+        /// <summary>
128
+        /// 获得数据列表
129
+        /// </summary>
130
+        public List<Model.T_Sys_UserAccount> DataTableToList(DataTable dt)
131
+        {
132
+            List<Model.T_Sys_UserAccount> modelList = new List<Model.T_Sys_UserAccount>();
133
+            int rowsCount = dt.Rows.Count;
134
+            if (rowsCount > 0)
135
+            {
136
+                Model.T_Sys_UserAccount model;
137
+                for (int n = 0; n < rowsCount; n++)
138
+                {
139
+                    model = dal.DataRowToModel(dt.Rows[n]);
140
+                    if (model != null)
141
+                    {
142
+                        modelList.Add(model);
143
+                    }
144
+                }
145
+            }
146
+            return modelList;
147
+        }
148
+
149
+        public List<Model.T_Sys_UserAccount> DataTableToList1(DataTable dt)
150
+        {
151
+            List<Model.T_Sys_UserAccount> modelList = new List<Model.T_Sys_UserAccount>();
152
+            int rowsCount = dt.Rows.Count;
153
+            if (rowsCount > 0)
154
+            {
155
+                Model.T_Sys_UserAccount model;
156
+                for (int n = 0; n < rowsCount; n++)
157
+                {
158
+                    model = dal.DataRowToModel1(dt.Rows[n]);
159
+                    if (model != null)
160
+                    {
161
+                        modelList.Add(model);
162
+                    }
163
+                }
164
+            }
165
+            return modelList;
166
+        }
167
+
168
+        /// <summary>
169
+        /// 获得数据列表
170
+        /// </summary>
171
+        public DataSet GetAllList()
172
+        {
173
+            return GetList("");
174
+        }
175
+
176
+        /// <summary>
177
+        /// 分页获取数据列表
178
+        /// </summary>
179
+        public int GetRecordCount(string strWhere)
180
+        {
181
+            return dal.GetRecordCount(strWhere);
182
+        }
183
+        /// <summary>
184
+        /// 分页获取数据列表
185
+        /// </summary>
186
+        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
187
+        {
188
+            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
189
+        }
190
+        /// <summary>
191
+        /// 分页获取数据列表
192
+        /// </summary>
193
+        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
194
+        //{
195
+        //return dal.GetList(PageSize,PageIndex,strWhere);
196
+        //}
197
+
198
+        #endregion  BasicMethod
199
+        #region  ExtensionMethod
200
+
201
+        #endregion  ExtensionMethod
202
+    }
203
+}

+ 74 - 0
SmsPlatform/Common/CommandInfo.cs

@@ -0,0 +1,74 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Data.SqlClient;
4
+using System.Linq;
5
+using System.Threading.Tasks;
6
+
7
+namespace SmsPlatform.Common
8
+{
9
+    public enum EffentNextType
10
+    {
11
+        /// <summary>
12
+        /// 对其他语句无任何影响 
13
+        /// </summary>
14
+        None,
15
+        /// <summary>
16
+        /// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
17
+        /// </summary>
18
+        WhenHaveContine,
19
+        /// <summary>
20
+        /// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
21
+        /// </summary>
22
+        WhenNoHaveContine,
23
+        /// <summary>
24
+        /// 当前语句影响到的行数必须大于0,否则回滚事务
25
+        /// </summary>
26
+        ExcuteEffectRows,
27
+        /// <summary>
28
+        /// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
29
+        /// </summary>
30
+        SolicitationEvent
31
+    }
32
+    public class CommandInfo
33
+    {
34
+        public object ShareObject = null;
35
+        public object OriginalData = null;
36
+        event EventHandler _solicitationEvent;
37
+        public event EventHandler SolicitationEvent
38
+        {
39
+            add
40
+            {
41
+                _solicitationEvent += value;
42
+            }
43
+            remove
44
+            {
45
+                _solicitationEvent -= value;
46
+            }
47
+        }
48
+        public void OnSolicitationEvent()
49
+        {
50
+            if (_solicitationEvent != null)
51
+            {
52
+                _solicitationEvent(this, new EventArgs());
53
+            }
54
+        }
55
+        public string CommandText;
56
+        public System.Data.Common.DbParameter[] Parameters;
57
+        public EffentNextType EffentNextType = EffentNextType.None;
58
+        public CommandInfo()
59
+        {
60
+
61
+        }
62
+        public CommandInfo(string sqlText, SqlParameter[] para)
63
+        {
64
+            this.CommandText = sqlText;
65
+            this.Parameters = para;
66
+        }
67
+        public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
68
+        {
69
+            this.CommandText = sqlText;
70
+            this.Parameters = para;
71
+            this.EffentNextType = type;
72
+        }
73
+    }
74
+}

Разница между файлами не показана из-за своего большого размера
+ 1419 - 0
SmsPlatform/Common/DbHelperSQL.cs


+ 836 - 0
SmsPlatform/Common/RedisHelper.cs

@@ -0,0 +1,836 @@
1
+using Newtonsoft.Json;
2
+using StackExchange.Redis;
3
+using System;
4
+using System.Collections.Generic;
5
+using System.Linq;
6
+using System.Threading.Tasks;
7
+
8
+namespace SmsPlatform.Common
9
+{
10
+    public abstract class RedisHelper
11
+    {
12
+        public static string connserver = "";
13
+        public static string connport = "";
14
+
15
+        #region 
16
+        //执行顺序---静态字段---静态构造函数---构造函数
17
+        private static ConnectionMultiplexer redis;
18
+        private static IDatabase database;
19
+        static RedisHelper()
20
+        {
21
+            if (connserver != "" && connport != "")
22
+            {
23
+                if (redis == null || !redis.IsConnected)
24
+                {
25
+                    redis = ConnectionMultiplexer.Connect(connserver + ":" + connport);
26
+                    //redis = ConnectionMultiplexer.Connect("192.168.4.18, abortConnect=false");
27
+
28
+                    database = redis.GetDatabase(10);
29
+                }
30
+            }
31
+        }
32
+
33
+        #endregion
34
+
35
+        /// <summary>
36
+        /// 判断是否连接
37
+        /// </summary>
38
+        /// <returns></returns>
39
+        public static bool IsCon()
40
+        {
41
+            if (redis == null || !redis.IsConnected)
42
+            {
43
+                try
44
+                {
45
+                    redis = ConnectionMultiplexer.Connect(connserver + ":" + connport);
46
+                    //redis = ConnectionMultiplexer.Connect("192.168.4.18, abortConnect=false");
47
+
48
+                    database = redis.GetDatabase(15);
49
+                }
50
+                catch (Exception e)
51
+                {
52
+                    return false;
53
+                }
54
+                
55
+            }
56
+            return redis.IsConnected;
57
+            
58
+
59
+        }
60
+
61
+        #region redis 字符串(string)操作
62
+
63
+        /// <summary>
64
+        /// 设置指定键的值
65
+        /// </summary>
66
+        /// <param name="key"></param>
67
+        /// <param name="value"></param>
68
+        /// <returns></returns>
69
+        public static bool StringSet(string key, string value)
70
+        {
71
+            return database.StringSet(key, value);
72
+        }
73
+
74
+        /// <summary>
75
+        /// 获取指定键的值
76
+        /// </summary>
77
+        /// <param name="key"></param>
78
+        /// <returns></returns>
79
+        public static object StringGet(string key)
80
+        {
81
+            if (redis == null || !redis.IsConnected)
82
+            {
83
+                redis = ConnectionMultiplexer.Connect(connserver + ":" + connport);
84
+                //redis = ConnectionMultiplexer.Connect("192.168.4.18, abortConnect=false");
85
+
86
+                database = redis.GetDatabase(15);
87
+            }
88
+            if (database.KeyExists(key))
89
+            {
90
+                var rt = database.StringGet(key);
91
+
92
+                if (rt.IsNull)
93
+                {
94
+                    return null;
95
+                }
96
+                else
97
+                {
98
+                    return rt;
99
+                }
100
+            }
101
+            else
102
+            { return null; }
103
+        }
104
+
105
+        /// <summary>
106
+        /// 获取存储在键上的字符串的子字符串
107
+        /// </summary>
108
+        /// <param name="key"></param>
109
+        /// <param name="start"></param>
110
+        /// <param name="end"></param>
111
+        /// <returns></returns>
112
+        public static object StringGet(string key, int start, int end)
113
+        {
114
+            var rt = database.StringGetRange(key, start, end);
115
+            if (rt.IsNull)
116
+            {
117
+                return null;
118
+            }
119
+            else
120
+            {
121
+                return rt;
122
+            }
123
+        }
124
+
125
+        /// <summary>
126
+        /// 设置键的字符串值并返回其旧值
127
+        /// </summary>
128
+        /// <param name="key"></param>
129
+        /// <param name="value"></param>
130
+        /// <returns></returns>
131
+        public static object StringGetAndSet(string key, string value)
132
+        {
133
+            var rt = database.StringGetSet(key, value);
134
+            if (rt.IsNull)
135
+            {
136
+                return null;
137
+            }
138
+            else
139
+            {
140
+                return rt;
141
+            }
142
+        }
143
+
144
+        /// <summary>
145
+        /// 返回在键处存储的字符串值中偏移处的位值
146
+        /// </summary>
147
+        /// <param name="key"></param>
148
+        /// <param name="offset"></param>
149
+        /// <returns></returns>
150
+        public static bool StringGetBit(string key, long offset)
151
+        {
152
+            return database.StringGetBit(key, offset);
153
+        }
154
+
155
+        /// <summary>
156
+        /// 获取所有给定键的值
157
+        /// </summary>
158
+        /// <param name="keys"></param>
159
+        /// <returns></returns>
160
+        public static List<object> StringMultiGet(string[] keys)
161
+        {
162
+            List<object> list = new List<object>();
163
+            for (int i = 0; i < keys.Length; i++)
164
+            {
165
+                list.Add(database.StringGet(keys[i]));
166
+            }
167
+            return list;
168
+        }
169
+
170
+        /// <summary>
171
+        /// 存储在键上的字符串值中设置或清除偏移处的位
172
+        /// </summary>
173
+        /// <param name="key"></param>
174
+        /// <param name="offset"></param>
175
+        /// <param name="value"></param>
176
+        /// <returns></returns>
177
+        public static bool StringSetBit(string key, long offset)
178
+        {
179
+            return database.StringSetBit(key, offset, true);
180
+        }
181
+
182
+        /// <summary>
183
+        /// 使用键和到期时间来设置值
184
+        /// </summary>
185
+        /// <param name="key"></param>
186
+        /// <param name="value"></param>
187
+        /// <param name="expiry"></param>
188
+        /// <returns></returns>
189
+        public static bool StringSet(string key, string value, TimeSpan expiry)
190
+        {
191
+            return database.StringSet(key, value, expiry);
192
+        }
193
+
194
+        /// <summary>
195
+        /// 设置键的值,仅当键不存在时
196
+        /// </summary>
197
+        /// <param name="key"></param>
198
+        /// <param name="value"></param>
199
+        /// <returns></returns>
200
+        public static void StringSetIfAbsent(string key, string value)
201
+        {
202
+            if (database.StringGet(key) == RedisValue.Null)
203
+            {
204
+                database.StringSet(key, value);
205
+            }
206
+        }
207
+
208
+        /// <summary>
209
+        /// 在指定偏移处开始的键处覆盖字符串的一部分
210
+        /// </summary>
211
+        /// <param name="key">键值</param>
212
+        /// <param name="value">值</param>
213
+        /// <param name="offset">偏移量</param>
214
+        /// <returns></returns>
215
+        public static object StringSet(string key, long offset, string value)
216
+        {
217
+            return database.StringSetRange(key, offset, value);
218
+        }
219
+
220
+        /// <summary>
221
+        /// 获取存储在键中的值的长度
222
+        /// </summary>
223
+        /// <param name="key">键值</param>
224
+        /// <returns></returns>
225
+        public static long StringSize(string key)
226
+        {
227
+            return database.StringLength(key);
228
+        }
229
+
230
+        /// <summary>
231
+        /// 为多个键分别设置它们的值
232
+        /// </summary>
233
+        /// <param name="keys"></param>
234
+        /// <returns></returns>
235
+        public static void StringMultiSet(Dictionary<string, string> dic)
236
+        {
237
+            foreach (KeyValuePair<string, string> key in dic)
238
+            {
239
+                database.StringSet(key.Key, key.Value);
240
+            }
241
+        }
242
+
243
+        /// <summary>
244
+        /// 为多个键分别设置它们的值,仅当键不存在时
245
+        /// </summary>
246
+        /// <param name="keys">键值集合</param>
247
+        /// <returns></returns>
248
+        public static void StringMultiSetIfAbsent(Dictionary<string, string> dic)
249
+        {
250
+            foreach (KeyValuePair<string, string> key in dic)
251
+            {
252
+                //判断键值是否存在
253
+                if (database.StringGet(key.Key) == RedisValue.Null)
254
+                {
255
+                    database.StringSet(key.Key, key.Value);
256
+                }
257
+            }
258
+        }
259
+
260
+        /// <summary>
261
+        /// 将键的整数值按给定的数值增加
262
+        /// </summary>
263
+        /// <param name="key">键值</param>
264
+        /// <param name="value">给定的数值</param>
265
+        /// <returns></returns>
266
+        public static double StringIncrement(string key, double value)
267
+        {
268
+            return database.StringIncrement(key, value);
269
+        }
270
+
271
+        /// <summary>
272
+        /// 在key键对应值的右面追加值value
273
+        /// </summary>
274
+        /// <param name="key"></param>
275
+        /// <param name="value"></param>
276
+        /// <returns></returns>
277
+        public static long StringAppend(string key, string value)
278
+        {
279
+            return database.StringAppend(key, value);
280
+        }
281
+
282
+        /// <summary>
283
+        /// 删除某个键值
284
+        /// </summary>
285
+        /// <param name="key"></param>
286
+        /// <returns></returns>
287
+        public static bool StringDelete(string key)
288
+        {
289
+            return false;
290
+        }
291
+
292
+        #endregion
293
+
294
+        #region redis 哈希/散列/字典(Hash)操作
295
+
296
+        /// <summary>
297
+        /// 删除指定的哈希字段
298
+        /// </summary>
299
+        /// <param name="key"></param>
300
+        /// <param name="field"></param>
301
+        /// <returns></returns>
302
+        public static bool HashDelete(string key, string field)
303
+        {
304
+            return database.HashDelete(key, field);
305
+        }
306
+
307
+        /// <summary>
308
+        /// 判断是否存在散列字段
309
+        /// </summary>
310
+        /// <param name=""></param>
311
+        /// <param name=""></param>
312
+        /// <returns></returns>
313
+        public static bool HashHasKey(string key, string field)
314
+        {
315
+            return database.HashExists(key, field);
316
+        }
317
+
318
+        /// <summary>
319
+        /// 获取存储在指定键的哈希字段的值
320
+        /// </summary>
321
+        /// <param name="key"></param>
322
+        /// <param name="field"></param>
323
+        /// <returns></returns>
324
+        public static object HashGet(string key, string field)
325
+        {
326
+            return database.HashGet(key, field);
327
+        }
328
+
329
+        /// <summary>
330
+        /// 获取存储在指定键的哈希中的所有字段和值
331
+        /// </summary>
332
+        /// <param name="key"></param>
333
+        /// <returns></returns>
334
+        public static Dictionary<string, object> HashGetAll(string key)
335
+        {
336
+            Dictionary<string, object> dic = new Dictionary<string, object>();
337
+            var collection = database.HashGetAll(key);
338
+            foreach (var item in collection)
339
+            {
340
+                dic.Add(item.Name, item.Value);
341
+            }
342
+            return dic;
343
+        }
344
+
345
+        /// <summary>
346
+        /// 将哈希字段的浮点值按给定数值增加
347
+        /// </summary>
348
+        /// <param name="key"></param>
349
+        /// <param name="field"></param>
350
+        /// <param name="value">给定的数值</param>
351
+        /// <returns></returns>
352
+        public static double HashIncrement(string key, string field, double value)
353
+        {
354
+            return database.HashIncrement(key, field, value);
355
+        }
356
+
357
+        /// <summary>
358
+        /// 获取哈希中的所有字段
359
+        /// </summary>
360
+        /// <param name="key"></param>
361
+        /// <returns></returns>
362
+        public static string[] HashKeys(string key)
363
+        {
364
+            return database.HashKeys(key).ToStringArray();
365
+        }
366
+
367
+        /// <summary>
368
+        /// 获取散列中的字段数量
369
+        /// </summary>
370
+        /// <param name="key"></param>
371
+        /// <returns></returns>
372
+        public static long HashSize(string key)
373
+        {
374
+            return database.HashLength(key);
375
+        }
376
+
377
+        /// <summary>
378
+        /// 获取所有给定哈希字段的值
379
+        /// </summary>
380
+        /// <param name="key"></param>
381
+        /// <param name="hashKeys"></param>
382
+        /// <returns></returns>
383
+        public static List<object> HashMultiGet(string key, List<string> hashKeys)
384
+        {
385
+            List<object> result = new List<object>();
386
+            foreach (string field in hashKeys)
387
+            {
388
+                result.Add(database.HashGet(key, field));
389
+            }
390
+            return result;
391
+        }
392
+
393
+        /// <summary>
394
+        /// 为多个哈希字段分别设置它们的值
395
+        /// </summary>
396
+        /// <param name="key"></param>
397
+        /// <param name="dic"></param>
398
+        /// <returns></returns>
399
+        public static void HashPutAll(string key, Dictionary<string, string> dic)
400
+        {
401
+            List<HashEntry> list = new List<HashEntry>();
402
+            for (int i = 0; i < dic.Count; i++)
403
+            {
404
+                KeyValuePair<string, string> param = dic.ElementAt(i);
405
+                list.Add(new HashEntry(param.Key, param.Value));
406
+            }
407
+            database.HashSet(key, list.ToArray());
408
+        }
409
+
410
+        /// <summary>
411
+        /// 设置散列字段的字符串值
412
+        /// </summary>
413
+        /// <param name="key"></param>
414
+        /// <param name="field"></param>
415
+        /// <param name="value"></param>
416
+        /// <returns></returns>
417
+        public static void HashPut(string key, string field, string value)
418
+        {
419
+            database.HashSet(key, new HashEntry[] { new HashEntry(field, value) });
420
+        }
421
+
422
+        /// <summary>
423
+        /// 仅当字段不存在时,才设置散列字段的值
424
+        /// </summary>
425
+        /// <param name="key"></param>
426
+        /// <param name="fiels"></param>
427
+        /// <param name="value"></param>
428
+        /// <returns></returns>
429
+        public static void HashPutIfAbsent(string key, string field, string value)
430
+        {
431
+            if (!HashHasKey(key, field))
432
+            {
433
+                database.HashSet(key, new HashEntry[] { new HashEntry(field, value) });
434
+            }
435
+        }
436
+
437
+        /// <summary>
438
+        /// 获取哈希中的所有值
439
+        /// </summary>
440
+        /// <param name="key"></param>
441
+        /// <returns></returns>
442
+        public static string[] HashValues(string key)
443
+        {
444
+            return database.HashValues(key).ToStringArray();
445
+        }
446
+
447
+        /// <summary>
448
+        /// redis中获取指定键的值并返回对象
449
+        /// </summary>
450
+        /// <typeparam name="T"></typeparam>
451
+        /// <param name="key"></param>
452
+        /// <returns></returns>
453
+        public static T GetHashValue<T>(string key)
454
+        {
455
+            HashEntry[] array = database.HashGetAll(key);
456
+            Dictionary<string, object> dic = new Dictionary<string, object>();
457
+            for (int i = 0; i < array.Length; i++)
458
+            {
459
+                dic.Add(array[i].Name, array[i].Value);
460
+            }
461
+            if (dic.Count > 0)
462
+            {
463
+                string strJson = JsonConvert.SerializeObject(dic);
464
+                return JsonConvert.DeserializeObject<T>(strJson);
465
+            }
466
+            else
467
+            {
468
+                return default(T);
469
+            }
470
+        }
471
+
472
+        /// <summary>
473
+        /// 把指定对象存储在键值为key的redis中
474
+        /// </summary>
475
+        /// <typeparam name="T"></typeparam>
476
+        /// <param name="t"></param>
477
+        /// <param name="key"></param>
478
+        public static void SetHashValue<T>(T t, string key)
479
+        {
480
+            string strJson = JsonConvert.SerializeObject(t);
481
+            Dictionary<string, string> param = JsonConvert.DeserializeObject<Dictionary<string, string>>(strJson);
482
+            HashPutAll(key, param);
483
+        }
484
+
485
+        #endregion
486
+
487
+        #region redis 列表(List)操作
488
+
489
+        /// <summary>
490
+        /// 从左向右存压栈
491
+        /// </summary>
492
+        /// <param name="key"></param>
493
+        /// <param name="value"></param>
494
+        /// <returns></returns>
495
+        public static long ListLeftPush(string key, string value)
496
+        {
497
+            return database.ListLeftPush(key, value);
498
+        }
499
+
500
+        /// <summary>
501
+        /// 从左出栈
502
+        /// </summary>
503
+        /// <param name="key"></param>
504
+        /// <returns></returns>
505
+        public static object ListLeftPop(string key)
506
+        {
507
+            return database.ListLeftPop(key);
508
+        }
509
+
510
+        /// <summary>
511
+        /// 队/栈长
512
+        /// </summary>
513
+        /// <param name="key"></param>
514
+        /// <returns></returns>
515
+        public static long ListSize(string key)
516
+        {
517
+            return database.ListLength(key);
518
+        }
519
+
520
+        /// <summary>
521
+        /// 范围检索,返回List
522
+        /// </summary>
523
+        /// <param name="key"></param>
524
+        /// <param name="start"></param>
525
+        /// <param name="end"></param>
526
+        /// <returns></returns>
527
+        public static string[] ListRange(string key, int start, int end)
528
+        {
529
+            return database.ListRange(key, start, end).ToStringArray();
530
+        }
531
+
532
+        /// <summary>
533
+        /// 移除key中值为value的i个,返回删除的个数;如果没有这个元素则返回0 
534
+        /// </summary>
535
+        /// <param name="key"></param>
536
+        /// <param name="i"></param>
537
+        /// <param name="value"></param>
538
+        /// <returns></returns>
539
+        public static long ListRemove(string key, string value)
540
+        {
541
+            return database.ListRemove(key, value);
542
+        }
543
+
544
+        /// <summary>
545
+        /// 检索
546
+        /// </summary>
547
+        /// <param name="key"></param>
548
+        /// <param name="index"></param>
549
+        /// <returns></returns>
550
+        public static object ListIndex(string key, long index)
551
+        {
552
+            return database.ListGetByIndex(key, index);
553
+        }
554
+
555
+        /// <summary>
556
+        /// 赋值
557
+        /// </summary>
558
+        /// <param name="key"></param>
559
+        /// <param name="index"></param>
560
+        /// <param name="value"></param>
561
+        /// <returns></returns>
562
+        public static void ListSet(string key, int index, string value)
563
+        {
564
+            database.ListSetByIndex(key, index, value);
565
+        }
566
+
567
+        /// <summary>
568
+        /// 裁剪,删除除了[start,end]以外的所有元素 
569
+        /// </summary>
570
+        /// <param name="key"></param>
571
+        /// <param name="start"></param>
572
+        /// <param name="end"></param>
573
+        /// <returns></returns>
574
+        public static void ListTrim(string key, int start, int end)
575
+        {
576
+            database.ListTrim(key, start, end);
577
+        }
578
+
579
+        /// <summary>
580
+        /// 将源key的队列的右边的一个值删除,然后塞入目标key的队列的左边,返回这个值
581
+        /// </summary>
582
+        /// <param name="sourceKey"></param>
583
+        /// <param name="destinationKey"></param>
584
+        /// <returns></returns>
585
+        public static object ListRightPopAndLeftPush(string sourceKey, string destinationKey)
586
+        {
587
+            return database.ListRightPopLeftPush(sourceKey, destinationKey);
588
+        }
589
+
590
+        #endregion
591
+
592
+        #region redis 集合(Set)操作
593
+
594
+        /// <summary>
595
+        /// 集合添加元素
596
+        /// </summary>
597
+        /// <param name="key"></param>
598
+        /// <param name="value"></param>
599
+        public static void SetAdd(string key, string value)
600
+        {
601
+            database.SetAdd(key, value);
602
+        }
603
+
604
+        /// <summary>
605
+        /// 集合组合操作
606
+        /// </summary>
607
+        /// <param name="point">操作标示:0--并集;1--交集;2--差集</param>
608
+        /// <param name="firstKey">第一个集合的键值</param>
609
+        /// <param name="secondKey">第二个集合的键值</param>
610
+        public static string[] SetCombine(int point, string firstKey, string secondKey)
611
+        {
612
+            RedisValue[] array;
613
+            switch (point)
614
+            {
615
+                case 0:
616
+                    array = database.SetCombine(SetOperation.Union, firstKey, secondKey);
617
+                    break;
618
+                case 1:
619
+                    array = database.SetCombine(SetOperation.Intersect, firstKey, secondKey);
620
+                    break;
621
+                case 2:
622
+                    array = database.SetCombine(SetOperation.Difference, firstKey, secondKey);
623
+                    break;
624
+                default:
625
+                    array = new RedisValue[0];
626
+                    break;
627
+            }
628
+            return array.ToStringArray();
629
+        }
630
+
631
+        /// <summary>
632
+        /// 
633
+        /// </summary>
634
+        /// <param name="key"></param>
635
+        /// <param name="value"></param>
636
+        /// <returns></returns>
637
+        public static bool SetContains(string key, string value)
638
+        {
639
+            return database.SetContains(key, value);
640
+        }
641
+
642
+        /// <summary>
643
+        /// 返回对应键值集合的长度
644
+        /// </summary>
645
+        /// <param name="key"></param>
646
+        /// <returns></returns>
647
+        public static long SetLength(string key)
648
+        {
649
+            return database.SetLength(key);
650
+        }
651
+
652
+        /// <summary>
653
+        /// 根据键值返回集合中所有的value
654
+        /// </summary>
655
+        /// <param name="key"></param>
656
+        /// <returns></returns>
657
+        public static string[] SetMembers(string key)
658
+        {
659
+            return database.SetMembers(key).ToStringArray();
660
+        }
661
+
662
+        /// <summary>
663
+        /// 将成员从源集移动到目标集
664
+        /// </summary>
665
+        /// <param name="sourceKey">源集key</param>
666
+        /// <param name="destinationKey">目标集key</param>
667
+        /// <param name="value"></param>
668
+        public static bool SetMove(string sourceKey, string destinationKey, string value)
669
+        {
670
+            return database.SetMove(sourceKey, destinationKey, value);
671
+        }
672
+
673
+        /// <summary>
674
+        /// 移除集合中指定键值随机元素
675
+        /// </summary>
676
+        /// <param name="key"></param>
677
+        public static string SetPop(string key)
678
+        {
679
+            return database.SetPop(key);
680
+        }
681
+
682
+        /// <summary>
683
+        /// 返回集合中指定键值随机元素
684
+        /// </summary>
685
+        /// <param name="key"></param>
686
+        /// <returns></returns>
687
+        public static string SetRandomMember(string key)
688
+        {
689
+            return database.SetRandomMember(key);
690
+        }
691
+
692
+        /// <summary>
693
+        /// 
694
+        /// </summary>
695
+        /// <param name="key"></param>
696
+        /// <param name="count"></param>
697
+        public static string[] SetRandomMembers(string key, long count)
698
+        {
699
+            return database.SetRandomMembers(key, count).ToStringArray();
700
+        }
701
+
702
+        /// <summary>
703
+        /// 移除集合中指定key值和value
704
+        /// </summary>
705
+        /// <param name="key"></param>
706
+        /// <param name="value"></param>
707
+        public static void SetRemove(string key, string value)
708
+        {
709
+            database.SetRemove(key, value);
710
+        }
711
+
712
+        /// <summary>
713
+        /// 
714
+        /// </summary>
715
+        /// <param name="key"></param>
716
+        public static void SetScan(string key)
717
+        {
718
+            database.SetScan(key);
719
+        }
720
+
721
+        #endregion
722
+
723
+        #region redis 有序集合(sorted set)操作
724
+
725
+        public static void Method(string key, string value, double score)
726
+        {
727
+            database.SortedSetAdd(key, new SortedSetEntry[] { new SortedSetEntry(value, score) });
728
+        }
729
+
730
+        #endregion
731
+
732
+        #region redis 键(Key)操作
733
+
734
+        /// <summary>
735
+        /// 获取 Key
736
+        /// </summary>
737
+        /// <param name="redisKey"></param>
738
+        /// <returns></returns>
739
+        //public static IEnumerable<RedisKey> GetKeyList(string redisKey)
740
+        //{
741
+        //    var server = redis.GetServer(Configs.GetValue("Redis_Server"), Configs.GetValue("Redis_Port"));
742
+        //    return server.Keys(pattern: "*"+ redisKey + "*");
743
+        //}
744
+        public static List<string> GetKeyList(string redisKey)
745
+        {
746
+            var server = redis.GetServer(connserver, Int32.Parse(connport)); 
747
+            List<string> keylist = new List<string>();
748
+            var redisenum = server.Keys(pattern: "*" + redisKey + "*");
749
+            foreach (var r in redisenum.ToList())
750
+            {
751
+                keylist.Add(r.ToString());
752
+            }
753
+            return keylist;
754
+        }
755
+
756
+        /// <summary>
757
+        /// 移除指定 Key
758
+        /// </summary>
759
+        /// <param name="redisKey"></param>
760
+        /// <returns></returns>
761
+        public static bool KeyDelete(string redisKey)
762
+        {
763
+            return database.KeyDelete(redisKey);
764
+        }
765
+
766
+        /// <summary>
767
+        /// 移除指定 Key
768
+        /// </summary>
769
+        /// <param name="redisKey"></param>
770
+        /// <returns></returns>
771
+        //public static long KeysDelete(IEnumerable<RedisKey> redisKeys)
772
+        //{
773
+        //    return database.KeyDelete(redisKeys.ToArray());
774
+        //}
775
+        public static long KeysDelete(List<string> redisKeys)
776
+        {
777
+            int n = 0;
778
+            foreach (var r in redisKeys)
779
+            {
780
+                if (database.KeyDelete(r))
781
+                {
782
+                    n++;
783
+                }
784
+            }
785
+            return n;
786
+        }
787
+
788
+        /// <summary>
789
+        /// 校验 Key 是否存在
790
+        /// </summary>
791
+        /// <param name="redisKey"></param>
792
+        /// <returns></returns>
793
+        public static bool KeyExists(string redisKey)
794
+        {
795
+            return database.KeyExists(redisKey);
796
+        }
797
+
798
+        /// <summary>
799
+        /// 重命名 Key
800
+        /// </summary>
801
+        /// <param name="redisKey"></param>
802
+        /// <param name="redisNewKey"></param>
803
+        /// <returns></returns>
804
+        public static bool KeyRename(string redisKey, string redisNewKey)
805
+        {
806
+            return database.KeyRename(redisKey, redisNewKey);
807
+        }
808
+
809
+        /// <summary>
810
+        /// 设置 Key 的时间
811
+        /// </summary>
812
+        /// <param name="redisKey"></param>
813
+        /// <param name="expiry"></param>
814
+        /// <returns></returns>
815
+        public static bool KeyExpire(string redisKey, TimeSpan? expiry)
816
+        {
817
+            return database.KeyExpire(redisKey, expiry);
818
+        }
819
+
820
+        #endregion
821
+
822
+        /// <summary>
823
+        /// 获取key过期时间
824
+        /// </summary>
825
+        /// <param name="redisKey"></param>
826
+        /// <returns></returns>
827
+        public static string GetKeyOutTime(string redisKey)
828
+        {
829
+            var server = redis.GetServer(connserver , Int32.Parse(connport));
830
+            var timeNow = server.Time().ToUniversalTime();
831
+            var time = database.KeyTimeToLive(redisKey);
832
+            var expire = time == null ? (DateTime?)null : timeNow.Add(time.Value); //返回UTC时间。
833
+            return expire.Value.AddHours(8).ToString("yyyy-MM-dd HH:mm:ss");
834
+        }
835
+    }
836
+}

+ 17 - 0
SmsPlatform/Common/SQLOption.cs

@@ -0,0 +1,17 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace SmsPlatform.Common
7
+{
8
+    public class SQLOption
9
+    {
10
+        /// <summary>
11
+        ///SQL数据库连接字符串
12
+        /// </summary>
13
+        public static  string ConnectionString { get; set; }
14
+
15
+        
16
+    }
17
+}

+ 376 - 145
SmsPlatform/Controllers/SmsController.cs

@@ -1,5 +1,6 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
+using System.Data;
3 4
 using System.Linq;
4 5
 using System.Threading.Tasks;
5 6
 using System.Transactions;
@@ -22,6 +23,8 @@ namespace SmsPlatform.Controllers
22 23
         private readonly ILogger<SmsController> _logger;
23 24
         private readonly IDistributedCache _cache;
24 25
         private readonly IConfiguration _configuration;
26
+        BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
27
+
25 28
         public SmsController(IDistributedCache cache, IConfiguration configuration, ILogger<SmsController> logger)
26 29
         {
27 30
             _cache = cache;
@@ -36,29 +39,85 @@ namespace SmsPlatform.Controllers
36 39
         [HttpGet("getbalance")]
37 40
         public async Task<IActionResult> GetBalance(string usercode, string password, string signcode)
38 41
         {
39
-            var liststr = await _cache.GetStringAsync("T_User_Account");
40
-            var list = new List<T_User_Account>();
41
-            if (!string.IsNullOrEmpty(liststr))
42
+            //var dtCache = RedisHelper.StringGet("T_User_Account");
43
+            if (RedisHelper .IsCon ()&& _cache != null)
42 44
             {
43
-                list = liststr.ToList<T_User_Account>();
44
-            }
45 45
 
46
-            var model = list.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
47
-            if (model != null)
48
-            {
49
-                string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
50
-                if (outsigncode.ToUpper() == signcode.ToUpper())
46
+                //if (_cache != null)
47
+                //{
48
+                    var liststr = await _cache.GetStringAsync("T_User_Account");
49
+                var list = new List<T_User_Account>();
50
+                if (!string.IsNullOrEmpty(liststr))
51 51
                 {
52
-                    return Success("成功", model.Balance);
52
+                    list = liststr.ToList<T_User_Account>();
53 53
                 }
54 54
                 else
55 55
                 {
56
-                    return Error("签名错误");
56
+                    //将sql中的数据保存到redis中
57
+                    string strwhere = " F_See='" + usercode + "' and F_Remark='" + password + "'";
58
+                    DataSet ds = bll.GetList(strwhere);
59
+                    if (ds != null)
60
+                    {
61
+                        DataTable dt = ds.Tables[0];
62
+                        if (dt.Rows.Count > 0)
63
+                        {
64
+                            var models = new T_User_Account();
65
+                            models.Id = int.Parse (dt.Rows [0]["F_UserId"].ToString ());
66
+                            models.UserCode = dt.Rows[0]["F_See"].ToString();
67
+                            models.Password = dt.Rows[0]["F_Remark"].ToString();
68
+                            models.UserName = "";
69
+                            models.Sign = dt.Rows[0]["F_Remark"].ToString();
70
+                            models.Balance = Decimal.Parse (dt.Rows[0]["F_DeptCode"].ToString());
71
+                            models.CreateTime = DateTime.Now;
72
+                            list.Add(models);
73
+                            await _cache.SetStringAsync("T_User_Account", list.ToJson());
74
+                            liststr = await _cache.GetStringAsync("T_User_Account");
75
+                            if (!string.IsNullOrEmpty(liststr))
76
+                            {
77
+                                list = liststr.ToList<T_User_Account>();
78
+                            }
79
+                        }
80
+                    }
81
+                }
82
+                var model = list.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
83
+                if (model != null)
84
+                {
85
+                    string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
86
+                    if (outsigncode.ToUpper() == signcode.ToUpper())
87
+                    {
88
+                        return Success("成功", model.Balance);
89
+                    }
90
+                    else
91
+                    {
92
+                        return Error("签名错误");
93
+                    }
94
+                }
95
+                else
96
+                {
97
+                    return Error("账号或者密码错误");
57 98
                 }
58 99
             }
59 100
             else
60 101
             {
61
-                return Error("账号或者密码错误");
102
+                string strwhere = " F_See='"+usercode + "' and F_Remark='" + password +"'";
103
+                DataSet ds = bll.GetList(strwhere);
104
+                if (ds != null)
105
+                {
106
+                    DataTable dt = ds.Tables[0];
107
+                    if (dt.Rows.Count > 0)
108
+                    {
109
+                        string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" +dt.Rows [0]["F_Remark"].ToString () + "+" + DateTime.Now.ToString("yyyyMMdd"));
110
+                        if (outsigncode.ToUpper() == signcode.ToUpper())
111
+                        {
112
+                            return Success("成功", dt.Rows[0]["F_DeptCode"].ToString());
113
+                        }
114
+                        else
115
+                        {
116
+                            return Error("签名错误");
117
+                        }
118
+                    }
119
+                }
120
+                return Error("获取失败");
62 121
             }
63 122
         }
64 123
 
@@ -69,51 +128,85 @@ namespace SmsPlatform.Controllers
69 128
         [HttpPost("updatebalance")]
70 129
         public async Task<IActionResult> UpdateBalance(string usercode, string password, decimal amount, string remark, string signcode)
71 130
         {
72
-            var userliststr = await _cache.GetStringAsync("T_User_Account");
73
-            var userlist = new List<T_User_Account>();
74
-            if (!string.IsNullOrEmpty(userliststr))
131
+            if (_cache != null)
75 132
             {
76
-                userlist = userliststr.ToList<T_User_Account>();
77
-            }
133
+                var userliststr = await _cache.GetStringAsync("T_User_Account");
134
+                var userlist = new List<T_User_Account>();
135
+                if (!string.IsNullOrEmpty(userliststr))
136
+                {
137
+                    userlist = userliststr.ToList<T_User_Account>();
138
+                }
78 139
 
79
-            var model = userlist.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
80
-            if (model != null)
81
-            {
82
-                string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
83
-                if (outsigncode.ToUpper() == signcode.ToUpper())
140
+                var model = userlist.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
141
+                if (model != null)
84 142
                 {
85
-                    model.Balance = model.Balance + amount;
86
-                    await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
143
+                    string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
144
+                    if (outsigncode.ToUpper() == signcode.ToUpper())
145
+                    {
146
+                        model.Balance = model.Balance + amount;
147
+                        await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
87 148
 
149
+                        #region 更新sql数据库余额
150
+                        BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
151
+                        Model.T_Sys_UserAccount mt = bll.GetModel(model.Id);
152
+                        mt.F_DeptCode = model.Balance.ToString();
153
+                        bll.Update(mt);
154
+                        #endregion
88 155
 
89
-                    var amtliststr = await _cache.GetStringAsync("T_User_Amount");
90
-                    var amtlist = new List<T_User_Amount>();
91
-                    if (!string.IsNullOrEmpty(amtliststr))
92
-                    {
93
-                        amtlist = amtliststr.ToList<T_User_Amount>();
94
-                    }
156
+                        var amtliststr = await _cache.GetStringAsync("T_User_Amount");
157
+                        var amtlist = new List<T_User_Amount>();
158
+                        if (!string.IsNullOrEmpty(amtliststr))
159
+                        {
160
+                            amtlist = amtliststr.ToList<T_User_Amount>();
161
+                        }
95 162
 
96
-                    var amt = new T_User_Amount();
97
-                    amt.Id = amtlist.Count > 0 ? amtlist.Max(p => p.Id) + 1 : 1;
98
-                    amt.UserCode = usercode;
99
-                    amt.Amount = amount;
100
-                    amt.Balance = model.Balance;
101
-                    amt.Remark = remark;
102
-                    amt.CreateTime = DateTime.Now;
163
+                        var amt = new T_User_Amount();
164
+                        amt.Id = amtlist.Count > 0 ? amtlist.Max(p => p.Id) + 1 : 1;
165
+                        amt.UserCode = usercode;
166
+                        amt.Amount = amount;
167
+                        amt.Balance = model.Balance;
168
+                        amt.Remark = remark;
169
+                        amt.CreateTime = DateTime.Now;
103 170
 
104
-                    amtlist.Add(amt);
105
-                    await _cache.SetStringAsync("T_User_Amount", amtlist.ToJson());
171
+                        amtlist.Add(amt);
172
+                        await _cache.SetStringAsync("T_User_Amount", amtlist.ToJson());
106 173
 
107
-                    return Success("成功", model.Balance);
174
+                        return Success("成功", model.Balance);
175
+                    }
176
+                    else
177
+                    {
178
+                        return Error("签名错误");
179
+                    }
108 180
                 }
109 181
                 else
110 182
                 {
111
-                    return Error("签名错误");
183
+                    return Error("账号或者密码错误");
112 184
                 }
113 185
             }
114 186
             else
115 187
             {
116
-                return Error("账号或者密码错误");
188
+                string strwhere = " F_See='" + usercode + "' and F_Remark='" + password + "'";
189
+                DataSet ds = bll.GetList(strwhere);
190
+                if (ds != null)
191
+                {
192
+                    DataTable dt = ds.Tables[0];
193
+                    if (dt.Rows.Count > 0)
194
+                    {
195
+                        string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + dt.Rows[0]["F_Remark"].ToString() + "+" + DateTime.Now.ToString("yyyyMMdd"));
196
+                        if (outsigncode.ToUpper() == signcode.ToUpper())
197
+                        {
198
+                            var m = bll.GetModel(int.Parse (dt.Rows[0]["F_UserId"].ToString ()));
199
+                            m.F_DeptCode = (Decimal.Parse (m.F_DeptCode) + amount).ToString ();
200
+                            bll.Update(m);
201
+                            return Success("成功", dt.Rows[0]["F_DeptCode"].ToString());
202
+                        }
203
+                        else
204
+                        {
205
+                            return Error("签名错误");
206
+                        }
207
+                    }
208
+                }
209
+                return Error("获取失败");
117 210
             }
118 211
         }
119 212
 
@@ -125,52 +218,113 @@ namespace SmsPlatform.Controllers
125 218
         [ApiExplorerSettings(IgnoreApi = true)]
126 219
         public async Task<IActionResult> DeductAmount(string usercode, string password, string phonenumber, string signcode)
127 220
         {
128
-            var userliststr = await _cache.GetStringAsync("T_User_Account");
129
-            var userlist = new List<T_User_Account>();
130
-            if (!string.IsNullOrEmpty(userliststr))
221
+            if (RedisHelper.IsCon() && _cache != null)
131 222
             {
132
-                userlist = userliststr.ToList<T_User_Account>();
133
-            }
223
+                
224
+                var userliststr = await _cache.GetStringAsync("T_User_Account");
225
+                var userlist = new List<T_User_Account>();
226
+                if (!string.IsNullOrEmpty(userliststr))
227
+                {
228
+                    userlist = userliststr.ToList<T_User_Account>();
229
+                }
230
+                else
231
+                {
232
+                    //将sql中的数据保存到redis中
233
+                    string strwhere = " F_See='" + usercode + "' and F_Remark='" + password + "'";
234
+                    DataSet ds = bll.GetList(strwhere);
235
+                    if (ds != null)
236
+                    {
237
+                        DataTable dt = ds.Tables[0];
238
+                        if (dt.Rows.Count > 0)
239
+                        {
240
+                            var models = new T_User_Account();
241
+                            models.Id = int.Parse(dt.Rows[0]["F_UserId"].ToString());
242
+                            models.UserCode = dt.Rows[0]["F_See"].ToString();
243
+                            models.Password = dt.Rows[0]["F_Remark"].ToString();
244
+                            models.UserName = "";
245
+                            models.Sign = dt.Rows[0]["F_Remark"].ToString();
246
+                            models.Balance = Decimal.Parse(dt.Rows[0]["F_DeptCode"].ToString());
247
+                            models.CreateTime = DateTime.Now;
248
+                            userlist.Add(models);
249
+                            await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
250
+                            
251
+                        }
252
+                    }
253
+                }
134 254
 
135
-            var model = userlist.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
136
-            if (model != null)
137
-            {
138
-                var amount = decimal.Parse(_configuration["amount"]);
139
-                string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
140
-                if (outsigncode.ToUpper() == signcode.ToUpper())
255
+                var model = userlist.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
256
+                if (model != null)
141 257
                 {
142
-                    model.Balance = model.Balance - amount;
143
-                    await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
258
+                    var amount = decimal.Parse(_configuration["amount"]);
259
+                    string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
260
+                    if (outsigncode.ToUpper() == signcode.ToUpper())
261
+                    {
262
+                        model.Balance = model.Balance - amount;
263
+                        await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
144 264
 
265
+                        #region 更新sql数据库余额
266
+                        BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
267
+                        Model.T_Sys_UserAccount mt = bll.GetModel(model.Id);
268
+                        mt.F_DeptCode = model.Balance.ToString();
269
+                        bll.Update(mt);
270
+                        #endregion
145 271
 
146
-                    var amtliststr = await _cache.GetStringAsync("T_User_Amount");
147
-                    var amtlist = new List<T_User_Amount>();
148
-                    if (!string.IsNullOrEmpty(amtliststr))
149
-                    {
150
-                        amtlist = amtliststr.ToList<T_User_Amount>();
151
-                    }
272
+                        var amtliststr = await _cache.GetStringAsync("T_User_Amount");
273
+                        var amtlist = new List<T_User_Amount>();
274
+                        if (!string.IsNullOrEmpty(amtliststr))
275
+                        {
276
+                            amtlist = amtliststr.ToList<T_User_Amount>();
277
+                        }
152 278
 
153
-                    var amt = new T_User_Amount();
154
-                    amt.Id = amtlist.Count > 0 ? amtlist.Max(p => p.Id) + 1 : 1;
155
-                    amt.UserCode = usercode;
156
-                    amt.Amount = amount;
157
-                    amt.Balance = model.Balance;
158
-                    amt.Remark = phonenumber + "发送短信";
159
-                    amt.CreateTime = DateTime.Now;
279
+                        var amt = new T_User_Amount();
280
+                        amt.Id = amtlist.Count > 0 ? amtlist.Max(p => p.Id) + 1 : 1;
281
+                        amt.UserCode = usercode;
282
+                        amt.Amount = amount;
283
+                        amt.Balance = model.Balance;
284
+                        amt.Remark = phonenumber + "发送短信";
285
+                        amt.CreateTime = DateTime.Now;
160 286
 
161
-                    amtlist.Add(amt);
162
-                    await _cache.SetStringAsync("T_User_Amount", amtlist.ToJson());
287
+                        amtlist.Add(amt);
288
+                        await _cache.SetStringAsync("T_User_Amount", amtlist.ToJson());
163 289
 
164
-                    return Success("成功", model.Balance);
290
+                        return Success("成功", model.Balance);
291
+                    }
292
+                    else
293
+                    {
294
+                        return Error("签名错误");
295
+                    }
165 296
                 }
166 297
                 else
167 298
                 {
168
-                    return Error("签名错误");
299
+                    return Error("账号或者密码错误");
169 300
                 }
170 301
             }
171 302
             else
172 303
             {
173
-                return Error("账号或者密码错误");
304
+                string strwhere = " F_See='" + usercode + "' and F_Remark='" + password + "'";
305
+                DataSet ds = bll.GetList(strwhere);
306
+                if (ds != null)
307
+                {
308
+                    DataTable dt = ds.Tables[0];
309
+                    if (dt.Rows.Count > 0)
310
+                    {
311
+
312
+                        string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + dt.Rows[0]["F_Remark"].ToString() + "+" + DateTime.Now.ToString("yyyyMMdd"));
313
+                        if (outsigncode.ToUpper() == signcode.ToUpper())
314
+                        {
315
+                            var amount = decimal.Parse(_configuration["amount"]);
316
+                            var m = bll.GetModel(int.Parse(dt.Rows[0]["F_UserId"].ToString()));
317
+                            m.F_DeptCode = (Decimal.Parse(m.F_DeptCode) - amount).ToString();
318
+                            bll.Update(m);
319
+                            return Success("成功", dt.Rows[0]["F_DeptCode"].ToString());
320
+                        }
321
+                        else
322
+                        {
323
+                            return Error("签名错误");
324
+                        }
325
+                    }
326
+                }
327
+                return Error("获取失败");
174 328
             }
175 329
         }
176 330
 
@@ -184,97 +338,174 @@ namespace SmsPlatform.Controllers
184 338
             string signname, string templatecode, string phonenumber, string paramname, string param)
185 339
         {
186 340
             //_logger.LogError(signname + "|||" + templatecode + "|||" + phonenumber + "|||" + paramname + "|||" + param );
187
-
188
-            var userliststr = await _cache.GetStringAsync("T_User_Account");
189
-            var userlist = new List<T_User_Account>();
190
-            if (!string.IsNullOrEmpty(userliststr))
341
+            if (RedisHelper.IsCon() && _cache != null)
191 342
             {
192
-                userlist = userliststr.ToList<T_User_Account>();
193
-            }
194
-
195
-            var model = userlist.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
196
-            if (model != null)
197
-            {
198
-                var amount = decimal.Parse(_configuration["amount"]);
199
-                string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
200
-                if (outsigncode.ToUpper() == signcode.ToUpper())
343
+                var userliststr = await _cache.GetStringAsync("T_User_Account");
344
+                var userlist = new List<T_User_Account>();
345
+                if (!string.IsNullOrEmpty(userliststr))
346
+                {
347
+                    userlist = userliststr.ToList<T_User_Account>();
348
+                }
349
+                else
201 350
                 {
202
-                    var tcount = content.Length + signname.Length + 2;
203
-                    if (tcount > 70)
351
+                    //将sql中的数据保存到redis中
352
+                    string strwhere = " F_See='" + usercode + "' and F_Remark='" + password + "'";
353
+                    DataSet ds = bll.GetList(strwhere);
354
+                    if (ds != null)
204 355
                     {
205
-                        amount = (tcount / 67 + 1) * amount;
206
-                    }
356
+                        DataTable dt = ds.Tables[0];
357
+                        if (dt.Rows.Count > 0)
358
+                        {
359
+                            var models = new T_User_Account();
360
+                            models.Id = int.Parse(dt.Rows[0]["F_UserId"].ToString());
361
+                            models.UserCode = dt.Rows[0]["F_See"].ToString();
362
+                            models.Password = dt.Rows[0]["F_Remark"].ToString();
363
+                            models.UserName = "";
364
+                            models.Sign = dt.Rows[0]["F_Remark"].ToString();
365
+                            models.Balance = Decimal.Parse(dt.Rows[0]["F_DeptCode"].ToString());
366
+                            models.CreateTime = DateTime.Now;
367
+                            userlist.Add(models);
368
+                            await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
207 369
 
208
-                    SmsHelper sh = new SmsHelper(_configuration);
370
+                        }
371
+                    }
372
+                }
209 373
 
210
-                    string date = DateTime.Now.ToString("yyyyMMdd");
211
-                    var result = sh.SendSms(signname, templatecode, phonenumber, paramname, param);
212
-                    if (result.Code == "OK")
374
+                var model = userlist.Where(p => p.UserCode == usercode && p.Password == password).SingleOrDefault();
375
+                if (model != null)
376
+                {
377
+                    var amount = decimal.Parse(_configuration["amount"]);
378
+                    string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + model.Sign + "+" + DateTime.Now.ToString("yyyyMMdd"));
379
+                    if (outsigncode.ToUpper() == signcode.ToUpper())
213 380
                     {
214
-                        //var sd = sh.Query(result.BizId, phonenumber, date);
215
-                        //if (sd.SendStatus == 2)
216
-                        //{
217
-                        //    var send = GetSend(result.BizId);
218
-
219
-                        //    _logger.LogError(phonenumber + " 发送短信失败,原因:" + send.ErrMsg);
220
-                        //    return Error(send.ErrMsg);
221
-                        //}
222
-                        model.Balance = model.Balance - amount;
223
-                        await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
381
+                        var tcount = content.Length + signname.Length + 2;
382
+                        if (tcount > 70)
383
+                        {
384
+                            amount = (tcount / 67 + 1) * amount;
385
+                        }
224 386
 
225
-                        //var amtliststr = await _cache.GetStringAsync("T_User_Amount");
226
-                        //var amtlist = new List<T_User_Amount>();
227
-                        //if (!string.IsNullOrEmpty(amtliststr))
228
-                        //{
229
-                        //    amtlist = amtliststr.ToList<T_User_Amount>();
230
-                        //}
231
-
232
-                        //var amt = new T_User_Amount();
233
-                        //amt.Id = amtlist.Count > 0 ? amtlist.Max(p => p.Id) + 1 : 1;
234
-                        //amt.UserCode = usercode;
235
-                        //amt.Amount = amount;
236
-                        //amt.Balance = model.Balance;
237
-                        //amt.Remark = phonenumber + " 发送短信";
238
-                        //amt.CreateTime = DateTime.Now;
239
-
240
-                        //amtlist.Add(amt);
241
-                        //await _cache.SetStringAsync("T_User_Amount", amtlist.ToJson());
242
-
243
-                        //var sendliststr = await _cache.GetStringAsync("T_Sms_Send");
244
-                        //var sendlist = new List<T_Sms_Send>();
245
-                        //if (!string.IsNullOrEmpty(sendliststr))
246
-                        //{
247
-                        //    sendlist = sendliststr.ToList<T_Sms_Send>();
248
-                        //}
249
-                        //var send = new T_Sms_Send();
250
-                        //send.Id = sendlist.Count > 0 ? sendlist.Max(p => p.Id) + 1 : 1;
251
-                        //send.BizId = result.BizId;
252
-                        //send.PhoneNumber = phonenumber;
253
-                        //send.SendTime = DateTime.Now;
254
-                        //send.State = 1;
255
-                        //sendlist.Add(send);
256
-                        //await _cache.SetStringAsync("T_Sms_Send", sendlist.ToJson());
257
-
258
-                        _logger.LogError(phonenumber + ":" + signname + "|||" + templatecode + "|||" + paramname + "|||" + param);
387
+                        SmsHelper sh = new SmsHelper(_configuration);
259 388
 
260
-                        return Success("成功", model.Balance);
389
+                        string date = DateTime.Now.ToString("yyyyMMdd");
390
+                        var result = sh.SendSms(signname, templatecode, phonenumber, paramname, param);
391
+                        if (result.Code == "OK")
392
+                        {
393
+                            //var sd = sh.Query(result.BizId, phonenumber, date);
394
+                            //if (sd.SendStatus == 2)
395
+                            //{
396
+                            //    var send = GetSend(result.BizId);
397
+
398
+                            //    _logger.LogError(phonenumber + " 发送短信失败,原因:" + send.ErrMsg);
399
+                            //    return Error(send.ErrMsg);
400
+                            //}
401
+                            model.Balance = model.Balance - amount;
402
+                            await _cache.SetStringAsync("T_User_Account", userlist.ToJson());
403
+
404
+                            #region 更新sql数据库余额
405
+                            BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
406
+                            Model.T_Sys_UserAccount mt = bll.GetModel(model.Id);
407
+                            mt.F_DeptCode = model.Balance.ToString();
408
+                            bll.Update(mt);
409
+                            #endregion
410
+                            //var amtliststr = await _cache.GetStringAsync("T_User_Amount");
411
+                            //var amtlist = new List<T_User_Amount>();
412
+                            //if (!string.IsNullOrEmpty(amtliststr))
413
+                            //{
414
+                            //    amtlist = amtliststr.ToList<T_User_Amount>();
415
+                            //}
416
+
417
+                            //var amt = new T_User_Amount();
418
+                            //amt.Id = amtlist.Count > 0 ? amtlist.Max(p => p.Id) + 1 : 1;
419
+                            //amt.UserCode = usercode;
420
+                            //amt.Amount = amount;
421
+                            //amt.Balance = model.Balance;
422
+                            //amt.Remark = phonenumber + " 发送短信";
423
+                            //amt.CreateTime = DateTime.Now;
424
+
425
+                            //amtlist.Add(amt);
426
+                            //await _cache.SetStringAsync("T_User_Amount", amtlist.ToJson());
427
+
428
+                            //var sendliststr = await _cache.GetStringAsync("T_Sms_Send");
429
+                            //var sendlist = new List<T_Sms_Send>();
430
+                            //if (!string.IsNullOrEmpty(sendliststr))
431
+                            //{
432
+                            //    sendlist = sendliststr.ToList<T_Sms_Send>();
433
+                            //}
434
+                            //var send = new T_Sms_Send();
435
+                            //send.Id = sendlist.Count > 0 ? sendlist.Max(p => p.Id) + 1 : 1;
436
+                            //send.BizId = result.BizId;
437
+                            //send.PhoneNumber = phonenumber;
438
+                            //send.SendTime = DateTime.Now;
439
+                            //send.State = 1;
440
+                            //sendlist.Add(send);
441
+                            //await _cache.SetStringAsync("T_Sms_Send", sendlist.ToJson());
442
+
443
+                            _logger.LogError(phonenumber + ":" + signname + "|||" + templatecode + "|||" + paramname + "|||" + param);
444
+
445
+                            return Success("成功", model.Balance);
446
+                        }
447
+                        else
448
+                        {
449
+                            _logger.LogError(phonenumber + " 发送短信失败,原因:" + result.Message);
450
+                            return Error(result.Message);
451
+                        }
261 452
                     }
262 453
                     else
263 454
                     {
264
-                        _logger.LogError(phonenumber + " 发送短信失败,原因:" + result.Message);
265
-                        return Error(result.Message);
455
+                        return Error("签名错误");
266 456
                     }
267 457
                 }
268 458
                 else
269 459
                 {
270
-                    return Error("签名错误");
460
+                    return Error("账号或者密码错误");
271 461
                 }
272 462
             }
273 463
             else
274 464
             {
275
-                return Error("账号或者密码错误");
276
-            }
465
+                string strwhere = " F_See='" + usercode + "' and F_Remark='" + password + "'";
466
+                DataSet ds = bll.GetList(strwhere);
467
+                if (ds != null)
468
+                {
469
+                    DataTable dt = ds.Tables[0];
470
+                    if (dt.Rows.Count > 0)
471
+                    {
472
+                        var amount = decimal.Parse(_configuration["amount"]);
473
+                        string outsigncode = SecureHelper.GetMD5(usercode + "+" + password + "+" + dt.Rows[0]["F_Remark"].ToString() + "+" + DateTime.Now.ToString("yyyyMMdd"));
474
+                        if (outsigncode.ToUpper() == signcode.ToUpper())
475
+                        {
476
+                            var tcount = content.Length + signname.Length + 2;
477
+                            if (tcount > 70)
478
+                            {
479
+                                amount = (tcount / 67 + 1) * amount;
480
+                            }
481
+
482
+                            SmsHelper sh = new SmsHelper(_configuration);
277 483
 
484
+                            string date = DateTime.Now.ToString("yyyyMMdd");
485
+                            var result = sh.SendSms(signname, templatecode, phonenumber, paramname, param);
486
+                            if (result.Code == "OK")
487
+                            {
488
+                                
489
+                                var m = bll.GetModel(int.Parse(dt.Rows[0]["F_UserId"].ToString()));
490
+                                m.F_DeptCode = (Decimal.Parse(m.F_DeptCode) - amount).ToString();
491
+                                bll.Update(m);
492
+                                _logger.LogError(phonenumber + ":" + signname + "|||" + templatecode + "|||" + paramname + "|||" + param);
493
+                                return Success("成功", dt.Rows[0]["F_DeptCode"].ToString());
494
+                            }
495
+                            else
496
+                            {
497
+                                _logger.LogError(phonenumber + " 发送短信失败,原因:" + result.Message);
498
+                                return Error(result.Message);
499
+                            }
500
+                        }
501
+                        else
502
+                        {
503
+                            return Error("签名错误");
504
+                        }
505
+                    }
506
+                }
507
+                return Error("获取失败");
508
+            }
278 509
         }
279 510
 
280 511
         /// <summary>

+ 89 - 22
SmsPlatform/Controllers/UserAccountController.cs

@@ -1,5 +1,6 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
+using System.Data;
3 4
 using System.Linq;
4 5
 using System.Threading.Tasks;
5 6
 using Microsoft.AspNetCore.Mvc;
@@ -19,6 +20,8 @@ namespace SmsPlatform.Controllers
19 20
     {
20 21
         private readonly ILogger<UserAccountController> _logger;
21 22
         private readonly IDistributedCache _cache;
23
+        BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
24
+
22 25
         public UserAccountController(IDistributedCache cache, ILogger<UserAccountController> logger)
23 26
         {
24 27
             _cache = cache;
@@ -32,13 +35,23 @@ namespace SmsPlatform.Controllers
32 35
         [HttpGet("getlist")]
33 36
         public async Task<IActionResult> GetList()
34 37
         {
35
-            var liststr = await _cache.GetStringAsync("T_User_Account");
36
-            var list = new List<T_User_Account>();
37
-            if (!string.IsNullOrEmpty(liststr))
38
+            if (_cache != null)
38 39
             {
39
-                list = liststr.ToList<T_User_Account>();
40
+                var liststr = await _cache.GetStringAsync("T_User_Account");
41
+                var list = new List<T_User_Account>();
42
+                if (!string.IsNullOrEmpty(liststr))
43
+                {
44
+                    list = liststr.ToList<T_User_Account>();
45
+                }
46
+                return Success("成功", list);
47
+            }
48
+            DataSet ds = bll.GetAllList();
49
+            if (ds != null)
50
+            {
51
+                return Success("成功", ds);
40 52
             }
41
-            return Success("成功", list);
53
+            else
54
+            { return Error("失败"); }
42 55
         }
43 56
 
44 57
         /// <summary>
@@ -49,24 +62,39 @@ namespace SmsPlatform.Controllers
49 62
         [HttpGet("getsingle")]
50 63
         public async Task<IActionResult> GetDetailsAsync(int id)
51 64
         {
52
-            var liststr = await _cache.GetStringAsync("T_User_Account");
53
-            var list = new List<T_User_Account>();
54
-            if (!string.IsNullOrEmpty(liststr))
65
+            if (_cache != null)
55 66
             {
56
-                list = liststr.ToList<T_User_Account>();
57
-            }
67
+                var liststr = await _cache.GetStringAsync("T_User_Account");
68
+                var list = new List<T_User_Account>();
69
+                if (!string.IsNullOrEmpty(liststr))
70
+                {
71
+                    list = liststr.ToList<T_User_Account>();
72
+                }
58 73
 
59
-            var amtliststr = await _cache.GetStringAsync("T_User_Amount");
60
-            var amtlist = new List<T_User_Amount>();
61
-            if (!string.IsNullOrEmpty(amtliststr))
74
+                var amtliststr = await _cache.GetStringAsync("T_User_Amount");
75
+                var amtlist = new List<T_User_Amount>();
76
+                if (!string.IsNullOrEmpty(amtliststr))
77
+                {
78
+                    amtlist = amtliststr.ToList<T_User_Amount>();
79
+                }
80
+
81
+                var model = list.Where(p => p.Id == id).SingleOrDefault();
82
+                var amountlist = amtlist.Where(p => p.UserCode == model.UserCode).ToList();
83
+                var obj = new { model, amountlist };
84
+                return Success("成功", obj);
85
+            }
86
+            //redis获取失败时从数据库读取
87
+            //BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
88
+            var m = bll.GetModel(id);
89
+            if (m != null)
62 90
             {
63
-                amtlist = amtliststr.ToList<T_User_Amount>();
91
+                await _cache.SetStringAsync("T_User_Account", m.ToJson());
92
+                return Success("成功", m);
93
+            }
94
+            else
95
+            {
96
+                return Error("获取用户详情失败");
64 97
             }
65
-
66
-            var model = list.Where(p => p.Id == id).SingleOrDefault();
67
-            var amountlist = amtlist.Where(p => p.UserCode == model.UserCode).ToList();
68
-            var obj = new { model , amountlist };
69
-            return Success("成功", obj);
70 98
         }
71 99
 
72 100
         /// <summary>
@@ -93,9 +121,33 @@ namespace SmsPlatform.Controllers
93 121
             {
94 122
                 list = liststr.ToList<T_User_Account>();
95 123
             }
96
-
124
+            var m = bll.GetModel(input.Id);
125
+            if (m != null)
126
+            {
127
+                T_Sys_UserAccount modelt = new T_Sys_UserAccount();
128
+                //modelt.F_UserId = input.Id;
129
+                modelt.F_UserCode = input.UserCode;
130
+                modelt.F_Password = input.Password;
131
+                modelt.F_UserName = input.UserName;
132
+                modelt.F_Remark = input.Sign;
133
+                modelt.F_DeptCode = input.Balance.ToString();//余额
134
+                modelt.F_CreateOn = DateTime.Now;
135
+                bll.Update(modelt);
136
+            }
137
+            else
138
+            {
139
+                T_Sys_UserAccount modelt = new T_Sys_UserAccount();
140
+                modelt.F_UserId = input.Id;
141
+                modelt.F_UserCode = input.UserCode;
142
+                modelt.F_Password = input.Password;
143
+                modelt.F_UserName = input.UserName;
144
+                modelt.F_Remark = input.Sign;
145
+                modelt.F_DeptCode = input.Balance.ToString();//余额
146
+                modelt.F_CreateOn = DateTime.Now;
147
+                bll.Add(modelt);
148
+            }
97 149
             var model = new T_User_Account();
98
-            if (input.Id != 0)
150
+            if (input.Id != 0&&_cache !=null )
99 151
             {
100 152
                 model = list.Where(p => p.Id == input.Id).SingleOrDefault();
101 153
                 if (model != null)
@@ -106,8 +158,22 @@ namespace SmsPlatform.Controllers
106 158
                     model.Sign = input.Sign;
107 159
                     model.Balance = input.Balance;
108 160
                     await _cache.SetStringAsync("T_User_Account", list.ToJson());
161
+                    
109 162
                     return Success("修改成功", model);
110 163
                 }
164
+                else
165
+                {
166
+                    model.Id = list.Count > 0 ? list.Max(p => p.Id) + 1 : 1;
167
+                    model.UserCode = input.UserCode;
168
+                    model.Password = input.Password;
169
+                    model.UserName = input.UserName;
170
+                    model.Sign = input.Sign;
171
+                    model.Balance = input.Balance;
172
+                    model.CreateTime = DateTime.Now;
173
+                    list.Add(model);
174
+                    await _cache.SetStringAsync("T_User_Account", list.ToJson());
175
+                    return Success("新增成功", model);
176
+                }
111 177
             }
112 178
             else
113 179
             {
@@ -122,7 +188,7 @@ namespace SmsPlatform.Controllers
122 188
                 await _cache.SetStringAsync("T_User_Account", list.ToJson());
123 189
                 return Success("新增成功", model);
124 190
             }
125
-
191
+            
126 192
             return Error("保存失败");
127 193
         }
128 194
 
@@ -144,6 +210,7 @@ namespace SmsPlatform.Controllers
144 210
             var model = list.Where(p => p.Id == id).SingleOrDefault();
145 211
             list.Remove(model);
146 212
             await _cache.SetStringAsync("T_User_Account", list.ToJson());
213
+            bll.Delete(id);
147 214
             return Success("删除成功");
148 215
         }
149 216
     }

+ 605 - 0
SmsPlatform/DAL/T_Sys_UserAccount.cs

@@ -0,0 +1,605 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Data;
4
+using System.Linq;
5
+using System.Threading.Tasks;
6
+
7
+using System.Text;
8
+using System.Data.SqlClient;
9
+using SmsPlatform.Common;
10
+
11
+namespace SmsPlatform.DAL
12
+{
13
+    /// <summary>
14
+	/// 数据访问类:T_Sys_UserAccount
15
+	/// </summary>
16
+	public partial class T_Sys_UserAccount
17
+    {
18
+        public T_Sys_UserAccount()
19
+        { }
20
+        #region  BasicMethod
21
+
22
+        /// <summary>
23
+        /// 得到最大ID
24
+        /// </summary>
25
+        public int GetMaxId()
26
+        {
27
+            return DbHelperSQL.GetMaxID("F_UserId", "T_Sys_UserAccount");
28
+        }
29
+
30
+        /// <summary>
31
+        /// 是否存在该记录
32
+        /// </summary>
33
+        public bool Exists(int F_UserId)
34
+        {
35
+            StringBuilder strSql = new StringBuilder();
36
+            strSql.Append("select count(1) from T_Sys_UserAccount");
37
+            strSql.Append(" where F_UserId=@F_UserId");
38
+            SqlParameter[] parameters = {
39
+                    new SqlParameter("@F_UserId", SqlDbType.Int,4)
40
+            };
41
+            parameters[0].Value = F_UserId;
42
+
43
+            return DbHelperSQL.Exists(strSql.ToString(), parameters);
44
+        }
45
+
46
+
47
+        /// <summary>
48
+        /// 增加一条数据
49
+        /// </summary>
50
+        public int Add(Model.T_Sys_UserAccount model)
51
+        {
52
+            StringBuilder strSql = new StringBuilder();
53
+            strSql.Append("insert into T_Sys_UserAccount(");
54
+            strSql.Append("F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode)");
55
+            strSql.Append(" values (");
56
+            strSql.Append("@F_UserCode,@F_Password,@F_ExtensionNumber,@F_UserName,@F_DeptId,@F_RoleId,@F_GroupId,@F_SeatFlag,@F_SeatRight,@F_SeatLevel,@F_SexFlag,@F_RemindFlag,@F_Remark,@F_Telephone,@F_Mobile,@F_HomePhone,@F_Birthday,@F_CreateOn,@F_CancelOn,@F_DeleteFlag,@F_APPOnFlag,@F_LastActiveTime,@F_See,@F_HJType,@F_PId,@F_TmId,@F_WorkNumber,@F_DeptCode)");
57
+            strSql.Append(";select @@IDENTITY");
58
+            SqlParameter[] parameters = {
59
+                    new SqlParameter("@F_UserCode", SqlDbType.VarChar,50),
60
+                    new SqlParameter("@F_Password", SqlDbType.VarChar,50),
61
+                    new SqlParameter("@F_ExtensionNumber", SqlDbType.VarChar,50),
62
+                    new SqlParameter("@F_UserName", SqlDbType.VarChar,50),
63
+                    new SqlParameter("@F_DeptId", SqlDbType.Int,4),
64
+                    new SqlParameter("@F_RoleId", SqlDbType.Int,4),
65
+                    new SqlParameter("@F_GroupId", SqlDbType.Int,4),
66
+                    new SqlParameter("@F_SeatFlag", SqlDbType.Bit,1),
67
+                    new SqlParameter("@F_SeatRight", SqlDbType.VarChar,50),
68
+                    new SqlParameter("@F_SeatLevel", SqlDbType.VarChar,50),
69
+                    new SqlParameter("@F_SexFlag", SqlDbType.VarChar,50),
70
+                    new SqlParameter("@F_RemindFlag", SqlDbType.Bit,1),
71
+                    new SqlParameter("@F_Remark", SqlDbType.VarChar,200),
72
+                    new SqlParameter("@F_Telephone", SqlDbType.VarChar,50),
73
+                    new SqlParameter("@F_Mobile", SqlDbType.VarChar,50),
74
+                    new SqlParameter("@F_HomePhone", SqlDbType.VarChar,50),
75
+                    new SqlParameter("@F_Birthday", SqlDbType.DateTime),
76
+                    new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
77
+                    new SqlParameter("@F_CancelOn", SqlDbType.DateTime),
78
+                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
79
+                    new SqlParameter("@F_APPOnFlag", SqlDbType.Bit,1),
80
+                    new SqlParameter("@F_LastActiveTime", SqlDbType.DateTime),
81
+                    new SqlParameter("@F_See", SqlDbType.VarChar,100),
82
+                    new SqlParameter("@F_HJType", SqlDbType.Int,4),
83
+                    new SqlParameter("@F_PId", SqlDbType.Int,4),
84
+                    new SqlParameter("@F_TmId", SqlDbType.Int,4),
85
+                    new SqlParameter("@F_WorkNumber", SqlDbType.VarChar,15),
86
+                    new SqlParameter("@F_DeptCode", SqlDbType.VarChar,50)};
87
+            parameters[0].Value = model.F_UserCode;
88
+            parameters[1].Value = model.F_Password;
89
+            parameters[2].Value = model.F_ExtensionNumber;
90
+            parameters[3].Value = model.F_UserName;
91
+            parameters[4].Value = model.F_DeptId;
92
+            parameters[5].Value = model.F_RoleId;
93
+            parameters[6].Value = model.F_GroupId;
94
+            parameters[7].Value = model.F_SeatFlag;
95
+            parameters[8].Value = model.F_SeatRight;
96
+            parameters[9].Value = model.F_SeatLevel;
97
+            parameters[10].Value = model.F_SexFlag;
98
+            parameters[11].Value = model.F_RemindFlag;
99
+            parameters[12].Value = model.F_Remark;
100
+            parameters[13].Value = model.F_Telephone;
101
+            parameters[14].Value = model.F_Mobile;
102
+            parameters[15].Value = model.F_HomePhone;
103
+            parameters[16].Value = model.F_Birthday;
104
+            parameters[17].Value = model.F_CreateOn;
105
+            parameters[18].Value = model.F_CancelOn;
106
+            parameters[19].Value = model.F_DeleteFlag;
107
+            parameters[20].Value = model.F_APPOnFlag;
108
+            parameters[21].Value = model.F_LastActiveTime;
109
+            parameters[22].Value = model.F_See;
110
+            parameters[23].Value = model.F_HJType;
111
+            parameters[24].Value = model.F_PId;
112
+            parameters[25].Value = model.F_TmId;
113
+            parameters[26].Value = model.F_WorkNumber;
114
+            parameters[27].Value = model.F_DeptCode;
115
+
116
+            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
117
+            if (obj == null)
118
+            {
119
+                return 0;
120
+            }
121
+            else
122
+            {
123
+                return Convert.ToInt32(obj);
124
+            }
125
+        }
126
+        /// <summary>
127
+        /// 更新一条数据
128
+        /// </summary>
129
+        public bool Update(Model.T_Sys_UserAccount model)
130
+        {
131
+            StringBuilder strSql = new StringBuilder();
132
+            strSql.Append("update T_Sys_UserAccount set ");
133
+            strSql.Append("F_UserCode=@F_UserCode,");
134
+            strSql.Append("F_Password=@F_Password,");
135
+            strSql.Append("F_ExtensionNumber=@F_ExtensionNumber,");
136
+            strSql.Append("F_UserName=@F_UserName,");
137
+            strSql.Append("F_DeptId=@F_DeptId,");
138
+            strSql.Append("F_RoleId=@F_RoleId,");
139
+            strSql.Append("F_GroupId=@F_GroupId,");
140
+            strSql.Append("F_SeatFlag=@F_SeatFlag,");
141
+            strSql.Append("F_SeatRight=@F_SeatRight,");
142
+            strSql.Append("F_SeatLevel=@F_SeatLevel,");
143
+            strSql.Append("F_SexFlag=@F_SexFlag,");
144
+            strSql.Append("F_RemindFlag=@F_RemindFlag,");
145
+            strSql.Append("F_Remark=@F_Remark,");
146
+            strSql.Append("F_Telephone=@F_Telephone,");
147
+            strSql.Append("F_Mobile=@F_Mobile,");
148
+            strSql.Append("F_HomePhone=@F_HomePhone,");
149
+            strSql.Append("F_Birthday=@F_Birthday,");
150
+            strSql.Append("F_CreateOn=@F_CreateOn,");
151
+            strSql.Append("F_CancelOn=@F_CancelOn,");
152
+            strSql.Append("F_DeleteFlag=@F_DeleteFlag,");
153
+            strSql.Append("F_APPOnFlag=@F_APPOnFlag,");
154
+            strSql.Append("F_LastActiveTime=@F_LastActiveTime,");
155
+            strSql.Append("F_See=@F_See,");
156
+            strSql.Append("F_HJType=@F_HJType,");
157
+            strSql.Append("F_PId=@F_PId,");
158
+            strSql.Append("F_TmId=@F_TmId,");
159
+            strSql.Append("F_WorkNumber=@F_WorkNumber,");
160
+            strSql.Append("F_DeptCode=@F_DeptCode");
161
+            strSql.Append(" where F_UserId=@F_UserId");
162
+            SqlParameter[] parameters = {
163
+                    new SqlParameter("@F_UserCode", SqlDbType.VarChar,50),
164
+                    new SqlParameter("@F_Password", SqlDbType.VarChar,50),
165
+                    new SqlParameter("@F_ExtensionNumber", SqlDbType.VarChar,50),
166
+                    new SqlParameter("@F_UserName", SqlDbType.VarChar,50),
167
+                    new SqlParameter("@F_DeptId", SqlDbType.Int,4),
168
+                    new SqlParameter("@F_RoleId", SqlDbType.Int,4),
169
+                    new SqlParameter("@F_GroupId", SqlDbType.Int,4),
170
+                    new SqlParameter("@F_SeatFlag", SqlDbType.Bit,1),
171
+                    new SqlParameter("@F_SeatRight", SqlDbType.VarChar,50),
172
+                    new SqlParameter("@F_SeatLevel", SqlDbType.VarChar,50),
173
+                    new SqlParameter("@F_SexFlag", SqlDbType.VarChar,50),
174
+                    new SqlParameter("@F_RemindFlag", SqlDbType.Bit,1),
175
+                    new SqlParameter("@F_Remark", SqlDbType.VarChar,200),
176
+                    new SqlParameter("@F_Telephone", SqlDbType.VarChar,50),
177
+                    new SqlParameter("@F_Mobile", SqlDbType.VarChar,50),
178
+                    new SqlParameter("@F_HomePhone", SqlDbType.VarChar,50),
179
+                    new SqlParameter("@F_Birthday", SqlDbType.DateTime),
180
+                    new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
181
+                    new SqlParameter("@F_CancelOn", SqlDbType.DateTime),
182
+                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
183
+                    new SqlParameter("@F_APPOnFlag", SqlDbType.Bit,1),
184
+                    new SqlParameter("@F_LastActiveTime", SqlDbType.DateTime),
185
+                    new SqlParameter("@F_See", SqlDbType.VarChar,100),
186
+                    new SqlParameter("@F_HJType", SqlDbType.Int,4),
187
+                    new SqlParameter("@F_PId", SqlDbType.Int,4),
188
+                    new SqlParameter("@F_TmId", SqlDbType.Int,4),
189
+                    new SqlParameter("@F_WorkNumber", SqlDbType.VarChar,15),
190
+                    new SqlParameter("@F_DeptCode", SqlDbType.VarChar,50),
191
+                    new SqlParameter("@F_UserId", SqlDbType.Int,4)};
192
+            parameters[0].Value = model.F_UserCode;
193
+            parameters[1].Value = model.F_Password;
194
+            parameters[2].Value = model.F_ExtensionNumber;
195
+            parameters[3].Value = model.F_UserName;
196
+            parameters[4].Value = model.F_DeptId;
197
+            parameters[5].Value = model.F_RoleId;
198
+            parameters[6].Value = model.F_GroupId;
199
+            parameters[7].Value = model.F_SeatFlag;
200
+            parameters[8].Value = model.F_SeatRight;
201
+            parameters[9].Value = model.F_SeatLevel;
202
+            parameters[10].Value = model.F_SexFlag;
203
+            parameters[11].Value = model.F_RemindFlag;
204
+            parameters[12].Value = model.F_Remark;
205
+            parameters[13].Value = model.F_Telephone;
206
+            parameters[14].Value = model.F_Mobile;
207
+            parameters[15].Value = model.F_HomePhone;
208
+            parameters[16].Value = model.F_Birthday;
209
+            parameters[17].Value = model.F_CreateOn;
210
+            parameters[18].Value = model.F_CancelOn;
211
+            parameters[19].Value = model.F_DeleteFlag;
212
+            parameters[20].Value = model.F_APPOnFlag;
213
+            parameters[21].Value = model.F_LastActiveTime;
214
+            parameters[22].Value = model.F_See;
215
+            parameters[23].Value = model.F_HJType;
216
+            parameters[24].Value = model.F_PId;
217
+            parameters[25].Value = model.F_TmId;
218
+            parameters[26].Value = model.F_WorkNumber;
219
+            parameters[27].Value = model.F_DeptCode;
220
+            parameters[28].Value = model.F_UserId;
221
+
222
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
223
+            if (rows > 0)
224
+            {
225
+                return true;
226
+            }
227
+            else
228
+            {
229
+                return false;
230
+            }
231
+        }
232
+
233
+        /// <summary>
234
+        /// 删除一条数据
235
+        /// </summary>
236
+        public bool Delete(int F_UserId)
237
+        {
238
+
239
+            StringBuilder strSql = new StringBuilder();
240
+            strSql.Append("delete from T_Sys_UserAccount ");
241
+            strSql.Append(" where F_UserId=@F_UserId");
242
+            SqlParameter[] parameters = {
243
+                    new SqlParameter("@F_UserId", SqlDbType.Int,4)
244
+            };
245
+            parameters[0].Value = F_UserId;
246
+
247
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
248
+            if (rows > 0)
249
+            {
250
+                return true;
251
+            }
252
+            else
253
+            {
254
+                return false;
255
+            }
256
+        }
257
+        /// <summary>
258
+        /// 批量删除数据
259
+        /// </summary>
260
+        public bool DeleteList(string F_UserIdlist)
261
+        {
262
+            StringBuilder strSql = new StringBuilder();
263
+            strSql.Append("delete from T_Sys_UserAccount ");
264
+            strSql.Append(" where F_UserId in (" + F_UserIdlist + ")  ");
265
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
266
+            if (rows > 0)
267
+            {
268
+                return true;
269
+            }
270
+            else
271
+            {
272
+                return false;
273
+            }
274
+        }
275
+
276
+
277
+        /// <summary>
278
+        /// 得到一个对象实体
279
+        /// </summary>
280
+        public Model.T_Sys_UserAccount GetModel(int F_UserId)
281
+        {
282
+
283
+            StringBuilder strSql = new StringBuilder();
284
+            strSql.Append("select  top 1 F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode from T_Sys_UserAccount ");
285
+            strSql.Append(" where F_UserId=@F_UserId");
286
+            SqlParameter[] parameters = {
287
+                    new SqlParameter("@F_UserId", SqlDbType.Int,4)
288
+            };
289
+            parameters[0].Value = F_UserId;
290
+
291
+            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
292
+            
293
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
294
+            if (ds.Tables[0].Rows.Count > 0)
295
+            {
296
+                return DataRowToModel(ds.Tables[0].Rows[0]);
297
+            }
298
+            else
299
+            {
300
+                return null;
301
+            }
302
+        }
303
+
304
+
305
+        /// <summary>
306
+        /// 得到一个对象实体
307
+        /// </summary>
308
+        public Model.T_Sys_UserAccount DataRowToModel(DataRow row)
309
+        {
310
+            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
311
+            if (row != null)
312
+            {
313
+                if (row["F_UserId"] != null && row["F_UserId"].ToString() != "")
314
+                {
315
+                    model.F_UserId = int.Parse(row["F_UserId"].ToString());
316
+                }
317
+                if (row["F_UserCode"] != null)
318
+                {
319
+                    model.F_UserCode = row["F_UserCode"].ToString();
320
+                }
321
+                if (row["F_Password"] != null)
322
+                {
323
+                    model.F_Password = row["F_Password"].ToString();
324
+                }
325
+                if (row["F_ExtensionNumber"] != null)
326
+                {
327
+                    model.F_ExtensionNumber = row["F_ExtensionNumber"].ToString();
328
+                }
329
+                if (row["F_UserName"] != null)
330
+                {
331
+                    model.F_UserName = row["F_UserName"].ToString();
332
+                }
333
+                if (row["F_DeptId"] != null && row["F_DeptId"].ToString() != "")
334
+                {
335
+                    model.F_DeptId = int.Parse(row["F_DeptId"].ToString());
336
+                }
337
+                if (row["F_RoleId"] != null && row["F_RoleId"].ToString() != "")
338
+                {
339
+                    model.F_RoleId = int.Parse(row["F_RoleId"].ToString());
340
+                }
341
+                if (row["F_GroupId"] != null && row["F_GroupId"].ToString() != "")
342
+                {
343
+                    model.F_GroupId = int.Parse(row["F_GroupId"].ToString());
344
+                }
345
+                if (row["F_SeatFlag"] != null && row["F_SeatFlag"].ToString() != "")
346
+                {
347
+                    if ((row["F_SeatFlag"].ToString() == "1") || (row["F_SeatFlag"].ToString().ToLower() == "true"))
348
+                    {
349
+                        model.F_SeatFlag = true;
350
+                    }
351
+                    else
352
+                    {
353
+                        model.F_SeatFlag = false;
354
+                    }
355
+                }
356
+                if (row["F_SeatRight"] != null)
357
+                {
358
+                    model.F_SeatRight = row["F_SeatRight"].ToString();
359
+                }
360
+                if (row["F_SeatLevel"] != null)
361
+                {
362
+                    model.F_SeatLevel = row["F_SeatLevel"].ToString();
363
+                }
364
+                if (row["F_SexFlag"] != null)
365
+                {
366
+                    model.F_SexFlag = row["F_SexFlag"].ToString();
367
+                }
368
+                if (row["F_RemindFlag"] != null && row["F_RemindFlag"].ToString() != "")
369
+                {
370
+                    if ((row["F_RemindFlag"].ToString() == "1") || (row["F_RemindFlag"].ToString().ToLower() == "true"))
371
+                    {
372
+                        model.F_RemindFlag = true;
373
+                    }
374
+                    else
375
+                    {
376
+                        model.F_RemindFlag = false;
377
+                    }
378
+                }
379
+                if (row["F_Remark"] != null)
380
+                {
381
+                    model.F_Remark = row["F_Remark"].ToString();
382
+                }
383
+                if (row["F_Telephone"] != null)
384
+                {
385
+                    model.F_Telephone = row["F_Telephone"].ToString();
386
+                }
387
+                if (row["F_Mobile"] != null)
388
+                {
389
+                    model.F_Mobile = row["F_Mobile"].ToString();
390
+                }
391
+                if (row["F_HomePhone"] != null)
392
+                {
393
+                    model.F_HomePhone = row["F_HomePhone"].ToString();
394
+                }
395
+                if (row["F_Birthday"] != null && row["F_Birthday"].ToString() != "")
396
+                {
397
+                    model.F_Birthday = DateTime.Parse(row["F_Birthday"].ToString());
398
+                }
399
+                if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "")
400
+                {
401
+                    model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString());
402
+                }
403
+                if (row["F_CancelOn"] != null && row["F_CancelOn"].ToString() != "")
404
+                {
405
+                    model.F_CancelOn = DateTime.Parse(row["F_CancelOn"].ToString());
406
+                }
407
+                if (row["F_DeleteFlag"] != null && row["F_DeleteFlag"].ToString() != "")
408
+                {
409
+                    model.F_DeleteFlag = int.Parse(row["F_DeleteFlag"].ToString());
410
+                }
411
+                if (row["F_APPOnFlag"] != null && row["F_APPOnFlag"].ToString() != "")
412
+                {
413
+                    if ((row["F_APPOnFlag"].ToString() == "1") || (row["F_APPOnFlag"].ToString().ToLower() == "true"))
414
+                    {
415
+                        model.F_APPOnFlag = true;
416
+                    }
417
+                    else
418
+                    {
419
+                        model.F_APPOnFlag = false;
420
+                    }
421
+                }
422
+                if (row["F_LastActiveTime"] != null && row["F_LastActiveTime"].ToString() != "")
423
+                {
424
+                    model.F_LastActiveTime = DateTime.Parse(row["F_LastActiveTime"].ToString());
425
+                }
426
+                if (row["F_See"] != null)
427
+                {
428
+                    model.F_See = row["F_See"].ToString();
429
+                }
430
+                if (row["F_HJType"] != null && row["F_HJType"].ToString() != "")
431
+                {
432
+                    model.F_HJType = int.Parse(row["F_HJType"].ToString());
433
+                }
434
+                if (row["F_PId"] != null && row["F_PId"].ToString() != "")
435
+                {
436
+                    model.F_PId = int.Parse(row["F_PId"].ToString());
437
+                }
438
+                if (row["F_TmId"] != null && row["F_TmId"].ToString() != "")
439
+                {
440
+                    model.F_TmId = int.Parse(row["F_TmId"].ToString());
441
+                }
442
+                if (row["F_WorkNumber"] != null)
443
+                {
444
+                    model.F_WorkNumber = row["F_WorkNumber"].ToString();
445
+                }
446
+                if (row["F_DeptCode"] != null)
447
+                {
448
+                    model.F_DeptCode = row["F_DeptCode"].ToString();
449
+                }
450
+            }
451
+            return model;
452
+        }
453
+
454
+        public Model.T_Sys_UserAccount DataRowToModel1(DataRow row)
455
+        {
456
+            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
457
+            if (row != null)
458
+            {
459
+                if (row["F_UserId"] != null && row["F_UserId"].ToString() != "")
460
+                {
461
+                    model.F_UserId = int.Parse(row["F_UserId"].ToString());
462
+                }
463
+                if (row["F_UserCode"] != null)
464
+                {
465
+                    model.F_UserCode = row["F_UserCode"].ToString();
466
+                }
467
+                if (row["F_UserName"] != null)
468
+                {
469
+                    model.F_UserName = row["F_UserName"].ToString();
470
+                }
471
+                if (row["F_GroupId"] != null && row["F_GroupId"].ToString() != "")
472
+                {
473
+                    model.F_GroupId = int.Parse(row["F_GroupId"].ToString());
474
+                }
475
+
476
+            }
477
+            return model;
478
+        }
479
+
480
+        /// <summary>
481
+        /// 获得数据列表
482
+        /// </summary>
483
+        public DataSet GetList(string strWhere)
484
+        {
485
+            StringBuilder strSql = new StringBuilder();
486
+            strSql.Append("select F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode ");
487
+            strSql.Append(" FROM T_Sys_UserAccount ");
488
+            if (strWhere.Trim() != "")
489
+            {
490
+                strSql.Append(" where " + strWhere);
491
+            }
492
+            return DbHelperSQL.Query(strSql.ToString());
493
+        }
494
+
495
+        public DataSet GetListView(string strWhere)
496
+        {
497
+            StringBuilder strSql = new StringBuilder();
498
+            strSql.Append("select * ");
499
+            strSql.Append(" FROM V_UserAccount ");
500
+            if (strWhere.Trim() != "")
501
+            {
502
+                strSql.Append(" where " + strWhere);
503
+            }
504
+            return DbHelperSQL.Query(strSql.ToString());
505
+        }
506
+
507
+        /// <summary>
508
+        /// 获得前几行数据
509
+        /// </summary>
510
+        public DataSet GetList(int Top, string strWhere, string filedOrder)
511
+        {
512
+            StringBuilder strSql = new StringBuilder();
513
+            strSql.Append("select ");
514
+            if (Top > 0)
515
+            {
516
+                strSql.Append(" top " + Top.ToString());
517
+            }
518
+            strSql.Append(" F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode ");
519
+            strSql.Append(" FROM T_Sys_UserAccount ");
520
+            if (strWhere.Trim() != "")
521
+            {
522
+                strSql.Append(" where " + strWhere);
523
+            }
524
+            strSql.Append(" order by " + filedOrder);
525
+            return DbHelperSQL.Query(strSql.ToString());
526
+        }
527
+
528
+        /// <summary>
529
+        /// 获取记录总数
530
+        /// </summary>
531
+        public int GetRecordCount(string strWhere)
532
+        {
533
+            StringBuilder strSql = new StringBuilder();
534
+            strSql.Append("select count(1) FROM T_Sys_UserAccount ");
535
+            if (strWhere.Trim() != "")
536
+            {
537
+                strSql.Append(" where " + strWhere);
538
+            }
539
+            object obj = DbHelperSQL.GetSingle(strSql.ToString());
540
+            if (obj == null)
541
+            {
542
+                return 0;
543
+            }
544
+            else
545
+            {
546
+                return Convert.ToInt32(obj);
547
+            }
548
+        }
549
+        /// <summary>
550
+        /// 分页获取数据列表
551
+        /// </summary>
552
+        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
553
+        {
554
+            StringBuilder strSql = new StringBuilder();
555
+            strSql.Append("SELECT * FROM ( ");
556
+            strSql.Append(" SELECT ROW_NUMBER() OVER (");
557
+            if (!string.IsNullOrEmpty(orderby.Trim()))
558
+            {
559
+                strSql.Append("order by T." + orderby);
560
+            }
561
+            else
562
+            {
563
+                strSql.Append("order by T.F_UserId desc");
564
+            }
565
+            strSql.Append(")AS Row, T.*  from T_Sys_UserAccount T ");
566
+            if (!string.IsNullOrEmpty(strWhere.Trim()))
567
+            {
568
+                strSql.Append(" WHERE " + strWhere);
569
+            }
570
+            strSql.Append(" ) TT");
571
+            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
572
+            return DbHelperSQL.Query(strSql.ToString());
573
+        }
574
+
575
+        /*
576
+		/// <summary>
577
+		/// 分页获取数据列表
578
+		/// </summary>
579
+		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
580
+		{
581
+			SqlParameter[] parameters = {
582
+					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
583
+					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
584
+					new SqlParameter("@PageSize", SqlDbType.Int),
585
+					new SqlParameter("@PageIndex", SqlDbType.Int),
586
+					new SqlParameter("@IsReCount", SqlDbType.Bit),
587
+					new SqlParameter("@OrderType", SqlDbType.Bit),
588
+					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
589
+					};
590
+			parameters[0].Value = "T_Sys_UserAccount";
591
+			parameters[1].Value = "F_UserId";
592
+			parameters[2].Value = PageSize;
593
+			parameters[3].Value = PageIndex;
594
+			parameters[4].Value = 0;
595
+			parameters[5].Value = 0;
596
+			parameters[6].Value = strWhere;	
597
+			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
598
+		}*/
599
+
600
+        #endregion  BasicMethod
601
+        #region  ExtensionMethod
602
+
603
+        #endregion  ExtensionMethod
604
+    }
605
+}

+ 281 - 0
SmsPlatform/Model/T_Sys_UserAccount.cs

@@ -0,0 +1,281 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace SmsPlatform.Model
7
+{
8
+    /// <summary>
9
+	/// T_Sys_UserAccount:实体类(属性说明自动提取数据库字段的描述信息)
10
+	/// </summary>
11
+	[Serializable]
12
+    public partial class T_Sys_UserAccount
13
+    {
14
+        public T_Sys_UserAccount()
15
+        { }
16
+        #region Model
17
+        private int _f_userid;
18
+        private string _f_usercode;
19
+        private string _f_password;
20
+        private string _f_extensionnumber;
21
+        private string _f_username;
22
+        private int _f_deptid = 0;
23
+        private int _f_roleid = 0;
24
+        private int? _f_groupid;
25
+        private bool _f_seatflag;
26
+        private string _f_seatright;
27
+        private string _f_seatlevel;
28
+        private string _f_sexflag;
29
+        private bool _f_remindflag;
30
+        private string _f_remark;
31
+        private string _f_telephone;
32
+        private string _f_mobile;
33
+        private string _f_homephone;
34
+        private DateTime? _f_birthday;
35
+        private DateTime? _f_createon = DateTime.Now;
36
+        private DateTime? _f_cancelon;
37
+        private int? _f_deleteflag = 0;
38
+        private bool _f_apponflag = false;
39
+        private DateTime? _f_lastactivetime = DateTime.Now;
40
+        private string _f_see;
41
+        private int? _f_hjtype;
42
+        private int? _f_pid;
43
+        private int? _f_tmid;
44
+        private string _f_worknumber;
45
+        private string _f_deptcode;
46
+        /// <summary>
47
+        /// 账户ID
48
+        /// </summary>
49
+        public int F_UserId
50
+        {
51
+            set { _f_userid = value; }
52
+            get { return _f_userid; }
53
+        }
54
+        /// <summary>
55
+        /// 员工工号
56
+        /// </summary>
57
+        public string F_UserCode
58
+        {
59
+            set { _f_usercode = value; }
60
+            get { return _f_usercode; }
61
+        }
62
+        /// <summary>
63
+        /// 密码
64
+        /// </summary>
65
+        public string F_Password
66
+        {
67
+            set { _f_password = value; }
68
+            get { return _f_password; }
69
+        }
70
+        /// <summary>
71
+        /// 分机号
72
+        /// </summary>
73
+        public string F_ExtensionNumber
74
+        {
75
+            set { _f_extensionnumber = value; }
76
+            get { return _f_extensionnumber; }
77
+        }
78
+        /// <summary>
79
+        /// 操作员名称
80
+        /// </summary>
81
+        public string F_UserName
82
+        {
83
+            set { _f_username = value; }
84
+            get { return _f_username; }
85
+        }
86
+        /// <summary>
87
+        /// 部门ID
88
+        /// </summary>
89
+        public int F_DeptId
90
+        {
91
+            set { _f_deptid = value; }
92
+            get { return _f_deptid; }
93
+        }
94
+        /// <summary>
95
+        /// 角色id
96
+        /// </summary>
97
+        public int F_RoleId
98
+        {
99
+            set { _f_roleid = value; }
100
+            get { return _f_roleid; }
101
+        }
102
+        /// <summary>
103
+        /// 用户组ID
104
+        /// </summary>
105
+        public int? F_GroupId
106
+        {
107
+            set { _f_groupid = value; }
108
+            get { return _f_groupid; }
109
+        }
110
+        /// <summary>
111
+        /// 标志(0:非话务;1话务标志)
112
+        /// </summary>
113
+        public bool F_SeatFlag
114
+        {
115
+            set { _f_seatflag = value; }
116
+            get { return _f_seatflag; }
117
+        }
118
+        /// <summary>
119
+        /// 坐席权限组1班长坐席0普通坐席
120
+        /// </summary>
121
+        public string F_SeatRight
122
+        {
123
+            set { _f_seatright = value; }
124
+            get { return _f_seatright; }
125
+        }
126
+        /// <summary>
127
+        /// 坐席等级
128
+        /// </summary>
129
+        public string F_SeatLevel
130
+        {
131
+            set { _f_seatlevel = value; }
132
+            get { return _f_seatlevel; }
133
+        }
134
+        /// <summary>
135
+        /// 性别(男/女/未知)
136
+        /// </summary>
137
+        public string F_SexFlag
138
+        {
139
+            set { _f_sexflag = value; }
140
+            get { return _f_sexflag; }
141
+        }
142
+        /// <summary>
143
+        /// 提醒标志0不提醒1提醒
144
+        /// </summary>
145
+        public bool F_RemindFlag
146
+        {
147
+            set { _f_remindflag = value; }
148
+            get { return _f_remindflag; }
149
+        }
150
+        /// <summary>
151
+        /// 备注说明
152
+        /// </summary>
153
+        public string F_Remark
154
+        {
155
+            set { _f_remark = value; }
156
+            get { return _f_remark; }
157
+        }
158
+        /// <summary>
159
+        /// 电话
160
+        /// </summary>
161
+        public string F_Telephone
162
+        {
163
+            set { _f_telephone = value; }
164
+            get { return _f_telephone; }
165
+        }
166
+        /// <summary>
167
+        /// 手机
168
+        /// </summary>
169
+        public string F_Mobile
170
+        {
171
+            set { _f_mobile = value; }
172
+            get { return _f_mobile; }
173
+        }
174
+        /// <summary>
175
+        /// 家庭电话
176
+        /// </summary>
177
+        public string F_HomePhone
178
+        {
179
+            set { _f_homephone = value; }
180
+            get { return _f_homephone; }
181
+        }
182
+        /// <summary>
183
+        /// 出生日期
184
+        /// </summary>
185
+        public DateTime? F_Birthday
186
+        {
187
+            set { _f_birthday = value; }
188
+            get { return _f_birthday; }
189
+        }
190
+        /// <summary>
191
+        /// 建档日期
192
+        /// </summary>
193
+        public DateTime? F_CreateOn
194
+        {
195
+            set { _f_createon = value; }
196
+            get { return _f_createon; }
197
+        }
198
+        /// <summary>
199
+        /// 注销日期
200
+        /// </summary>
201
+        public DateTime? F_CancelOn
202
+        {
203
+            set { _f_cancelon = value; }
204
+            get { return _f_cancelon; }
205
+        }
206
+        /// <summary>
207
+        /// 删除标志
208
+        /// </summary>
209
+        public int? F_DeleteFlag
210
+        {
211
+            set { _f_deleteflag = value; }
212
+            get { return _f_deleteflag; }
213
+        }
214
+        /// <summary>
215
+        /// app在线标志0不在线1在线
216
+        /// </summary>
217
+        public bool F_APPOnFlag
218
+        {
219
+            set { _f_apponflag = value; }
220
+            get { return _f_apponflag; }
221
+        }
222
+        /// <summary>
223
+        /// 最后活跃时间
224
+        /// </summary>
225
+        public DateTime? F_LastActiveTime
226
+        {
227
+            set { _f_lastactivetime = value; }
228
+            get { return _f_lastactivetime; }
229
+        }
230
+        /// <summary>
231
+        /// 察看权限(1:个人;2:班组;3:所有)
232
+        /// </summary>
233
+        public string F_See
234
+        {
235
+            set { _f_see = value; }
236
+            get { return _f_see; }
237
+        }
238
+        /// <summary>
239
+        /// 此坐席任务是呼入还是呼出(0:呼入;1:呼出)
240
+        /// </summary>
241
+        public int? F_HJType
242
+        {
243
+            set { _f_hjtype = value; }
244
+            get { return _f_hjtype; }
245
+        }
246
+        /// <summary>
247
+        /// 任务计划id
248
+        /// </summary>
249
+        public int? F_PId
250
+        {
251
+            set { _f_pid = value; }
252
+            get { return _f_pid; }
253
+        }
254
+        /// <summary>
255
+        /// 团队id
256
+        /// </summary>
257
+        public int? F_TmId
258
+        {
259
+            set { _f_tmid = value; }
260
+            get { return _f_tmid; }
261
+        }
262
+        /// <summary>
263
+        /// 
264
+        /// </summary>
265
+        public string F_WorkNumber
266
+        {
267
+            set { _f_worknumber = value; }
268
+            get { return _f_worknumber; }
269
+        }
270
+        /// <summary>
271
+        /// 用于余额
272
+        /// </summary>
273
+        public string F_DeptCode
274
+        {
275
+            set { _f_deptcode = value; }
276
+            get { return _f_deptcode; }
277
+        }
278
+        #endregion Model
279
+
280
+    }
281
+}

+ 8 - 4
SmsPlatform/SmsPlatform.csproj

@@ -9,6 +9,14 @@
9 9
   </PropertyGroup>
10 10
 
11 11
   <ItemGroup>
12
+    <Compile Remove="Common\SQLOption.cs" />
13
+  </ItemGroup>
14
+
15
+  <ItemGroup>
16
+    <Content Remove="Web.config" />
17
+  </ItemGroup>
18
+
19
+  <ItemGroup>
12 20
     <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
13 21
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
14 22
     <PackageReference Include="NLog.Web.AspNetCore" Version="4.4.1" />
@@ -20,10 +28,6 @@
20 28
   </ItemGroup>
21 29
 
22 30
   <ItemGroup>
23
-    <Folder Include="Model\" />
24
-  </ItemGroup>
25
-
26
-  <ItemGroup>
27 31
     <Reference Include="aliyun-net-sdk-core">
28 32
       <HintPath>dll\aliyun-net-sdk-core.dll</HintPath>
29 33
     </Reference>

+ 10 - 1
SmsPlatform/Startup.cs

@@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging;
13 13
 using Microsoft.Extensions.Options;
14 14
 using NLog.Extensions.Logging;
15 15
 using NLog.Web;
16
+using SmsPlatform.Common;
16 17
 using Swashbuckle.AspNetCore.Swagger;
17 18
 
18 19
 namespace SmsPlatform
@@ -29,7 +30,7 @@ namespace SmsPlatform
29 30
                             .Build();
30 31
         }
31 32
 
32
-        public IConfiguration Configuration { get; }
33
+        public  IConfiguration Configuration { get; }
33 34
 
34 35
         // This method gets called by the runtime. Use this method to add services to the container.
35 36
         public void ConfigureServices(IServiceCollection services)
@@ -57,13 +58,21 @@ namespace SmsPlatform
57 58
             #endregion
58 59
 
59 60
             #region redis配置
61
+            RedisHelper .connserver = Configuration.GetSection("Redis:HostName").Value; //Configuration["Redis:HostName"].ToString();
62
+            RedisHelper .connport = Configuration["Redis:Port"].ToString();
60 63
             services.AddDistributedRedisCache(options =>
61 64
             {
62 65
                 options.InstanceName = Configuration["Redis:InstanceName"].ToString();
63 66
                 options.Configuration = $"{Configuration["Redis:HostName"].ToString()}:{Configuration["Redis:Port"].ToString()},allowAdmin=true,password={Configuration["Redis:Password"].ToString()},defaultdatabase={Configuration["Redis:Defaultdatabase"].ToString()}";
67
+                //options.Configuration = $"{Configuration["Redis:HostName"].ToString()}:{Configuration["Redis:Port"].ToString()},defaultdatabase={Configuration["Redis:Defaultdatabase"].ToString()}";
64 68
             });
65 69
             #endregion
66 70
 
71
+            #region SQL配置
72
+            DbHelperSQL .connectionString = Configuration.GetSection("connectionStrings:conn").Value;
73
+            
74
+            #endregion
75
+
67 76
             //注册Swagger生成器,定义一个和多个Swagger 文档
68 77
             services.AddSwaggerGen(c =>
69 78
             {

+ 5 - 2
SmsPlatform/appsettings.Development.json

@@ -8,8 +8,8 @@
8 8
     }
9 9
   },
10 10
   "Redis": {
11
-    "HostName": "139.224.236.21",
12
-    "Port": "4000",
11
+    "HostName": "139.224.236.21", //139.224.236.21
12
+    "Port": "6379", //4000
13 13
     "Password": "sms+800100",
14 14
     "Defaultdatabase": "15",
15 15
     "InstanceName": "sms"
@@ -20,5 +20,8 @@
20 20
     "domain": "dysmsapi.aliyuncs.com",
21 21
     "accesskeyid": "LTAID8jj0g51ZsYv",
22 22
     "accesskeysecret": "EH0S0XbUQihHSGA7FMutP0J8kzXqPk"
23
+  },
24
+  "connectionStrings": {
25
+    "conn": "Server=192.168.4.18;Database=GSZLS;Persist Security Info=True;User ID=sa;password=800100;"
23 26
   }
24 27
 }

+ 3 - 0
SmsPlatform/appsettings.Production.json

@@ -20,5 +20,8 @@
20 20
     "domain": "dysmsapi.aliyuncs.com",
21 21
     "accesskeyid": "LTAIICc6dV9MdBHK",
22 22
     "accesskeysecret": "Ed5qMOJIp4QMMERpmMr48Zpu0BTcTN"
23
+  },
24
+  "connectionStrings": {
25
+    "conn": "Server=192.168.4.18;Database=GSZLS;Persist Security Info=True;User ID=sa;password=800100;"
23 26
   }
24 27
 }