Compare commits
1 Commits
master
...
refactor/c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
706665dd4f |
@ -1,10 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ELT.Client.Managers
|
||||
{
|
||||
public class AuthInfo
|
||||
{
|
||||
public string Login { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ELT.Client.Models.Insurance;
|
||||
|
||||
namespace ELT.Client.Managers.Insurance
|
||||
{
|
||||
public abstract class InsuranceManager<T1, T2>
|
||||
{
|
||||
protected AuthInfo AuthInfo =>
|
||||
new AuthInfo
|
||||
{
|
||||
Login = Environment.GetEnvironmentVariable("eltLogin"),
|
||||
Password = Environment.GetEnvironmentVariable("eltPassword")
|
||||
};
|
||||
|
||||
public abstract Dictionary<string, T2> Calculate(T1 calculateRequest, ELTPreData preRequestData);
|
||||
}
|
||||
}
|
||||
@ -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<CalculateKaskoRequest, KASKOCalculationResult>
|
||||
{
|
||||
private readonly EltSoapClient _eltKaskoSoap;
|
||||
|
||||
public KaskoManager()
|
||||
{
|
||||
_eltKaskoSoap = new EltSoapClient();
|
||||
}
|
||||
|
||||
public override Dictionary<string, KASKOCalculationResult> 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<string, KASKOCalculationResult>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<CalculateOsagoRequest, OSAGOFullCalculationResponse>
|
||||
{
|
||||
private readonly EltSoap _eltOsagoSoap;
|
||||
|
||||
public OsagoManager()
|
||||
{
|
||||
_eltOsagoSoap = new EltSoapClient();
|
||||
}
|
||||
|
||||
public override Dictionary<string, OSAGOFullCalculationResponse> Calculate(
|
||||
CalculateOsagoRequest calculateOsagoRequest, ELTPreData preRequestData)
|
||||
{
|
||||
var result = new Dictionary<string, OSAGOFullCalculationResponse>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
ELT.Client/Models/Common/Request.cs
Normal file
43
ELT.Client/Models/Common/Request.cs
Normal file
@ -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; }
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
using ELTKasko;
|
||||
|
||||
namespace ELT.Client.Models.Insurance.Request
|
||||
{
|
||||
public class CalculateKaskoRequest : CalculateRequest<PreliminaryKASKOCalculationParams>
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
using ELTOsago;
|
||||
|
||||
namespace ELT.Client.Models.Insurance.Request
|
||||
{
|
||||
public class CalculateOsagoRequest : CalculateRequest<OSAGOFullCalculationRequest>
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
namespace ELT.Client.Models.Insurance.Request
|
||||
{
|
||||
public class CalculateRequest<T>
|
||||
{
|
||||
public string[] CompanyIds { get; set; }
|
||||
public Preparams Preparams { get; set; }
|
||||
public T ELTParams { get; set; }
|
||||
}
|
||||
}
|
||||
6
ELT.sln
6
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
|
||||
|
||||
110
ELT/Controllers/CommonController.cs
Normal file
110
ELT/Controllers/CommonController.cs
Normal file
@ -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<KASKOCalculationResult> 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<OSAGOFullCalculationResponse> 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);
|
||||
}
|
||||
}
|
||||
@ -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<Dictionary<string, KASKOCalculationResult>> 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<Dictionary<string, OSAGOFullCalculationResponse>> CalculateOsago(
|
||||
[FromBody] CalculateOsagoRequest calculateOsagoRequest)
|
||||
{
|
||||
var preRequestManager = new PreRequestManager();
|
||||
var preRequestData = preRequestManager.GetPreRequestData(calculateOsagoRequest.Preparams);
|
||||
|
||||
var osagoManager = new OsagoManager();
|
||||
return osagoManager.Calculate(calculateOsagoRequest, preRequestData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user