2021-07-31 22:27:59 +05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using Newtonsoft;
|
2021-07-30 14:49:24 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-07-31 22:27:59 +05:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NLog;
|
|
|
|
|
using DataClient.Struct;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using ApiServer.ApiStruct;
|
2021-07-30 14:49:24 +05:00
|
|
|
|
|
|
|
|
|
namespace ApiServer.Controllers
|
|
|
|
|
{
|
2021-07-31 22:27:59 +05:00
|
|
|
|
[ApiController, Route("[controller]")]
|
2021-07-30 14:49:24 +05:00
|
|
|
|
public class PasportController : ControllerBase
|
|
|
|
|
{
|
2021-07-31 22:27:59 +05:00
|
|
|
|
private Logger log = LogManager.GetCurrentClassLogger();
|
2021-08-01 19:48:09 +05:00
|
|
|
|
|
2021-07-31 22:27:59 +05:00
|
|
|
|
[HttpPost, Route("check")]
|
2021-08-01 19:48:09 +05:00
|
|
|
|
public PasportCheckClient Check([FromBody] object value)
|
2021-07-30 14:49:24 +05:00
|
|
|
|
{
|
2021-07-31 22:27:59 +05:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-08-01 19:48:09 +05:00
|
|
|
|
var getResult = JsonConvert.DeserializeObject<PasportCheckApi>(value.ToString());
|
|
|
|
|
if (!getResult.Status || string.IsNullOrEmpty(getResult.Name))
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Wrong answer.");
|
|
|
|
|
return new PasportCheckClient();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 22:27:59 +05:00
|
|
|
|
var paspName =
|
2021-08-01 19:48:09 +05:00
|
|
|
|
getResult.DateAndTime.Hour.ToString("D2") +
|
|
|
|
|
getResult.DateAndTime.Minute.ToString("D2") +
|
|
|
|
|
getResult.DateAndTime.Second.ToString("D2") +
|
|
|
|
|
"-" + getResult.Name;
|
2021-07-31 22:27:59 +05:00
|
|
|
|
var paspDir = Path.Combine(
|
|
|
|
|
Directory.GetCurrentDirectory(),
|
|
|
|
|
"data", "pasport",
|
2021-08-01 19:48:09 +05:00
|
|
|
|
getResult.DateAndTime.Year.ToString("D4"),
|
|
|
|
|
getResult.DateAndTime.Month.ToString("D2"),
|
|
|
|
|
getResult.DateAndTime.Day.ToString("D2"),
|
2021-07-31 22:27:59 +05:00
|
|
|
|
paspName);
|
2021-08-01 19:48:09 +05:00
|
|
|
|
log.Info("Search pasport: " + paspDir);
|
2021-07-31 22:27:59 +05:00
|
|
|
|
if (!System.IO.File.Exists(paspDir))
|
2021-08-01 19:48:09 +05:00
|
|
|
|
{
|
|
|
|
|
log.Info("Psport not exist: " + paspDir);
|
|
|
|
|
return new PasportCheckClient { Status = true, Exist = false, PaspSum = 0 };
|
|
|
|
|
}
|
|
|
|
|
var pasport = System.IO.File.ReadAllBytes(paspDir);
|
|
|
|
|
ulong paspResult = 0;
|
|
|
|
|
foreach (var b in pasport)
|
|
|
|
|
paspResult += b;
|
|
|
|
|
log.Info("Send pasport size: " + paspResult + " | " + paspDir);
|
|
|
|
|
return new PasportCheckClient { Status = true, Exist = true, PaspSum = paspResult };
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Warn(e);
|
|
|
|
|
return new PasportCheckClient();
|
2021-07-31 22:27:59 +05:00
|
|
|
|
}
|
2021-07-30 14:49:24 +05:00
|
|
|
|
}
|
2021-07-31 22:27:59 +05:00
|
|
|
|
|
|
|
|
|
[HttpPost, Route("create")]
|
2021-08-01 19:48:09 +05:00
|
|
|
|
public PasportCreateClient Create([FromBody] object value)
|
2021-07-31 22:27:59 +05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-08-01 19:48:09 +05:00
|
|
|
|
var getResult = JsonConvert.DeserializeObject<PasportCreateApi>(value.ToString());
|
|
|
|
|
if (!getResult.Status ||
|
|
|
|
|
getResult.Pasp == null ||
|
|
|
|
|
!getResult.Pasp.HasData)
|
|
|
|
|
{
|
|
|
|
|
log.Warn("Wrong answer.");
|
|
|
|
|
return new PasportCreateClient();
|
|
|
|
|
}
|
2021-07-31 22:27:59 +05:00
|
|
|
|
var paspName =
|
2021-08-01 19:48:09 +05:00
|
|
|
|
getResult.Pasp.dEnd.Value.Hour.ToString("D2") +
|
|
|
|
|
getResult.Pasp.dEnd.Value.Minute.ToString("D2") +
|
|
|
|
|
getResult.Pasp.dEnd.Value.Second.ToString("D2") +
|
|
|
|
|
"-" + (string.IsNullOrEmpty(getResult.Pasp.nplav) ?
|
|
|
|
|
getResult.Pasp.numVDP.Value.ToString("D2") :
|
|
|
|
|
getResult.Pasp.nplav);
|
2021-07-31 22:27:59 +05:00
|
|
|
|
var dir = Path.Combine(
|
|
|
|
|
Directory.GetCurrentDirectory(),
|
|
|
|
|
"data", "pasport",
|
2021-08-01 19:48:09 +05:00
|
|
|
|
getResult.Pasp.dEnd.Value.Year.ToString("D4"),
|
|
|
|
|
getResult.Pasp.dEnd.Value.Month.ToString("D2"),
|
|
|
|
|
getResult.Pasp.dEnd.Value.Day.ToString("D2"));
|
2021-07-31 22:27:59 +05:00
|
|
|
|
var paspDir = Path.Combine(dir, paspName);
|
|
|
|
|
if (!Directory.Exists(dir))
|
|
|
|
|
Directory.CreateDirectory(dir);
|
2021-08-01 19:48:09 +05:00
|
|
|
|
System.IO.File.WriteAllBytes(paspDir, getResult.Pasp.PaspByte);
|
|
|
|
|
log.Info("Save pasport: " + paspDir);
|
|
|
|
|
return new PasportCreateClient { Status = true };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Warn(e);
|
|
|
|
|
return new PasportCreateClient();
|
2021-07-31 22:27:59 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-12 15:00:41 +05:00
|
|
|
|
|
|
|
|
|
[HttpPost, Route("getlist")]
|
|
|
|
|
public PasportGetListClient GetList([FromBody] object value)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var pasportNameList = new List<string>();
|
2024-09-22 04:27:05 +05:00
|
|
|
|
var pasportTimeList = new List<string>();
|
|
|
|
|
var getResult = JsonConvert.DeserializeObject<PasportGetListApi>(
|
|
|
|
|
value.ToString(),
|
|
|
|
|
new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
|
|
|
|
|
log.Info("Ask pasport list: " + getResult.Date.ToString("yyyy-MM-dd"));
|
2021-11-12 15:00:41 +05:00
|
|
|
|
var pasportDir = Path.Combine(
|
|
|
|
|
Directory.GetCurrentDirectory(),
|
|
|
|
|
"data",
|
|
|
|
|
"pasport",
|
|
|
|
|
getResult.Date.Year.ToString("D4"),
|
2024-09-22 04:27:05 +05:00
|
|
|
|
getResult.Date.Month.ToString("D2"),
|
2021-11-12 15:00:41 +05:00
|
|
|
|
getResult.Date.Day.ToString("D2")
|
|
|
|
|
);
|
|
|
|
|
if (!Directory.Exists(pasportDir))
|
2024-09-22 04:27:05 +05:00
|
|
|
|
throw new Exception("Directory not exist: " + pasportDir);
|
2021-11-12 15:00:41 +05:00
|
|
|
|
var allPasportFiles = Directory.GetFiles(pasportDir);
|
|
|
|
|
foreach (var fullPasportName in allPasportFiles)
|
|
|
|
|
{
|
|
|
|
|
var name = Path.GetFileNameWithoutExtension(fullPasportName);
|
|
|
|
|
var pasportParts = name.Split('-');
|
|
|
|
|
var pasport = "";
|
|
|
|
|
for (var i = 1; i < pasportParts.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (pasport.Length != 0)
|
|
|
|
|
pasport += "-";
|
|
|
|
|
pasport += pasportParts[i];
|
|
|
|
|
}
|
2024-09-22 04:27:05 +05:00
|
|
|
|
pasportTimeList.Add(pasportParts[0]);
|
2021-11-12 15:00:41 +05:00
|
|
|
|
pasportNameList.Add(pasport);
|
|
|
|
|
}
|
|
|
|
|
log.Info("Send pasport list: " + pasportNameList);
|
2024-09-22 04:27:05 +05:00
|
|
|
|
return new PasportGetListClient()
|
|
|
|
|
{
|
|
|
|
|
Name = pasportNameList.ToArray(),
|
|
|
|
|
Time = pasportTimeList.ToArray()
|
|
|
|
|
};
|
2021-11-12 15:00:41 +05:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Warn(e);
|
|
|
|
|
return new PasportGetListClient();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-22 04:27:05 +05:00
|
|
|
|
[HttpPost, Route("getpasport")]
|
|
|
|
|
public PasportGetPasportClient GetPasport([FromBody] object value)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var getResult = JsonConvert.DeserializeObject<PasportGetPasportApi>(
|
|
|
|
|
value.ToString(),
|
|
|
|
|
new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
|
|
|
|
|
log.Info("Ask pasport: " + getResult.Date.ToString("yyyy-MM-dd") + " " + getResult.Name);
|
|
|
|
|
var pasportFile = Path.Combine(
|
|
|
|
|
Directory.GetCurrentDirectory(),
|
|
|
|
|
"data",
|
|
|
|
|
"pasport",
|
|
|
|
|
getResult.Date.Year.ToString("D4"),
|
|
|
|
|
getResult.Date.Month.ToString("D2"),
|
|
|
|
|
getResult.Date.Day.ToString("D2"),
|
|
|
|
|
getResult.Name
|
|
|
|
|
);
|
|
|
|
|
if (!System.IO.File.Exists(pasportFile))
|
|
|
|
|
throw new Exception("File not exist: " + pasportFile);
|
|
|
|
|
var pasport = new Pasport(System.IO.File.ReadAllBytes(pasportFile));
|
|
|
|
|
return new PasportGetPasportClient()
|
|
|
|
|
{
|
|
|
|
|
HasData = pasport.HasData,
|
|
|
|
|
NumVDP = pasport.numVDP,
|
|
|
|
|
DStart = pasport.dStart.HasValue ? pasport.dStart.Value.ToString("yyyy.MM.dd HH:mm:ss") : "",
|
|
|
|
|
DEnd = pasport.dEnd.HasValue ? pasport.dEnd.Value.ToString("yyyy.MM.dd HH:mm:ss") : "",
|
|
|
|
|
|
|
|
|
|
HasPasport = pasport.hasPasport,
|
|
|
|
|
Kod_npl = pasport.kod_npl,
|
|
|
|
|
Nplav = pasport.nplav,
|
|
|
|
|
Rm = pasport.rm,
|
|
|
|
|
Splav = pasport.splav,
|
|
|
|
|
IS = pasport.iS,
|
|
|
|
|
Notd = pasport.notd,
|
|
|
|
|
Vessl = pasport.vessl,
|
|
|
|
|
Diam = pasport.diam,
|
|
|
|
|
Prpl = pasport.prpl,
|
|
|
|
|
Tin = pasport.tin,
|
|
|
|
|
Dzap = pasport.dzap,
|
|
|
|
|
Dlog = pasport.dlog,
|
|
|
|
|
Last = pasport.last,
|
|
|
|
|
Dlper = pasport.dlper,
|
|
|
|
|
Nazn = pasport.nazn,
|
|
|
|
|
Kompl = pasport.kompl,
|
|
|
|
|
Izl = pasport.izl,
|
|
|
|
|
Robm = pasport.robm,
|
|
|
|
|
Rizol = pasport.rizol,
|
|
|
|
|
Dkr = pasport.dkr,
|
|
|
|
|
Nkon = pasport.nkon,
|
|
|
|
|
Pos = pasport.pos,
|
|
|
|
|
Ukaz = pasport.ukaz,
|
|
|
|
|
Zakaz = pasport.zakaz,
|
|
|
|
|
Kat = pasport.kat,
|
|
|
|
|
Pril = pasport.pril,
|
|
|
|
|
Rezerved = pasport.rezerved,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Warn(e);
|
|
|
|
|
return new PasportGetPasportClient()
|
|
|
|
|
{
|
|
|
|
|
HasData = false,
|
|
|
|
|
HasPasport = false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 22:27:59 +05:00
|
|
|
|
|
2021-07-30 14:49:24 +05:00
|
|
|
|
}
|
2021-07-31 22:27:59 +05:00
|
|
|
|
|
2021-07-30 14:49:24 +05:00
|
|
|
|
}
|