| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using Library;
- using System.Net;
- using System.IO;
- using MySystem.MpMainModels2;
- namespace MySystem
- {
- /// <summary>
- /// 获取好哒ftp数据
- /// </summary>
- public class GetHaoDaBlueCircleBindService
- {
- public readonly static GetHaoDaBlueCircleBindService Instance = new GetHaoDaBlueCircleBindService();
- private GetHaoDaBlueCircleBindService()
- { }
- public void Start()
- {
- //每天凌晨执行获取好哒FTP昨日交易数据
- Thread th = new Thread(GetBlueCircleBindDataReady);
- th.IsBackground = true;
- th.Start();
- }
- /// <summary>
- /// 获取好哒FTP昨日交易数据
- /// </summary>
- public void GetBlueCircleBindDataReady()
- {
- while (true)
- {
- if (DateTime.Now > DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 10:05:00"))
- {
- SaveBlueCircleBindData(DateTime.Now.ToString("yyyyMMdd"));
- // DateTime start = DateTime.Parse("2025-05-27 00:00:00");
- // DateTime end = DateTime.Parse("2025-06-24 00:00:00");
- // for(DateTime i = start; i <= end; i = i.AddDays(1))
- // {
- // SaveBlueCircleBindData(i.ToString("yyyyMMdd"));
- // }
- }
- Thread.Sleep(180000);
- }
- }
- public void StartListen()
- {
- //每天凌晨执行获取好哒FTP昨日交易数据
- Thread th2 = new Thread(ListenBlueCircleBindDataReady);
- th2.IsBackground = true;
- th2.Start();
- }
- /// <summary>
- /// 获取好哒FTP昨日交易数据
- /// </summary>
- public void ListenBlueCircleBindDataReady()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("ListenBlueCircleBindDataQueue");
- if (!string.IsNullOrEmpty(content))
- {
- SaveBlueCircleBindData(content);
- Thread.Sleep(2000);
- }
- else
- {
- Thread.Sleep(60000);
- }
- }
- }
- public void SaveBlueCircleBindData(string Date, bool IsRedis = false)
- {
- // 要下载的文件路径
- string filePath = "/haoda-deposit/xlh_bind_" + Date + ".csv";
- try
- {
- // 创建FtpWebRequest对象
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create(GetHaoDaFTPInfoService.Instance.ftpServerAddress + filePath);
- request.Method = WebRequestMethods.Ftp.DownloadFile;
- request.Credentials = new NetworkCredential(GetHaoDaFTPInfoService.Instance.ftpUser, GetHaoDaFTPInfoService.Instance.ftpPassword);
- // 使用WebResponse获取响应
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- // 打开数据流
- Stream responseStream = response.GetResponseStream();
- StreamReader reader = new StreamReader(responseStream);
- // 读取数据
- string fileContents = reader.ReadToEnd();
- if (!string.IsNullOrEmpty(fileContents))
- {
- MpMainModels2.WebCMSEntities db = new MpMainModels2.WebCMSEntities();
- List<string> SnNos = db.HdBlueCircleTmp.Select(m => m.SnNo).ToList();
- List<string> ChkSnNos = new List<string>();
- var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
- if (DataInfo.Length > 1)
- {
- // int index = 0;
- var DataList = DataInfo[1].Split('\n');
- foreach (var DataListItem in DataList)
- {
- if(IsRedis)
- {
- RedisDbconn.Instance.AddList("ListenBlueCircleBindDataByOneQueue", DataListItem);
- }
- else
- {
- SaveBlueCircleBindDataOneReady(db, DataListItem);
- // index += 1;
- // if(index % 200 == 0 && index > 0)
- // {
- // index = 0;
- // db.SaveChanges();
- // }
- }
- }
- // if(!IsRedis)
- // {
- // index = 0;
- // db.SaveChanges();
- // }
- }
- db.Dispose();
- }
- // 关闭响应
- reader.Dispose();
- responseStream.Dispose();
- response.Close();
- }
- catch (WebException ex)
- {
- function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP小蓝环绑定数据异常");
- }
- }
- public void StartBlueCircleBindListenBridge()
- {
- Thread th2 = new Thread(ListenBlueCircleBindDataBridgeReady);
- th2.IsBackground = true;
- th2.Start();
- }
- public void ListenBlueCircleBindDataBridgeReady()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("cache:ListenBlueCircleBindDataByOneQueue");
- if (!string.IsNullOrEmpty(content))
- {
- RedisDbconn.Instance.AddList("ListenBlueCircleBindDataByOneQueue", content);
- }
- else
- {
- Thread.Sleep(10000);
- }
- }
- }
- public void StartBlueCircleBindListenByOne()
- {
- //每天凌晨执行获取好哒FTP昨日交易数据
- Thread th2 = new Thread(ListenBlueCircleBindDataByOneReady);
- th2.IsBackground = true;
- th2.Start();
- }
- /// <summary>
- /// 获取好哒FTP昨日交易数据
- /// </summary>
- public void ListenBlueCircleBindDataByOneReady()
- {
- int index = 0;
- MpMainModels2.WebCMSEntities db = new MpMainModels2.WebCMSEntities();
- bool dbConn = true;
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("ListenBlueCircleBindDataByOneQueue");
- if (!string.IsNullOrEmpty(content))
- {
- if(!dbConn)
- {
- db = new MpMainModels2.WebCMSEntities();
- dbConn = true;
- }
- SaveBlueCircleBindDataOneReady(db, content);
- index += 1;
- if(index % 200 == 0 && index > 0)
- {
- index = 0;
- db.SaveChanges();
- }
- }
- else
- {
- index = 0;
- if(dbConn)
- {
- db.SaveChanges();
- db.Dispose();
- dbConn = false;
- }
- }
- }
- }
- public void SaveBlueCircleBindDataOneReady(MpMainModels2.WebCMSEntities db, string content)
- {
- try
- {
- var DataListInfo = content.Split(',');
- string sn_no = DataListInfo[0]; //SN号
- string bind_date = DataListInfo[1]; //绑定日期
- string bind_date_detail = DataListInfo[2]; //绑定时间
- string mcht_no = DataListInfo[3]; //商户号
- string mcht_nm = DataListInfo[4]; //商户名称
- string through_date = DataListInfo[5]; //截止日期
- string channel_kind = DataListInfo[6]; //商户类型
- HdBlueCircleTmp edit = db.HdBlueCircleTmp.FirstOrDefault(m => m.SnNo == sn_no);
- if(edit == null)
- {
- function.WriteLog(DateTime.Now.ToString() + ":add:" + sn_no, "好哒小蓝环绑定");
- int PrizeFlag = db.HdBlueCircleTmp.Any(m => m.MchtNo == mcht_no && m.PrizeFlag == 1) ? 1 : 0;
- db.HdBlueCircleTmp.Add(new HdBlueCircleTmp()
- {
- SnNo = sn_no,
- BindDate = bind_date,
- BindDateDetail = bind_date_detail,
- MchtNo = mcht_no,
- MchtNm = mcht_nm,
- ThroughDate = through_date,
- ChannelKind = channel_kind,
- Status = 1,
- PrizeFlag = PrizeFlag,
- });
- if(PrizeFlag == 0 && !MerNos().Contains(mcht_no))
- {
- MerchantAddInfo merAdd = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == mcht_no);
- if(merAdd != null)
- {
- MerchantInfo mer = db.MerchantInfo.FirstOrDefault(m => m.Id == merAdd.Id && m.UserId > 0) ?? new MerchantInfo();
- function.GetWebRequest("http://logic-executor-api.kexiaoshuang.com/noauth/prize/pushbyone?n=QUEUE_KXS_LKB_PRO_PRIZE_CONFIG_DIVISION&m={\"brand_id\":200,\"ext_field\":\"xlh\",\"mch_no\":\"" + mcht_no + "\",\"user_id\":" + mer.UserId + "}&ids=69");
- }
- }
- }
- else
- {
- function.WriteLog(DateTime.Now.ToString() + ":update:" + sn_no, "好哒小蓝环绑定");
- edit.Status += 1;
- edit.BindDate = bind_date;
- edit.BindDateDetail = bind_date_detail;
- edit.MchtNo = mcht_no;
- edit.MchtNm = mcht_nm;
- edit.ThroughDate = through_date;
- edit.ChannelKind = channel_kind;
- }
- db.SaveChanges();
- }
- catch(Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒小蓝环绑定异常");
- }
- }
- public List<string> MerNos()
- {
- List<string> nos = new List<string>();
- nos.Add("015210308251137");
- nos.Add("015320609101833");
- nos.Add("015371608435497");
- nos.Add("015460108410056");
- nos.Add("015500108329008");
- nos.Add("015520107846870");
- nos.Add("015520208185069");
- nos.Add("015620108398869");
- nos.Add("066130608917409");
- nos.Add("066131108845193");
- nos.Add("066140208861265");
- nos.Add("066141108868081");
- nos.Add("066141108967906");
- nos.Add("066150108844321");
- nos.Add("066150108867768");
- nos.Add("066150108868251");
- nos.Add("066150108868494");
- nos.Add("066150108905702");
- nos.Add("066150108910557");
- nos.Add("066150108946097");
- nos.Add("066150208852166");
- nos.Add("066150208950877");
- nos.Add("066150408867918");
- nos.Add("066150908876451");
- nos.Add("066210308905750");
- nos.Add("066210308905750");
- nos.Add("066210308905750");
- nos.Add("066210308916415");
- nos.Add("066210308916446");
- nos.Add("066210309056478");
- nos.Add("066210808916478");
- nos.Add("066330108852832");
- nos.Add("066331108860880");
- nos.Add("066370208891591");
- nos.Add("066370208909763");
- nos.Add("066371608884640");
- nos.Add("066371608885517");
- nos.Add("066371608885579");
- nos.Add("066371608893623");
- nos.Add("066371608916999");
- nos.Add("066410108868693");
- nos.Add("066410108933765");
- nos.Add("066410608852198");
- nos.Add("066422808917617");
- nos.Add("066422808942270");
- nos.Add("066422808960700");
- nos.Add("066430108891813");
- nos.Add("066430108952336");
- nos.Add("066430108952452");
- nos.Add("066430108959408");
- nos.Add("066430108960367");
- nos.Add("066430108960479");
- nos.Add("066431008877196");
- nos.Add("066440808866736");
- nos.Add("066460108852030");
- nos.Add("066460108852470");
- nos.Add("066460108853082");
- nos.Add("066460108859673");
- nos.Add("066460108861699");
- nos.Add("066460108868206");
- nos.Add("066460108868690");
- nos.Add("066460108868698");
- nos.Add("066460108875241");
- nos.Add("066460108883541");
- nos.Add("066460108893039");
- nos.Add("066460108900376");
- nos.Add("066460108906995");
- nos.Add("066460108913209");
- nos.Add("066460108916779");
- nos.Add("066460108937873");
- nos.Add("066469008884386");
- nos.Add("066469008884386");
- nos.Add("066469008925034");
- nos.Add("066469008933813");
- nos.Add("066469008968133");
- nos.Add("066500108845174");
- nos.Add("066500108852664");
- nos.Add("066500108867852");
- nos.Add("066500108903035");
- nos.Add("066500108903055");
- nos.Add("066500108912630");
- nos.Add("066500108950978");
- nos.Add("066510108851765");
- nos.Add("066510108851877");
- nos.Add("066510108851991");
- nos.Add("066510108856232");
- nos.Add("066510108901699");
- nos.Add("066510108910198");
- nos.Add("066510108910198");
- nos.Add("066510108916984");
- nos.Add("066510108931507");
- nos.Add("066510108944825");
- nos.Add("066510108959313");
- nos.Add("066510108972240");
- nos.Add("066510608925630");
- nos.Add("066511708876775");
- nos.Add("066520108843822");
- nos.Add("066520108858552");
- nos.Add("066520108888754");
- nos.Add("066520108917867");
- nos.Add("066520108925675");
- nos.Add("066520108966825");
- nos.Add("066520109086073");
- nos.Add("066520408924894");
- nos.Add("066520408971393");
- nos.Add("066532608843661");
- nos.Add("066610108843648");
- nos.Add("066610108845179");
- nos.Add("066610108853054");
- nos.Add("066610108869513");
- nos.Add("066610108924754");
- nos.Add("066610108925067");
- nos.Add("066610108926277");
- nos.Add("066610108931503");
- nos.Add("066610108941316");
- nos.Add("066610108941513");
- nos.Add("066610108968505");
- nos.Add("066610408877908");
- nos.Add("066610408901562");
- nos.Add("066610408906775");
- nos.Add("066610608892225");
- nos.Add("066610608901370");
- nos.Add("066610608925084");
- nos.Add("066610608972000");
- nos.Add("066620608863825");
- nos.Add("066620608940304");
- nos.Add("066620608946214");
- nos.Add("066621108959029");
- return nos;
- }
- }
- }
|