using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading;
using MySystem.Models;
using Library;
namespace MySystem
{
///
/// 设置机具费率标记并推送消息
///
public class SetFeeFlagService
{
public readonly static SetFeeFlagService Instance = new SetFeeFlagService();
private SetFeeFlagService()
{ }
public void Start()
{
Thread th = new Thread(doSomething);
th.IsBackground = true;
th.Start();
}
public void doSomething()
{
while (true)
{
if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
{
try
{
string check = function.ReadInstance("/Fee/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
if (string.IsNullOrEmpty(check))
{
function.WritePage("/Fee/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
WebCMSEntities db = new WebCMSEntities();
List BrandIds = new List();
BrandIds.Add(1);
BrandIds.Add(2);
BrandIds.Add(3);
BrandIds.Add(4);
BrandIds.Add(5);
var date = DateTime.Now.AddDays(-178);
var posList = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BindingTime <= date && m.BindingState == 1 && m.UpFeeFlag == 0 && BrandIds.Contains(m.BrandId)).ToList();
//循环修改机具费率调升标记
//统计需要推送消息的用户Id
foreach (var item in posList)
{
string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"0\",\"OpMan\": \""+"系统"+"\"}";
RedisDbconn.Instance.AddList("SetDepositQueue", info);
}
}
}
catch (Exception ex)
{
function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "机具费率标记设置异常");
}
}
Thread.Sleep(1200000);
}
}
}
}