You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HKCore.cs 12 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. using HandyControl.Controls;
  2. using HKCardOUT.Helper;
  3. using HKCardOUT.Logic.Model;
  4. using HKControl;
  5. using HKLog;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using UHFHelper;
  13. using XExten.Advance.LinqFramework;
  14. namespace HKCardOUT.Logic.Service
  15. {
  16. public class HKCore
  17. {
  18. List<SaleLog> Commom(SaleLog input)
  19. {
  20. if (DataBus.StartDevice)
  21. {
  22. var checkDevice = !Main.GetInstance.GetIsSwipe(input.Location.AsInt());
  23. HKLogImport.WriteInfo("设备出餐状态:" + checkDevice);
  24. if (checkDevice) return null;
  25. }
  26. var Old = DbContext.Context.Queryable<SaleLog>()
  27. .Where(t => t.CardNo == input.CardNo)
  28. .Where(t => t.CreateTime.Year == DateTime.Now.Year)
  29. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  30. .Where(t => t.CreateTime.Day == DateTime.Now.Day).ToList();
  31. if (DataBus.Admin.Contains(input.CardNo))
  32. {
  33. return Old;
  34. }
  35. else
  36. {
  37. if (DataBus.Cancel)
  38. if (Old.Count > 3) return null;
  39. return Old;
  40. }
  41. }
  42. bool GetCardStutas(string CardNo)
  43. {
  44. var data = DbContext.Context.Queryable<CardStutas>().First(t => t.CardNo == CardNo);
  45. if (data == null) return false;
  46. if (data.Stutas != 1) return false;
  47. return true;
  48. }
  49. public static void AddCard(List<CardStutas> input)
  50. {
  51. var temp = DbContext.Context.Queryable<CardStutas>().Where(t => input.Select(m => m.CardNo).Contains(t.CardNo)).Distinct().ToList();
  52. List<CardStutas> waitUpdate = new List<CardStutas>();
  53. List<CardStutas> waitInsert = new List<CardStutas>();
  54. foreach (var item in input)
  55. {
  56. if (temp.Select(t => t.CardNo).Contains(item.CardNo))
  57. {
  58. waitUpdate.Add(item);
  59. }
  60. else
  61. {
  62. waitInsert.Add(item);
  63. }
  64. }
  65. if (waitUpdate.Count > 0)
  66. {
  67. waitUpdate.ForEach(t =>
  68. {
  69. DbContext.Context.Updateable<CardStutas>().SetColumns(t => t.Stutas == t.Stutas).Where(t => t.CardNo == t.CardNo).ExecuteCommand();
  70. });
  71. }
  72. if (waitInsert.Count > 0)
  73. {
  74. DbContext.Context.Insertable(waitInsert).CallEntityMethod(t => t.Create()).ExecuteCommand();
  75. }
  76. }
  77. /// <summary>
  78. /// 早上消费
  79. /// </summary>
  80. /// <param name="input"></param>
  81. /// <returns></returns>
  82. public bool DeviceSaleAM(SaleLog input)
  83. {
  84. try
  85. {
  86. if (!GetCardStutas(input.CardNo))
  87. {
  88. HKLogImport.WriteInfo($"当前卡异常,卡号:【{input.CardNo}】");
  89. return false;
  90. }
  91. var Old = Commom(input);
  92. if (Old == null) return false;
  93. var AMDay = Old.Where(t => t.CreateTime >= DataBus.Times.AMStartTime && t.CreateTime < DataBus.Times.AMEndTime)
  94. .Where(t => t.CreateTime.Year == DateTime.Now.Year)
  95. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  96. .Where(t => t.CreateTime.Day == DateTime.Now.Day)
  97. .Count();
  98. HKLogImport.WriteInfo($"卡号{input.CardNo}上午消费次数:{AMDay}");
  99. if (DataBus.Admin.Contains(input.CardNo))
  100. {
  101. DataBus.Entitys.Enqueue(input);
  102. if (DataBus.StartDevice)
  103. {
  104. DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
  105. {
  106. CardNo = input.CardNo,
  107. Location = input.Location
  108. });
  109. Main.GetInstance.Start(input.Location.AsInt());
  110. HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
  111. }
  112. return true;
  113. }
  114. else if (AMDay < DataBus.Count)
  115. {
  116. DataBus.Entitys.Enqueue(input);
  117. if (DataBus.StartDevice)
  118. {
  119. DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
  120. {
  121. CardNo = input.CardNo,
  122. Location = input.Location
  123. });
  124. Main.GetInstance.Start(input.Location.AsInt());
  125. HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
  126. }
  127. return true;
  128. }
  129. return false;
  130. }
  131. catch (Exception ex)
  132. {
  133. HKLog.HKLogImport.WriteError(ex);
  134. return false;
  135. }
  136. }
  137. /// <summary>
  138. /// 中午消费
  139. /// </summary>
  140. /// <param name="input"></param>
  141. /// <param name="Old"></param>
  142. /// <returns></returns>
  143. public bool DeviceSalePM(SaleLog input)
  144. {
  145. try
  146. {
  147. if (!GetCardStutas(input.CardNo))
  148. {
  149. HKLogImport.WriteInfo($"当前卡异常,卡号:【{input.CardNo}】");
  150. return false;
  151. }
  152. var Old = Commom(input);
  153. if (Old == null) return false;
  154. var PMDay = Old.Where(t => t.CreateTime >= DataBus.Times.PMStartTime && t.CreateTime < DataBus.Times.PMEndTime).
  155. Where(t => t.CreateTime.Year == DateTime.Now.Year)
  156. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  157. .Where(t => t.CreateTime.Day == DateTime.Now.Day)
  158. .Count();
  159. HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}中午消费次数:{PMDay}");
  160. if (DataBus.Admin.Contains(input.CardNo))
  161. {
  162. DataBus.Entitys.Enqueue(input);
  163. if (DataBus.StartDevice)
  164. {
  165. DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
  166. {
  167. CardNo = input.CardNo,
  168. Location = input.Location
  169. });
  170. Main.GetInstance.Start(input.Location.AsInt());
  171. HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
  172. }
  173. return true;
  174. }
  175. else if (PMDay < DataBus.Count)
  176. {
  177. DataBus.Entitys.Enqueue(input);
  178. if (DataBus.StartDevice)
  179. {
  180. DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
  181. {
  182. CardNo = input.CardNo,
  183. Location = input.Location
  184. });
  185. Main.GetInstance.Start(input.Location.AsInt());
  186. HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
  187. }
  188. return true;
  189. }
  190. return false;
  191. }
  192. catch (Exception ex)
  193. {
  194. HKLog.HKLogImport.WriteError(ex);
  195. return false;
  196. }
  197. }
  198. /// <summary>
  199. /// 晚上
  200. /// </summary>
  201. /// <param name="input"></param>
  202. /// <param name="Old"></param>
  203. /// <returns></returns>
  204. public bool DeviceSaleAT(SaleLog input)
  205. {
  206. try
  207. {
  208. if (!GetCardStutas(input.CardNo))
  209. {
  210. HKLogImport.WriteInfo($"当前卡异常,卡号:【{input.CardNo}】");
  211. return false;
  212. }
  213. var Old = Commom(input);
  214. if (Old == null) return false;
  215. var ATDay = Old.Where(t => t.CreateTime >= DataBus.Times.ATStartTime && t.CreateTime < DataBus.Times.ATEndTime)
  216. .Where(t => t.CreateTime.Year == DateTime.Now.Year)
  217. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  218. .Where(t => t.CreateTime.Day == DateTime.Now.Day)
  219. .Count();
  220. HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}下午消费次数:{ATDay}");
  221. if (DataBus.Admin.Contains(input.CardNo))
  222. {
  223. DataBus.Entitys.Enqueue(input);
  224. if (DataBus.StartDevice)
  225. {
  226. DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
  227. {
  228. CardNo = input.CardNo,
  229. Location = input.Location
  230. });
  231. Main.GetInstance.Start(input.Location.AsInt());
  232. HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
  233. }
  234. return true;
  235. }
  236. else if (ATDay < DataBus.Count)
  237. {
  238. DataBus.Entitys.Enqueue(input);
  239. if (DataBus.StartDevice)
  240. {
  241. DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
  242. {
  243. CardNo = input.CardNo,
  244. Location = input.Location
  245. });
  246. Main.GetInstance.Start(input.Location.AsInt());
  247. HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
  248. }
  249. return true;
  250. }
  251. return false;
  252. }
  253. catch (Exception ex)
  254. {
  255. HKLog.HKLogImport.WriteError(ex);
  256. return false;
  257. }
  258. }
  259. /// <summary>
  260. /// 获取当天消费前100条展示
  261. /// </summary>
  262. /// <returns></returns>
  263. public Dictionary<string, int> PullDaySaleLog(int[] screen)
  264. {
  265. // var today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  266. // var count = DbContext.Context.Queryable<SaleLog>().Where(t => t.CreateTime >= today)
  267. // .WhereIF(screen == 0, t => t.Location == "3" || t.Location == "4")
  268. // .WhereIF(screen == 1, t => t.Location == "1" || t.Location == "2")
  269. // .WhereIF(screen ==2, t => t.Location == "5" || t.Location == "6").Select(t => t.Location).ToList();
  270. //return count.GroupBy(t => t).ToDictionary(t => t.Key, t => t.Count());
  271. string a = screen[0].ToString();
  272. string b = screen[1].ToString();
  273. var today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  274. var count = DbContext.Context.Queryable<SaleLog>().Where(t => t.CreateTime >= today)
  275. .WhereIF(screen.Length == 2, t => t.Location == a || t.Location == b).Select(t => t.Location).ToList();
  276. return count.GroupBy(t => t).ToDictionary(t => t.Key, t => t.Count());
  277. }
  278. public void WriteData()
  279. {
  280. if (DataBus.Entitys.Count > 0)
  281. {
  282. DataBus.Entitys.TryDequeue(out var entity);
  283. entity.State = true;
  284. HKLogImport.WriteInfo("正在写入数据库,当前数据:" + entity.ToJson());
  285. DbContext.Context.Insertable(entity).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
  286. }
  287. }
  288. }
  289. }