From b42a9bb284de4b973815827c55520c905951652f Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 4 Oct 2023 17:37:26 +0300 Subject: [PATCH] merge refactor/common --- ELT.Client/Managers/BaseManager.cs | 10 -- .../Managers/Insurance/InsuranceManager.cs | 18 --- ELT.Client/Managers/Insurance/KaskoManager.cs | 71 ----------- ELT.Client/Managers/Insurance/OsagoManager.cs | 49 -------- .../Managers/Insurance/PreRequestManager.cs | 40 ------- ELT.Client/Models/Common/Request.cs | 43 +++++++ ELT.Client/Models/Insurance/ELTPreData.cs | 11 -- ELT.Client/Models/Insurance/Preparams.cs | 13 --- .../Request/CalculateKaskoRequest.cs | 8 -- .../Request/CalculateOsagoRequest.cs | 8 -- .../Insurance/Request/CalculateRequest.cs | 9 -- ELT.sln | 6 - ELT/Controllers/CommonController.cs | 110 ++++++++++++++++++ ELT/Controllers/InsuranceController.cs | 36 ------ ELT/Properties/launchSettings.json | 10 +- 15 files changed, 159 insertions(+), 283 deletions(-) delete mode 100644 ELT.Client/Managers/BaseManager.cs delete mode 100644 ELT.Client/Managers/Insurance/InsuranceManager.cs delete mode 100644 ELT.Client/Managers/Insurance/KaskoManager.cs delete mode 100644 ELT.Client/Managers/Insurance/OsagoManager.cs delete mode 100644 ELT.Client/Managers/Insurance/PreRequestManager.cs create mode 100644 ELT.Client/Models/Common/Request.cs delete mode 100644 ELT.Client/Models/Insurance/ELTPreData.cs delete mode 100644 ELT.Client/Models/Insurance/Preparams.cs delete mode 100644 ELT.Client/Models/Insurance/Request/CalculateKaskoRequest.cs delete mode 100644 ELT.Client/Models/Insurance/Request/CalculateOsagoRequest.cs delete mode 100644 ELT.Client/Models/Insurance/Request/CalculateRequest.cs create mode 100644 ELT/Controllers/CommonController.cs delete mode 100644 ELT/Controllers/InsuranceController.cs diff --git a/ELT.Client/Managers/BaseManager.cs b/ELT.Client/Managers/BaseManager.cs deleted file mode 100644 index 9b2dead..0000000 --- a/ELT.Client/Managers/BaseManager.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace ELT.Client.Managers -{ - public class AuthInfo - { - public string Login { get; set; } - public string Password { get; set; } - } -} \ No newline at end of file diff --git a/ELT.Client/Managers/Insurance/InsuranceManager.cs b/ELT.Client/Managers/Insurance/InsuranceManager.cs deleted file mode 100644 index 9f3c628..0000000 --- a/ELT.Client/Managers/Insurance/InsuranceManager.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using ELT.Client.Models.Insurance; - -namespace ELT.Client.Managers.Insurance -{ - public abstract class InsuranceManager - { - protected AuthInfo AuthInfo => - new AuthInfo - { - Login = Environment.GetEnvironmentVariable("eltLogin"), - Password = Environment.GetEnvironmentVariable("eltPassword") - }; - - public abstract Dictionary Calculate(T1 calculateRequest, ELTPreData preRequestData); - } -} \ No newline at end of file diff --git a/ELT.Client/Managers/Insurance/KaskoManager.cs b/ELT.Client/Managers/Insurance/KaskoManager.cs deleted file mode 100644 index a0da212..0000000 --- a/ELT.Client/Managers/Insurance/KaskoManager.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ELT.Client.Models.Insurance; -using ELT.Client.Models.Insurance.Request; -using ELTKasko; - -namespace ELT.Client.Managers.Insurance -{ - public class KaskoManager : InsuranceManager - { - private readonly EltSoapClient _eltKaskoSoap; - - public KaskoManager() - { - _eltKaskoSoap = new EltSoapClient(); - } - - public override Dictionary Calculate( - CalculateKaskoRequest calculateKaskoRequest, - ELTPreData preRequestData) - { - var kaskoParams = calculateKaskoRequest.ELTParams; - kaskoParams.UsageCityKLADR = preRequestData.Kladr; - kaskoParams.Mark = preRequestData.Brand; - kaskoParams.Model = preRequestData.Model; - - if (kaskoParams.Modification != null) - kaskoParams.Modification.Name = preRequestData.Modification; - - var specialMachinery = calculateKaskoRequest.Preparams.SpecialMachinery; - specialMachinery.SpecialMachineryMark = preRequestData.Brand; - specialMachinery.SpecialMachineryModel = preRequestData.Model; - kaskoParams.SpecialMachinery = specialMachinery; - - - var result = new Dictionary(); - - var tasks = calculateKaskoRequest.CompanyIds.Distinct().Select(companyId => - new Task(() => - { - var res = _eltKaskoSoap.PreliminaryKASKOCalculation( - new ELTKasko.AuthInfo - { - Login = AuthInfo.Login, - Password = AuthInfo.Password - } - , null - , companyId - , 0 - , 0 - , null - , null - , null - , "13" - , null - , false - , null - , null - , kaskoParams); - result.Add(companyId, res); - })); - - var tasksArray = tasks as Task[] ?? tasks.ToArray(); - Parallel.ForEach(tasksArray, (t) => t.Start()); - Task.WaitAll(tasksArray.ToArray()); - - return result; - } - } -} \ No newline at end of file diff --git a/ELT.Client/Managers/Insurance/OsagoManager.cs b/ELT.Client/Managers/Insurance/OsagoManager.cs deleted file mode 100644 index 37281ef..0000000 --- a/ELT.Client/Managers/Insurance/OsagoManager.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ELT.Client.Models.Insurance; -using ELT.Client.Models.Insurance.Request; -using ELTOsago; - -namespace ELT.Client.Managers.Insurance -{ - public class OsagoManager : InsuranceManager - { - private readonly EltSoap _eltOsagoSoap; - - public OsagoManager() - { - _eltOsagoSoap = new EltSoapClient(); - } - - public override Dictionary Calculate( - CalculateOsagoRequest calculateOsagoRequest, ELTPreData preRequestData) - { - var result = new Dictionary(); - - var osagoParams = calculateOsagoRequest.ELTParams; - osagoParams.UsagePlace = preRequestData.Kladr; - osagoParams.CarInfo.Mark = preRequestData.Brand; - osagoParams.CarInfo.Model = preRequestData.Model; - osagoParams.AuthInfo = new ELTOsago.AuthInfo - { - Login = AuthInfo.Login, - Password = AuthInfo.Password - }; - - var tasks = calculateOsagoRequest.CompanyIds.Distinct().Select(companyId => new Task(() => - { - osagoParams.InsuranceCompany = companyId; - var res = _eltOsagoSoap.OSAGOFullCalculation(osagoParams); - result.Add(companyId, res); - })); - - var tasksArray = tasks as Task[] ?? tasks.ToArray(); - Parallel.ForEach(tasksArray, (t) => t.Start()); - Task.WaitAll(tasksArray.ToArray()); - - return result; - } - } -} \ No newline at end of file diff --git a/ELT.Client/Managers/Insurance/PreRequestManager.cs b/ELT.Client/Managers/Insurance/PreRequestManager.cs deleted file mode 100644 index 2487db4..0000000 --- a/ELT.Client/Managers/Insurance/PreRequestManager.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Linq; -using ELT.Client.Models.Insurance; -using ELTKasko; - -namespace ELT.Client.Managers.Insurance -{ - public class PreRequestManager - { - private readonly EltSoap _eltKaskoSoap; - - public PreRequestManager() - { - _eltKaskoSoap = new EltSoapClient(); - } - - public ELTPreData GetPreRequestData(Preparams preparams) - { - var eltPreData = new ELTPreData(); - - eltPreData.Kladr = preparams.Kladr; - //KLADR - - //CAR - var mappedCars = _eltKaskoSoap.MappedCars(new MappedCarsRequest - { - Marka = preparams.BrandId, - Model = preparams.ModelId - }); - - - eltPreData.Brand = mappedCars.Mark; - eltPreData.Model = mappedCars.Model; - if (mappedCars?.Modification?.Name != null) - eltPreData.Modification = mappedCars.Modification.Name; - //CAR - - return eltPreData; - } - } -} \ No newline at end of file diff --git a/ELT.Client/Models/Common/Request.cs b/ELT.Client/Models/Common/Request.cs new file mode 100644 index 0000000..217a124 --- /dev/null +++ b/ELT.Client/Models/Common/Request.cs @@ -0,0 +1,43 @@ +using System.ComponentModel.DataAnnotations; +using ELTKasko; +using ELTOsago; + +namespace ELT.Client.Models.Common; + +public class GetPreRequestDataInput +{ + public string Kladr { get; set; } + public string BrandId { get; set; } + public string ModelId { get; set; } + public SpecialMachinery SpecialMachinery { get; set; } +} + +public class GetPreRequestDataOutput +{ + public string Kladr { get; set; } + [Required] + public string Brand { get; set; } + [Required] + public string Model { get; set; } + public string Modification { get; set; } +} + +public class GetKaskoCalculationInput +{ + [Required] + public string CompanyId { get; set; } + [Required] + public PreliminaryKASKOCalculationParams Params { get; set; } + [Required] + public GetPreRequestDataInput Preparams { get; set; } +} + +public class GetOsagoCalculationInput +{ + [Required] + public string CompanyId { get; set; } + [Required] + public OSAGOFullCalculationRequest Params { get; set; } + [Required] + public GetPreRequestDataInput Preparams { get; set; } +} \ No newline at end of file diff --git a/ELT.Client/Models/Insurance/ELTPreData.cs b/ELT.Client/Models/Insurance/ELTPreData.cs deleted file mode 100644 index 97601c5..0000000 --- a/ELT.Client/Models/Insurance/ELTPreData.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace ELT.Client.Models.Insurance -{ - public class ELTPreData - { - public string Kladr { get; set; } - public string Brand { get; set; } - public string Model { get; set; } - - public string Modification { get; set; } - } -} \ No newline at end of file diff --git a/ELT.Client/Models/Insurance/Preparams.cs b/ELT.Client/Models/Insurance/Preparams.cs deleted file mode 100644 index ad5ec6e..0000000 --- a/ELT.Client/Models/Insurance/Preparams.cs +++ /dev/null @@ -1,13 +0,0 @@ -using ELTKasko; - -namespace ELT.Client.Models.Insurance -{ - public class Preparams - { - public string Kladr { get; set; } - public string BrandId { get; set; } - public string ModelId { get; set; } - - public SpecialMachinery SpecialMachinery { get; set; } - } -} \ No newline at end of file diff --git a/ELT.Client/Models/Insurance/Request/CalculateKaskoRequest.cs b/ELT.Client/Models/Insurance/Request/CalculateKaskoRequest.cs deleted file mode 100644 index b48b45e..0000000 --- a/ELT.Client/Models/Insurance/Request/CalculateKaskoRequest.cs +++ /dev/null @@ -1,8 +0,0 @@ -using ELTKasko; - -namespace ELT.Client.Models.Insurance.Request -{ - public class CalculateKaskoRequest : CalculateRequest - { - } -} \ No newline at end of file diff --git a/ELT.Client/Models/Insurance/Request/CalculateOsagoRequest.cs b/ELT.Client/Models/Insurance/Request/CalculateOsagoRequest.cs deleted file mode 100644 index a8eb3bd..0000000 --- a/ELT.Client/Models/Insurance/Request/CalculateOsagoRequest.cs +++ /dev/null @@ -1,8 +0,0 @@ -using ELTOsago; - -namespace ELT.Client.Models.Insurance.Request -{ - public class CalculateOsagoRequest : CalculateRequest - { - } -} \ No newline at end of file diff --git a/ELT.Client/Models/Insurance/Request/CalculateRequest.cs b/ELT.Client/Models/Insurance/Request/CalculateRequest.cs deleted file mode 100644 index 5b216d3..0000000 --- a/ELT.Client/Models/Insurance/Request/CalculateRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace ELT.Client.Models.Insurance.Request -{ - public class CalculateRequest - { - public string[] CompanyIds { get; set; } - public Preparams Preparams { get; set; } - public T ELTParams { get; set; } - } -} \ No newline at end of file diff --git a/ELT.sln b/ELT.sln index 03a47a9..d66f9d9 100644 --- a/ELT.sln +++ b/ELT.sln @@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ELT", "ELT\ELT.csproj", "{2 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ELT.Client", "ELT.Client\ELT.Client.csproj", "{9EC7C85B-FC9C-4BCE-A587-CB3B75AEE554}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ELT.Tests", "ELT.Tests\ELT.Tests.csproj", "{F86CEFE3-5F4A-4666-94E9-2BB37C83A9CB}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,10 +21,6 @@ Global {9EC7C85B-FC9C-4BCE-A587-CB3B75AEE554}.Debug|Any CPU.Build.0 = Debug|Any CPU {9EC7C85B-FC9C-4BCE-A587-CB3B75AEE554}.Release|Any CPU.ActiveCfg = Release|Any CPU {9EC7C85B-FC9C-4BCE-A587-CB3B75AEE554}.Release|Any CPU.Build.0 = Release|Any CPU - {F86CEFE3-5F4A-4666-94E9-2BB37C83A9CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F86CEFE3-5F4A-4666-94E9-2BB37C83A9CB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F86CEFE3-5F4A-4666-94E9-2BB37C83A9CB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F86CEFE3-5F4A-4666-94E9-2BB37C83A9CB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ELT/Controllers/CommonController.cs b/ELT/Controllers/CommonController.cs new file mode 100644 index 0000000..b3ee465 --- /dev/null +++ b/ELT/Controllers/CommonController.cs @@ -0,0 +1,110 @@ +using System; +using ELT.Client.Models.Common; +using ELTKasko; +using ELTOsago; +using Microsoft.AspNetCore.Mvc; +using EltKaskoSoap = ELTKasko.EltSoap; +using ELTOsagoSoap = ELTOsago.EltSoap; + +namespace ELT.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class CommonController : ControllerBase +{ + private EltKaskoSoap _eltKaskoClient = new ELTKasko.EltSoapClient(); + private ELTOsagoSoap _eltOsagoClient = new ELTOsago.EltSoapClient(); + string _login = Environment.GetEnvironmentVariable("eltLogin"); + string _password = Environment.GetEnvironmentVariable("eltPassword"); + + private GetPreRequestDataOutput GetPreRequestData([FromBody] GetPreRequestDataInput data) + { + var mappedCars = _eltKaskoClient.MappedCars(new MappedCarsRequest + { + Marka = data.BrandId, + Model = data.ModelId + }); + + return new GetPreRequestDataOutput + { + Kladr = data.Kladr, + Brand = mappedCars.Mark, + Model = mappedCars.Model, + Modification = mappedCars.Modification?.Name + }; + } + + [HttpPost("get-kasko-calculation")] + public ActionResult GetKaskoCalculation([FromBody] GetKaskoCalculationInput data) + { + var preRequestData = this.GetPreRequestData(data.Preparams); + + var request = data.Params; + request.UsageCityKLADR = preRequestData.Kladr; + request.Mark = preRequestData.Brand; + request.Model = preRequestData.Model; + + if (request.Modification != null) + request.Modification.Name = preRequestData.Modification; + + var specialMachinery = data.Preparams.SpecialMachinery; + specialMachinery.SpecialMachineryMark = preRequestData.Brand; + specialMachinery.SpecialMachineryModel = preRequestData.Model; + request.SpecialMachinery = specialMachinery; + + var res = _eltKaskoClient.PreliminaryKASKOCalculation( + new ELTKasko.AuthInfo + { + Login = _login, + Password = _password + } + , null + , data.CompanyId + , 0 + , 0 + , null + , null + , null + , "13" + , null + , false + , null + , null + , request); + + if (res?.Error is { Length: > 0 }) + { + return BadRequest(res); + } + + return Ok(res); + } + + [HttpPost("get-osago-calculation")] + public ActionResult GetOsagoCalculation([FromBody] GetOsagoCalculationInput data) + { + var prerequestData = this.GetPreRequestData(data.Preparams); + + var request = data.Params; + request.UsagePlace = prerequestData.Kladr; + request.CarInfo.Mark = prerequestData.Brand; + request.CarInfo.Model = prerequestData.Model; + + request.AuthInfo = new ELTOsago.AuthInfo + { + Login = _login, + Password = _password + }; + + request.InsuranceCompany ??= data.CompanyId; + + var res = _eltOsagoClient.OSAGOFullCalculation(data.Params); + + if (res?.Error is { Length: > 0 }) + { + return BadRequest(res); + } + + return Ok(res); + } +} \ No newline at end of file diff --git a/ELT/Controllers/InsuranceController.cs b/ELT/Controllers/InsuranceController.cs deleted file mode 100644 index 965016f..0000000 --- a/ELT/Controllers/InsuranceController.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using ELT.Client.Managers.Insurance; -using ELT.Client.Models.Insurance.Request; -using ELTKasko; -using ELTOsago; -using Microsoft.AspNetCore.Mvc; - -namespace ELT.Controllers -{ - [ApiController] - [Route("[controller]")] - public class InsuranceController : ControllerBase - { - [HttpPost("[action]")] - public ActionResult> CalculateKasko( - [FromBody] CalculateKaskoRequest calculateKaskoRequest) - { - var preRequestManager = new PreRequestManager(); - var preRequestData = preRequestManager.GetPreRequestData(calculateKaskoRequest.Preparams); - - var kaskoManager = new KaskoManager(); - return kaskoManager.Calculate(calculateKaskoRequest, preRequestData); - } - - [HttpPost("[action]")] - public ActionResult> CalculateOsago( - [FromBody] CalculateOsagoRequest calculateOsagoRequest) - { - var preRequestManager = new PreRequestManager(); - var preRequestData = preRequestManager.GetPreRequestData(calculateOsagoRequest.Preparams); - - var osagoManager = new OsagoManager(); - return osagoManager.Calculate(calculateOsagoRequest, preRequestData); - } - } -} \ No newline at end of file diff --git a/ELT/Properties/launchSettings.json b/ELT/Properties/launchSettings.json index a760566..bc7b49d 100644 --- a/ELT/Properties/launchSettings.json +++ b/ELT/Properties/launchSettings.json @@ -14,17 +14,19 @@ "launchBrowser": false, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "eltPassword": "evo12345", - "eltLogin": "dmitrienko" + "eltPassword": "123456", + "eltLogin": "Evo123" } }, "ELT": { "commandName": "Project", "launchBrowser": false, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "eltPassword": "123456", + "eltLogin": "Evo123" }, - "applicationUrl": "http://localhost:5000" + "applicationUrl": "http://localhost:2000" }, "Docker": { "commandName": "Docker",