181 lines
7.1 KiB
C#
181 lines
7.1 KiB
C#
using Infrastructure;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Enums;
|
|
using Infrastructure.Model;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ARW.Admin.WebApi.Extensions;
|
|
using ARW.Admin.WebApi.Filters;
|
|
using ARW.Common;
|
|
using ARW.Model.Dto.Business.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Service.Business.IBusinessService.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Admin.WebApi.Controllers;
|
|
using ARW.Model.Models.Business.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Model.Vo.Business.LogisticsManage.LogisticsCompanys;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using ARW.Admin.WebApi.Framework;
|
|
|
|
|
|
namespace ARW.WebApi.Controllers.Business.LogisticsManage.LogisticsCompanys
|
|
{
|
|
/// <summary>
|
|
/// 物流公司控制器
|
|
///
|
|
/// @author 黎文豪
|
|
/// @date 2023-06-18
|
|
/// </summary>
|
|
[Verify]
|
|
[Route("business/[controller]")]
|
|
public class LogisticsCompanyController : BaseController
|
|
{
|
|
private readonly ILogisticsCompanyService _LogisticsCompanyService;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
/// <param name="LogisticsCompanyService">物流公司服务</param>
|
|
public LogisticsCompanyController(ILogisticsCompanyService LogisticsCompanyService)
|
|
{
|
|
_LogisticsCompanyService = LogisticsCompanyService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取物流公司列表
|
|
/// </summary>
|
|
/// <param name="parm">查询参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet("getLogisticsCompanyList")]
|
|
[ActionPermissionFilter(Permission = "business:logisticscompany:list")]
|
|
public async Task<IActionResult> GetLogisticsCompanyList([FromQuery] LogisticsCompanyQueryDto parm)
|
|
{
|
|
var res = await _LogisticsCompanyService.GetLogisticsCompanyList(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改物流公司
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("addOrUpdateLogisticsCompany")]
|
|
[ActionPermissionFilter(Permission = "business:logisticscompany:addOrUpdate")]
|
|
[Log(Title = "添加或修改物流公司", BusinessType = BusinessType.ADDORUPDATE)]
|
|
public async Task<IActionResult> AddOrUpdateLogisticsCompany([FromBody] LogisticsCompanyDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
|
|
var modal = new LogisticsCompany();
|
|
if (parm.LogisticsCompanyId != 0) modal = parm.Adapt<LogisticsCompany>().ToUpdate(HttpContext);
|
|
else modal = parm.Adapt<LogisticsCompany>().ToCreate(HttpContext);
|
|
|
|
var res = await _LogisticsCompanyService.AddOrUpdateLogisticsCompany(modal);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除物流公司
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpDelete("{ids}")]
|
|
[ActionPermissionFilter(Permission = "business:logisticscompany:delete")]
|
|
[Log(Title = "物流公司删除", BusinessType = BusinessType.DELETE)]
|
|
public IActionResult Delete(string ids)
|
|
{
|
|
long[] idsArr = Tools.SpitLongArrary(ids);
|
|
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
|
var response = _LogisticsCompanyService.Delete(idsArr);
|
|
return SUCCESS("删除成功!");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入物流公司
|
|
/// </summary>
|
|
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
|
/// <param name="updateSupport">是否需要更新</param>
|
|
/// <returns></returns>
|
|
[HttpPost("importData")]
|
|
[Log(Title = "物流公司导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
|
[ActionPermissionFilter(Permission = "business:logisticscompany:import")]
|
|
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile, bool updateSupport)
|
|
{
|
|
var isUpdateSupport = updateSupport;
|
|
IEnumerable<LogisticsCompanyVo> parm = ExcelHelper<LogisticsCompanyVo>.ImportData(formFile.OpenReadStream());
|
|
|
|
var i = 0;
|
|
var msgList = new List<string>();
|
|
foreach (LogisticsCompanyVo item in parm)
|
|
{
|
|
i++;
|
|
var LogisticsCompany = await _LogisticsCompanyService.HandleImportData(item);
|
|
var modal = LogisticsCompany.Adapt<LogisticsCompany>().ToCreate(HttpContext);
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext).UserName;
|
|
var msg = await _LogisticsCompanyService.ImportExcel(modal, i, isUpdateSupport, user);
|
|
msgList.Add(msg);
|
|
}
|
|
|
|
return SUCCESS(msgList.ToArray());
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 物流公司导入模板下载
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("importTemplate")]
|
|
[Log(Title = "物流公司模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
|
[AllowAnonymous]
|
|
public IActionResult ImportTemplateExcel()
|
|
{
|
|
List<LogisticsCompanyVo> LogisticsCompany = new List<LogisticsCompanyVo>();
|
|
MemoryStream stream = new MemoryStream();
|
|
|
|
// 示例数据
|
|
var values = new List<string>() { "顺丰速运", "shunfeng", "100" };
|
|
string sFileName = DownloadImportTemplate(LogisticsCompany, stream, "物流公司导入模板", values);
|
|
|
|
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出物流公司
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Log(Title = "物流公司导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
|
[HttpGet("exportLogisticsCompany")]
|
|
[ActionPermissionFilter(Permission = "business:logisticscompany:export")]
|
|
public async Task<IActionResult> ExportExcel([FromQuery] LogisticsCompanyQueryDto parm)
|
|
{
|
|
parm.PageSize = 10000;
|
|
var list = await _LogisticsCompanyService.GetLogisticsCompanyList(parm);
|
|
var data = list.Result;
|
|
|
|
// 选中数据
|
|
if (!string.IsNullOrEmpty(parm.ids))
|
|
{
|
|
int[] idsArr = Tools.SpitIntArrary(parm.ids);
|
|
var selectDataList = new List<LogisticsCompanyVo>();
|
|
foreach (var item in idsArr)
|
|
{
|
|
var select_data = data.Where(s => s.LogisticsCompanyId == item).First();
|
|
selectDataList.Add(select_data);
|
|
}
|
|
data = selectDataList;
|
|
}
|
|
|
|
|
|
|
|
// 导出数据处理
|
|
var handleData = await _LogisticsCompanyService.HandleExportData(data);
|
|
|
|
string sFileName = ExportExcel(handleData, "LogisticsCompany", "物流公司列表");
|
|
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|