71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using Dlhis.Basic.Device.Services;
|
|
using Dlhis.Basic.Organization.Request;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Sys.Entities;
|
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
|
|
|
public class GainfoOutsourceSettingService : IGainfoOutsourceSettingService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly ICurrentUser _currentUser;
|
|
private readonly IDevicePermissionService _devicePermissionService;
|
|
|
|
public GainfoOutsourceSettingService(IDbContext dbContext, ICurrentUser currentUser, IDevicePermissionService devicePermissionService)
|
|
{
|
|
_dbContext = dbContext;
|
|
_currentUser = currentUser;
|
|
_devicePermissionService = devicePermissionService;
|
|
}
|
|
|
|
public async Task SaveAsync(GainfoOutsourceSettingSaveRequest request)
|
|
{
|
|
var userNos = await _dbContext.Queryable<GainfoEntity>()
|
|
.Where(x => SqlFunc.Subqueryable<OutsourceEntity>().Where(p => p.Code == x.Code).Any())
|
|
.Select(x => x.No)
|
|
.ToListAsync();
|
|
|
|
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
|
|
{
|
|
var currentTenantId = _currentUser.GetStringTenantId();
|
|
|
|
(!request.Id.HasValue && await _dbContext.Queryable<FactorySettingEntity>()
|
|
.Where(x => x.TenantId == currentTenantId)
|
|
.AnyAsync()).ThrowIfTrue("保存失败,请检查参数");
|
|
|
|
if (!request.Id.HasValue)
|
|
{
|
|
var entity = new FactorySettingEntity
|
|
{
|
|
EnableOutsourceDown = request.EnableFactory,
|
|
TenantId = currentTenantId
|
|
};
|
|
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
var entity = await _dbContext.Queryable<FactorySettingEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
|
entity.ThrowIfNull("数据不存在,保存失败");
|
|
|
|
entity.EnableOutsourceDown = request.EnableFactory;
|
|
|
|
await _dbContext.UpdateAsync(entity);
|
|
}
|
|
}, userNos);
|
|
}
|
|
|
|
|
|
public async Task<object> GetSettingAsync()
|
|
{
|
|
var currentTenantId = _currentUser.GetStringTenantId();
|
|
return await _dbContext.Queryable<FactorySettingEntity>().Where(x => x.TenantId == currentTenantId).Select(x => new
|
|
{
|
|
x.Id, EnableFactory = x.EnableOutsourceDown
|
|
}).SingleAsync();
|
|
}
|
|
} |