|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- using HandyControl.Controls;
- using HKCardOUT.Helper;
- using HKCardOUT.Logic.Model;
- using HKControl;
- using HKLog;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using UHFHelper;
- using XExten.Advance.LinqFramework;
-
- namespace HKCardOUT.Logic.Service
- {
- public class HKCore
- {
- List<SaleLog> Commom(SaleLog input)
- {
- if (DataBus.StartDevice)
- {
-
- var checkDevice = !Main.GetInstance.GetIsSwipe(input.Location.AsInt());
- HKLogImport.WriteInfo("设备出餐状态:" + checkDevice);
- if (checkDevice) return null;
- }
- var Old = DbContext.Context.Queryable<SaleLog>()
- .Where(t => t.CardNo == input.CardNo)
- .Where(t => t.CreateTime.Year == DateTime.Now.Year)
- .Where(t => t.CreateTime.Month == DateTime.Now.Month)
- .Where(t => t.CreateTime.Day == DateTime.Now.Day).ToList();
-
- if (DataBus.Admin.Contains(input.CardNo))
- {
- return Old;
- }
- else
- {
- if (DataBus.Cancel)
- if (Old.Count > 3) return null;
- return Old;
- }
- }
-
- bool GetCardStutas(string CardNo)
- {
- var data = DbContext.Context.Queryable<CardStutas>().First(t => t.CardNo == CardNo);
- if (data == null) return false;
- if (data.Stutas != 1) return false;
- return true;
- }
- public static void AddCard(List<CardStutas> input)
- {
- var temp = DbContext.Context.Queryable<CardStutas>().Where(t => input.Select(m => m.CardNo).Contains(t.CardNo)).Distinct().ToList();
- List<CardStutas> waitUpdate = new List<CardStutas>();
- List<CardStutas> waitInsert = new List<CardStutas>();
- foreach (var item in input)
- {
- if (temp.Select(t => t.CardNo).Contains(item.CardNo))
- {
- waitUpdate.Add(item);
- }
- else
- {
- waitInsert.Add(item);
- }
- }
- if (waitUpdate.Count > 0)
- {
- waitUpdate.ForEach(t =>
- {
- DbContext.Context.Updateable<CardStutas>().SetColumns(t => t.Stutas == t.Stutas).Where(t => t.CardNo == t.CardNo).ExecuteCommand();
- });
- }
- if (waitInsert.Count > 0)
- {
- DbContext.Context.Insertable(waitInsert).CallEntityMethod(t => t.Create()).ExecuteCommand();
- }
- }
-
- /// <summary>
- /// 早上消费
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public bool DeviceSaleAM(SaleLog input)
- {
- try
- {
- if (!GetCardStutas(input.CardNo))
- {
- HKLogImport.WriteInfo($"当前卡异常,卡号:【{input.CardNo}】");
- return false;
- }
- var Old = Commom(input);
- if (Old == null) return false;
- var AMDay = Old.Where(t => t.CreateTime >= DataBus.Times.AMStartTime && t.CreateTime < DataBus.Times.AMEndTime)
- .Where(t => t.CreateTime.Year == DateTime.Now.Year)
- .Where(t => t.CreateTime.Month == DateTime.Now.Month)
- .Where(t => t.CreateTime.Day == DateTime.Now.Day)
- .Count();
- HKLogImport.WriteInfo($"卡号{input.CardNo}上午消费次数:{AMDay}");
- if (DataBus.Admin.Contains(input.CardNo))
- {
- DataBus.Entitys.Enqueue(input);
- if (DataBus.StartDevice)
- {
- DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
- {
- CardNo = input.CardNo,
- Location = input.Location
- });
- Main.GetInstance.Start(input.Location.AsInt());
- HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
- }
- return true;
- }
- else if (AMDay < DataBus.Count)
- {
- DataBus.Entitys.Enqueue(input);
- if (DataBus.StartDevice)
- {
- DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
- {
- CardNo = input.CardNo,
- Location = input.Location
- });
- Main.GetInstance.Start(input.Location.AsInt());
- HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
- }
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- HKLog.HKLogImport.WriteError(ex);
- return false;
- }
-
- }
- /// <summary>
- /// 中午消费
- /// </summary>
- /// <param name="input"></param>
- /// <param name="Old"></param>
- /// <returns></returns>
- public bool DeviceSalePM(SaleLog input)
- {
- try
- {
- if (!GetCardStutas(input.CardNo))
- {
- HKLogImport.WriteInfo($"当前卡异常,卡号:【{input.CardNo}】");
- return false;
- }
- var Old = Commom(input);
- if (Old == null) return false;
- var PMDay = Old.Where(t => t.CreateTime >= DataBus.Times.PMStartTime && t.CreateTime < DataBus.Times.PMEndTime).
- Where(t => t.CreateTime.Year == DateTime.Now.Year)
- .Where(t => t.CreateTime.Month == DateTime.Now.Month)
- .Where(t => t.CreateTime.Day == DateTime.Now.Day)
- .Count();
- HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}中午消费次数:{PMDay}");
- if (DataBus.Admin.Contains(input.CardNo))
- {
- DataBus.Entitys.Enqueue(input);
- if (DataBus.StartDevice)
- {
- DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
- {
- CardNo = input.CardNo,
- Location = input.Location
- });
- Main.GetInstance.Start(input.Location.AsInt());
- HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
- }
- return true;
- }
- else if (PMDay < DataBus.Count)
- {
- DataBus.Entitys.Enqueue(input);
- if (DataBus.StartDevice)
- {
- DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
- {
- CardNo = input.CardNo,
- Location = input.Location
- });
- Main.GetInstance.Start(input.Location.AsInt());
- HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
- }
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- HKLog.HKLogImport.WriteError(ex);
- return false;
- }
-
- }
- /// <summary>
- /// 晚上
- /// </summary>
- /// <param name="input"></param>
- /// <param name="Old"></param>
- /// <returns></returns>
- public bool DeviceSaleAT(SaleLog input)
- {
- try
- {
- if (!GetCardStutas(input.CardNo))
- {
- HKLogImport.WriteInfo($"当前卡异常,卡号:【{input.CardNo}】");
- return false;
- }
- var Old = Commom(input);
- if (Old == null) return false;
- var ATDay = Old.Where(t => t.CreateTime >= DataBus.Times.ATStartTime && t.CreateTime < DataBus.Times.ATEndTime)
- .Where(t => t.CreateTime.Year == DateTime.Now.Year)
- .Where(t => t.CreateTime.Month == DateTime.Now.Month)
- .Where(t => t.CreateTime.Day == DateTime.Now.Day)
- .Count();
- HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}下午消费次数:{ATDay}");
- if (DataBus.Admin.Contains(input.CardNo))
- {
- DataBus.Entitys.Enqueue(input);
-
- if (DataBus.StartDevice)
- {
- DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
- {
- CardNo = input.CardNo,
- Location = input.Location
- });
- Main.GetInstance.Start(input.Location.AsInt());
- HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
- }
- return true;
- }
- else if (ATDay < DataBus.Count)
- {
- DataBus.Entitys.Enqueue(input);
- if (DataBus.StartDevice)
- {
- DataBus.saleLogDtos.Enqueue(new DTO.SaleLogDto
- {
- CardNo = input.CardNo,
- Location = input.Location
- });
- Main.GetInstance.Start(input.Location.AsInt());
- HKLogImport.WriteInfo($"设备位置:{input.Location},卡号:{input.CardNo},成功出餐");
- }
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- HKLog.HKLogImport.WriteError(ex);
- return false;
- }
- }
- /// <summary>
- /// 获取当天消费前100条展示
- /// </summary>
- /// <returns></returns>
- public Dictionary<string, int> PullDaySaleLog(int[] screen)
- {
- // var today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
- // var count = DbContext.Context.Queryable<SaleLog>().Where(t => t.CreateTime >= today)
- // .WhereIF(screen == 0, t => t.Location == "3" || t.Location == "4")
- // .WhereIF(screen == 1, t => t.Location == "1" || t.Location == "2")
- // .WhereIF(screen ==2, t => t.Location == "5" || t.Location == "6").Select(t => t.Location).ToList();
- //return count.GroupBy(t => t).ToDictionary(t => t.Key, t => t.Count());
- string a = screen[0].ToString();
- string b = screen[1].ToString();
- var today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
- var count = DbContext.Context.Queryable<SaleLog>().Where(t => t.CreateTime >= today)
- .WhereIF(screen.Length == 2, t => t.Location == a || t.Location == b).Select(t => t.Location).ToList();
- return count.GroupBy(t => t).ToDictionary(t => t.Key, t => t.Count());
- }
-
- public void WriteData()
- {
- if (DataBus.Entitys.Count > 0)
- {
- DataBus.Entitys.TryDequeue(out var entity);
- entity.State = true;
- HKLogImport.WriteInfo("正在写入数据库,当前数据:" + entity.ToJson());
- DbContext.Context.Insertable(entity).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
- }
- }
- }
- }
|