using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Flow.Dtos; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Interface; using DS.WMS.Core.TaskInteraction.Dtos; using DS.WMS.Core.TaskInteraction.Interface; using Mapster; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.Core.Op.Method { /// /// 海运出口退仓接口 /// public class SeaExportChangeETDService : ISeaExportChangeETDService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; private readonly ISaasDbService saasService; readonly ITaskService taskService; private readonly ISeaExportCommonService seaComService; /// /// /// /// public SeaExportChangeETDService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); seaComService = _serviceProvider.GetRequiredService(); taskService = serviceProvider.GetRequiredService(); } #region 发起改配 public async Task CreateChangeETDTaskAsync(RefundTaskReq req) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var info = await tenantDb.Queryable().Where(x => x.Id == req.Id).FirstAsync(); if (info.IsNull()) return await Task.FromResult(DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist)); if (!req.IsReserveFee && tenantDb.Queryable().Where(x => x.BusinessId == req.Id).Any()) { return await Task.FromResult(DataResult.Failed("存在业务相关费用,是否保留费用?")); } if (req.IsReserveFee && tenantDb.Queryable().Where(x => x.BusinessId == req.Id && x.FeeStatus == FeeStatus.Entering).Any()) { return await Task.FromResult(DataResult.Failed("存在录入状态的费用!")); } var taskReq = new TaskCreationRequest() { BusinessId = req.Id, BusinessType = BusinessType.OceanShippingExport, TaskTypeName = TaskBaseTypeEnum.RETURN_CABIN.ToString(), }; var result = await taskService.CreateTaskAsync(taskReq, false); if (!result.Succeeded) { return await Task.FromResult(DataResult.Failed(result.Message)); } else { await seaComService.SetGoodsStatus("YFTC", req.Id, tenantDb); return await Task.FromResult(DataResult.Successed(result.Message)); } } #endregion /// /// 改配审核完成回调 /// /// 回调信息 /// public async Task ChangeETDAuditCallbackAsync(FlowCallback callback) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (callback.AuditType != TaskBaseTypeEnum.RETURN_CABIN) return DataResult.FailedWithDesc(nameof(MultiLanguageConst.NoAuditItems)); var info = await tenantDb.Queryable().Where(x => x.Id == callback.BusinessId).FirstAsync(); if (info.IsNull()) return await Task.FromResult(DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist)); var oldOrder = info.Adapt(); info.IsRefund = callback.FlowStatus == FlowStatusEnum.Approve ? true : false; int rows = await tenantDb.Updateable(info).UpdateColumns(x => new { x.IsRefund, }).ExecuteCommandAsync(); await seaComService.SetGoodsStatus("YTC", callback.BusinessId, tenantDb); await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog() { OperateType = "Update", OldOrder = oldOrder, NewOrder = info, SourceCode = "ChangeETDAuditCallbackAsync", SourceName = "改配审核完成回调", }, tenantDb); return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); } } }