Skip to content

Commit

Permalink
biz lic printing (#1418)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- spdbt-2611(Bc MailPlus, openshift provide Biz license printing api for
Dynamics.)
  • Loading branch information
esdd1995 authored Sep 18, 2024
2 parents 220a811 + b97cf8a commit 80eae9e
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Spd.Manager.Printing/Configurer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void Configure(ConfigurationContext configurationServices)
configurationServices.Services.AddScoped<IDocumentTransformStrategy, FingerprintLetterTransformStrategy>();
configurationServices.Services.AddScoped<IDocumentTransformStrategy, PersonalLicencePreviewTransformStrategy>();
configurationServices.Services.AddScoped<IDocumentTransformStrategy, PersonalLicencePrintingTransformStrategy>();
configurationServices.Services.AddScoped<IDocumentTransformStrategy, BizLicencePrintingTransformStrategy>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using AutoMapper;
using Spd.Resource.Repository;
using Spd.Resource.Repository.Biz;
using Spd.Resource.Repository.Licence;
using Spd.Resource.Repository.PersonLicApplication;
using Spd.Resource.Repository.ServiceTypes;
using Spd.Resource.Repository.WorkerLicenceCategory;
using Spd.Utilities.Printing.BCMailPlus;
using Spd.Utilities.Shared.Exceptions;
using System.Net;
using System.Text.Json.Serialization;

namespace Spd.Manager.Printing.Documents.TransformationStrategies;

internal class BizLicencePrintingTransformStrategy(
ILicenceRepository licRepository,
IServiceTypeRepository serviceTypeRepository,
IWorkerLicenceCategoryRepository workerLicenceCategoryRepository,
IBizRepository bizRepository,
IMapper mapper)
: BcMailPlusTransformStrategyBase<BizLicencePrintingTransformRequest, BizLicencePrintingJson>(Jobs.BusinessLicense)
{
protected override async Task<BizLicencePrintingJson> CreateDocument(BizLicencePrintingTransformRequest request, CancellationToken cancellationToken)
{
LicenceListResp lics = await licRepository.QueryAsync(new LicenceQry() { LicenceId = request.LicenceId }, cancellationToken);
if (lics == null || !lics.Items.Any())
throw new ApiException(HttpStatusCode.BadRequest, "No licence found for the licenceId");
LicenceResp lic = lics.Items.First();
if (lic.WorkerLicenceTypeCode != WorkerLicenceTypeEnum.SecurityBusinessLicence)
throw new ApiException(HttpStatusCode.BadRequest, "The licence is not a business licence.");

BizLicencePrintingJson bizLicJson = mapper.Map<BizLicencePrintingJson>(lic);
var serviceTypeListResp = await serviceTypeRepository.QueryAsync(
new ServiceTypeQry(null, Enum.Parse<ServiceTypeEnum>(bizLicJson.LicenceType)), cancellationToken);
bizLicJson.LicenceType = serviceTypeListResp.Items.First().ServiceTypeName;
if (lic.WorkerLicenceTypeCode == WorkerLicenceTypeEnum.SecurityBusinessLicence)
bizLicJson.LicenceCategories = await GetCategoryNamesAsync(lic.CategoryCodes, cancellationToken);

BizResult? biz = await bizRepository.GetBizAsync((Guid)lic.LicenceHolderId, cancellationToken);
mapper.Map(biz, bizLicJson);

return bizLicJson;
}

private async Task<IEnumerable<string>> GetCategoryNamesAsync(IEnumerable<WorkerCategoryTypeEnum> categoryTypeEnums, CancellationToken ct)
{
List<string> names = new();
foreach (WorkerCategoryTypeEnum categoryTypeEnum in categoryTypeEnums)
{
var listResult = await workerLicenceCategoryRepository.QueryAsync(
new WorkerLicenceCategoryQry(null, categoryTypeEnum),
ct);
names.Add(listResult.Items.First().WorkerCategoryTypeName);
}
return names;
}
}

public record BizLicencePrintingTransformRequest(Guid LicenceId) : DocumentTransformRequest;

