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.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.GetListByPageAsync(request); } /// /// 根据指定的查询条件获取统计信息 /// /// 查询条件 /// [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 == null || 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; } return await _feeService.SaveAsync(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(AuditType.FeeAudit, 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(AuditType.FeeDelete, 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(IdModel model) { if (model == null || !long.TryParse(model.Id, out long bid)) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.SubmitBusinessAuditAsync(bid, (BusinessType)model.BusinessType.Value); } /// /// 获取费用核算单打印信息 /// /// 费用记录ID /// [HttpPost, Route("GetPrintInfo")] public async Task> GetPrintInfoAsync(IdModel model) { if (model == null || model.Ids?.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return await _feeService.GetPrintInfoAsync((BusinessType)model.BusinessType.Value, model.Ids); } /// /// 设置费用是否启用发票 /// /// 费用记录ID /// [HttpPost, Route("SetInvoiceEnabled")] public async Task SetInvoiceEnabledAsync(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); } } }