Skip to content

Commit 045f43b

Browse files
authored
Merge pull request #549 from bcgov/yj
Yj
2 parents 5e39633 + b042f04 commit 045f43b

File tree

6 files changed

+69
-6
lines changed

6 files changed

+69
-6
lines changed

database/ddl/STR_dss_process_biz_lic_table_Sprint_12.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ BEGIN
2222
business_owner_nm, business_owner_phone_no, business_owner_email_address_dsc, business_operator_nm,
2323
business_operator_phone_no, business_operator_email_address_dsc, infraction_txt, infraction_dt,
2424
property_zone_txt, available_bedrooms_qty, max_guests_allowed_qty,
25-
CASE WHEN is_principal_residence = 'Y' THEN TRUE ELSE FALSE END, -- Convert 'Y'/'N' to boolean
26-
CASE WHEN is_owner_living_onsite = 'Y' THEN TRUE ELSE FALSE END, -- Convert 'Y'/'N' to boolean
27-
CASE WHEN is_owner_property_tenant = 'Y' THEN TRUE ELSE FALSE END, -- Convert 'Y'/'N' to boolean
25+
is_principal_residence, is_owner_living_onsite, is_owner_property_tenant,
2826
property_folio_no, property_parcel_identifier_no, property_legal_description_txt,
2927
licence_status_type, providing_organization_id,
3028
NOW() -- Set the current timestamp for upd_dtm

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.Common/CommonUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static byte[] CreateZip(string csvContent, string fileName)
7272
return memoryStream.ToArray();
7373
}
7474

75-
static string SanitizeAndUppercaseString(string input)
75+
public static string SanitizeAndUppercaseString(string input)
7676
{
7777
if (string.IsNullOrWhiteSpace(input)) return "";
7878

server/StrDss.Data/Repositories/BizLicenseRepository.cs

Lines changed: 31 additions & 1 deletion
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,6 +15,7 @@ public interface IBizLicenseRepository
1415
Task CreateBizLicTempTable();
1516
Task InsertRowToBizLicTempTable(BizLicenseRowUntyped row, long providingOrganizationId);
1617
Task ProcessBizLicTempTable();
18+
Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo);
1719
}
1820

1921
public class BizLicenseRepository : RepositoryBase<DssBusinessLicence>, IBizLicenseRepository
@@ -93,7 +95,7 @@ INSERT INTO biz_lic_table (
9395

9496
var parameters = new List<NpgsqlParameter>
9597
{
96-
new NpgsqlParameter("@businessLicenceNo", row.BusinessLicenceNo.ToUpper()),
98+
new NpgsqlParameter("@businessLicenceNo", row.BusinessLicenceNo.Trim().ToUpper()),
9799

98100
new NpgsqlParameter("@expiryDt", NpgsqlTypes.NpgsqlDbType.Date)
99101
{
@@ -141,5 +143,33 @@ public async Task ProcessBizLicTempTable()
141143
{
142144
await _dbContext.Database.ExecuteSqlRawAsync("CALL dss_process_biz_lic_table();");
143145
}
146+
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+
//}
156+
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));
173+
}
144174
}
145175
}

server/StrDss.Service/BizLicenseService.cs

Lines changed: 8 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
{
@@ -137,6 +138,8 @@ private async Task ProcessBizLicenseUploadAsync(DssUploadDelivery upload)
137138
return (row.OrgCd, row.BusinessLicenceNo);
138139
}
139140

141+
row.LicenceStatusType = row.LicenceStatusType.IsEmpty() ? "ISSUED" : row.LicenceStatusType;
142+
140143
await _bizLicenseRepo.InsertRowToBizLicTempTable(row, org.OrganizationId);
141144

142145
SaveUploadLine(line, errors, false, "");
@@ -157,5 +160,10 @@ private void SaveUploadLine(DssUploadLine uploadLine, Dictionary<string, List<st
157160

158161
uploadLine.IsProcessed = true;
159162
}
163+
164+
public async Task<(long?, string?)> GetMatchingBusinessLicenseIdAndNo(long orgId, string effectiveBizLicNo)
165+
{
166+
return await _bizLicenseRepo.GetMatchingBusinessLicenseIdAndNo(orgId, effectiveBizLicNo);
167+
}
160168
}
161169
}

server/StrDss.Service/RentalListingReportService.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ public class RentalListingReportService : ServiceBase, IRentalListingReportServi
3434
private IUserRepository _userRepo;
3535
private IEmailMessageService _emailService;
3636
private IEmailMessageRepository _emailRepo;
37+
private IBizLicenseRepository _bizLicRepo;
3738
private IConfiguration _config;
3839

3940
public RentalListingReportService(ICurrentUser currentUser, IFieldValidatorService validator, IUnitOfWork unitOfWork, IMapper mapper, IHttpContextAccessor httpContextAccessor,
4041
IOrganizationRepository orgRepo, IUploadDeliveryRepository uploadRepo, IRentalListingReportRepository reportRepo, IPhysicalAddressRepository addressRepo,
41-
IGeocoderApi geocoder, IUserRepository userRepo, IEmailMessageService emailService, IEmailMessageRepository emailRepo,
42+
IGeocoderApi geocoder, IUserRepository userRepo, IEmailMessageService emailService, IEmailMessageRepository emailRepo, IBizLicenseRepository bizLicRepo,
4243
IConfiguration config, ILogger<StrDssLogger> logger)
4344
: base(currentUser, validator, unitOfWork, mapper, httpContextAccessor, logger)
4445
{
@@ -50,6 +51,7 @@ public RentalListingReportService(ICurrentUser currentUser, IFieldValidatorServi
5051
_userRepo = userRepo;
5152
_emailService = emailService;
5253
_emailRepo = emailRepo;
54+
_bizLicRepo = bizLicRepo;
5355
_config = config;
5456
}
5557
public async Task ProcessRentalReportUploadAsync()
@@ -412,6 +414,30 @@ private async Task<DssRentalListing> CreateOrUpdateRentalListing(DssRentalListin
412414
masterListing.DerivedFromRentalListingId = listing.RentalListingId;
413415
masterListing.LocatingPhysicalAddressId = physicalAddress.PhysicalAddressId;
414416

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
436+
{
437+
masterListing.GoverningBusinessLicenceId = null;
438+
masterListing.EffectiveBusinessLicenceNo = string.Empty;
439+
}
440+
415441
(masterListing.NightsBookedQty, masterListing.SeparateReservationsQty) =
416442
await _reportRepo.GetYtdValuesOfListingAsync(reportPeriodYm, offeringOrg.OrganizationId, masterListing.PlatformListingNo);
417443

0 commit comments

Comments
 (0)