public record BizLicencePrintingJson
{
[JsonPropertyName("licenceNumber")]
public string LicenceNumber { get; set; } = null!;

[JsonPropertyName("licenceType")]
public string LicenceType { get; set; } = null!; //Armoured Vehicle Permit, Body Armour Permit, Security Worker Licence, Security Business Licence

[JsonPropertyName("photo")]
public string Photo { get; set; } = null!; //only apply to personal licence, no photo for biz licence

[JsonPropertyName("licenceCategories")]
public IEnumerable<string> LicenceCategories { get; set; } = Enumerable.Empty<string>();//["Security Guard", "Locksmith"], only has value for swl and biz licence

[JsonPropertyName("applicantName")]
public string ApplicantName { get; set; } = null!; //we guess it is biz legal name

[JsonPropertyName("doingBusinessAsName")]
public string? DoingBusinessAsName { get; set; } //only apply to biz licence

[JsonPropertyName("issuedDate")]
public string? IssuedDate { get; set; } //yyyy-MM-dd

[JsonPropertyName("expiryDate")]
public string? ExpiryDate { get; set; } //yyyy-MM-dd

[JsonPropertyName("mailingAddress1")]
public string? MailingAddress1 { get; set; }

[JsonPropertyName("mailingAddress2")]
public string? MailingAddress2 { get; set; }

[JsonPropertyName("city")]
public string? City { get; set; }

[JsonPropertyName("provinceState")]
public string? ProvinceState { get; set; }

[JsonPropertyName("postalCode")]
public string? PostalCode { get; set; }

[JsonPropertyName("country")]
public string? Country { get; set; }

[JsonPropertyName("branchOffices")]
public IEnumerable<BranchAddress> BranchOffices { get; set; } = Enumerable.Empty<BranchAddress>(); //only apply to biz licence

[JsonPropertyName("conditions")]
public IEnumerable<string> Conditions { get; set; } = Enumerable.Empty<string>(); //only apply to personal licence, no conditions for biz licence

[JsonPropertyName("SPD_CARD")]
public SPD_CARD? SPD_CARD { get; set; } //only apply to personal licence, no spd_card for biz licence
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Spd.Resource.Repository.Application;
using Spd.Resource.Repository.Biz;
using Spd.Resource.Repository.Contact;
using Spd.Resource.Repository.Licence;
using Spd.Resource.Repository.Org;
Expand Down Expand Up @@ -67,6 +68,40 @@ public Mappings()
.ForMember(d => d.Height, opt => opt.MapFrom(s => GetHeightStr(s)))
.ForMember(d => d.Weight, opt => opt.MapFrom(s => GetWeightStr(s)))
.ForMember(d => d.CardType, opt => opt.MapFrom(s => "SECURITY-WORKER-AND-ARMOUR"));

CreateMap<LicenceResp, BizLicencePrintingJson>()
.ForMember(d => d.ApplicantName, opt => opt.Ignore())
.ForMember(d => d.LicenceNumber, opt => opt.MapFrom(s => s.LicenceNumber))
.ForMember(d => d.LicenceType, opt => opt.MapFrom(s => s.WorkerLicenceTypeCode))
.ForMember(d => d.IssuedDate, opt => opt.MapFrom(s => DateTime.Now.ToString("yyyy-MM-dd")))
.ForMember(d => d.ExpiryDate, opt => opt.MapFrom(s => s.ExpiryDate.ToString("yyyy-MM-dd")))
.ForMember(d => d.LicenceCategories, opt => opt.MapFrom(s => s.CategoryCodes));

CreateMap<BizResult, BizLicencePrintingJson>()
.ForMember(d => d.ApplicantName, opt => opt.MapFrom(s => s.BizLegalName))
.ForMember(d => d.LicenceNumber, opt => opt.Ignore())
.ForMember(d => d.LicenceType, opt => opt.Ignore())
.ForMember(d => d.IssuedDate, opt => opt.Ignore())
.ForMember(d => d.ExpiryDate, opt => opt.Ignore())
.ForMember(d => d.Photo, opt => opt.Ignore())
.ForMember(d => d.Conditions, opt => opt.Ignore())
.ForMember(d => d.LicenceCategories, opt => opt.Ignore())
.ForMember(d => d.DoingBusinessAsName, opt => opt.MapFrom(s => s.BizName))
.ForMember(d => d.MailingAddress1, opt => opt.MapFrom(s => s.MailingAddress == null ? null : s.MailingAddress.AddressLine1))
.ForMember(d => d.MailingAddress2, opt => opt.MapFrom(s => s.MailingAddress == null ? null : s.MailingAddress.AddressLine2))
.ForMember(d => d.City, opt => opt.MapFrom(s => s.MailingAddress == null ? null : s.MailingAddress.City))
.ForMember(d => d.ProvinceState, opt => opt.MapFrom(s => s.MailingAddress == null ? null : s.MailingAddress.Province))
.ForMember(d => d.Country, opt => opt.MapFrom(s => s.MailingAddress == null ? null : s.MailingAddress.Country))
.ForMember(d => d.PostalCode, opt => opt.MapFrom(s => s.MailingAddress == null ? null : s.MailingAddress.PostalCode))
.ForMember(d => d.BranchOffices, opt => opt.MapFrom(s => s.BranchAddresses));

CreateMap<BranchAddr, BranchAddress>()
.ForMember(d => d.MailingAddress1, opt => opt.MapFrom(s => s.AddressLine1))
.ForMember(d => d.MailingAddress2, opt => opt.MapFrom(s => s.AddressLine2))
.ForMember(d => d.City, opt => opt.MapFrom(s => s.City))
.ForMember(d => d.ProvinceState, opt => opt.MapFrom(s => s.Province))
.ForMember(d => d.Country, opt => opt.MapFrom(s => s.Country))
.ForMember(d => d.PostalCode, opt => opt.MapFrom(s => s.PostalCode));
}

