GetHaoDaBlueCircleBindService.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using Library;
  7. using System.Net;
  8. using System.IO;
  9. using MySystem.MpMainModels2;
  10. namespace MySystem
  11. {
  12. /// <summary>
  13. /// 获取好哒ftp数据
  14. /// </summary>
  15. public class GetHaoDaBlueCircleBindService
  16. {
  17. public readonly static GetHaoDaBlueCircleBindService Instance = new GetHaoDaBlueCircleBindService();
  18. private GetHaoDaBlueCircleBindService()
  19. { }
  20. public void Start()
  21. {
  22. //每天凌晨执行获取好哒FTP昨日交易数据
  23. Thread th = new Thread(GetBlueCircleBindDataReady);
  24. th.IsBackground = true;
  25. th.Start();
  26. }
  27. /// <summary>
  28. /// 获取好哒FTP昨日交易数据
  29. /// </summary>
  30. public void GetBlueCircleBindDataReady()
  31. {
  32. while (true)
  33. {
  34. if (DateTime.Now > DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 10:05:00"))
  35. {
  36. SaveBlueCircleBindData(DateTime.Now.ToString("yyyyMMdd"));
  37. // DateTime start = DateTime.Parse("2025-05-27 00:00:00");
  38. // DateTime end = DateTime.Parse("2025-06-24 00:00:00");
  39. // for(DateTime i = start; i <= end; i = i.AddDays(1))
  40. // {
  41. // SaveBlueCircleBindData(i.ToString("yyyyMMdd"));
  42. // }
  43. }
  44. Thread.Sleep(180000);
  45. }
  46. }
  47. public void StartListen()
  48. {
  49. //每天凌晨执行获取好哒FTP昨日交易数据
  50. Thread th2 = new Thread(ListenBlueCircleBindDataReady);
  51. th2.IsBackground = true;
  52. th2.Start();
  53. }
  54. /// <summary>
  55. /// 获取好哒FTP昨日交易数据
  56. /// </summary>
  57. public void ListenBlueCircleBindDataReady()
  58. {
  59. while (true)
  60. {
  61. string content = RedisDbconn.Instance.RPop<string>("ListenBlueCircleBindDataQueue");
  62. if (!string.IsNullOrEmpty(content))
  63. {
  64. SaveBlueCircleBindData(content);
  65. Thread.Sleep(2000);
  66. }
  67. else
  68. {
  69. Thread.Sleep(60000);
  70. }
  71. }
  72. }
  73. public void SaveBlueCircleBindData(string Date, bool IsRedis = false)
  74. {
  75. // 要下载的文件路径
  76. string filePath = "/haoda-deposit/xlh_bind_" + Date + ".csv";
  77. try
  78. {
  79. // 创建FtpWebRequest对象
  80. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(GetHaoDaFTPInfoService.Instance.ftpServerAddress + filePath);
  81. request.Method = WebRequestMethods.Ftp.DownloadFile;
  82. request.Credentials = new NetworkCredential(GetHaoDaFTPInfoService.Instance.ftpUser, GetHaoDaFTPInfoService.Instance.ftpPassword);
  83. // 使用WebResponse获取响应
  84. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  85. // 打开数据流
  86. Stream responseStream = response.GetResponseStream();
  87. StreamReader reader = new StreamReader(responseStream);
  88. // 读取数据
  89. string fileContents = reader.ReadToEnd();
  90. if (!string.IsNullOrEmpty(fileContents))
  91. {
  92. MpMainModels2.WebCMSEntities db = new MpMainModels2.WebCMSEntities();
  93. List<string> SnNos = db.HdBlueCircleTmp.Select(m => m.SnNo).ToList();
  94. List<string> ChkSnNos = new List<string>();
  95. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  96. if (DataInfo.Length > 1)
  97. {
  98. // int index = 0;
  99. var DataList = DataInfo[1].Split('\n');
  100. foreach (var DataListItem in DataList)
  101. {
  102. if(IsRedis)
  103. {
  104. RedisDbconn.Instance.AddList("ListenBlueCircleBindDataByOneQueue", DataListItem);
  105. }
  106. else
  107. {
  108. SaveBlueCircleBindDataOneReady(db, DataListItem);
  109. // index += 1;
  110. // if(index % 200 == 0 && index > 0)
  111. // {
  112. // index = 0;
  113. // db.SaveChanges();
  114. // }
  115. }
  116. }
  117. // if(!IsRedis)
  118. // {
  119. // index = 0;
  120. // db.SaveChanges();
  121. // }
  122. }
  123. db.Dispose();
  124. }
  125. // 关闭响应
  126. reader.Dispose();
  127. responseStream.Dispose();
  128. response.Close();
  129. }
  130. catch (WebException ex)
  131. {
  132. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP小蓝环绑定数据异常");
  133. }
  134. }
  135. public void StartBlueCircleBindListenBridge()
  136. {
  137. Thread th2 = new Thread(ListenBlueCircleBindDataBridgeReady);
  138. th2.IsBackground = true;
  139. th2.Start();
  140. }
  141. public void ListenBlueCircleBindDataBridgeReady()
  142. {
  143. while (true)
  144. {
  145. string content = RedisDbconn.Instance.RPop<string>("cache:ListenBlueCircleBindDataByOneQueue");
  146. if (!string.IsNullOrEmpty(content))
  147. {
  148. RedisDbconn.Instance.AddList("ListenBlueCircleBindDataByOneQueue", content);
  149. }
  150. else
  151. {
  152. Thread.Sleep(10000);
  153. }
  154. }
  155. }
  156. public void StartBlueCircleBindListenByOne()
  157. {
  158. //每天凌晨执行获取好哒FTP昨日交易数据
  159. Thread th2 = new Thread(ListenBlueCircleBindDataByOneReady);
  160. th2.IsBackground = true;
  161. th2.Start();
  162. }
  163. /// <summary>
  164. /// 获取好哒FTP昨日交易数据
  165. /// </summary>
  166. public void ListenBlueCircleBindDataByOneReady()
  167. {
  168. int index = 0;
  169. MpMainModels2.WebCMSEntities db = new MpMainModels2.WebCMSEntities();
  170. bool dbConn = true;
  171. while (true)
  172. {
  173. string content = RedisDbconn.Instance.RPop<string>("ListenBlueCircleBindDataByOneQueue");
  174. if (!string.IsNullOrEmpty(content))
  175. {
  176. if(!dbConn)
  177. {
  178. db = new MpMainModels2.WebCMSEntities();
  179. dbConn = true;
  180. }
  181. SaveBlueCircleBindDataOneReady(db, content);
  182. index += 1;
  183. if(index % 200 == 0 && index > 0)
  184. {
  185. index = 0;
  186. db.SaveChanges();
  187. }
  188. }
  189. else
  190. {
  191. index = 0;
  192. if(dbConn)
  193. {
  194. db.SaveChanges();
  195. db.Dispose();
  196. dbConn = false;
  197. }
  198. }
  199. }
  200. }
  201. public void SaveBlueCircleBindDataOneReady(MpMainModels2.WebCMSEntities db, string content)
  202. {
  203. try
  204. {
  205. var DataListInfo = content.Split(',');
  206. string sn_no = DataListInfo[0]; //SN号
  207. string bind_date = DataListInfo[1]; //绑定日期
  208. string bind_date_detail = DataListInfo[2]; //绑定时间
  209. string mcht_no = DataListInfo[3]; //商户号
  210. string mcht_nm = DataListInfo[4]; //商户名称
  211. string through_date = DataListInfo[5]; //截止日期
  212. string channel_kind = DataListInfo[6]; //商户类型
  213. HdBlueCircleTmp edit = db.HdBlueCircleTmp.FirstOrDefault(m => m.SnNo == sn_no);
  214. if(edit == null)
  215. {
  216. function.WriteLog(DateTime.Now.ToString() + ":add:" + sn_no, "好哒小蓝环绑定");
  217. int PrizeFlag = db.HdBlueCircleTmp.Any(m => m.MchtNo == mcht_no && m.PrizeFlag == 1) ? 1 : 0;
  218. db.HdBlueCircleTmp.Add(new HdBlueCircleTmp()
  219. {
  220. SnNo = sn_no,
  221. BindDate = bind_date,
  222. BindDateDetail = bind_date_detail,
  223. MchtNo = mcht_no,
  224. MchtNm = mcht_nm,
  225. ThroughDate = through_date,
  226. ChannelKind = channel_kind,
  227. Status = 1,
  228. PrizeFlag = PrizeFlag,
  229. });
  230. if(PrizeFlag == 0 && !MerNos().Contains(mcht_no))
  231. {
  232. MerchantAddInfo merAdd = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == mcht_no);
  233. if(merAdd != null)
  234. {
  235. MerchantInfo mer = db.MerchantInfo.FirstOrDefault(m => m.Id == merAdd.Id && m.UserId > 0) ?? new MerchantInfo();
  236. 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");
  237. }
  238. }
  239. }
  240. else
  241. {
  242. function.WriteLog(DateTime.Now.ToString() + ":update:" + sn_no, "好哒小蓝环绑定");
  243. edit.Status += 1;
  244. edit.BindDate = bind_date;
  245. edit.BindDateDetail = bind_date_detail;
  246. edit.MchtNo = mcht_no;
  247. edit.MchtNm = mcht_nm;
  248. edit.ThroughDate = through_date;
  249. edit.ChannelKind = channel_kind;
  250. }
  251. db.SaveChanges();
  252. }
  253. catch(Exception ex)
  254. {
  255. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒小蓝环绑定异常");
  256. }
  257. }
  258. public List<string> MerNos()
  259. {
  260. List<string> nos = new List<string>();
  261. nos.Add("015210308251137");
  262. nos.Add("015320609101833");
  263. nos.Add("015371608435497");
  264. nos.Add("015460108410056");
  265. nos.Add("015500108329008");
  266. nos.Add("015520107846870");
  267. nos.Add("015520208185069");
  268. nos.Add("015620108398869");
  269. nos.Add("066130608917409");
  270. nos.Add("066131108845193");
  271. nos.Add("066140208861265");
  272. nos.Add("066141108868081");
  273. nos.Add("066141108967906");
  274. nos.Add("066150108844321");
  275. nos.Add("066150108867768");
  276. nos.Add("066150108868251");
  277. nos.Add("066150108868494");
  278. nos.Add("066150108905702");
  279. nos.Add("066150108910557");
  280. nos.Add("066150108946097");
  281. nos.Add("066150208852166");
  282. nos.Add("066150208950877");
  283. nos.Add("066150408867918");
  284. nos.Add("066150908876451");
  285. nos.Add("066210308905750");
  286. nos.Add("066210308905750");
  287. nos.Add("066210308905750");
  288. nos.Add("066210308916415");
  289. nos.Add("066210308916446");
  290. nos.Add("066210309056478");
  291. nos.Add("066210808916478");
  292. nos.Add("066330108852832");
  293. nos.Add("066331108860880");
  294. nos.Add("066370208891591");
  295. nos.Add("066370208909763");
  296. nos.Add("066371608884640");
  297. nos.Add("066371608885517");
  298. nos.Add("066371608885579");
  299. nos.Add("066371608893623");
  300. nos.Add("066371608916999");
  301. nos.Add("066410108868693");
  302. nos.Add("066410108933765");
  303. nos.Add("066410608852198");
  304. nos.Add("066422808917617");
  305. nos.Add("066422808942270");
  306. nos.Add("066422808960700");
  307. nos.Add("066430108891813");
  308. nos.Add("066430108952336");
  309. nos.Add("066430108952452");
  310. nos.Add("066430108959408");
  311. nos.Add("066430108960367");
  312. nos.Add("066430108960479");
  313. nos.Add("066431008877196");
  314. nos.Add("066440808866736");
  315. nos.Add("066460108852030");
  316. nos.Add("066460108852470");
  317. nos.Add("066460108853082");
  318. nos.Add("066460108859673");
  319. nos.Add("066460108861699");
  320. nos.Add("066460108868206");
  321. nos.Add("066460108868690");
  322. nos.Add("066460108868698");
  323. nos.Add("066460108875241");
  324. nos.Add("066460108883541");
  325. nos.Add("066460108893039");
  326. nos.Add("066460108900376");
  327. nos.Add("066460108906995");
  328. nos.Add("066460108913209");
  329. nos.Add("066460108916779");
  330. nos.Add("066460108937873");
  331. nos.Add("066469008884386");
  332. nos.Add("066469008884386");
  333. nos.Add("066469008925034");
  334. nos.Add("066469008933813");
  335. nos.Add("066469008968133");
  336. nos.Add("066500108845174");
  337. nos.Add("066500108852664");
  338. nos.Add("066500108867852");
  339. nos.Add("066500108903035");
  340. nos.Add("066500108903055");
  341. nos.Add("066500108912630");
  342. nos.Add("066500108950978");
  343. nos.Add("066510108851765");
  344. nos.Add("066510108851877");
  345. nos.Add("066510108851991");
  346. nos.Add("066510108856232");
  347. nos.Add("066510108901699");
  348. nos.Add("066510108910198");
  349. nos.Add("066510108910198");
  350. nos.Add("066510108916984");
  351. nos.Add("066510108931507");
  352. nos.Add("066510108944825");
  353. nos.Add("066510108959313");
  354. nos.Add("066510108972240");
  355. nos.Add("066510608925630");
  356. nos.Add("066511708876775");
  357. nos.Add("066520108843822");
  358. nos.Add("066520108858552");
  359. nos.Add("066520108888754");
  360. nos.Add("066520108917867");
  361. nos.Add("066520108925675");
  362. nos.Add("066520108966825");
  363. nos.Add("066520109086073");
  364. nos.Add("066520408924894");
  365. nos.Add("066520408971393");
  366. nos.Add("066532608843661");
  367. nos.Add("066610108843648");
  368. nos.Add("066610108845179");
  369. nos.Add("066610108853054");
  370. nos.Add("066610108869513");
  371. nos.Add("066610108924754");
  372. nos.Add("066610108925067");
  373. nos.Add("066610108926277");
  374. nos.Add("066610108931503");
  375. nos.Add("066610108941316");
  376. nos.Add("066610108941513");
  377. nos.Add("066610108968505");
  378. nos.Add("066610408877908");
  379. nos.Add("066610408901562");
  380. nos.Add("066610408906775");
  381. nos.Add("066610608892225");
  382. nos.Add("066610608901370");
  383. nos.Add("066610608925084");
  384. nos.Add("066610608972000");
  385. nos.Add("066620608863825");
  386. nos.Add("066620608940304");
  387. nos.Add("066620608946214");
  388. nos.Add("066621108959029");
  389. return nos;
  390. }
  391. }
  392. }