浏览代码

跑金控费率

lcl 2 年之前
父节点
当前提交
26b8c61a69
共有 3 个文件被更改,包括 85 次插入4 次删除
  1. 0 4
      AppStart/Redis/RedisDbconn.cs
  2. 83 0
      AppStart/SetFeeService.cs
  3. 2 0
      Startup.cs

+ 0 - 4
AppStart/Redis/RedisDbconn.cs

@@ -14,10 +14,6 @@ namespace MySystem
         public static CSRedis.CSRedisClient csredis;
         private RedisDbconn()
         {
-            if (csredis == null)
-            {
-                csredis = new CSRedis.CSRedisClient(ConfigurationManager.AppSettings["RedisConnStr"].ToString());
-            }
         }
 
         #region 设置单个字段

+ 83 - 0
AppStart/SetFeeService.cs

@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Threading;
+using MySystem.MainModels;
+using Library;
+using LitJson;
+
+namespace MySystem
+{
+    /// <summary>
+    /// 设置机具费率标记并推送消息
+    /// </summary>
+    public class SetFeeService
+    {
+        public readonly static SetFeeService Instance = new SetFeeService();
+        private SetFeeService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(doSomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void doSomething()
+        {
+            DataTable dt = CustomerSqlConn.dtable("select Id from PosMachinesTwo where BrandId in (1,3) and BindingState=1 and BindingTime<'" + DateTime.Now.AddDays(-90).ToString("yyyy-MM-dd") + " 00:00:00' and UpFeeFlag=0", Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString());
+            foreach(DataRow dr in dt.Rows)
+            {
+                RedisDbconn.Instance.AddList("JkFeeQueue", dr["Id"].ToString());
+            }
+            dt = CustomerSqlConn.dtable("select Id from PosMachinesTwo where BrandId in (1,3) and BindingState=1 and BindingTime<'" + DateTime.Now.AddDays(-90).ToString("yyyy-MM-dd") + " 00:00:00' and DownFeeFlag=1", Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString());
+            foreach(DataRow dr in dt.Rows)
+            {
+                RedisDbconn.Instance.AddList("JkFeeQueue", dr["Id"].ToString());
+            }
+            dt.Dispose();
+            dt.Clear();
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("JkFeeQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        int PosId = int.Parse(content);
+                        WebCMSEntities db = new WebCMSEntities();
+                        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
+                        if(pos != null)
+                        {
+                            PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                            if(mer != null)
+                            {
+                                function.WriteLog("KqMerNo:" + mer.KqMerNo + ";PosSn:" + pos.PosSn + ";", "金控机具费率设置日志");
+                                string result = PublicImportDataService.Instance.SetFee(mer.KqMerNo, pos.PosSn, 0.63M);
+                                function.WriteLog(result, "金控机具费率设置日志");
+                                JsonData obj = JsonMapper.ToObject(result);
+                                if (obj["code"].ToString() == "000000")
+                                {
+                                    function.WriteLog(PublicImportDataService.Instance.Decrypt(obj["data"].ToString()), "金控机具费率设置日志");
+                                }
+                                function.WriteLog("\n\n", "金控机具费率设置日志");
+                            }
+                        }
+                        db.Dispose();
+                        Thread.Sleep(100);
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "金控机具费率设置异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(60000);
+                }
+            }
+        }
+    }
+}

+ 2 - 0
Startup.cs

@@ -93,6 +93,7 @@ namespace MySystem
             // 必须打开
 
             MySystemLib.SystemPublicFuction.appcheck = "success";
+            RedisDbconn.csredis = new CSRedis.CSRedisClient(Configuration["Setting:RedisConnStr"]);
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -140,6 +141,7 @@ namespace MySystem
                     pattern: "{controller=Home}/{action=Index}/{Id?}");
             });
 
+            SetFeeService.Instance.Start();
         }
     }
 }