|
|
@@ -8,7 +8,6 @@ namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Quality;
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/base-types")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
{
|
|
|
@@ -22,8 +21,9 @@ public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
x.TypeCategory.Contains(q.Keyword!)
|
|
|
|| x.TypeCode.Contains(q.Keyword!)
|
|
|
@@ -36,15 +36,20 @@ public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsQualityBaseTypeUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
// C4 唯一性 pre-check:(TypeCategory, TypeCode) 全局唯一
|
|
|
var category = dto.TypeCategory.Trim();
|
|
|
var code = dto.TypeCode.Trim();
|
|
|
- if (await _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()).AnyAsync(x => x.TypeCategory == category && x.TypeCode == code))
|
|
|
+ if (await _rep.AsQueryable().Where(x => x.TenantId == tenantId).AnyAsync(x => x.TypeCategory == category && x.TypeCode == code))
|
|
|
{
|
|
|
return AdoS0ApiErrors.Conflict(AdoS0ErrorCodes.QualityBaseTypeDuplicate,
|
|
|
$"质量基础类型 '{category} / {code}' 已存在");
|
|
|
@@ -52,7 +57,7 @@ public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
|
|
|
var entity = new AdoS0QmsQualityBaseType();
|
|
|
ApplyQualityBaseType(entity, dto, true);
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -60,13 +65,14 @@ public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsQualityBaseTypeUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
|
|
|
// C4 唯一性 pre-check:(TypeCategory, TypeCode) 全局唯一,排除自身
|
|
|
var category = dto.TypeCategory.Trim();
|
|
|
var code = dto.TypeCode.Trim();
|
|
|
- if (await _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()).AnyAsync(x => x.TypeCategory == category && x.TypeCode == code && x.Id != id))
|
|
|
+ if (await _rep.AsQueryable().Where(x => x.TenantId == tenantId).AnyAsync(x => x.TypeCategory == category && x.TypeCode == code && x.Id != id))
|
|
|
{
|
|
|
return AdoS0ApiErrors.Conflict(AdoS0ErrorCodes.QualityBaseTypeDuplicate,
|
|
|
$"质量基础类型 '{category} / {code}' 已存在");
|
|
|
@@ -78,7 +84,11 @@ public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static void ApplyQualityBaseType(AdoS0QmsQualityBaseType entity, AdoS0QmsQualityBaseTypeUpsertDto dto, bool isCreate)
|
|
|
{
|
|
|
@@ -95,7 +105,6 @@ public class AdoS0QmsQualityBaseTypesController : ControllerBase
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/raw-whitelists")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
{
|
|
|
@@ -109,8 +118,9 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
(x.SupplierCode != null && x.SupplierCode.Contains(q.Keyword!)) ||
|
|
|
(x.SupplierName != null && x.SupplierName.Contains(q.Keyword!)) ||
|
|
|
@@ -122,12 +132,17 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpGet("options")]
|
|
|
public async Task<IActionResult> GetOptionsAsync()
|
|
|
{
|
|
|
- var list = await _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var list = await _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.OrderBy(x => x.SupplierCode)
|
|
|
.Select(x => new AdoS0QualitySimpleOptionDto { Value = x.Id, Label = (x.SupplierCode ?? "") + " / " + (x.SupplierName ?? "") })
|
|
|
.ToListAsync();
|
|
|
@@ -137,6 +152,7 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsRawWhitelistUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var err = ValidateRawWhitelist(dto, out var dimensionType);
|
|
|
if (err != null) return AdoS0ApiErrors.InvalidRequest(err);
|
|
|
var entity = new AdoS0QmsRawWhitelist
|
|
|
@@ -147,7 +163,7 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
MaterialName = NullIfWhiteSpace(dto.MaterialName),
|
|
|
DimensionType = dimensionType
|
|
|
};
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -155,7 +171,8 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsRawWhitelistUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
var err = ValidateRawWhitelist(dto, out var dimensionType);
|
|
|
if (err != null) return AdoS0ApiErrors.InvalidRequest(err);
|
|
|
@@ -169,7 +186,11 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static string? ValidateRawWhitelist(AdoS0QmsRawWhitelistUpsertDto dto, out string dimensionType)
|
|
|
{
|
|
|
@@ -196,7 +217,6 @@ public class AdoS0QmsRawWhitelistsController : ControllerBase
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/sampling-schemes")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsSamplingSchemesController : ControllerBase
|
|
|
{
|
|
|
@@ -210,8 +230,9 @@ public class AdoS0QmsSamplingSchemesController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
(x.Number != null && x.Number.Contains(q.Keyword!)) ||
|
|
|
(x.Name != null && x.Name.Contains(q.Keyword!)));
|
|
|
@@ -221,17 +242,26 @@ public class AdoS0QmsSamplingSchemesController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpGet("options")]
|
|
|
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ public async Task<IActionResult> GetOptionsAsync()
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == tenantId), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ }
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsSamplingSchemeUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var entity = new AdoS0QmsSamplingScheme();
|
|
|
ApplySamplingScheme(entity, dto, true);
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -239,7 +269,8 @@ public class AdoS0QmsSamplingSchemesController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsSamplingSchemeUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
ApplySamplingScheme(entity, dto, false);
|
|
|
await _rep.AsUpdateable(entity).ExecuteCommandAsync();
|
|
|
@@ -247,7 +278,11 @@ public class AdoS0QmsSamplingSchemesController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static void ApplySamplingScheme(AdoS0QmsSamplingScheme entity, AdoS0QmsSamplingSchemeUpsertDto dto, bool isCreate)
|
|
|
{
|
|
|
@@ -271,7 +306,6 @@ public class AdoS0QmsSamplingSchemesController : ControllerBase
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/instruments")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsInspectionInstrumentsController : ControllerBase
|
|
|
{
|
|
|
@@ -285,8 +319,9 @@ public class AdoS0QmsInspectionInstrumentsController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
(x.Number != null && x.Number.Contains(q.Keyword!)) ||
|
|
|
(x.Name != null && x.Name.Contains(q.Keyword!)) ||
|
|
|
@@ -297,17 +332,26 @@ public class AdoS0QmsInspectionInstrumentsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpGet("options")]
|
|
|
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ public async Task<IActionResult> GetOptionsAsync()
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == tenantId), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ }
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionInstrumentUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var entity = new AdoS0QmsInspectionInstrument();
|
|
|
ApplyInspectionInstrument(entity, dto, true);
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -315,7 +359,8 @@ public class AdoS0QmsInspectionInstrumentsController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionInstrumentUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
ApplyInspectionInstrument(entity, dto, false);
|
|
|
await _rep.AsUpdateable(entity).ExecuteCommandAsync();
|
|
|
@@ -323,7 +368,11 @@ public class AdoS0QmsInspectionInstrumentsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static void ApplyInspectionInstrument(AdoS0QmsInspectionInstrument entity, AdoS0QmsInspectionInstrumentUpsertDto dto, bool isCreate)
|
|
|
{
|
|
|
@@ -345,7 +394,6 @@ public class AdoS0QmsInspectionInstrumentsController : ControllerBase
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/inspection-methods")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsInspectionMethodsController : ControllerBase
|
|
|
{
|
|
|
@@ -359,8 +407,9 @@ public class AdoS0QmsInspectionMethodsController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
(x.Number != null && x.Number.Contains(q.Keyword!)) ||
|
|
|
(x.Name != null && x.Name.Contains(q.Keyword!)));
|
|
|
@@ -370,17 +419,26 @@ public class AdoS0QmsInspectionMethodsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpGet("options")]
|
|
|
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ public async Task<IActionResult> GetOptionsAsync()
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == tenantId), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ }
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionMethodUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var entity = new AdoS0QmsInspectionMethod();
|
|
|
ApplyInspectionMethod(entity, dto, true);
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -388,7 +446,8 @@ public class AdoS0QmsInspectionMethodsController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionMethodUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
ApplyInspectionMethod(entity, dto, false);
|
|
|
await _rep.AsUpdateable(entity).ExecuteCommandAsync();
|
|
|
@@ -396,7 +455,11 @@ public class AdoS0QmsInspectionMethodsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static void ApplyInspectionMethod(AdoS0QmsInspectionMethod entity, AdoS0QmsInspectionMethodUpsertDto dto, bool isCreate)
|
|
|
{
|
|
|
@@ -413,7 +476,6 @@ public class AdoS0QmsInspectionMethodsController : ControllerBase
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/inspection-items")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsInspectionItemsController : ControllerBase
|
|
|
{
|
|
|
@@ -427,8 +489,9 @@ public class AdoS0QmsInspectionItemsController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
(x.Number != null && x.Number.Contains(q.Keyword!)) ||
|
|
|
(x.Name != null && x.Name.Contains(q.Keyword!)));
|
|
|
@@ -438,17 +501,26 @@ public class AdoS0QmsInspectionItemsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpGet("options")]
|
|
|
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ public async Task<IActionResult> GetOptionsAsync()
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == tenantId), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ }
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionItemUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var entity = new AdoS0QmsInspectionItem();
|
|
|
ApplyInspectionItem(entity, dto, true);
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -456,7 +528,8 @@ public class AdoS0QmsInspectionItemsController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionItemUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
ApplyInspectionItem(entity, dto, false);
|
|
|
await _rep.AsUpdateable(entity).ExecuteCommandAsync();
|
|
|
@@ -464,7 +537,11 @@ public class AdoS0QmsInspectionItemsController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static void ApplyInspectionItem(AdoS0QmsInspectionItem entity, AdoS0QmsInspectionItemUpsertDto dto, bool isCreate)
|
|
|
{
|
|
|
@@ -486,7 +563,6 @@ public class AdoS0QmsInspectionItemsController : ControllerBase
|
|
|
|
|
|
[ApiController]
|
|
|
[Route("api/s0/quality/inspection-frequencies")]
|
|
|
-[AllowAnonymous]
|
|
|
[NonUnify]
|
|
|
public class AdoS0QmsInspectionFrequenciesController : ControllerBase
|
|
|
{
|
|
|
@@ -500,8 +576,9 @@ public class AdoS0QmsInspectionFrequenciesController : ControllerBase
|
|
|
[HttpGet]
|
|
|
public async Task<IActionResult> GetPagedAsync([FromQuery] AdoS0QualityPagedQueryDto q)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
(q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
|
|
|
- var query = _rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current())
|
|
|
+ var query = _rep.AsQueryable().Where(x => x.TenantId == tenantId)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(q.Keyword), x =>
|
|
|
(x.Number != null && x.Number.Contains(q.Keyword!)) ||
|
|
|
(x.Name != null && x.Name.Contains(q.Keyword!)));
|
|
|
@@ -511,17 +588,26 @@ public class AdoS0QmsInspectionFrequenciesController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpGet("{id:long}")]
|
|
|
- public async Task<IActionResult> GetAsync(long id) => OkOrNotFound(await _rep.GetByIdAsync(id));
|
|
|
+ public async Task<IActionResult> GetAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return OkOrNotFound(await _rep.ByIdScopedByColumnAsync(id, tenantId));
|
|
|
+ }
|
|
|
|
|
|
[HttpGet("options")]
|
|
|
- public async Task<IActionResult> GetOptionsAsync() => Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == QmsTenantScope.Current()), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ public async Task<IActionResult> GetOptionsAsync()
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return Ok(await BuildOptionsAsync(_rep.AsQueryable().Where(x => x.TenantId == tenantId), x => x.Id, x => $"{x.Number} / {x.Name}"));
|
|
|
+ }
|
|
|
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0QmsInspectionFrequencyUpsertDto dto)
|
|
|
{
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var entity = new AdoS0QmsInspectionFrequency();
|
|
|
ApplyInspectionFrequency(entity, dto, true);
|
|
|
- entity.TenantId = QmsTenantScope.Current();
|
|
|
+ entity.TenantId = tenantId;
|
|
|
await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
|
|
|
return Ok(entity);
|
|
|
}
|
|
|
@@ -529,7 +615,8 @@ public class AdoS0QmsInspectionFrequenciesController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0QmsInspectionFrequencyUpsertDto dto)
|
|
|
{
|
|
|
- var entity = await _rep.GetByIdAsync(id);
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ var entity = await _rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (entity == null) return NotFound();
|
|
|
ApplyInspectionFrequency(entity, dto, false);
|
|
|
await _rep.AsUpdateable(entity).ExecuteCommandAsync();
|
|
|
@@ -537,7 +624,11 @@ public class AdoS0QmsInspectionFrequenciesController : ControllerBase
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{id:long}")]
|
|
|
- public async Task<IActionResult> DeleteAsync(long id) => await DeleteByIdAsync(_rep, id);
|
|
|
+ public async Task<IActionResult> DeleteAsync(long id)
|
|
|
+ {
|
|
|
+ if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
+ return await DeleteByIdAsync(_rep, id, tenantId);
|
|
|
+ }
|
|
|
|
|
|
private static void ApplyInspectionFrequency(AdoS0QmsInspectionFrequency entity, AdoS0QmsInspectionFrequencyUpsertDto dto, bool isCreate)
|
|
|
{
|
|
|
@@ -553,9 +644,10 @@ public class AdoS0QmsInspectionFrequenciesController : ControllerBase
|
|
|
|
|
|
internal static partial class AdoS0QmsControllerHelpers
|
|
|
{
|
|
|
- internal static async Task<IActionResult> DeleteByIdAsync<TEntity>(SqlSugarRepository<TEntity> rep, long id) where TEntity : class, new()
|
|
|
+ /// <summary>租户内按主键删除:越租户的 id 一律按 NotFound 处理,不泄露存在性。</summary>
|
|
|
+ internal static async Task<IActionResult> DeleteByIdAsync<TEntity>(SqlSugarRepository<TEntity> rep, long id, long tenantId) where TEntity : class, new()
|
|
|
{
|
|
|
- var item = await rep.GetByIdAsync(id);
|
|
|
+ var item = await rep.ByIdScopedByColumnAsync(id, tenantId);
|
|
|
if (item == null) return new NotFoundResult();
|
|
|
await rep.DeleteAsync(item);
|
|
|
return new OkObjectResult(new { message = "删除成功" });
|