Skip to content

Commit b37f1a0

Browse files
authored
Merge pull request #664 from bcgov/yj
Yj
2 parents 8d5b65f + 4d0ba47 commit b37f1a0

17 files changed

+154
-89
lines changed

database/ddl/STR_DSS_Views_Sprint_14.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CREATE OR REPLACE VIEW dss_rental_listing_vw AS select drl.rental_listing_id
5555
, drl.effective_business_licence_no
5656
, drl.effective_host_nm
5757
, drl.is_changed_business_licence
58+
, drl.lg_transfer_dtm
5859
FROM dss_rental_listing drl
5960
join dss_organization org on org.organization_id=drl.offering_organization_id
6061
LEFT JOIN dss_listing_status_type dlst on drl.listing_status_type=dlst.listing_status_type

server/StrDss.Data/Entities/DssDbContext.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
439439
entity.Property(e => e.IsPrincipalResidenceRequired)
440440
.HasComment("Indicates whether a LOCAL GOVERNMENT SUBDIVISION is subject to Provincial Principal Residence Short Term Rental restrictions")
441441
.HasColumnName("is_principal_residence_required");
442+
entity.Property(e => e.IsStrProhibited)
443+
.HasComment("Indicates whether a LOCAL GOVERNMENT ORGANIZATION entirely prohibits short term housing rentals")
444+
.HasColumnName("is_str_prohibited");
442445
entity.Property(e => e.LocalGovernmentType)
443446
.HasMaxLength(50)
444447
.HasComment("A sub-type of local government organization used for sorting and grouping or members")
@@ -663,6 +666,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
663666

664667
entity.HasIndex(e => new { e.OfferingOrganizationId, e.PlatformListingNo }, "dss_rental_listing_i1");
665668

669+
entity.HasIndex(e => e.LgTransferDtm, "dss_rental_listing_i11");
670+
666671
entity.HasIndex(e => e.IncludingRentalListingReportId, "dss_rental_listing_i2");
667672

668673
entity.HasIndex(e => e.DerivedFromRentalListingId, "dss_rental_listing_i3");
@@ -738,6 +743,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
738743
entity.Property(e => e.IsTakenDown)
739744
.HasComment("Indicates whether a CURRENT RENTAL LISTING has been reported as taken down by the offering platform")
740745
.HasColumnName("is_taken_down");
746+
entity.Property(e => e.LgTransferDtm)
747+
.HasComment("Indicates when a CURRENT RENTAL LISTING was most recently transferred to a different Local Goverment Organization as a result of address changes")
748+
.HasColumnName("lg_transfer_dtm");
741749
entity.Property(e => e.ListingStatusType)
742750
.HasMaxLength(2)
743751
.HasComment("Foreign key")
@@ -989,6 +997,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
989997
.HasMaxLength(250)
990998
.HasColumnName("last_action_nm");
991999
entity.Property(e => e.LatestReportPeriodYm).HasColumnName("latest_report_period_ym");
1000+
entity.Property(e => e.LgTransferDtm).HasColumnName("lg_transfer_dtm");
9921001
entity.Property(e => e.LicenceStatusType)
9931002
.HasMaxLength(25)
9941003
.HasColumnName("licence_status_type");

server/StrDss.Data/Entities/DssOrganization.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public partial class DssOrganization
7474
/// </summary>
7575
public string? LocalGovernmentType { get; set; }
7676

77+
/// <summary>
78+
/// Indicates whether a LOCAL GOVERNMENT ORGANIZATION entirely prohibits short term housing rentals
79+
/// </summary>
80+
public bool? IsStrProhibited { get; set; }
81+
7782
public virtual ICollection<DssBusinessLicence> DssBusinessLicences { get; set; } = new List<DssBusinessLicence>();
7883

7984
public virtual ICollection<DssEmailMessage> DssEmailMessageInvolvedInOrganizations { get; set; } = new List<DssEmailMessage>();

server/StrDss.Data/Entities/DssRentalListing.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public partial class DssRentalListing
143143
/// </summary>
144144
public long? GoverningBusinessLicenceId { get; set; }
145145

