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.Flow.Dtos; using DS.WMS.Core.Flow.Interface; using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace DS.WMS.FeeApi.Controllers { /// /// 费用记录服务 /// public class FeeRecordController : ApiController { readonly IFeeRecordService _feeService; readonly IClientFlowInstanceService _flowService; /// /// 构造函数 /// /// /// public FeeRecordController(IFeeRecordService feeService, IClientFlowInstanceService flowService) { _feeService = feeService; _flowService = flowService; } /// /// 列表 /// /// /// [HttpPost] [Route("GetList")] public DataResult> GetList([FromBody] PageRequest request) { var res = _feeService.GetListByPage(request); return res; } /// /// 根据指定的查询条件获取统计信息 /// /// 查询条件 /// [HttpPost, Route("FeeStatistics")] public DataResult FeeStatistics([FromBody] FeeStatisticsRequest request) { if (request == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); var res = _feeService.GetList(request.QueryCondition); if (!res.Succeeded) return DataResult.Error(res.Message); var stat = new FeeStatistics(res.Data); return DataResult.Success(stat); } /// /// 根据费用明细转换为模板明细 /// /// 费用明细ID /// [HttpGet, Route("ReadAsTemplate")] public DataResult> ReadAsTemplate([FromQuery] long[] ids) { var res = _feeService.ReadAsTemplate(ids); return res; } /// /// 提交费用 /// /// 费用提交参数 /// [HttpPost, Route("Submit")] public DataResult Submit([FromBody] FeeRecordSubmit recordSubmit) { if (recordSubmit == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering)) return DataResult.Failed("只能提交状态为‘录入’的费用", MultiLanguageConst.IllegalRequest); var list = recordSubmit.Items.Select(x => x.Adapt()); return _feeService.InsertOrUpdate(recordSubmit.BusinessId, list); } /// /// 根据一组模板ID创建费用记录(引入模板) /// /// 请求参数 /// [HttpPost, Route("CreateByTemplate"), NonAction] public DataResult CreateByTemplate([FromBody] FeeRecordByTemplate request) { if (request == null || request.TemplateIdList.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); var res = _feeService.CreateByTemplate(request.BusinessId, request.TemplateIdList); return res; } /// /// 根据费用记录ID删除 /// /// 费用记录ID /// [HttpPost, Route("Delete")] public DataResult Delete([FromBody] IdModel model) { if (model == null || model.Ids.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); var res = _feeService.Delete(model.Ids); return res; } /// /// 提交审批 /// /// 费用记录ID /// [HttpPost, Route("ApplyAudit")] public DataResult ApplyAudit([FromBody] IdModel model) { if (model == null || model.Ids.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return _feeService.SubmitForApproval(FeeAuditType.ApplyAudit, model.Ids); } /// /// 申请修改 /// /// 费用记录ID /// [HttpPost, Route("ApplyModification")] public DataResult ApplyModification([FromBody] IdModel model) { if (model == null || model.Ids.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return _feeService.SubmitForApproval(FeeAuditType.ApplyModification, model.Ids); } /// /// 申请删除 /// /// 费用记录ID /// [HttpPost, Route("ApplyDeletion")] public DataResult ApplyDeletion([FromBody] IdModel model) { if (model == null || model.Ids.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return _feeService.SubmitForApproval(FeeAuditType.ApplyDeletion, model.Ids); } /// /// 撤销审批申请 /// /// 费用记录ID /// [HttpPost, Route("Withdraw")] public DataResult Withdraw([FromBody] IdModel model) { if (model == null || model.Ids.Length == 0) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return _feeService.Withdraw(model.Ids); } /// /// 变更费用审批状态回调 /// /// 回调信息 /// [HttpPost, Route("ChangeStatus"), AllowAnonymous] public DataResult ChangeStatus([FromBody] FlowCallback callback) { if (callback == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); return _feeService.UpdateAuditStatus(callback.BusinessId, callback.FlowStatus); } } }