using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Check.Entity;
using DS.WMS.Core.Finance.Interface;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Op.View;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using NLog;
using Org.BouncyCastle.Ocsp;
using SqlSugar;
using Logger = NLog.Logger;
namespace DS.WMS.Core.Finance.Method
{
///
/// 业务锁定
///
public class BusinessLockService: IBusinessLockService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
///
///
///
///
public BusinessLockService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
}
public async Task>> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = await tenantDb.Queryable()
.Where(whereList)
.ToQueryPageAsync(request.PageCondition);
return data;
}
///
/// 业务锁定
///
/// 主表Ids
///
public DataResult BusinessLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsBusinessLocking == true).Any())
{
return DataResult.Failed("存在已业务锁定的业务信息!");
}
var billLists = tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId)).ToList();
if (billLists.Count > 0)
{
foreach (var bill in billLists) {
bill.BusinessLockingUserId = long.Parse(user.UserId);
bill.BusinessLockingUserName = user.UserName;
bill.BusinessLockingTime = DateTime.Now;
bill.IsBusinessLocking = true;
}
tenantDb.Updateable(billLists).ExecuteCommand();
}
return DataResult.Successed("业务锁定成功!", MultiLanguageConst.DataUpdateSuccess);
}
///
/// 业务解除锁定
///
/// 主表Ids
///
public DataResult BusinessUnLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsBusinessLocking == false).Any())
{
return DataResult.Failed("存在已解除业务锁定的业务信息!");
}
var billLists = tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId)).ToList();
if (billLists.Count > 0)
{
foreach (var bill in billLists)
{
bill.BusinessLockingUserId = long.Parse(user.UserId);
bill.BusinessLockingUserName = user.UserName;
bill.BusinessLockingTime = DateTime.Now;
bill.IsBusinessLocking = false;
}
tenantDb.Updateable(billLists).ExecuteCommand();
}
return DataResult.Successed("业务解除锁定成功!", MultiLanguageConst.DataUpdateSuccess);
}
///
/// 费用锁定
///
/// 主表Ids
///
public DataResult FeeLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsFeeLocking == true).Any())
{
return DataResult.Failed("存在已费用锁定的业务信息!");
}
var billLists = tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId)).ToList();
if (billLists.Count > 0)
{
foreach (var bill in billLists)
{
bill.FeeLockingUserId = long.Parse(user.UserId);
bill.FeeLockingUserName = user.UserName;
bill.FeeLockingTime = DateTime.Now;
bill.IsFeeLocking = true;
}
tenantDb.Updateable(billLists).ExecuteCommand();
}
return DataResult.Successed("费用锁定成功!", MultiLanguageConst.DataUpdateSuccess);
}
///
/// 费用解除锁定
///
/// 主表Ids
///
public DataResult FeeUnLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsFeeLocking == false).Any())
{
return DataResult.Failed("存在已解除费用锁定的业务信息!");
}
var billLists = tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId)).ToList();
if (billLists.Count > 0)
{
foreach (var bill in billLists)
{
bill.FeeLockingUserId = long.Parse(user.UserId);
bill.FeeLockingUserName = user.UserName;
bill.FeeLockingTime = DateTime.Now;
bill.IsFeeLocking = false;
}
tenantDb.Updateable(billLists).ExecuteCommand();
}
return DataResult.Successed("解除费用锁定成功!", MultiLanguageConst.DataUpdateSuccess);
}
}
}