using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Fee.Interface;
using Mapster;
namespace DS.WMS.Core.Fee.Method
{
///
/// 往来单位费用模板明细
///
public class FeeCustTemplateDetailService : FeeServiceBase, IFeeCustTemplateDetailService
{
///
/// 初始化
///
///
public FeeCustTemplateDetailService(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
///
/// 列表
///
///
///
public DataResult> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = request.GetConditionalModels(Db);
var data = TenantDb.Queryable().Where(whereList)
.Select().ToQueryPage(request.PageCondition);
return data;
}
///
/// 编辑
///
///
///
public async Task EditAsync(FeeCustTemplateDetailReq req)
{
if (req.Id == 0)
{
if (TenantDb.Queryable().Where(x => x.FeeId == req.FeeId && x.FeeType == req.FeeType).Any())
return DataResult.Failed("往来单位固定费用已存在!", MultiLanguageConst.FeeCustTemplateDetailExist);
var data = req.Adapt();
var entity = await TenantDb.Insertable(data).ExecuteReturnEntityAsync();
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = TenantDb.Queryable().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
await TenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
}
}
///
/// 详情
///
///
///
public DataResult GetFeeCustTemplateDetailInfo(string id)
{
var data = TenantDb.Queryable()
.Where(x => x.Id == long.Parse(id))
.Select()
.First();
return DataResult.Success(data, MultiLanguageConst.DataQuerySuccess);
}
///
/// 根据ID批量删除
///
///
///
public async Task DeleteAsync(IdModel model)
{
int rows = await TenantDb.Deleteable().Where(x => model.Ids.Contains(x.Id)).ExecuteCommandAsync();
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
}