Skip to content

Commit b042f04

Browse files
committed
chore: effective biz lic no
1 parent 99f8183 commit b042f04

File tree

6 files changed

+55
-17
lines changed

6 files changed

+55
-17
lines changed

server/StrDss.Api/Controllers/BizLicensesController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public async Task<ActionResult> GetUploadHistory(long? orgId, int pageSize, int
7777
//[HttpGet("process")]
7878
//public async Task<ActionResult> ProcessUpload()
7979
//{
80+
// // var info = await _bizLicenseService.GetMatchingBusinessLicenseIdAndNo(256, "X567B");
8081
// await _bizLicenseService.ProcessBizLicenseUploadAsync();
8182
// return Ok();
8283
//}

server/StrDss.Data/Mappings/ModelToEntityProfile.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public ModelToEntityProfile()
2121
.ForMember(dest => dest.PlatformListingNo, opt => opt.MapFrom(src => src.ListingId))
2222
.ForMember(dest => dest.PlatformListingUrl, opt => opt.MapFrom(src => src.ListingUrl))
2323
.ForMember(dest => dest.BusinessLicenceNo, opt => opt.MapFrom(src => src.BusLicNo))
24-
.ForMember(dest => dest.EffectiveBusinessLicenceNo, opt => opt.MapFrom(src => src.EffectiveBusinessLicenceNo))
25-
.ForMember(dest => dest.EffectiveHostNm, opt => opt.MapFrom(src => src.EffectiveHostNm))
2624
.ForMember(dest => dest.BcRegistryNo, opt => opt.MapFrom(src => src.BcRegNo))
2725
.ForMember(dest => dest.IsEntireUnit, opt => opt.MapFrom(src => src.IsEntireUnit == "Y"))
2826
.ForMember(dest => dest.AvailableBedroomsQty, opt => opt.MapFrom(src => CommonUtils.StringToShort(src.BedroomsQty)))

server/StrDss.Data/Repositories/BizLicenseRepository.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using StrDss.Common;
66
using StrDss.Data.Entities;
77
using StrDss.Model;
8+
using System.Text.RegularExpressions;
89

910
namespace StrDss.Data.Repositories
1011
{
@@ -14,7 +15,7 @@ public interface IBizLicenseRepository
1415
Task CreateBizLicTempTable();
1516
Task InsertRowToBizLicTempTable(BizLicenseRowUntyped row, long providingOrganizationId);
1617
Task ProcessBizLicTempTable();
17-
Task<long?> GetMatchingBusinessLicenseId(long orgId, string effectiveBizLicNo);
18+
Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo);
1819
}
1920

2021
public class BizLicenseRepository : RepositoryBase<DssBusinessLicence>, IBizLicenseRepository
@@ -143,13 +144,32 @@ public async Task ProcessBizLicTempTable()
143144
await _dbContext.Database.ExecuteSqlRawAsync("CALL dss_process_biz_lic_table();");
144145
}
145146

146-
public async Task<long?> GetMatchingBusinessLicenseId(long orgId, string effectiveBizLicNo)
147-
{
148-
//todo: need to use effectiveBizLicNo from the table
149-
var bizLic = await _dbSet.AsNoTracking()
150-
.FirstOrDefaultAsync(x => x.ProvidingOrganizationId == orgId && x.BusinessLicenceNo == effectiveBizLicNo);
147+
//public async Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo)
148+
//{
149+
// var license = await _dbSet.AsNoTracking()
150+
// .Where(x => x.ProvidingOrganizationId == orgId && x.BusinessLicenceNo == effectiveBizLicNo)
151+
// .Select(x => new { x.BusinessLicenceId, x.BusinessLicenceNo })
152+
// .FirstOrDefaultAsync();
153+
154+
// return license == null ? (null, null) : (license.BusinessLicenceId, CommonUtils.SanitizeAndUppercaseString(license.BusinessLicenceNo));
155+
//}
151156

152-
return bizLic == null ? null : bizLic.BusinessLicenceId;
157+
public async Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo)
158+
{
159+
// Raw SQL query using PostgreSQL regexp_replace to remove non-alphanumeric characters in the database query
160+
var sqlQuery = @"
161+
SELECT business_licence_id, business_licence_no
162+
FROM dss_business_licence
163+
WHERE providing_organization_id = @orgId
164+
AND regexp_replace(business_licence_no, '[^a-zA-Z0-9]', '', 'g') = @sanitizedBizLicNo
165+
LIMIT 1";
166+
167+
var license = await _dbContext.DssBusinessLicences
168+
.FromSqlRaw(sqlQuery, new NpgsqlParameter("orgId", orgId), new NpgsqlParameter("sanitizedBizLicNo", effectiveBizLicNo))
169+
.Select(x => new { x.BusinessLicenceId, x.BusinessLicenceNo })
170+
.FirstOrDefaultAsync();
171+
172+
return license == null ? (null, null) : (license.BusinessLicenceId, CommonUtils.SanitizeAndUppercaseString(license.BusinessLicenceNo));
153173
}
154174
}
155175
}

