模块和项目的绑定和解绑原理,已经在【总部运营后台运作原理】中说明,这里主要讲后端如何处理。
目前的问题是:在总部运营后台,解除项目和模块的绑定关系之后,在总部管理后台和开放平台的数据库都作了相应的处理。但,在项目数据库,并没有处理。这样导致与项目解除绑定的模块,仍然可以在项目库数据库中存在,在
APP
上被看到。
解决思路是:当在总部运营后台,解除项目和模块关系的那一刻,在现在的处理逻辑上再加上:把项目数据库的模块和线路标记为物理删除。在办公楼版中,需要把macs
、breakers
、breakerdatas
中的相关模块或线路设置为物理删除。然后在显示的时候,把标记为逻辑删除的模块和线路排除。
具体步骤大致是:
ProjectId
获取办公楼版的上下文。类似如下:
public class TestRequestHandler : IRequestHandler<TestRequest, DDResponseWrapper<TestRequestDto>>
{
private readonly DDOfficeDbHelper _officeHelper;//获取办公楼版上下文的帮助类
private ICompanyRepository _companyRepo;//办公楼版的某个仓储
public TestRequestHandler(DDOfficeDbHelper officeHelper)
{
_officeHelper = officeHelper;
}
public async Task<DDResponseWrapper<TestRequestDto>> Handle(TestRequest request, CancellationToken cancellationToken)
{
var result = new DDResponseWrapper<TestRequestDto>();
var dto = new TestRequestDto();
var ef = await _officeHelper.GetOfficeContextByProjectIdAsync("4");//根据ProjectId获取办公楼版的上下文
_companyRepo = new CompanyRepository(ef);//实例化办公楼版的某个仓储
var company = _companyRepo.GetAll().FirstOrDefault();
dto.Message = company.Name;
result.data = dto;
return await Task.FromResult(result);
}
}
public class TestRequest : IRequest<DDResponseWrapper<TestRequestDto>>
{
}
public class TestRequestDto
{
public string Message { get; set; }
}
基础设施层的版本如下:
DD.Libs 1.0.93
DD.Infra1.0.74
办公楼版有哪些仓储呢?
services.AddScoped<ICompanyRepository, CompanyRepository>();
services.AddScoped<ICompanyUserRepository, CompanyUserRepository>();
services.AddScoped<IElectricBoxRepository, ElectricBoxRepository>();
services.AddScoped<IMacRepository, MacRepository>();
services.AddScoped<IBreakerRepository, BreakerRepository>();
services.AddScoped<ILocationRepository, LocationRepository>();
services.AddScoped<IOperationRepository, OperationRepository>();
services.AddScoped<IDateJobRepository, DateJobRepository>();
services.AddScoped<IJobRepository, JobRepository>();
services.AddScoped<IJobBreakerRepository, JobBreakerRepository>();
services.AddScoped<IProjectSettingRepository, ProjectSettingRepository>();
services.AddScoped<IPowerRepository, PowerRepository>();
services.AddScoped<IRealWarningRepository, RealWarningRepository>();
services.AddScoped<IRealWarningDataRepository, RealWarningDataRepository>();
services.AddScoped<IWarningHistoryRepository, WarningHistoryRepository>();
services.AddScoped<IWarningHistoryDataRepository, WarningHistoryDataRepository>();
services.AddScoped<IBreakerDataRepository, BreakerDataRepository>();
services.AddScoped<INotiRepository, NotiRepository>();
services.AddScoped<ITestPowerRepository, TestPowerRepository>();
services.AddScoped<IBreakerWarningPolicyRepository, BreakerWarningPolicyRepository>();
services.AddScoped<IMockBreakerDataRepository, MockBreakerDataRepository>();
services.AddScoped<IElectricFeeRepository, ElectricFeeRepository>();
逻辑删除调用哪个方法?在Mac
, Breaker
, BreakerData
领域实体中都定义了LogicDel
方法。当IsLogicDel=1
表示逻辑删除,当IsLogicDel=0
表示正常显示。
/// <summary>
/// 逻辑删除
/// </summary>
public void LogicDel()
{
IsLogicDel = CommonConstants.LogicDelYes;
}