You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
6.1 KiB
C#
182 lines
6.1 KiB
C#
using System.Net;
|
|
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 Microsoft.AspNetCore.Mvc;
|
|
using MiniExcelLibs;
|
|
|
|
namespace DS.WMS.FeeApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 自动费用模板API
|
|
/// </summary>
|
|
public class FeeCustTemplateController : ApiController
|
|
{
|
|
readonly IFeeCustTemplateService _invokeService;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="invokeService"></param>
|
|
public FeeCustTemplateController(IFeeCustTemplateService invokeService)
|
|
{
|
|
_invokeService = invokeService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成订单费用
|
|
/// </summary>
|
|
/// <param name="etd">开船日期</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GenerateFees")]
|
|
public async Task<IActionResult> GenerateFeesAsync(DateTime? etd)
|
|
{
|
|
HttpStatusCode httpStatusCode;
|
|
try
|
|
{
|
|
await _invokeService.GenerateFeesAsync(etd ?? DateTime.Now.Date);
|
|
httpStatusCode = HttpStatusCode.NoContent;
|
|
}
|
|
catch
|
|
{
|
|
httpStatusCode = HttpStatusCode.InternalServerError;
|
|
throw;
|
|
}
|
|
|
|
return new StatusCodeResult((int)httpStatusCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入费用模板
|
|
/// </summary>
|
|
/// <param name="file"></param>
|
|
/// <param name="sourceCode"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("Import")]
|
|
public async Task<IActionResult> ImportAsync(IFormFile file, string? sourceCode)
|
|
{
|
|
if (file == null)
|
|
return BadRequest("请求未包含文件流");
|
|
|
|
var stream = file.OpenReadStream();
|
|
var query = await MiniExcel.QueryAsync(stream, excelType: ExcelType.XLSX, startCell: "A4");
|
|
List<FeeCustTemplateModel> list = [];
|
|
try
|
|
{
|
|
foreach (IDictionary<string, object> item in query)
|
|
{
|
|
var model = new FeeCustTemplateModel
|
|
{
|
|
StatusText = item["A"]?.ToString(),
|
|
FeeName = item["B"].ToString(),
|
|
CarrierName = item["C"]?.ToString(),
|
|
POL = item["D"]?.ToString(),
|
|
POD = item["E"]?.ToString(),
|
|
LaneName = item["F"]?.ToString(),
|
|
PaymentType = item["G"]?.ToString(),
|
|
Currency = item["L"]?.ToString(),
|
|
CustomerName = item["M"]?.ToString(),
|
|
SourceCode = sourceCode
|
|
};
|
|
|
|
if (!string.IsNullOrEmpty(model.Currency))
|
|
model.Currency = model.Currency.Replace("CNY", FeeCurrency.RMB_CODE);
|
|
|
|
if (int.TryParse(item["H"]?.ToString(), out int hVal))
|
|
model.GP20 = hVal;
|
|
|
|
if (int.TryParse(item["I"]?.ToString(), out int iVal))
|
|
model.GP40 = iVal;
|
|
|
|
if (int.TryParse(item["J"]?.ToString(), out int jVal))
|
|
model.HQ40 = jVal;
|
|
|
|
if (int.TryParse(item["K"]?.ToString(), out int kVal))
|
|
model.UnitPrice = kVal;
|
|
|
|
if (DateTime.TryParse(item["N"]?.ToString(), out DateTime nVal))
|
|
model.StartTime = nVal;
|
|
|
|
if (DateTime.TryParse(item["O"]?.ToString(), out DateTime oVal))
|
|
model.EndTime = oVal;
|
|
|
|
list.Add(model);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Ok(DataResult.Failed("读取文件失败:" + ex.Message));
|
|
}
|
|
|
|
var result = await _invokeService.ImportAsync(list);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetList")]
|
|
public async Task<DataResult<List<FeeCustTemplate>>> GetListAsync([FromBody] PageRequest request)
|
|
{
|
|
return await _invokeService.GetListAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("Edit")]
|
|
public async Task<DataResult> EditAsync([FromBody] FeeCustTemplate model)
|
|
{
|
|
if (model == null)
|
|
return DataResult.FailedWithDesc(MultiLanguageConst.IllegalRequest);
|
|
|
|
return await _invokeService.EditAsync(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("Edit")]
|
|
public async Task<DataResult<FeeCustTemplate>> GetAsync([FromQuery] long id)
|
|
{
|
|
return await _invokeService.GetAsync(id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ID删除
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("Delete")]
|
|
public async Task<DataResult> DeleteAsync([FromBody] IdModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
|
|
|
|
return await _invokeService.DeleteAsync(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ID删除明细
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("DeleteDetails")]
|
|
public async Task<DataResult> DeleteAsync([FromServices] IFeeCustTemplateDetailService detailService, [FromBody] IdModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
|
|
|
|
return await detailService.DeleteAsync(model);
|
|
}
|
|
}
|
|
}
|