server/StrDss.Model/RentalReportDtos/RentalListingRowUntyped.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,5 @@ public class RentalListingRowUntyped
142142

143143
[Name("supplier_host_5_id")]
144144
public string SupplierHost5Id { get; set; } = "";
145-
public string EffectiveBusinessLicenceNo { get; set; }
146-
public string EffectiveHostNm { get; set; }
147145
}
148146
}

server/StrDss.Service/BizLicenseService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IBizLicenseService
1616
{
1717
Task<BizLicenseDto?> GetBizLicense(long businessLicenceId);
1818
Task ProcessBizLicenseUploadAsync();
19+
Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo);
1920
}
2021
public class BizLicenseService : ServiceBase, IBizLicenseService
2122
{
@@ -159,5 +160,10 @@ private void SaveUploadLine(DssUploadLine uploadLine, Dictionary<string, List<st
159160

160161
uploadLine.IsProcessed = true;
161162
}
163+
164+
public async Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo)
165+
{
166+
return await _bizLicenseRepo.GetMatchingBusinessLicenseIdAndNo(orgId, effectiveBizLicNo);
167+
}
162168
}
163169
}

server/StrDss.Service/RentalListingReportService.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ private async Task<bool> ProcessUploadLine(DssRentalListingReport report, DssUpl
224224
return false;
225225
}
226226

227-
row.EffectiveHostNm = CommonUtils.SanitizeAndUppercaseString(row.PropertyHostNm);
228-
row.EffectiveBusinessLicenceNo = CommonUtils.SanitizeAndUppercaseString(row.BusLicNo);
229-
230227
var offeringOrg = await _orgRepo.GetOrganizationByOrgCdAsync(row.OrgCd); //already validated in the file upload
231228

232229
using var tran = _unitOfWork.BeginTransaction();
@@ -417,10 +414,28 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
417414
masterListing.DerivedFromRentalListingId = listing.RentalListingId;
418415
masterListing.LocatingPhysicalAddressId = physicalAddress.PhysicalAddressId;
419416

420-
if (physicalAddress.ContainingOrganizationId != null && (masterListing.IsChangedBusinessLicence == null || masterListing.IsChangedBusinessLicence.Value == false))
417+
masterListing.EffectiveHostNm = CommonUtils.SanitizeAndUppercaseString(row.PropertyHostNm);
418+
419+
if (masterListing.IsChangedBusinessLicence == true)
420+
{
421+
// keep the original effective business licence no and id
422+
}
423+
else if (!string.IsNullOrEmpty(masterListing.BusinessLicenceNo) && physicalAddress.ContainingOrganizationId.HasValue)
424+
{
425+
var sanitizedBizLicNo = CommonUtils.SanitizeAndUppercaseString(masterListing.BusinessLicenceNo);
426+
427+
var (businessLicenceId, businessLicenceNo) = await _bizLicRepo.GetMatchingBusinessLicenseIdAndNo(
428+
physicalAddress.ContainingOrganizationId.Value,
429+
sanitizedBizLicNo
430+
);
431+
432+
masterListing.GoverningBusinessLicenceId = businessLicenceId;
433+
masterListing.EffectiveBusinessLicenceNo = businessLicenceNo ?? sanitizedBizLicNo;
434+
}
435+
else
421436
{
422-
masterListing.GoverningBusinessLicenceId
423-
= await _bizLicRepo.GetMatchingBusinessLicenseId(physicalAddress.ContainingOrganizationId.Value, row.EffectiveBusinessLicenceNo);
437+
masterListing.GoverningBusinessLicenceId = null;
438+
masterListing.EffectiveBusinessLicenceNo = string.Empty;
424439
}
425440

426441
(masterListing.NightsBookedQty, masterListing.SeparateReservationsQty) =

0 commit comments

Comments
 (0)