|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Interface;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using AngleSharp.Dom;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
public class FeeTemplateService: IFeeTemplateService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
private readonly ISaasDbService saasService;
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public FeeTemplateService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<List<FeeTemplateRes>> GetListByPage(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
//序列化查询条件
|
|
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
var data = tenantDb.Queryable<FeeTemplate>()
|
|
|
|
|
.Where(whereList)
|
|
|
|
|
.Select<FeeTemplateRes>().ToQueryPage(request.PageCondition);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult EditFeeTemplate(FeeTemplateReq req)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
if (req.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
if (tenantDb.Queryable<FeeTemplate>()
|
|
|
|
|
.Where(x => x.OpType == req.OpType && x.FeeType == req.FeeType).Any())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("费用模板已存在!", MultiLanguageConst.FeeTemplateExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = req.Adapt<FeeTemplate>();
|
|
|
|
|
|
|
|
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
|
|
|
|
|
|
if (req.Detail.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in req.Detail)
|
|
|
|
|
{
|
|
|
|
|
var detail = item.Adapt<FeeTemplateDetail>();
|
|
|
|
|
detail.TemplateId = entity.Id;
|
|
|
|
|
tenantDb.Insertable(detail).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var info = tenantDb.Queryable<FeeTemplate>().Where(x => x.Id == req.Id).First();
|
|
|
|
|
|
|
|
|
|
info = req.Adapt(info);
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.Detail.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var detailList = tenantDb.Queryable<FeeTemplateDetail>().Where(x => x.TemplateId == req.Id).ToList();
|
|
|
|
|
foreach (var item in req.Detail)
|
|
|
|
|
{
|
|
|
|
|
if (item.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
var detail = item.Adapt<FeeTemplateDetail>();
|
|
|
|
|
detail.TemplateId = info.Id;
|
|
|
|
|
tenantDb.Insertable(detail).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var detail = detailList.First(x => x.Id == item.Id);
|
|
|
|
|
detail = item.Adapt(detail);
|
|
|
|
|
tenantDb.Updateable(detail).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<FeeTemplateRes> GetFeeTemplateInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var data = tenantDb.Queryable<FeeTemplate>()
|
|
|
|
|
.Where(x => x.Id == long.Parse(id))
|
|
|
|
|
.Select<FeeTemplateRes>()
|
|
|
|
|
.First();
|
|
|
|
|
return DataResult<FeeTemplateRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|