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.
266 lines
11 KiB
C#
266 lines
11 KiB
C#
using AngleSharp.Dom;
|
|
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.Code.Dtos;
|
|
using DS.WMS.Core.Code.Entity;
|
|
using DS.WMS.Core.Code.Interface;
|
|
using DS.WMS.Core.Fee.Entity;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Code.Method
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class CodeCheckBillTemplateService : ICodeCheckBillTemplateService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
private readonly ISaasDbService saasService;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public CodeCheckBillTemplateService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
}
|
|
|
|
public DataResult EditCheckBillTemplate(CheckBillTemplateReq req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Id == 0)
|
|
{
|
|
|
|
if (tenantDb.Queryable<CodeCheckBillTemplate>().Where(x => x.Name == req.Name.Trim()).Any())
|
|
return DataResult.Failed("对账模板信息已存在!", MultiLanguageConst.CheckBillTemplateExist);
|
|
|
|
|
|
var data = req.Adapt<CodeCheckBillTemplate>();
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
//添加费用明细
|
|
if (req.FeeList.Count > 0)
|
|
{
|
|
var feeList = new List<CodeCheckBillTemplateFee>();
|
|
foreach (var item in req.FeeList)
|
|
{
|
|
var fee = item.Adapt<CodeCheckBillTemplateFee>();
|
|
fee.TemplateId = entity.Id;
|
|
feeList.Add(fee);
|
|
}
|
|
tenantDb.Insertable(feeList).ExecuteCommand();
|
|
}
|
|
//添加排序明细
|
|
if (req.SortList.Count > 0)
|
|
{
|
|
var sortList = new List<CodeCheckBillTemplateSort>();
|
|
foreach (var item in req.FeeList)
|
|
{
|
|
var sort = item.Adapt<CodeCheckBillTemplateSort>();
|
|
sort.TemplateId = entity.Id;
|
|
sortList.Add(sort);
|
|
}
|
|
tenantDb.Insertable(sortList).ExecuteCommand();
|
|
}
|
|
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
}
|
|
else
|
|
{
|
|
var info = tenantDb.Queryable<CodeCheckBillTemplate>().Where(x => x.Id == req.Id).First();
|
|
|
|
info = req.Adapt(info);
|
|
|
|
//更新费用明细
|
|
if (req.FeeList.Count > 0)
|
|
{
|
|
var feeList = tenantDb.Queryable<CodeCheckBillTemplateFee>().Where(x => x.TemplateId == req.Id).ToList();
|
|
var addFeeList = new List<CodeCheckBillTemplateFee>();
|
|
var updateFeeList = new List<CodeCheckBillTemplateFee>();
|
|
foreach (var item in req.FeeList)
|
|
{
|
|
if (item.Id == 0)
|
|
{
|
|
var fee = item.Adapt<CodeCheckBillTemplateFee>();
|
|
fee.TemplateId = info.Id;
|
|
addFeeList.Add(fee);
|
|
}
|
|
else
|
|
{
|
|
var fee = feeList.Where(x => x.Id == item.Id).First();
|
|
fee = item.Adapt(fee);
|
|
updateFeeList.Add(fee);
|
|
}
|
|
}
|
|
if (addFeeList.Count > 0)
|
|
tenantDb.Insertable(addFeeList).ExecuteCommand();
|
|
|
|
if (updateFeeList.Count > 0)
|
|
tenantDb.Updateable(updateFeeList).ExecuteCommand();
|
|
}
|
|
//更新排序明细
|
|
if (req.SortList.Count > 0)
|
|
{
|
|
var sortList = tenantDb.Queryable<CodeCheckBillTemplateSort>().Where(x => x.TemplateId == req.Id).ToList();
|
|
var addSortList = new List<CodeCheckBillTemplateSort>();
|
|
var updateSortList = new List<CodeCheckBillTemplateSort>();
|
|
foreach (var item in req.SortList)
|
|
{
|
|
if (item.Id == 0)
|
|
{
|
|
var sort = item.Adapt<CodeCheckBillTemplateSort>();
|
|
sort.TemplateId = info.Id;
|
|
addSortList.Add(sort);
|
|
}
|
|
else
|
|
{
|
|
var sort = sortList.Where(x => x.Id == item.Id).First();
|
|
sort = item.Adapt(sort);
|
|
updateSortList.Add(sort);
|
|
}
|
|
}
|
|
if (addSortList.Count > 0)
|
|
tenantDb.Insertable(addSortList).ExecuteCommand();
|
|
|
|
if (updateSortList.Count > 0)
|
|
tenantDb.Updateable(updateSortList).ExecuteCommand();
|
|
}
|
|
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
}
|
|
|
|
public DataResult<CheckBillTemplateInfoRes> GetCheckBillTemplateInfo(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var users = db.Queryable<SysUser>().Select(x => new { x.Id, x.UserName }).ToList();
|
|
|
|
var data = tenantDb.Queryable<CodeCheckBillTemplate>()
|
|
.Where(x => x.Id == long.Parse(id))
|
|
.Select<CheckBillTemplateInfoRes>()
|
|
.Mapper(it =>
|
|
{
|
|
it.CreateByName = users.Find(x => x.Id == it.CreateBy).UserName;
|
|
it.FeeList = tenantDb.Queryable<CodeCheckBillTemplateFee>()
|
|
.Where(x => x.TemplateId == it.Id)
|
|
.Select<CheckBillTemplateFeeRes>().ToList();
|
|
it.SortList = tenantDb.Queryable<CodeCheckBillTemplateSort>()
|
|
.Where(x => x.TemplateId == it.Id)
|
|
.Select<CheckBillTemplateSortRes>().OrderBy(x=>x.OrderNo).ToList();
|
|
}).First();
|
|
return DataResult<CheckBillTemplateInfoRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
}
|
|
|
|
public DataResult<List<CheckBillTemplateRes>> GetListByPage(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var users = db.Queryable<SysUser>().Select(x => new { x.Id, x.UserName }).ToList();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = tenantDb.Queryable<CodeCheckBillTemplate>()
|
|
.Where(whereList)
|
|
.Select<CheckBillTemplateRes>()
|
|
.Mapper(it =>
|
|
{
|
|
it.CreateByName = users.Find(x => x.Id == it.CreateBy).UserName;
|
|
})
|
|
.ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对账模板费用批量删除
|
|
/// </summary>
|
|
/// <param name="req">主表Id及费用明细Ids</param>
|
|
/// <returns></returns>
|
|
public DataResult BatchDelCheckBillTemplateFee(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var tmpId = long.Parse(req.Id);
|
|
if (req.Id.IsNull())
|
|
return DataResult.Failed("主表Id不能为空");
|
|
|
|
var info = tenantDb.Queryable<CodeCheckBillTemplate>().First(x => x.Id == tmpId);
|
|
if (info.IsNull())
|
|
return DataResult.Failed("对账模板信息不存在");
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("费用明细Ids不能为空");
|
|
|
|
|
|
var feeList = tenantDb.Queryable<CodeCheckBillTemplateFee>().Where(x => x.TemplateId == tmpId && req.Ids.Contains(x.Id)).ToList();
|
|
|
|
if (feeList.Count > 0)
|
|
tenantDb.Deleteable(feeList).ExecuteCommand();
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对账模板排序批量删除
|
|
/// </summary>
|
|
/// <param name="req">主表Id及费用明细Ids</param>
|
|
/// <returns></returns>
|
|
public DataResult BatchDelCheckBillTemplateSort(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var tmpId = long.Parse(req.Id);
|
|
if (req.Id.IsNull())
|
|
return DataResult.Failed("主表Id不能为空");
|
|
|
|
var info = tenantDb.Queryable<CodeCheckBillTemplate>().First(x => x.Id == tmpId);
|
|
if (info.IsNull())
|
|
return DataResult.Failed("对账模板信息不存在");
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("排序明细Ids不能为空");
|
|
|
|
|
|
var sortList = tenantDb.Queryable<CodeCheckBillTemplateSort>().Where(x => x.TemplateId == tmpId && req.Ids.Contains(x.Id)).ToList();
|
|
|
|
if (sortList.Count > 0)
|
|
tenantDb.Deleteable(sortList).ExecuteCommand();
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对账模板批量删除
|
|
/// </summary>
|
|
/// <param name="req">主表Ids</param>
|
|
/// <returns></returns>
|
|
public DataResult BatchDelCheckBillTemplate(IdModel req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
if (req.Ids.Length == 0)
|
|
return DataResult.Failed("对账模板Ids不能为空");
|
|
|
|
var tmpList = tenantDb.Queryable<CodeCheckBillTemplate>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
if (tmpList.Count > 0)
|
|
tenantDb.Deleteable(tmpList).ExecuteCommand();
|
|
|
|
var feeList = tenantDb.Queryable<CodeCheckBillTemplateFee>().Where(x => req.Ids.Contains(x.TemplateId)).ToList();
|
|
if (feeList.Count > 0)
|
|
tenantDb.Deleteable(feeList).ExecuteCommand();
|
|
var sortList = tenantDb.Queryable<CodeCheckBillTemplateSort>().Where(x => req.Ids.Contains(x.TemplateId)).ToList();
|
|
if (sortList.Count > 0)
|
|
tenantDb.Deleteable(sortList).ExecuteCommand();
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
}
|
|
}
|