146+
/// <summary>
147+
/// Indicates when a CURRENT RENTAL LISTING was most recently transferred to a different Local Goverment Organization as a result of address changes
148+
/// </summary>
149+
public DateTime? LgTransferDtm { get; set; }
150+
146151
public virtual DssRentalListing? DerivedFromRentalListing { get; set; }
147152

148153
public virtual ICollection<DssEmailMessage> DssEmailMessages { get; set; } = new List<DssEmailMessage>();

server/StrDss.Data/Entities/DssRentalListingVw.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ public partial class DssRentalListingVw
102102
public string? EffectiveHostNm { get; set; }
103103

104104
public bool? IsChangedBusinessLicence { get; set; }
105+
106+
public DateTime? LgTransferDtm { get; set; }
105107
}

server/StrDss.Data/Repositories/OrganizationRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ FROM dss_organization
140140
OrganizationNm = o.OrganizationNm,
141141
IsPrincipalResidenceRequired = o.IsPrincipalResidenceRequired,
142142
IsBusinessLicenceRequired = o.IsBusinessLicenceRequired,
143-
IsStrProhibited = null //todo: map with the new column
143+
IsStrProhibited = o.IsStrProhibited,
144144
})
145145
.OrderBy(o => o.OrganizationNm)
146146
.FirstOrDefaultAsync();

server/StrDss.Data/Repositories/RentalListingRepository.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using AutoMapper;
22
using Microsoft.EntityFrameworkCore;
33
using Microsoft.Extensions.Logging;
4+
using Npgsql;
45
using StrDss.Common;
56
using StrDss.Data.Entities;
67
using StrDss.Model;
78
using StrDss.Model.DelistingDtos;
89
using StrDss.Model.RentalReportDtos;
910
using System.Diagnostics;
10-
using System.Reflection;
1111

1212
namespace StrDss.Data.Repositories
1313
{
@@ -28,9 +28,10 @@ Task<PagedDto<RentalListingGroupDto>> GetGroupedRentalListings(string? all, stri
2828
Task ConfirmAddressAsync(long rentalListingId);
2929
Task<DssRentalListing> UpdateAddressAsync(UpdateListingAddressDto dto);
3030
DateTime GetLatestRentalListingExportTime();
31-
Task<bool> IsListingUploadProcessRunning();
31+
Task<bool> ListingDataToProcessExists();
3232
Task LinkBizLicence(long rentalListingId, long licenceId);
3333
Task UnLinkBizLicence(long rentalListingId);
34+
Task ResetLgTransferFlag();
3435
}
3536
public class RentalListingRepository : RepositoryBase<DssRentalListingVw>, IRentalListingRepository
3637
{
@@ -746,7 +747,7 @@ public DateTime GetLatestRentalListingExportTime()
746747
}
747748
}
748749

749-
public async Task<bool> IsListingUploadProcessRunning()
750+
public async Task<bool> ListingDataToProcessExists()
750751
{
751752
return await _dbContext.DssUploadLines
752753
.AnyAsync(x => x.IncludingUploadDelivery.UploadDeliveryType == UploadDeliveryTypes.ListingData && x.IsProcessed == false);
@@ -780,5 +781,23 @@ public async Task UnLinkBizLicence(long rentalListingId)
780781
listing.EffectiveBusinessLicenceNo = CommonUtils.SanitizeAndUppercaseString(listing.BusinessLicenceNo);
781782
listing.IsChangedBusinessLicence = true;
782783
}
784+
785+
public async Task ResetLgTransferFlag()
786+
{
787+
var sql = "UPDATE dss_rental_listing SET is_lg_transferred = null, lg_transfer_dtm = null WHERE lg_transfer_dtm <= @twomonth";
788+
789+
var parameters = new List<NpgsqlParameter>
790+
{
791+
new NpgsqlParameter("@twomonth", NpgsqlTypes.NpgsqlDbType.Date)
792+
{
793+
Value = DateTime.UtcNow.Date.AddMonths(-2)
794+
},
795+
};
796+
797+
var rowsAffected = await _dbContext.Database.ExecuteSqlRawAsync(sql, parameters.ToArray());
798+
799+
if (rowsAffected > 0)
800+
_logger.LogInformation("{RowsAffected} rental listings had the lg_transfer_dtm and is_lg_transferred fields reset.", rowsAffected);
801+
}
783802
}
784803
}

