You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
7.0 KiB
C#

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
{
/// <summary>
/// 业务锁定
/// </summary>
public class BusinessLockService: IBusinessLockService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public BusinessLockService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
public async Task<DataResult<List<VW_Op_Business_Lock>>> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = await tenantDb.Queryable<VW_Op_Business_Lock>()
.Where(whereList)
.ToQueryPageAsync(request.PageCondition);
return data;
}
/// <summary>
/// 业务锁定
/// </summary>
/// <param name="req">主表Ids</param>
/// <returns></returns>
public DataResult BusinessLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable<BusinessFeeStatus>().Where(x => req.Ids.Contains(x.BusinessId) && x.IsBusinessLocking == true).Any())
{
return DataResult.Failed("存在已业务锁定的业务信息!");
}
var billLists = tenantDb.Queryable<BusinessFeeStatus>().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);
}
/// <summary>
/// 业务解除锁定
/// </summary>
/// <param name="req">主表Ids</param>
/// <returns></returns>
public DataResult BusinessUnLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable<BusinessFeeStatus>().Where(x => req.Ids.Contains(x.BusinessId) && x.IsBusinessLocking == false).Any())
{
return DataResult.Failed("存在已解除业务锁定的业务信息!");
}
var billLists = tenantDb.Queryable<BusinessFeeStatus>().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);
}
/// <summary>
/// 费用锁定
/// </summary>
/// <param name="req">主表Ids</param>
/// <returns></returns>
public DataResult FeeLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable<BusinessFeeStatus>().Where(x => req.Ids.Contains(x.BusinessId) && x.IsFeeLocking == true).Any())
{
return DataResult.Failed("存在已费用锁定的业务信息!");
}
var billLists = tenantDb.Queryable<BusinessFeeStatus>().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);
}
/// <summary>
/// 费用解除锁定
/// </summary>
/// <param name="req">主表Ids</param>
/// <returns></returns>
public DataResult FeeUnLocking(IdModel req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (req.Ids.Length == 0)
return DataResult.Failed("业务Ids不能为空");
if (tenantDb.Queryable<BusinessFeeStatus>().Where(x => req.Ids.Contains(x.BusinessId) && x.IsFeeLocking == false).Any())
{
return DataResult.Failed("存在已解除费用锁定的业务信息!");
}
var billLists = tenantDb.Queryable<BusinessFeeStatus>().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);
}
}
}