|
- using DTO;
- using HKCardOUT.Helper;
- using HKCardOUT.Logic.Model;
- using HKCardOUT.Logic.Service;
- using HKLib.Dto;
- using Logic.RemoteModel;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Markup;
- using UHFHelper;
- using XExten.Advance.HttpFramework.MultiCommon;
- using XExten.Advance.HttpFramework.MultiFactory;
- using XExten.Advance.LinqFramework;
- using XExten.Advance.StaticFramework;
-
- namespace HKCardOUT.Logic
- {
- public class RemoteService
- {
- private static readonly object locker = new();
- /// <summary>
- /// 获取所有卡状态和卡号
- /// </summary>
- /// <param name="input"></param>
- public static int GetCardStuatas()
- {
- var res = IHttpMultiClient.HttpMulti.AddNode(t =>
- {
- t.NodePath = ApiRoute.CheckCardStatus;
- t.ReqType = MultiType.GET;
- }).Build().RunStringFirst();
- var data = res.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<CardInfo>>();
- var entity = data.Select(t => new CardStutas
- {
- CardNo = t.CardNum,
- Stutas = t.State
- }).ToList();
- HKCore.AddCard(entity);
- return data != null ? data.ToString().AsInt() : 0;
- }
- /// <summary>
- /// 同步时间段
- /// </summary>
- public static void SyncTime()
- {
- /*
- {"statusCode":200,"data":{"isSuccess":true,"msg":null,"data":{"amStartTime":"17:50","amEndTime":"17:50","pmStartTime":"17:50","pmEndTime":"17:50","atStartTime":"17:50","atEndTime":"17:50"}},"succeeded":true,"errors":null,"extras":null,"timestamp":1665654784093}
- */
- var data = IHttpMultiClient.HttpMulti.AddNode(t =>
- {
- t.NodePath = ApiRoute.GetTime;
- t.ReqType = MultiType.GET;
- }).Build().RunStringFirst();
- DataBus.Times = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
- }
-
- /// <summary>
- /// 同步消费记录
- /// </summary>
- /// <param name="CardNo"></param>
- /// <param name="Money"></param>
- public static bool SyncSaleLog(string CardNo, string StallId)
- {
- try
- {
- var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId;
- var data = IHttpMultiClient.HttpMulti.AddNode(t =>
- {
- t.ReqType = MultiType.POST;
- t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson();
- t.NodePath = ApiRoute.SyncSaleLog;
- }).Build().RunStringFirst();
- HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}");
- return bool.Parse(data.ToModel<JObject>()["data"].ToString());
- }
- catch (Exception ex)
- {
- HKLog.HKLogImport.WriteError(ex);
- return false;
- }
-
- }
- /// <summary>
- /// 批量同步同步消费记录
- /// </summary>
- /// <returns></returns>
- public static bool SyncSaleLogList(List<SaleDto> dto)
- {
- try
- {
- lock (locker)
- {
- var Ids = dto.Select(t => t.Id).ToList();
- var check = DbContext.Context.Queryable<SaleLog>().Where(t => Ids.Contains(t.Id)).Any(t => t.IsSync);
- if (check) return false;
- var data = IHttpMultiClient.HttpMulti.AddHeader(t =>
- {
- t.HeaderKey = "TenantId";
- t.HeaderValue = DataBus.TenantId;
- }).AddNode(t =>
- {
- t.ReqType = MultiType.POST;
- t.JsonParam = dto.ToJson();
- t.NodePath = ApiRoute.SyncSaleLogList;
- }).Build().RunStringFirst();
- HKLog.HKLogImport.WriteInfo($"批量同步同步消费记录调用:{data}");
- return bool.Parse(data.ToModel<JObject>()["data"].ToString());
- }
- }
- catch (Exception ex)
- {
- HKLog.HKLogImport.WriteError(ex);
- return false;
- }
-
-
- }
- /// <summary>
- /// 获取店铺信息
- /// </summary>
- public static void PullShopInfo()
- {
- if (DataBus.NetWordState)
- {
- var data = IHttpMultiClient.HttpMulti.AddNode(t =>
- {
- t.NodePath = ApiRoute.PullShopInfo;
- }).Build().RunStringFirst()
- .ToModel<JObject>()["data"].ToJson().ToModel<StoreInfoResponse>();
- DataBus.StoreInfo = data;
- var storeinfo = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json"));
- SyncStatic.WriteFile(Encoding.UTF8.GetBytes(data.ToJson()), storeinfo);
- }
- else
- {
- DataBus.StoreInfo = SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json")).ToModel<StoreInfoResponse>();
- }
- }
- }
- }
|