server/StrDss.Data/Repositories/UploadDeliveryRepository.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface IUploadDeliveryRepository
1313
Task<bool> IsDuplicateRentalReportUploadAsnyc(DateOnly? periodYm, long orgId, string hashValue);
1414
Task AddUploadDeliveryAsync(DssUploadDelivery upload);
1515
Task<DssUploadDelivery?> GetUploadToProcessAsync(string reportType);
16+
Task<DssUploadDelivery?> GetNonTakedownUploadToProcessAsync();
1617
Task<DssUploadDelivery[]> GetUploadsToProcessAsync(string reportType);
1718
Task<DssUploadDelivery?> GetRentalListingUploadWithErrors(long uploadId);
1819
Task<DssUploadLine?> GetUploadLineAsync(long uploadId, string orgCd, string listingId);
@@ -55,6 +56,15 @@ public async Task<bool> IsDuplicateRentalReportUploadAsnyc(DateOnly? periodYm, l
5556
.FirstOrDefaultAsync();
5657
}
5758

59+
public async Task<DssUploadDelivery?> GetNonTakedownUploadToProcessAsync()
60+
{
61+
return await _dbSet
62+
.Include(x => x.ProvidingOrganization)
63+
.Where(x => x.UploadDeliveryType != UploadDeliveryTypes.TakedownData && x.DssUploadLines.Any(line => !line.IsProcessed))
64+
.OrderBy(x => x.UpdDtm)
65+
.FirstOrDefaultAsync();
66+
}
67+
5868
public async Task<DssUploadDelivery[]> GetUploadsToProcessAsync(string reportType)
5969
{
6070
return await _dbSet

server/StrDss.Hangfire/Program.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Npgsql;
1717
using StrDss.Hangfire;
1818
using Serilog;
19+
using Hangfire.Storage;
1920

2021
var builder = WebApplication.CreateBuilder(args);
2122

@@ -170,10 +171,23 @@
170171
app.UseHangfireDashboard();
171172

172173
// make sure this is after app.UseHangfireDashboard()
173-
RecurringJob.AddOrUpdate<HangfireJobs>("Process Rental Listing Report", job => job.ProcessRentalListingReports(), "*/2 * * * *");
174+
175+
// Retrieve all recurring jobs
176+
var recurringJobs = JobStorage.Current.GetConnection().GetRecurringJobs();
177+
178+
// Remove each recurring job
179+
foreach (var job in recurringJobs)
180+
{
181+
RecurringJob.RemoveIfExists(job.Id);
182+
}
183+
184+
// process uploads
185+
RecurringJob.AddOrUpdate<HangfireJobs>("Process Uploaded Data", job => job.ProcessUpload(), "*/5 * * * *");
186+
187+
// process nightly job of sending takedown request emails to plaforms
174188
RecurringJob.AddOrUpdate<HangfireJobs>("Process Takedown Request Batch Emails", job => job.ProcessTakedownRequestBatchEmails(), "50 6 * * *");
189+
190+
// daily export
175191
RecurringJob.AddOrUpdate<HangfireJobs>("Create Rental Listing Export Files", job => job.CreateRentalListingExportFiles(), "50 5 * * *");
176-
RecurringJob.AddOrUpdate<HangfireJobs>("Process Takedown Confirmation Report", job => job.ProcessTakedownConfirmation(), "0 * * * *");
177-
RecurringJob.AddOrUpdate<HangfireJobs>("Process Business Licences", job => job.ProcessBusinessLicences(), "*/10 * * * *");
178192

179193
app.Run();

server/StrDss.Model/OrganizationDtos/OrganizationDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class OrganizationDto
2626
public bool? IsLgParticipating { get; set; }
2727
public bool? IsPrincipalResidenceRequired { get; set; }
2828
public bool? IsBusinessLicenceRequired { get; set; }
29+
public bool? IsStrProhibited { get; set; }
2930
public virtual ICollection<ContactPersonDto> ContactPeople { get; set; } = new List<ContactPersonDto>();
3031

3132
}

0 commit comments

Comments
 (0)