feat 厂区配置
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 厂区配置
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class FactorySettingController : ControllerBase
|
||||
{
|
||||
private readonly IFactorySettingService _factorySettingService;
|
||||
|
||||
public FactorySettingController(IFactorySettingService factorySettingService)
|
||||
{
|
||||
_factorySettingService = factorySettingService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取厂区列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[IgnoreTenant]
|
||||
public async Task<List<FactorySettingResponse>> GetListAsync()
|
||||
{
|
||||
return await _factorySettingService.GetListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存配置
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[HttpPost("save")]
|
||||
[IgnoreTenant]
|
||||
public async Task SaveAsync(FactorySettingSaveRequest request)
|
||||
{
|
||||
await _factorySettingService.SaveAsync(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Request;
|
||||
|
||||
public class FactorySettingSaveRequest
|
||||
{
|
||||
[Required]
|
||||
public string Factory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 外包人员自动下发
|
||||
/// </summary>
|
||||
public bool EnableOutsourceDown { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 档案二维码过期时间
|
||||
/// </summary>
|
||||
public int? UserQrCodeExpiration { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Dlhis.Basic.Organization.Response;
|
||||
|
||||
public class FactorySettingResponse
|
||||
{
|
||||
public string Factory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用外包自动下发
|
||||
/// </summary>
|
||||
public bool EnableOutsourceDown { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 档案二维码过期时间
|
||||
/// </summary>
|
||||
public int? UserQrCodeExpiration { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services;
|
||||
|
||||
public interface IFactorySettingService : IScopeDependency
|
||||
{
|
||||
Task<List<FactorySettingResponse>> GetListAsync();
|
||||
|
||||
Task SaveAsync(FactorySettingSaveRequest request);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Sys.Api;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
public class FactorySettingService : IFactorySettingService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
|
||||
public FactorySettingService(IDbContext dbContext, ITenantApi tenantApi)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_tenantApi = tenantApi;
|
||||
}
|
||||
|
||||
public async Task<List<FactorySettingResponse>> GetListAsync()
|
||||
{
|
||||
var apiResult = await _tenantApi.GetMyTenantsAsync();
|
||||
var factories = apiResult.Data;
|
||||
|
||||
var factoryCodes = factories.Select(x => x.Code).ToList();
|
||||
var settings = await _dbContext.Queryable<FactorySettingEntity>().Where(x => factoryCodes.Contains(x.TenantId))
|
||||
.ToListAsync();
|
||||
|
||||
return factories.Select(item =>
|
||||
{
|
||||
return new FactorySettingResponse
|
||||
{
|
||||
Factory = factories.FirstOrDefault(x => x.Code == item.Code)?.Name,
|
||||
EnableOutsourceDown = settings.FirstOrDefault(x => x.TenantId == item.Code)?.EnableOutsourceDown ?? false,
|
||||
UserQrCodeExpiration = settings.FirstOrDefault(x => x.TenantId == item.Code)?.UserQrCodeExpiration,
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task SaveAsync(FactorySettingSaveRequest request)
|
||||
{
|
||||
var setting = await _dbContext.Queryable<FactorySettingEntity>().Where(x => request.Factory == x.TenantId).SingleAsync();
|
||||
if (setting == null)
|
||||
{
|
||||
setting = request.Adapt<FactorySettingEntity>();
|
||||
setting.TenantId = request.Factory;
|
||||
|
||||
await _dbContext.InsertAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Adapt(setting);
|
||||
setting.TenantId = request.Factory;
|
||||
|
||||
await _dbContext.UpdateAsync(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,20 +13,20 @@ public class FactorySettingEntity : SugarBaseEntity, ITenantId
|
||||
/// <summary>
|
||||
/// 是否启用外包自动下发
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用外包自动下发")]
|
||||
[SugarColumn(ColumnDataType = "bit", ColumnDescription = "是否启用外包自动下发", DefaultValue = "0")]
|
||||
public bool EnableOutsourceDown { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 档案二维码过期时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "档案二维码过期时间")]
|
||||
public int UserQrCodeExpiration { get; set; }
|
||||
[SugarColumn(ColumnDescription = "档案二维码过期时间", IsNullable = true)]
|
||||
public int? UserQrCodeExpiration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 电子餐券二维码过期时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "电子餐券二维码过期时间")]
|
||||
public int EMealVoucherQrCodeExpiration { get; set; }
|
||||
[SugarColumn(ColumnDescription = "电子餐券二维码过期时间", IsNullable = true)]
|
||||
public int? EMealVoucherQrCodeExpiration { get; set; }
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user