fix 人事范围调整
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Dlhis.Sys.Api.Response;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -11,7 +13,6 @@ namespace Dlhis.Basic.Organization.Controllers;
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[Obsolete]
|
||||
public class WerksController : ControllerBase
|
||||
{
|
||||
private readonly IWerkService _werkService;
|
||||
@@ -22,22 +23,24 @@ public class WerksController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人事范围列表
|
||||
/// 分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public async Task<List<TenantResponse>> GetListAsync()
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<WerkResponse>> GetPageAsync([FromQuery] PageDto request)
|
||||
{
|
||||
return await _werkService.GetListAsync();
|
||||
return await _werkService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前组织信息
|
||||
/// 保存人事范围
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("current")]
|
||||
public async Task<TenantResponse> GetCurrentAsync()
|
||||
[HttpPost("save")]
|
||||
public async Task SaveAsync(WerkRequest request)
|
||||
{
|
||||
return await _werkService.GetCurrentAsync();
|
||||
await _werkService.SaveAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
22
Src/Dlhis.Basic/Organization/Request/WerkRequest.cs
Normal file
22
Src/Dlhis.Basic/Organization/Request/WerkRequest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Request;
|
||||
|
||||
public class WerkRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人事范围
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Werk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
21
Src/Dlhis.Basic/Organization/Response/WerkResponse.cs
Normal file
21
Src/Dlhis.Basic/Organization/Response/WerkResponse.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Dlhis.Basic.Organization.Response;
|
||||
|
||||
public class WerkResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人事范围
|
||||
/// </summary>
|
||||
public string Werk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using Dlhis.Sys.Api.Response;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services;
|
||||
|
||||
public interface IWerkService : IScopeDependency
|
||||
{
|
||||
Task<List<TenantResponse>> GetListAsync();
|
||||
Task<Pagination<WerkResponse>> GetPageAsync(PageDto request);
|
||||
|
||||
Task<TenantResponse> GetCurrentAsync();
|
||||
Task SaveAsync(WerkRequest request);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,48 @@
|
||||
using Dlhis.Sys.Api;
|
||||
using Dlhis.Sys.Api.Response;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.Result;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
public class WerkService : IWerkService
|
||||
{
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public WerkService(ICurrentUser currentUser, ITenantApi tenantApi)
|
||||
public WerkService(IDbContext dbContext)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_tenantApi = tenantApi;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<List<TenantResponse>> GetListAsync()
|
||||
public async Task<Pagination<WerkResponse>> GetPageAsync(PageDto request)
|
||||
{
|
||||
var tenantResult = await _tenantApi.GetTenantsAsync();
|
||||
(tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg);
|
||||
|
||||
var tenants = tenantResult.Data;
|
||||
return tenants;
|
||||
return await _dbContext.Queryable<WerkEntity>()
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search))
|
||||
.Select<WerkResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<TenantResponse> GetCurrentAsync()
|
||||
public async Task SaveAsync(WerkRequest request)
|
||||
{
|
||||
var tenant = _currentUser.GetStringTenantId();
|
||||
var tenantResult = await _tenantApi.GetTenantsAsync();
|
||||
(tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg);
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<WerkEntity>();
|
||||
entity.Werk = request.Werk;
|
||||
|
||||
var tenants = tenantResult.Data;
|
||||
return tenants.FirstOrDefault(x => x.Code == tenant);
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<WerkEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
entity.ThrowIfNull("人事范围不存在,无法更新!");
|
||||
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Kurisu.SqlSugar;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
@@ -9,6 +10,7 @@ public class WerkEntity : SugarBaseEntity
|
||||
/// <summary>
|
||||
/// 人事范围
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(UniqueGroupNameList = new[] { "idx_Werk_Werk" })]
|
||||
public string Werk { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user