using DS.Module.Core; using DS.Module.Core.Data; using DS.WMS.Core.Fee.Dtos; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Fee.Interface; using DS.WMS.Core.Fee.Method.ReportProviders; using DS.WMS.Core.Op.Entity; using Microsoft.AspNetCore.Mvc; namespace DS.WMS.FeeApi.Controllers { /// /// 费用记录服务 /// public class FeeRecordController : ApiController { readonly IFeeRecordService _feeService; /// /// 构造函数 /// /// public FeeRecordController(IFeeRecordService feeService) { _feeService = feeService; } /// /// 列表 /// /// /// [HttpPost] [Route("GetList")] public async Task>> GetListAsync([FromBody] PageRequest request) { return await _feeService.GetListAsync(request); } /// /// 根据查询条件获取费用数据(仅用于获取数据,不作UI展示用) /// /// JSON格式的查询条件 /// [HttpGet, Route("GetQuery")] public async Task>> GetListAsync(string query) { return await _feeService.GetListAsync(query); } /// /// 获取费用申请修改的新值 /// /// 费用记录ID /// [HttpGet, Route("GetModifyValue")] public async Task> GetModifyValue(long id) { return await _feeService.GetModifyValue(id); } /// /// 根据指定的查询条件获取统计信息 /// /// 查询条件 /// [HttpPost, Route("FeeStatistics")] public async Task> StatisticsAsync([FromBody] FeeStatisticsRequest request) { if (request == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); var res = await _feeService.GetListAsync(request.QueryCondition); if (!res.Succeeded) return DataResult.Error(res.Message); var stat = new FeeStatistics(res.Data); return DataResult.Success(stat); } /// /// 保存费用 /// /// /// [HttpPost, Route("Submit")] public async Task SubmitAsync([FromBody] FeeRecordSubmit recordSubmit) { if (recordSubmit.Items == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)) return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest); foreach (var item in recordSubmit.Items) { item.BusinessId = recordSubmit.BusinessId; item.BusinessType = recordSubmit.BusinessType; item.FeeStatus = FeeStatus.Entering; item.InputMethod = InputMethod.Manual; } return await _feeService.SaveAsync(recordSubmit.Items); } /// /// 保存费用并提交审核 /// /// /// [HttpPost, Route("SubmitWithAudit")] public async Task SubmitWithAuditAsync([FromBody] FeeRecordSubmit recordSubmit) { if (recordSubmit.Items == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)) return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest); foreach (var item in recordSubmit.Items) { item.BusinessId = recordSubmit.BusinessId; item.BusinessType = recordSubmit.BusinessType; item.FeeStatus = FeeStatus.Entering; item.InputMethod = InputMethod.Manual; } return await _feeService.SaveAndSubmitAsync(recordSubmit.Items); } /// /// 根据一组模板ID创建费用记录(引入模板) /// /// 请求参数 /// [HttpPost, Route("CreateByTemplate")] public async Task CreateByTemplateAsync([FromBody] FeeRecordByTemplate request) { if (request == null || request.TemplateIdList?.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.CreateByTemplateAsync(request.BusinessId, request.BusinessType, request.TemplateIdList); } /// /// 根据费用记录ID删除 /// /// 费用记录ID /// [HttpPost, Route("Delete")] public async Task DeleteAsync([FromBody] IdModel model) { if (model.Ids == null || model.Ids.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.DeleteAsync(model.Ids); } /// /// 提交审批 /// /// 费用记录ID /// [HttpPost, Route("ApplyAudit")] public async Task ApplyAuditAsync([FromBody] IdModel model) { if (model.Ids == null || model.Ids?.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.SubmitForApprovalAsync(TaskBaseTypeEnum.FEE_AUDIT, model.Remark, model.Ids); } /// /// 申请删除 /// /// 费用记录ID /// [HttpPost, Route("ApplyDeletion")] public async Task ApplyDeletionAsync([FromBody] IdModel model) { if (model == null || model.Ids?.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.SubmitForApprovalAsync(TaskBaseTypeEnum.FEE_DELETE_AUDIT, model.Remark, model.Ids); } /// /// 申请修改 /// /// 费用修改信息 /// [HttpPost, Route("ApplyModification")] public async Task ApplyModificationAsync([FromBody] IEnumerable items) { if (items == null || !items.Any()) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.SubmitForModificationAsync(items); } /// /// 撤销审批申请 /// /// 费用记录ID /// [HttpPost, Route("Withdraw")] public async Task WithdrawAsync([FromBody] IdModel model) { if (model == null || model.Ids?.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.WithdrawAsync(model.Ids); } /// /// 发起整票审核 /// /// 业务ID和类型 /// [HttpPost, Route("ApplyBusinessAudit")] public async Task ApplyBusinessAuditAsync([FromBody] IdModel model) { if (!long.TryParse(model.Id, out long bid) || model.BusinessType == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.SubmitBusinessAuditAsync(bid, (BusinessType)model.BusinessType.Value); } /// /// 撤销整票审核 /// /// 业务ID和类型 /// [HttpPost, Route("WithdrawBusiness")] public async Task WithdrawBusinessAsync([FromBody] IdModel model) { if (!long.TryParse(model.Id, out long bid) || model.BusinessType == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.SubmitBusinessAuditAsync(bid, (BusinessType)model.BusinessType.Value); } /// /// 获取费用打印数据 /// /// /// [HttpPost, Route("GetPrintInfo")] public async Task> GetPrintInfoAsync([FromBody] IdModel model) { if (model == null || !long.TryParse(model.Id, out long bsId)) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); string? providerName = model.Value?.ToString(); if (string.IsNullOrEmpty(providerName)) providerName = typeof(CostAccountingReport).AssemblyQualifiedName; if (!providerName.Contains('.')) providerName = "DS.WMS.Core.Fee.Method.ReportProviders." + providerName; return await _feeService.GetPrintInfoAsync(providerName, bsId, (BusinessType)model.BusinessType.Value, model.Ids); } /// /// 设置费用是否启用发票 /// /// 费用记录ID /// [HttpPost, Route("SetInvoiceEnabled")] public async Task SetInvoiceEnabledAsync([FromBody] IdModel model) { if (model == null || model.Ids?.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); bool enabled = Convert.ToBoolean(model.Value); return await _feeService.SetInvoiceEnabledAsync(enabled, model.Ids); } /// /// 刷新业务表费用状态 /// /// 业务ID /// 业务类型 /// [HttpPost, Route("RefreshBusinessFeeStatus")] public async Task RefreshBusinessFeeStatusAsync(long bsId, BusinessType bsType) { await _feeService.WriteBackStatusAsync(bsId, bsType); return Ok(); } } }