using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
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 DS.WMS.Core.Op.Entity;
using Mapster;
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);
}
///
/// 提交费用
///
/// 费用提交参数
///
[HttpPost, Route("Submit")]
public DataResult Submit([FromBody] FeeRecordSubmit recordSubmit)
{
if (recordSubmit == null || recordSubmit.Items.IsNullOrEmpty())
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission))
return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest);
var list = recordSubmit.Items.Select(x => x.Adapt());
foreach (var item in list)
{
item.BusinessId = recordSubmit.BusinessId;
item.BusinessType = recordSubmit.BusinessType;
}
return _feeService.InsertOrUpdate(list);
}
///
/// 根据一组模板ID创建费用记录(引入模板)
///
/// 请求参数
///
[HttpPost, Route("CreateByTemplate")]
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.BusinessType, 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.Remark, 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.Remark, model.Ids);
}
///
/// 申请修改
///
/// 费用修改信息
///
[HttpPost, Route("ApplyModification")]
public DataResult ApplyModification([FromBody] IEnumerable items)
{
if (items.IsNullOrEmpty())
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return _feeService.SubmitForModification(items);
}
///
/// 撤销审批申请
///
/// 费用记录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")]
public DataResult ChangeStatus([FromBody] FlowCallback callback)
{
if (callback == null)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return _feeService.UpdateAuditStatus(callback);
}
///
/// 获取费用核算单打印信息
///
/// 费用记录ID
///
[HttpGet, Route("GetPrintInfo")]
public DataResult GetPrintInfo(IdModel model)
{
if (model == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return _feeService.GetPrintInfo((BusinessType)model.BusinessType, model.Ids);
}
}
}