|
@@ -76,10 +76,12 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public Dictionary<int, List<int>> PumpSiteNozzleNoDict { get; private set; }
|
|
|
|
|
|
- public MysqlDbContext MysqlDbContext { get; private set; }
|
|
|
+ //public MysqlDbContext MysqlDbContext { get; private set; }
|
|
|
|
|
|
public StationInfo stationInfo { get; set; }
|
|
|
|
|
|
+ public Dictionary<long,string> stationPayment = new Dictionary<long,string>();
|
|
|
+
|
|
|
public List<DetailsNozzleInfoOutput> nozzleInfoList { get; private set; }
|
|
|
|
|
|
public TcpClient? client { get; set; }
|
|
@@ -437,7 +439,7 @@ namespace HengshanPaymentTerminal
|
|
|
CommIdentity = context.Processor.Communicator.Identity;
|
|
|
_context = context;
|
|
|
|
|
|
- this.MysqlDbContext = new MysqlDbContext();
|
|
|
+ //this.MysqlDbContext = new MysqlDbContext();
|
|
|
this.httpClientUtil = new HttpClientUtils();
|
|
|
|
|
|
this.serverPort = CommIdentity.Replace("*:", "").ToInt();
|
|
@@ -706,15 +708,32 @@ namespace HengshanPaymentTerminal
|
|
|
/// </summary>
|
|
|
private async void GetInfo()
|
|
|
{
|
|
|
- Edge.Core.Domain.FccStationInfo.FccStationInfo? fccStationInfo = MysqlDbContext.FccStationInfos.FirstOrDefault();
|
|
|
- if(fccStationInfo != null) stationInfo = new StationInfo(fccStationInfo);
|
|
|
- Edge.Core.Domain.FccMachineInfo.FccMachineInfo? fccMachineInfo = await MysqlDbContext.FccMachineInfos.FirstOrDefaultAsync(machine => machine.Port == serverPort);
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ Edge.Core.Domain.FccStationInfo.FccStationInfo? fccStationInfo = mysqlDbContext.FccStationInfos.FirstOrDefault();
|
|
|
+ if(fccStationInfo != null)
|
|
|
+ {
|
|
|
+ stationInfo = new StationInfo(fccStationInfo);
|
|
|
+ string paymentType = stationInfo.PaymentType;
|
|
|
+ string[] paymentGround = paymentType.Split(",");
|
|
|
+ foreach (var item in paymentGround)
|
|
|
+ {
|
|
|
+ string[] payment = item.Split("+");
|
|
|
+ if (payment.Length == 2)
|
|
|
+ {
|
|
|
+ if (long.TryParse(payment[0], out long id))
|
|
|
+ {
|
|
|
+ stationPayment.Add(id, payment[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Edge.Core.Domain.FccMachineInfo.FccMachineInfo? fccMachineInfo = await mysqlDbContext.FccMachineInfos.FirstOrDefaultAsync(machine => machine.Port == serverPort);
|
|
|
if(fccMachineInfo == null)
|
|
|
{
|
|
|
nozzleInfoList = new List<DetailsNozzleInfoOutput>();
|
|
|
} else
|
|
|
{
|
|
|
- nozzleInfoList = MysqlDbContext.NozzleInfos.Where(nozzle => nozzle.MachineId == fccMachineInfo.Id).Select(n => new DetailsNozzleInfoOutput(n)).ToList();
|
|
|
+ nozzleInfoList = mysqlDbContext.NozzleInfos.Where(nozzle => nozzle.MachineId == fccMachineInfo.Id).Select(n => new DetailsNozzleInfoOutput(n)).ToList();
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -749,7 +768,7 @@ namespace HengshanPaymentTerminal
|
|
|
case MQTT_TYPE.PAID:
|
|
|
{
|
|
|
MqttPaidRequest? mqttPaidRequest = JsonConvert.DeserializeObject<MqttPaidRequest>(mqttRequest.data);
|
|
|
- await SendActuallyPaid(mqttPaidRequest);
|
|
|
+ await SendActuallyPaid(mqttPaidRequest, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
break;
|
|
|
}
|
|
|
case MQTT_TYPE.REFUND:
|
|
@@ -826,8 +845,9 @@ namespace HengshanPaymentTerminal
|
|
|
/// 发送实付金额给油机
|
|
|
/// </summary>
|
|
|
/// <param name="orderInfo"></param>
|
|
|
- public async Task SendActuallyPaid(MqttPaidRequest? request)
|
|
|
+ public async Task SendActuallyPaid(MqttPaidRequest? request,string? userName,string? phoneNumber)
|
|
|
{
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
if (request == null)
|
|
|
{
|
|
|
logger.Error($"mqtt get paid request is null");
|
|
@@ -842,16 +862,27 @@ namespace HengshanPaymentTerminal
|
|
|
};
|
|
|
await httpClientUtil.SendRecievePaidNotice(JsonConvert.SerializeObject(onGetPaidInfo));
|
|
|
|
|
|
- FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order =>
|
|
|
+ order.NozzleNum == request.NozzleId
|
|
|
+ && order.Ttc.ToString() == request.TransactionNumber
|
|
|
+ && order.PumpCode == request.FuelItemPumpTotalizerVolume);
|
|
|
if (fccOrderInfo == null)
|
|
|
{
|
|
|
logger.Error($"[mqtt paid order notice]:can not find order by clounid:{request.Id}");
|
|
|
return;
|
|
|
}
|
|
|
+ fccOrderInfo.CloundOrderId = request.Id;
|
|
|
fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
fccOrderInfo.PaymentTime = request.TransactionTime;
|
|
|
- fccOrderInfo.PaymentStatus = 1;
|
|
|
- MysqlDbContext.SaveChanges();
|
|
|
+ if(request.PaymentMethod != null)
|
|
|
+ {
|
|
|
+ fccOrderInfo.PayType = (int)request.PaymentMethod;
|
|
|
+ fccOrderInfo.PaymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
+ }
|
|
|
+ fccOrderInfo.UserName = userName??"";
|
|
|
+ fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
+
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
//SendActuallyPaid sendActuallyPaid = new SendActuallyPaid(orderInfo.NozzleNum, orderInfo.Ttc, orderInfo.AmountPayable ?? orderInfo.Amount, getFrame(null));
|
|
|
//byte[] commandAndNozzle = { sendActuallyPaid.Handle, (byte)sendActuallyPaid.NozzleNum };
|
|
@@ -874,6 +905,7 @@ namespace HengshanPaymentTerminal
|
|
|
/// <returns></returns>
|
|
|
public async Task SendAuthorizationAsync(MqttAuthorizationRequest? request)
|
|
|
{
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
if(request == null)
|
|
|
{
|
|
|
logger.Error($"mqtt authorization request is null");
|
|
@@ -883,7 +915,7 @@ namespace HengshanPaymentTerminal
|
|
|
//添加订单到数据库
|
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
FccOrderInfo fccOrderInfo = request.ToComponent(authorizationTime);
|
|
|
- MysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
+ mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
|
|
|
//发送授权申请到油机
|
|
|
SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1,request.OriginalAmount, getFrame(null));
|
|
@@ -934,7 +966,7 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
|
|
|
|
|
|
//更新订单
|
|
|
- MysqlDbContext.SaveChanges();
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -943,6 +975,7 @@ namespace HengshanPaymentTerminal
|
|
|
/// <param name="request"></param>
|
|
|
public async Task SendUnAuthorizartion(MqttUnAhorizationRequest? request)
|
|
|
{
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
if (request == null)
|
|
|
{
|
|
|
logger.Error($"mqtt unauthorization request is null");
|
|
@@ -955,7 +988,7 @@ namespace HengshanPaymentTerminal
|
|
|
bool ttsIntResult = int.TryParse(request.TransactionNumber, out ttc);
|
|
|
if (request.AuthorizationTime == null || !ttsIntResult)
|
|
|
{
|
|
|
- FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
if(fccOrderInfo != null)
|
|
|
{
|
|
|
ttc = fccOrderInfo.Ttc;
|
|
@@ -1023,6 +1056,7 @@ namespace HengshanPaymentTerminal
|
|
|
/// <returns></returns>
|
|
|
private async Task OnRecieveOrderRefund(MqttRefundRequest? request)
|
|
|
{
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
if (request == null)
|
|
|
{
|
|
|
logger.Error($"mqtt OnRecieveOrderRefund request is null");
|
|
@@ -1036,7 +1070,7 @@ namespace HengshanPaymentTerminal
|
|
|
};
|
|
|
await httpClientUtil.SendRecieveRefundNotice(JsonConvert.SerializeObject(onGetRefundInfo));
|
|
|
|
|
|
- FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
if (fccOrderInfo == null)
|
|
|
{
|
|
|
logger.Error($"[mqtt refund order notice]:can not find order by clounid:{request.Id}");
|
|
@@ -1044,7 +1078,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
fccOrderInfo.PaymentStatus = 2;
|
|
|
- MysqlDbContext.SaveChanges();
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1298,16 +1332,17 @@ namespace HengshanPaymentTerminal
|
|
|
/// <returns></returns>
|
|
|
public FccOrderInfo UpLoadOrder(OrderFromMachine order)
|
|
|
{
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
//接收到油机发送过来的订单信息
|
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)order;
|
|
|
- string? oilName = MysqlDbContext.OilInfos.Where(oil => orderFromMachine.oilCode.Equals(oil.Code)).Select(oil => oil.Name).FirstOrDefault();
|
|
|
+ string? oilName = mysqlDbContext.OilInfos.Where(oil => orderFromMachine.oilCode.Equals(oil.Code)).Select(oil => oil.Name).FirstOrDefault();
|
|
|
FccOrderInfo orderByMessage = orderFromMachine.ToComponent(oilName);
|
|
|
|
|
|
/** 根据枪号+流水号+授权时间来确定订单,因为冷启动后流水号会从头开始计算
|
|
|
* 后支付时直接将数据库直接插入
|
|
|
* 预支付时由于是云端先创建订单,发起授权响应成功后会插入数据库,响应成功时会回复授权时间,枪号,流水号
|
|
|
*/
|
|
|
- FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos
|
|
|
.Where(order =>
|
|
|
order.NozzleNum == orderFromMachine.nozzleNum && order.Ttc == orderFromMachine.ttc
|
|
|
&& order.AuthorizationTime == orderFromMachine.dispenserTime)
|
|
@@ -1315,15 +1350,15 @@ namespace HengshanPaymentTerminal
|
|
|
if (fccOrderInfo == null)
|
|
|
{
|
|
|
logger.Info($"receive order from machine,find order from database is null");
|
|
|
- MysqlDbContext.FccOrderInfos.Add(orderByMessage);
|
|
|
- MysqlDbContext.SaveChanges();
|
|
|
+ mysqlDbContext.FccOrderInfos.Add(orderByMessage);
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
return orderByMessage;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
logger.Info($"receive order from machine,padding data right now");
|
|
|
orderFromMachine.PaddingAuthorizationOrderData(fccOrderInfo);
|
|
|
- MysqlDbContext.SaveChanges();
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
return fccOrderInfo;
|
|
|
}
|
|
|
|
|
@@ -1331,6 +1366,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
private async void CreateTransaction(FccOrderInfo fccOrderInfo)
|
|
|
{
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
@@ -1343,7 +1379,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
- MysqlDbContext.SaveChanges();
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|