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.

423 lines
16 KiB
C#

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ys.Core.Common;
using djy.Paas.IService;
using djy.Paas.Model;
using Microsoft.AspNetCore.Authorization;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Hangfire;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using NPOI.SS.Util;
namespace djyweb_djyPaasApi.Controllers
{
/// <summary>
///外部结合跳转控制
/// </summary>
public class BaoguanController : ApiBase
{
IBaoguanService _server = IOC.AddServer<IBaoguanService>();
//货主端
IBaoguanOrderClientService _cservice = IOC.AddServer<IBaoguanOrderClientService>();
private string _moduleKey = "baoguanorder";
#region 货主
/// <summary>
/// 货主报关单查询
/// </summary>
/// <param name="Dto"></param>
/// <param name="apiFrom"></param>
/// <returns></returns>
[HttpGet("client")]
public object ClientList([FromQuery] BaoguanOrderClientDto Dto, [FromQuery] ApiFromDto apiFrom)
{
var aut = GetUserAuthorityToFormDto(_moduleKey);
if (!aut.IsPower)
{
return new ReturnResult<int>() { Message = "没有权限" };
}
Dto.CompGId = aut.CompayId;
Dto.UserGid = aut.UserId;
return _cservice.GetList(Dto, apiFrom);
}
/// <summary>
/// 货主端创建
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost("client")]
public object Clientorderadd([FromBody] tb_BaoguanOrderClient Dto)
{
var rs = new ReturnResult<string>();
Dto.UserGid = GetLoginId;
Dto.CompGId = Guid.Parse(GetUserInfo().CompId);
if (Dto.ShipOrderNo.IsNull() || Dto.IEFlag.IsNull() || Dto.BaoguanAgent.IsNull())
{
rs.Not("进出口类型 提单号 报关行不允许为空!");
return rs;
}
if (Dto.FileUrl.IsNull())
{
rs.Not("请上传资料文件");
return rs;
}
var list = _cservice.GetList(new BaoguanOrderClientDto { ShipOrderNo = Dto.ShipOrderNo, CompGId = Dto.CompGId }, new ApiFromDto());
if (list.Count > 0)
{
rs.Not("此提单号已经提交过了");
return rs;
}
return _cservice.Add(Dto);
}
/// <summary>
/// 更新 货主端海关单
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost("client/up")]
public object ClientOrderUp([FromBody] tb_BaoguanOrderClient Dto)
{
if (Dto == null)
{
return new ReturnResult<object>() { Status = false, Message = "非法请求!", Code = 400 };
}
if (!_GetData_authority(new Guid?[] { Dto.Gid }))
{
return new ReturnResult<object>() { Status = false, Message = "没有操作权限!", Code = 400 };
}
return _cservice.Up(Dto);
}
/// <summary>
///删除 货主订单
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost("client/del")]
public object ClientOrderDel([FromBody] Guid?[] gidlist)
{
if (gidlist == null || gidlist.Length == 0)
{
return new ReturnResult<object>() { Status = false, Message = "没有要删除的数据!", Code = 400 };
}
if (!_GetData_authority(gidlist))
{
return new ReturnResult<object>() { Status = false, Message = "没有操作权限!", Code = 400 };
}
return _cservice.Del(gidlist);
}
/// <summary>
/// 执行接收阿里报关数据并解析报关数据
/// </summary>
/// <returns></returns>
[HttpPost("baoguanjob")]
public async Task<object> BaoguanJob()
{
return await _server.AutoAllibonBaoguanJob(new ApiFromDto { UserId = GetLoginId.ToString(), Name = GetLoginName });
}
/// <summary>
/// 判断数是否有操作更新权限
/// </summary>
/// <param name="gidlist"></param>
/// <returns></returns>
private bool _GetData_authority(Guid?[] gidlist)
{
//权限方式查询可删除数据
var Dto = new BaoguanOrderClientDto();
var aut = GetUserAuthorityToFormDto(_moduleKey, 1);
Dto.UserGid = aut.UserId;
Dto.CompGId = aut.CompayId;
Dto.Gidlist = gidlist.ToList();
var getdata = _cservice.GetList(Dto, new ApiFromDto());
if (getdata.Data == null || getdata.Data.Count == 0)
{
return false;
}
else
{
return true;
}
}
#endregion
/// <summary>
/// 绑定客户关系
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost("bindclient")]
public async Task<object> BindClient([FromBody] ClientLinkInfoDto Dto) => await _server.BindClient(Dto);
/// <summary>
/// 指定order 文件Email发送 Gid filename
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost("sendmail")]
public object SendMail([FromBody] ApiFromDto Dto) => _server.EmailSend(Dto);
/// <summary>
/// 报关单查询
/// </summary>
/// <param name="Dto"></param>
/// <param name="apiFrom"></param>
/// <returns></returns>
[HttpGet]
public async Task<object> GetBaoguanOrderList([FromQuery] tb_BaoGuanOrderList Dto, [FromQuery] ApiFromDto apiFrom)
{
var aut = GetUserAuthorityToFormDto(_moduleKey);
if (!aut.IsPower)
{
return new ReturnResult<int>() { Message = "没有权限" };
}
Dto.CompId = aut.CompayId;
return await _server.GetBaoguanOrderList(Dto, apiFrom);
}
/// <summary>
/// 更新指定订单数据
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[HttpPost]
public object BaoguanOrderUp([FromBody] tb_BaoGuanOrderList Dto) => _server.Up(Dto, Notcolumns: new List<string> { nameof(tb_BaoGuanOrderList.FileInfo), nameof(tb_BaoGuanOrderList.FileList) });
/// <summary>
/// 报关校验审核保存
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpPost("ordercheck")]
public async Task<object> OrderCheck([FromBody] tb_BaoGuanOrderList Dto) => await _server.OrderCheck(Dto);
/// <summary>
///获取单条报关单数据
/// </summary>
/// <param name="Gid"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("{Gid}")]
public async Task<object> GetOrderDto(Guid? Gid)
{
var Rs = new ReturnResult<tb_BaoGuanOrderList>();
var Dto = new tb_BaoGuanOrderList();
Dto.Gid = Gid;
var getlist = await _server.GetBaoguanOrderList(Dto, new ApiFromDto());
if (getlist.Status && getlist.Data.Count > 0)
{
Rs.Data = getlist.Data[0];
Rs.OK();
}
return Rs;
}
3 years ago
///// <summary>
/////获取阿里云报关跳转token
///// </summary>
///// <returns></returns>
//[HttpGet("gettoken")]
//public async Task<object> GetBaoguanToken()
//{
// var rs = await _server.AliyunBaoguanToken(new djy.Model.User { GID = GetLoginId.ToString() });
// if (rs.Status)
// {//直接跳转到报关预录
// rs.MemoData = @"https://onetouch-partner.alibaba.com/ptnProvider/customs/thirdParty.htm?token={" + rs.Data + "}&platform=DaJianYun&targetUrl=%2F%2Fonetouch.alibaba.com%2FsaasCustomer%2Flist.htm%3Fplatform%3DDaJianYun";
// }
// return rs;
//}
///// <summary>
///// 接收阿里推送的绑定反馈
///// </summary>
///// <param name="Dto"></param>
///// <returns></returns>
//[AllowAnonymous]
//[HttpPost("aliback")]
//public async Task<object> Aliback([FromBody] ApiFromDto Dto) => await _server.AliBack(Dto);
///// <summary>
///// 报关用户离职 [key=usergid base64位加密字符串]
///// </summary>
///// <param name="Dto"></param>
///// <returns></returns>
//[AllowAnonymous]
//[HttpPost("userquit")]
//public async Task<object> UserQuit([FromBody] ApiFromDto Dto)
//{
// //2022-4-1配合大简云主程序员工离职流程调整特修改开发测试环境不调用阿里离职
// if (sysOptionConfig.YsWebconfig.IsDev)
// {
// var rs = new ReturnResult<string>();
// rs.OK();
// return rs;
// }
// _LogsAdd("userquit", "api", Dto);
// var userid = Dto.Key;
// if (userid.IsNotNull())
// {
// return await _server.AliUserQuit(userid);
// }
// else
// {
// return new ReturnResult<string>() { Message = "错误的请求" };
// }
//}
/// <summary>
/// 根据箱子编号获取箱内详细报关数据 Code 多个,间隔
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("open/container")]
public async Task<object> GetContainerList([FromQuery] ApiFromDto Dto)
{
return await _server.GetContainerList(Dto.Code.Split(',').ToList());
}
//导出EXCEL
[HttpGet("export")]
public object Export([FromQuery] tb_BaoGuanOrderList Dto, [FromQuery] ApiFromDto apiFrom)
{
var aut = GetUserAuthorityToFormDto(_moduleKey);
if (!aut.IsPower)
{
return new ReturnResult<int>() { Message = "没有权限" };
}
_LogsAdd("export", "api", "执行导出");
apiFrom.Limit = int.MaxValue;
Dto.CompId = aut.CompayId;
var bgOrdList = _server.GetBaoguanOrderList(Dto, apiFrom).Result;
_LogsAdd("export", "api", $"获得结果{bgOrdList.Count}条");
var rs = new ReturnResult<string>();
try
{
var excelwork = new HSSFWorkbook();
var sheet = excelwork.CreateSheet("报关订单");
sheet.ForceFormulaRecalculation = true;
//单元格样式
var cellStyle = NpoiExcelExportHelper._.CreateStyle(excelwork, HorizontalAlignment.Center, VerticalAlignment.Center, 10, true, 0);
//行高
var cellheigth = 20;
//表头名称
var headerName = new[] {
new{title="客户名称",width=20 },
new{title="联系人",width=15 },
new{title="EMAIL",width=40 },
new{title="报关行名称",width=30 },
new{title="进口/出口",width=10 },
new{title="报关订单号",width=23 },
new{title="报关单号",width=20 },
new{title="申报地海关",width=10 },
new{title="境内收发",width=40 },
new{title="提单号",width=20 },
new{title="查验时间",width=22 },
new{title="主单号",width=22 },
new{title="申报状态",width=15 },
new{title="创建时间",width=22 }
};
var row = NpoiExcelExportHelper._.CreateRow(sheet, 0, cellheigth);
for (int i = 0; i < headerName.Length; i++)
{
var cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, i, headerName[i].title);
sheet.SetColumnWidth(cell.ColumnIndex, headerName[i].width * 256);
}
var columnwidth = 20 * 256;
for (int i = 0; i < bgOrdList.Data.Count; i++)
{
row = NpoiExcelExportHelper._.CreateRow(sheet, i + 1, cellheigth);
var item = bgOrdList.Data[i];
var cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 0, item.ClientName);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 1, item.ClientMain);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 2, item.ClientEmail);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 3, item.CompName);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 4, item.IEFlag == "I" ? "进口" : item.IEFlag == "E" ? "出口" : "");
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 5, item.UniqueNumber);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 6, item.CustomsNo);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 7, item.DeclareCustoms);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 8, item.TradeName);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 9, item.ShipOrderNo);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 10, item.CheckTime.ToDataTime().ToString("yyyy-MM-dd HH:mm:ss"));
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 11, item.ShipOrderNoMain);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 12, item.stateName);
cell = NpoiExcelExportHelper._.CreateCells(row, cellStyle, 13, item.AddTime.ToDataTime().ToString("yyyy-MM-dd HH:mm:ss"));
}
var _environment = IOC.AddServer<IHostingEnvironment>();
var filepath = _environment.WebRootPath.Trim() + "/excel/";
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
var filename = string.Format("{0}.xls", YsTools.GetNewNo());
var filestream = new FileStream(filepath + filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
excelwork.Write(filestream);
filestream.Close();
filestream.Dispose();
_LogsAdd("export", "api", $"excel写入完成{filename}");
rs.OK("生成成功!", filename);
//过期删除
BackgroundJob.Schedule(() => System.IO.File.Delete(filepath + filename), TimeSpan.FromMinutes(5));
//直接输出数据流
//var exceldata = excelwork.GetBytes();
//rs.OK();
// return File(exceldata, "application/ms-excel", filename);
return rs;
}
catch (Exception ex)
{
rs.Not("下载失败");
rs.MemoData = ex.Message;
_LogsAdd("error", "api", ex.Message);
_LogsAdd("error", "api", ex.StackTrace);
}
return rs;
}
}
}