private string GetHeightStr(LicenceApplicationResp resp)
Expand Down
6 changes: 5 additions & 1 deletion src/Spd.Manager.Printing/PrintingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ private static DocumentTransformRequest CreateDocumentTransformRequest(EventResp
if (eventResp.EventTypeEnum == EventTypeEnum.BCMPBodyArmourPermitPrinting && (eventResp.RegardingObjectId == null || eventResp.RegardingObjectName != "spd_licence"))
throw new ApiException(System.Net.HttpStatusCode.BadRequest, "LicenceId cannot be null if it is BCMPBodyArmourPermitPrinting");

if (eventResp.EventTypeEnum == EventTypeEnum.BCMPBusinessLicencePrinting && (eventResp.RegardingObjectId == null || eventResp.RegardingObjectName != "spd_licence"))
throw new ApiException(System.Net.HttpStatusCode.BadRequest, "LicenceId cannot be null if it is BCMPBusinessLicencePrinting");

return eventResp.EventTypeEnum switch
{
EventTypeEnum.BCMPScreeningFingerprintPrinting => new FingerprintLetterTransformRequest((Guid)eventResp.RegardingObjectId),
EventTypeEnum.BCMPScreeningFingerprintPrinting => new FingerprintLetterTransformRequest(eventResp.RegardingObjectId.Value),
EventTypeEnum.BCMPSecurityWorkerLicencePrinting => new PersonalLicencePrintingTransformRequest((Guid)eventResp.RegardingObjectId),
EventTypeEnum.BCMPBodyArmourPermitPrinting => new PersonalLicencePrintingTransformRequest((Guid)eventResp.RegardingObjectId),
EventTypeEnum.BCMPArmouredVehiclePermitPrinting => new PersonalLicencePrintingTransformRequest((Guid)eventResp.RegardingObjectId),
EventTypeEnum.BCMPBusinessLicencePrinting => new BizLicencePrintingTransformRequest((Guid)eventResp.RegardingObjectId),
_ => throw new NotImplementedException()
};
}
Expand Down

0 comments on commit 80eae9e

Please sign in to comment.