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.

135 lines
5.1 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Info.Dtos;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Info.Interface;
using DS.WMS.Core.Sys.Entity;
using Mapster;
namespace DS.WMS.Core.Info.Method;
/// <summary>
/// 账期日
/// </summary>
public class ClientAccountDateService : ServiceBase, IClientAccountDateService
{
const string KEY_StartDate = "infoclient_business_accountStartDate";
const string KEY_Type = "infoclient_business_accountType";
/// <summary>
/// 初始化
/// </summary>
/// <param name="serviceProvider"></param>
public ClientAccountDateService(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<ClientAccountDateRes>> GetListByPage(PageRequest request)
{
var whereList = request.GetConditionalModels(Db);
var result = TenantDb.Queryable<InfoClientAccountDate>()
.Where(whereList)
.Select<ClientAccountDateRes>().ToQueryPage(request.PageCondition);
if (result.Data != null)
{
var values1 = result.Data.Where(x => x.AccountStartDate != null).Select(x => x.AccountStartDate).Distinct();
var startDateList = Db.Queryable<SysDictData>().Where(x => x.Type.Code == KEY_StartDate && values1.Contains(x.Value))
.Select(x => new { x.Value, x.Name }).ToList();
var values2 = result.Data.Where(x => x.AccountType != null).Select(x => x.AccountType).Distinct();
var typeList = Db.Queryable<SysDictData>().Where(x => x.Type.Code == KEY_Type && values2.Contains(x.Value))
.Select(x => new { x.Value, x.Name }).ToList();
foreach (var item in result.Data)
{
item.AccountStartDateName = startDateList.Find(x => item.AccountStartDate == x.Value)?.Name;
item.AccountTypeName = typeList.Find(x => item.AccountType == x.Value)?.Name;
}
}
return result;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditClientAccountDate(ClientAccountDateReq req)
{
if (req.Id == 0)
{
if (TenantDb.Queryable<InfoClientAccountDate>().Where(x => x.AccountType == req.AccountType &&
x.AccountType == req.AccountType &&
x.SaleId == req.SaleId &&
x.BeginDate == req.BeginDate &&
x.EndDate == req.EndDate).Any())
{
return DataResult.Failed("客户账期信息已存在!", MultiLanguageConst.ClientAccountDateExist);
}
var data = req.Adapt<InfoClientAccountDate>();
var entity = TenantDb.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = TenantDb.Queryable<InfoClientAccountDate>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
TenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<ClientAccountDateRes> GetClientAccountDateInfo(string id)
{
var data = TenantDb.Queryable<InfoClientAccountDate>()
.Where(a => a.Id == long.Parse(id))
.Select<ClientAccountDateRes>()
.First();
return DataResult<ClientAccountDateRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
/// <summary>
/// 根据ID批量删除
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public async Task<DataResult> DeleteAsync(IdModel model)
{
int rows = await TenantDb.Deleteable<InfoClientAccountDate>().Where(x => model.Ids.Contains(x.Id)).ExecuteCommandAsync();
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
/// <summary>
/// 获取组织机构银行账户列表
/// </summary>
/// <param name="currency">账户币别</param>
/// <returns></returns>
public async Task<DataResult<List<SysBank>>> GetTenantBanksAsync(string? currency = null)
{
var list = await Db.Queryable<SysBank>()
.WhereIF(!string.IsNullOrEmpty(currency), x => x.Currency == currency)
.OrderBy(x => x.OrderNo).ToListAsync();
var result = DataResult<List<SysBank>>.Success(list);
result.Count = list.Count;
return result;
}
}