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.
DS7/BookingJieFeng/Controllers/BookingController.cs

3208 lines
130 KiB
C#

3 years ago
using BarcodeLib;
using BookingJieFeng.DB;
using BookingJieFeng.DB.Model;
using BookingJieFeng.Helper;
using BookingJieFeng.Models;
using DotNet4.Utilities;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Resources;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Mvc;
namespace BookingJieFeng.Controllers
{
public class BookingController : BaseController
{
private static readonly string AttachUpDir = "UserUploads";
private BookingDB bookingDB = new BookingDB();
private JiefengDB jiefengDB = new JiefengDB();
private ILog log = LogManager.GetLogger("BookingController");
#region 订舱
public ActionResult Order(string ordno)
{
var indentified = CurrentCompany.IDENTIFICATION_STATE == UserIdentiState.Indentified.ToString();
if (!indentified)
{
ViewBag.IsAdmin = CurrentCompany.GID == CurrentUser.GID;
return View("CannotBooking");
}
OrderEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(ordno))
{
var model = bookingDB.Orders.FirstOrDefault(o => o.ORDNO == ordno);
if (model == null)
{
return Content(LangAll.MsgViewDataNotExist);
}
viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == ordno).AsOrderEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.RemainTimeClosing = string.Format("距离截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.RemainTimeClosing = string.Format("超过截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
}
if (model.BSSTATUS == OrderStatus.Confirm.ToString() &&
model.SISTATUS != OrderConfirmStatus.Confirm.ToString())
{
ViewBag.ShowConfirmBtn = true;
}
//状态日志
var staLogs = bookingDB.StatusLogs.Where(l => l.RELATIVE_ID == viewModel.ORDNO);
var staOrderSave = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderSave.ToString());
if (staOrderSave != null)
{
ViewBag.StaOrderSave = true;
ViewBag.StaOrderSaveTime = staOrderSave.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staOrderSubmit = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderSubmit.ToString());
if (staOrderSubmit != null)
{
ViewBag.StaOrderSubmit = true;
ViewBag.StaOrderSubmitTime = staOrderSubmit.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staOrderConfirm = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderConfirm.ToString());
if (staOrderConfirm != null)
{
ViewBag.StaOrderConfirm = true;
ViewBag.StaOrderConfirmTime = staOrderConfirm.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staConfirmSave = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.ConfirmSave.ToString());
if (staConfirmSave != null)
{
ViewBag.StaConfirmSave = true;
ViewBag.StaConfirmSaveTime = staConfirmSave.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staConfirmSubmit = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.ConfirmSubmit.ToString());
if (staConfirmSubmit != null)
{
ViewBag.StaConfirmSubmit = true;
ViewBag.StaConfirmSubmitTime = staConfirmSubmit.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staConfirmConfirm = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.ConfirmConfirm.ToString());
if (staConfirmConfirm != null)
{
ViewBag.StaConfirmConfirm = true;
ViewBag.StaConfirmConfirmTime = staConfirmConfirm.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staOrderCancel = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderCancel.ToString());
if (staOrderCancel != null)
{
ViewBag.StaOrderCancel = true;
ViewBag.StaOrderCancelTime = staOrderCancel.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
//状态记录
var typeOrder = OpLogModule.Order.ToString();
var logList = bookingDB.Logs.AsNoTracking().Where(l => l.BillNO == ordno && l.Module == typeOrder).OrderBy(l => l.LogId).ToList();
var listDisplay = new List<LogListDisplayModel>();
for (int i = 0; i < logList.Count; i++)
{
var chgList = ChangeLogHelper.Compare(i == 0 ? new OP_LOG() { Module = OpLogModule.Order.ToString() } : logList[i - 1], logList[i]);
listDisplay.Add(new LogListDisplayModel
{
OpUserName = logList[i].OpUserName,
OpTime = logList[i].OpTime.ToString("yyyy-MM-dd HH:mm:ss"),
Type = logList[i].Type,
ChangeList = chgList,
OpCompanyName = logList[i].OpCompanyName,
Module = logList[i].Module
});
}
ViewBag.LogList = listDisplay;
}
else
{
viewModel = new OrderEditViewModel();
viewModel.MARKS = "N/M";
//viewModel.BLFRT = "FREIGHT PREPAID";
viewModel.NOBILL = "THREE";
viewModel.COPYNOBILLL = "ONE";
}
ViewBag.EmployeeJson = JsonConvert.SerializeObject(jiefengDB.Employee.Select(emp => new { name = emp. }).ToList());
ViewBag.Attach = bookingDB.Attaches.FirstOrDefault(a => a.RELATIVEID == ordno);
return View(viewModel);
}
public ActionResult Copy(string srcORDNO)
{
var model = bookingDB.Orders.First(o => o.ORDNO == srcORDNO);
OrderEditViewModel viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == srcORDNO).AsOrderEditViewModelList();
viewModel.ORDNO = string.Empty;
viewModel.BSSTATUS = OrderStatus.Create.ToString();
viewModel.ORDERNO = string.Empty;
viewModel.BSNO = model.BSNO;
viewModel.BusinessNO = string.Empty;
viewModel.YARD = string.Empty;
viewModel.YardContract = string.Empty;
viewModel.CLOSEDOCDATE = null;
viewModel.CLOSINGDATE = null;
viewModel.PONO = string.Empty;
viewModel.MBLNO = string.Empty;
ViewBag.EmployeeJson = JsonConvert.SerializeObject(jiefengDB.Employee.Select(emp => new { name = emp. }).ToList());
return View("Order", viewModel);
}
[HttpPost]
public ActionResult OrderSave(OrderEditViewModel viewModel)
{
OP_SEAE_ORDER model = null;
bool isNew = false;
if (string.IsNullOrWhiteSpace(viewModel.ORDNO))
{
isNew = true;
viewModel.ORDNO = Guid.NewGuid().ToString();
viewModel.ORDERNO = GenOrderCode();
model = viewModel.AsModel();
model.CORPID = CurrentCompany.GID;
model.USERID = CurrentUser.GID;
model.BSDATE = DateTime.Today;
model.SISTATUS = OrderConfirmStatus.None.ToString();
model.CREATETIME = DateTime.Now;
model.INPUTBY = CurrentUser.NAME;
if (model.MODIFYTIME == DateTime.MinValue)
{
model.MODIFYTIME = null;
}
bookingDB.Orders.Add(model);
}
else
{
model = bookingDB.Orders.First(o => o.ORDNO == viewModel.ORDNO);
if (model.MODIFYTIME != null && model.MODIFYTIME.Value.Ticks != viewModel.MODIFYTIME)
{
return Json(new RespCommon() { Success = false, Message = LangAll.MsgDataSaveByOther });
}
viewModel.AsModel(model);
model.MODIFYTIME = DateTime.Now;
}
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == viewModel.ORDNO));
var ctrns = viewModel.CtrnList.AsModelList();
ctrns.ForEach(c =>
{
c.CTN_ID = Guid.NewGuid().ToString();
c.ORDNO = viewModel.ORDNO;
bookingDB.Ctns.Add(c);
});
var strCtrnList = viewModel.CtrnList.Select(c => $"{c.CTNALL}*{c.CTNNUM}");
model.CNTRTOTAL = string.Join(" / ", strCtrnList);
bookingDB.SaveChanges();
var isSubmit = model.BSSTATUS == OrderStatus.Submit.ToString();
if (isNew || (!isNew && !isSubmit))
{
//日志-保存
LogHelper.Log(OpLogModule.Order, OpLogType.Save, model.ORDNO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志-保存
string strSaveSta = OrderLogStatus.OrderSave.ToString();
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSaveSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSaveSta;
bookingDB.StatusLogs.Add(staLog);
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
}
//日志-提交
if (isSubmit)
{
string strSubmitSta = OrderLogStatus.OrderSubmit.ToString();
LogHelper.Log(OpLogModule.Order, OpLogType.Submit, model.ORDNO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志-提交
var staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSubmitSta;
bookingDB.StatusLogs.Add(staLog);
}
bookingDB.SaveChanges();
//DS6任务
if (isSubmit)
{
var names = jiefengDB.Employee.AsNoTracking().Where(e => e. == model.CARRIER).Select(e => e.).ToList();
var strname = string.Join(",", names);
var sqlDs6 = $@"insert into t_op_task(任务编号,任务类型,任务来源,任务状态,任务说明,发起人,录入日期,任务开始时间,提单号,是否公共,任务相关人员,SEA编号,是否完成,备注)
values(newid(),'','','','{CurrentCompany.INFO_CLIENT}{model.MBLNO};{model.PORTDISCHARGE};{model.DESTINATION}',
'DEMO-SA',GETDATE(),GETDATE(),'{model.MBLNO}',0,'{strname}','{model.ORDNO}',0,'')";
log.Debug(sqlDs6);
jiefengDB.Database.ExecuteSqlCommand(sqlDs6);
}
RespRedirect resp = new RespRedirect();
resp.Success = true;
resp.Message = isSubmit ? LangAll.MsgSubmitSuccess : LangAll.MsgSaveSuccess;
resp.Url = Url.Action("Order", new { ordno = model.ORDNO });
resp.Id = model.ORDNO;
return Json(resp);
}
[HttpPost]
public ActionResult CancelSubmit(string ordno)
{
RespCommon resp = new RespCommon();
var ord = bookingDB.Orders.First(o => o.ORDNO == ordno);
if (ord.BSSTATUS == OrderStatus.Submit.ToString())
{
ord.BSSTATUS = OrderStatus.Create.ToString();
bookingDB.SaveChanges();
//日志
var viewModel = ord.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == ordno).AsOrderEditViewModelList();
LogHelper.Log(OpLogModule.Order, OpLogType.Cancel, ordno, ord.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志
string strSubmitSta = OrderLogStatus.OrderSubmit.ToString();
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSubmitSta);
if (staLog != null)
{
bookingDB.StatusLogs.Remove(staLog);
bookingDB.SaveChanges();
}
//删除DS6任务
var sqlDs6 = $@"delete t_op_task where 任务类型='网上订舱' and SEA编号='{ord.ORDNO}'";
log.Debug(sqlDs6);
jiefengDB.Database.ExecuteSqlCommand(sqlDs6);
resp.Success = true;
resp.Message = Resources.LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangOrder.MsgCannotCancelStatus;
}
return Json(resp);
}
[HttpPost]
public ActionResult OrderDelete(string ordno)
{
RespCommon resp = new RespCommon();
var ord = bookingDB.Orders.First(o => o.ORDNO == ordno);
if (ord != null && (ord.BSSTATUS == OrderStatus.Create.ToString() || ord.BSSTATUS == OrderStatus.Back.ToString()))
{
bookingDB.Orders.Remove(ord);
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == ordno));
bookingDB.StatusLogs.RemoveRange(bookingDB.StatusLogs.Where(c => c.RELATIVE_ID == ordno));
bookingDB.Logs.RemoveRange(bookingDB.Logs.Where(c => c.BillNO == ordno));
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangAll.MsgOptFail;
}
return Json(resp);
}
//订舱提交后发邮件
[HttpGet]
public ActionResult SendMailAfterOrderSubmit(string ordno)
{
var model = bookingDB.Orders.First(o => o.ORDNO == ordno);
var mailAddr = CurrentUser.EMAIL;
var crm = jiefengDB.CrmClients.AsNoTracking().FirstOrDefault(c => c. == CurrentCompany.INFO_CLIENT || c. == model.CARRIER);
if (crm != null && !string.IsNullOrEmpty(crm.))
{
mailAddr += "," + crm.;
}
ViewBag.MailAddr = mailAddr;
var etd = model.ETD.HasValue ? model.ETD.Value.ToString("yyyy-MM-dd") : string.Empty;
ViewBag.Title = $"{CurrentCompany.COMPANY_NAME} 提交订舱:{model.ORDERNO}|{model.VESSEL}|{etd}|{model.CNTRTOTAL}|{model.PORTDISCHARGE}";
ViewBag.Body = $"订舱公司:{CurrentCompany.COMPANY_NAME}\r\n订舱编号{model.ORDERNO}\r\nETD{etd}\r\n船公司{model.CARRIER}\r\n箱型箱量{model.CNTRTOTAL}\r\n卸货港{model.PORTDISCHARGE}\r\n操作人{CurrentUser.NAME} {CurrentUser.MOBILE}";
return View("SendMailAfterSubmit");
}
[HttpPost]
public ActionResult SendMailAfterSubmit(string mailAddr, string title, string body)
{
RespCommon resp = new RespCommon();
OP_SEND_MAIL sendMail = new OP_SEND_MAIL();
sendMail.GID = Guid.NewGuid().ToString();
sendMail.SEND_TO = mailAddr;
sendMail.TITLE = title;
sendMail.BODY = body;
sendMail.CREATE_TIME = DateTime.Now;
sendMail.STATUS = SendMailStatus.Create.ToString();
bookingDB.SendMails.Add(sendMail);
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "发送成功";
return Json(resp);
}
#endregion
#region 订舱列表(台账)
public ActionResult OrderList()
{
var colCfg = bookingDB.ConfigDatas.FirstOrDefault(c => c.Module == ConfigData.ModuleOrder && c.Category == ConfigData.CateListColumn && c.UserId == CurrentUser.GID);
if (colCfg != null)
{
ViewBag.ColumnConfigData = JsonConvert.DeserializeAnonymousType(colCfg.JsonData, new dynamic[] { new { colName = "", visible = false, sort = 0, width = 0 } }).OrderBy(c => Convert.ToInt32(c.sort)).ToList();
}
ViewBag.ColDic = GetColDicOrder();
return View();
}
[HttpPost]
public ActionResult OrderListData(ReqOrderList req, int offset = 1, int limit = 10, string sort = "", string order = "asc")
{
var query = bookingDB.Orders.Where(o => o.CORPID == CurrentCompany.GID);
if (!string.IsNullOrWhiteSpace(req.MBLNO))
{
query = query.Where(o => o.MBLNO == req.MBLNO);
}
#region 条件
if (!string.IsNullOrWhiteSpace(req.ETD_START))
{
var dtStart = DateTime.Parse(req.ETD_START);
query = query.Where(o => o.ETD >= dtStart);
}
if (!string.IsNullOrWhiteSpace(req.ETD_END))
{
var dtEnd = DateTime.Parse(req.ETD_END);
query = query.Where(o => o.ETD >= dtEnd);
}
if (!string.IsNullOrWhiteSpace(req.VESSEL))
{
req.VESSEL = req.VESSEL.ToLower();
query = query.Where(o => o.VESSEL.ToLower().IndexOf(req.VESSEL) > -1);
}
if (!string.IsNullOrWhiteSpace(req.VOYNO))
{
req.VOYNO = req.VOYNO.ToLower();
query = query.Where(o => o.VOYNO.ToLower().IndexOf(req.VOYNO) > -1);
}
if (!string.IsNullOrWhiteSpace(req.SISTATUS))
{
if (req.SISTATUS == "NOT")
{
var strSiStaNone = OrderConfirmStatus.None.ToString();
var strSiStaCreate = OrderConfirmStatus.Create.ToString();
query = query.Where(o => o.SISTATUS == strSiStaNone || o.SISTATUS == strSiStaCreate);
}
else if (req.SISTATUS == "YES")
{
var strSiStaSubmit = OrderConfirmStatus.Submit.ToString();
var strSiStaConfirm = OrderConfirmStatus.Confirm.ToString();
query = query.Where(o => o.SISTATUS == strSiStaSubmit || o.SISTATUS == strSiStaConfirm);
}
}
if (!string.IsNullOrWhiteSpace(req.BSSTATUS))
{
query = query.Where(o => o.BSSTATUS == req.BSSTATUS);
}
#endregion
#region 排序
if (!string.IsNullOrWhiteSpace(sort) && !string.IsNullOrWhiteSpace(order))
{
if (order.ToLower() == "asc")
{
if (sort.ToUpper() == "CARRIER")
{
query = query.OrderBy(o => o.CARRIER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderBy(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderBy(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderBy(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderBy(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderBy(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderBy(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderBy(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderBy(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderBy(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderBy(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
else
{
if (sort.ToUpper() == "SHIPPER")
{
query = query.OrderByDescending(o => o.SHIPPER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderByDescending(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderByDescending(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderByDescending(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderByDescending(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderByDescending(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderByDescending(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderByDescending(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderByDescending(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderByDescending(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderByDescending(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
#endregion
int count = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
RespPageData resp = new RespPageData();
resp.Total = count;
var dataList = list.AsListViewModelList();
resp.DataList = dataList;
foreach (var item in dataList)
{
var c = bookingDB.Confirms.Count(cfm => cfm.ORDNO == item.ORDNO);
if (c > 0)
{
item.HasConfirm = true;
}
}
//截单数据
dataList.ForEach(x => x.ConfirmList = bookingDB.Confirms.Where(c => c.ORDNO == x.ORDNO).AsListViewModelList());
return Json(resp);
}
#endregion
#region 截单
public ActionResult Confirm(string ordno)
{
ConfirmEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(ordno))
{
var model = bookingDB.Orders.First(o => o.ORDNO == ordno);
if (model.BSSTATUS == OrderStatus.Confirm.ToString())
{
viewModel = model.AsConfirmEditViewModel();
viewModel.BSSTATUS = OrderConfirmStatus.Create.ToString();
//viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == ordno).AsConfirmEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.RemainTimeClosing = string.Format("距离截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.RemainTimeClosing = string.Format("超过截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
}
ViewBag.EmployeeJson = JsonConvert.SerializeObject(jiefengDB.Employee.Select(emp => new { name = emp. }).ToList());
return View(viewModel);
}
else
{
return Content(LangConfirm.MsgOrderNotConfirm);
}
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
public ActionResult ConfirmCopy(string srcSINO)
{
ConfirmEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(srcSINO))
{
var model = bookingDB.Confirms.First(o => o.SINO == srcSINO);
viewModel = model.AsEditViewModel();
viewModel.SINO = string.Empty;
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == srcSINO).AsConfirmEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.RemainTimeClosing = string.Format("距离截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.RemainTimeClosing = string.Format("超过截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
}
if (model.CLOSINGDATE.HasValue && model.CLOSINGDATE.Value < DateTime.Now)
{
ViewBag.ClosingDateExpire = true;
}
else
{
ViewBag.ClosingDateExpire = false;
}
ViewBag.EmployeeJson = JsonConvert.SerializeObject(jiefengDB.Employee.Select(emp => new { name = emp. }).ToList());
return View("Confirm", viewModel);
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
public ActionResult ConfirmEdit(string sino)
{
ConfirmEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(sino))
{
var model = bookingDB.Confirms.First(o => o.SINO == sino);
viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == sino).AsConfirmEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.RemainTimeClosing = string.Format("距离截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.RemainTimeClosing = string.Format("超过截单时间({0}){1}天{2}小时", model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss"), ts.Days, ts.Hours);
}
}
if (model.CLOSINGDATE.HasValue && model.CLOSINGDATE.Value < DateTime.Now)
{
ViewBag.ClosingDateExpire = true;
}
else
{
ViewBag.ClosingDateExpire = false;
}
ViewBag.EmployeeJson = JsonConvert.SerializeObject(jiefengDB.Employee.Select(emp => new { name = emp. }).ToList());
//状态记录
var typeConfirm = OpLogModule.Confirm.ToString();
var logList = bookingDB.Logs.AsNoTracking().Where(l => l.BillNO == sino && l.Module == typeConfirm).OrderBy(l => l.LogId).ToList();
var listDisplay = new List<LogListDisplayModel>();
for (int i = 0; i < logList.Count; i++)
{
var chgList = ChangeLogHelper.Compare(i == 0 ? new OP_LOG() { Module = OpLogModule.Order.ToString() } : logList[i - 1], logList[i]);
listDisplay.Add(new LogListDisplayModel
{
OpUserName = logList[i].OpUserName,
OpTime = logList[i].OpTime.ToString("yyyy-MM-dd HH:mm:ss"),
Type = logList[i].Type,
ChangeList = chgList,
OpCompanyName = logList[i].OpCompanyName,
Module = logList[i].Module
});
}
ViewBag.LogList = listDisplay;
return View("Confirm", viewModel);
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
[HttpPost]
public ActionResult ConfirmSave(ConfirmEditViewModel viewModel)
{
RespRedirect resp = new RespRedirect();
#region 保存
if (!string.IsNullOrEmpty(viewModel.MBLNO))
{
var obj = bookingDB.Confirms.FirstOrDefault(c => c.MBLNO == viewModel.MBLNO);
if (obj != null && obj.SINO != viewModel.SINO)
{
resp.Success = false;
resp.Message = LangConfirm.ValidInputMBLNO_REPEAT;
return Json(resp);
}
}
OP_SEAE_SI model = null;
if (string.IsNullOrWhiteSpace(viewModel.SINO))
{
viewModel.SINO = Guid.NewGuid().ToString();
model = viewModel.AsModel();
model.CORPID = CurrentCompany.GID;
model.USERID = CurrentUser.GID;
//model.BSSTATUS = OrderConfirmStatus.Create.ToString();
model.BSDATE = DateTime.Today;
model.CREATETIME = DateTime.Now;
model.INPUTBY = CurrentUser.NAME;
if (model.MODIFYTIME == DateTime.MinValue)
{
model.MODIFYTIME = null;
}
bookingDB.Confirms.Add(model);
}
else
{
model = bookingDB.Confirms.First(o => o.SINO == viewModel.SINO);
if (model.MODIFYTIME != null && model.MODIFYTIME.Value.Ticks != viewModel.MODIFYTIME)
{
return Json(new RespCommon() { Success = false, Message = LangAll.MsgDataSaveByOther });
}
viewModel.AsModel(model);
model.MODIFYTIME = DateTime.Now;
}
var dbCtnList = bookingDB.Ctns.Where(c => c.ORDNO == viewModel.SINO).ToList(); ;
dbCtnList.ForEach(dbCtn =>
{
if (viewModel.CtrnList.FirstOrDefault(c => c.CTN_ID == dbCtn.CTN_ID) == null)
{
bookingDB.Ctns.Remove(dbCtn);
}
});
viewModel.CtrnList.ForEach(ctn =>
{
ctn.CTNNUM = 1;//截单的箱量固定为1
//计算teu
var tmpStr = ctn.CTNALL.Substring(0, 2);
if (tmpStr == "20")
{
ctn.TEU = ctn.CTNNUM;
}
else if (tmpStr == "40" || tmpStr == "45")
{
ctn.TEU = ctn.CTNNUM * 2;
}
var dbCtn = dbCtnList.FirstOrDefault(c => c.CTN_ID == ctn.CTN_ID);
if (dbCtn != null)
{
ctn.AsModel(dbCtn);
}
else
{
var saveModel = ctn.AsModel();
saveModel.CTN_ID = Guid.NewGuid().ToString();
saveModel.ORDNO = viewModel.SINO;
bookingDB.Ctns.Add(saveModel);
}
});
var strCtrnList = viewModel.CtrnList.Select(c => $"{c.CTNALL}*{c.CTNNUM}");
model.CNTRTOTAL = string.Join(" / ", strCtrnList);
var isSubmit = model.BSSTATUS == OrderConfirmStatus.Submit.ToString();
//2020-10-30提交时校验箱型箱量
if (isSubmit)
{
var hasErr = false;
var ctnOrder = bookingDB.Ctns.AsNoTracking().Where(c => c.ORDNO == model.ORDNO).ToList();
foreach (var ctn in ctnOrder)
{
var count = viewModel.CtrnList.Where(c => c.CTNALL == ctn.CTNALL).Count();
if (count > ctn.CTNNUM)
{
hasErr = true;
resp.Message += $"箱型{ctn.CTNALL}的箱量大于订舱时填写的值<br/>";
}
}
if (hasErr)
{
resp.Success = false;
return Json(resp);
}
}
bookingDB.SaveChanges();
#endregion
var otherCount = bookingDB.Confirms.Count(c => c.ORDNO == viewModel.ORDNO && c.SINO != viewModel.SINO);
var orderObj = bookingDB.Orders.First(o => o.ORDNO == viewModel.ORDNO);
//日志-提交
if (isSubmit)
{
LogHelper.Log(OpLogModule.Confirm, OpLogType.Submit, model.SINO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
string strSubmitSta = OrderLogStatus.ConfirmSubmit.ToString();
if (otherCount == 0) //没有其他截单
{
OP_STATUS_LOG staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSubmitSta;
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
bookingDB.StatusLogs.Add(staLog);
orderObj.SISTATUS = OrderConfirmStatus.Submit.ToString();
model.SUBMITDATE = DateTime.Now;
}
else
{
string strConfirmStatusSave = OrderConfirmStatus.Create.ToString();
string strConfirmStatusReject = OrderConfirmStatus.Reject.ToString();
var otherNoSubmitCount = bookingDB.Confirms.Count(c => c.ORDNO == viewModel.ORDNO && c.SINO != viewModel.SINO && (c.BSSTATUS == strConfirmStatusSave || c.BSSTATUS == strConfirmStatusReject));
if (otherNoSubmitCount == 0) //没有未提交的其他截单
{
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSubmitSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSubmitSta;
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
bookingDB.StatusLogs.Add(staLog);
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
orderObj.SISTATUS = OrderConfirmStatus.Submit.ToString();
model.SUBMITDATE = DateTime.Now;
}
else
{
model.SUBMITDATE = DateTime.Now;
}
}
}
else
{
//日志
LogHelper.Log(OpLogModule.Confirm, OpLogType.Save, model.SINO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志
string strSaveSta = OrderLogStatus.ConfirmSave.ToString();
if (otherCount == 0) //没有其他截单
{
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSaveSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSaveSta;
bookingDB.StatusLogs.Add(staLog);
orderObj.SISTATUS = OrderConfirmStatus.Create.ToString();
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
}
else
{
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSaveSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSaveSta;
bookingDB.StatusLogs.Add(staLog);
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
}
}
bookingDB.SaveChanges();
//DS6任务
if (isSubmit)
{
var names = jiefengDB.Employee.AsNoTracking().Where(e => e. == model.CARRIER).Select(e => e.).ToList();
var strname = string.Join(",", names);
var sqlDs6 = $@"insert into t_op_task(任务编号,任务类型,任务来源,任务状态,任务说明,发起人,录入日期,任务开始时间,提单号,是否公共,任务相关人员,SEA编号,是否完成,备注)
values(newid(),'','','','{CurrentCompany.INFO_CLIENT}{model.MBLNO};{model.PORTDISCHARGE};{model.DESTINATION}',
'DEMO-SA',GETDATE(),GETDATE(),'{model.MBLNO}',0,'{strname}','{model.SINO}',0,'')";
log.Debug(sqlDs6);
jiefengDB.Database.ExecuteSqlCommand(sqlDs6);
}
resp.Success = true;
resp.Message = isSubmit ? LangAll.MsgSubmitSuccess : LangAll.MsgSaveSuccess;
resp.Url = Url.Action("ConfirmEdit", new { sino = model.SINO });
resp.Id = model.SINO;
return Json(resp);
}
[HttpPost]
public ActionResult ConfirmCancel(string sino)
{
RespCommon resp = new RespCommon();
var ord = bookingDB.Confirms.First(o => o.SINO == sino);
if (ord.BSSTATUS == OrderConfirmStatus.Submit.ToString())
{
string strConfirmStatusConfirm = OrderConfirmStatus.Confirm.ToString();
var confirmCount = bookingDB.Confirms.Count(c => c.BSSTATUS == strConfirmStatusConfirm && c.ORDNO == ord.ORDNO);
if (confirmCount > 0) //存在已确认的截单,不允许取消
{
resp.Success = false;
resp.Message = LangConfirm.MsgCannotCancelWithConfirm;
return Json(resp);
}
ord.BSSTATUS = OrderConfirmStatus.Create.ToString();
var orderObj = bookingDB.Orders.First(o => o.ORDNO == ord.ORDNO);
orderObj.SISTATUS = OrderConfirmStatus.Create.ToString();
//日志
var viewModel = ord.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == sino).AsConfirmEditViewModelList();
LogHelper.Log(OpLogModule.Confirm, OpLogType.Cancel, sino, ord.MBLNO, JsonConvert.SerializeObject(viewModel));
string strSubmitSta = OrderLogStatus.ConfirmSubmit.ToString();
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSubmitSta);
if (staLog != null)
{
bookingDB.StatusLogs.Remove(staLog);
}
bookingDB.SaveChanges();
//删除DS6任务
var sqlDs6 = $@"delete t_op_task where 任务类型='网上截单' and SEA编号='{ord.SINO}'";
log.Debug(sqlDs6);
jiefengDB.Database.ExecuteSqlCommand(sqlDs6);
resp.Success = true;
resp.Message = LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangConfirm.MsgCannotCancelStatus;
}
return Json(resp);
}
[HttpPost]
public ActionResult ConfirmDelete(string sino)
{
RespCommon resp = new RespCommon();
var confirm = bookingDB.Confirms.First(o => o.SINO == sino);
string strSaveSta = OrderLogStatus.ConfirmSave.ToString();
if (confirm != null && (confirm.BSSTATUS == OrderConfirmStatus.Create.ToString() || confirm.BSSTATUS == OrderConfirmStatus.Reject.ToString()))
{
var otherCount = bookingDB.Confirms.Count(c => c.ORDNO == confirm.ORDNO && c.SINO != confirm.SINO);
if (otherCount == 0) //没有其他截单
{
bookingDB.Confirms.Remove(confirm);
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == confirm.SINO));
bookingDB.Logs.RemoveRange(bookingDB.Logs.Where(c => c.BillNO == confirm.SINO));
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == confirm.ORDNO && sl.STATUS == strSaveSta);
if (staLog != null)
{
bookingDB.StatusLogs.Remove(staLog);
}
var orderObj = bookingDB.Orders.First(o => o.ORDNO == confirm.ORDNO);
orderObj.SISTATUS = OrderConfirmStatus.None.ToString();
}
else
{
string strConfirmStatusSubmit = OrderConfirmStatus.Submit.ToString();
var otherSubmitCount = bookingDB.Confirms.Count(c => c.ORDNO == confirm.ORDNO && c.BSSTATUS == strConfirmStatusSubmit && c.SINO != confirm.SINO);
if (otherSubmitCount > 0) //存在其他已提交的截单,不允许删除
{
resp.Success = false;
resp.Message = LangConfirm.MsgCannotDeleteWithSubmit;
return Json(resp);
}
bookingDB.Confirms.Remove(confirm);
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == confirm.SINO));
bookingDB.Logs.RemoveRange(bookingDB.Logs.Where(c => c.BillNO == confirm.SINO));
}
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangAll.MsgOptFail;
}
return Json(resp);
}
//订舱提交后发邮件
[HttpGet]
public ActionResult SendMailAfterConfirmSubmit(string sino)
{
var model = bookingDB.Confirms.First(o => o.SINO == sino);
var mailAddr = CurrentUser.EMAIL;
var crm = jiefengDB.CrmClients.AsNoTracking().FirstOrDefault(c => c. == CurrentCompany.INFO_CLIENT || c. == model.CARRIER);
if (crm != null && !string.IsNullOrEmpty(crm.))
{
mailAddr += "," + crm.;
}
ViewBag.MailAddr = mailAddr;
var etd = model.ETD.HasValue ? model.ETD.Value.ToString("yyyy-MM-dd") : string.Empty;
ViewBag.Title = $"{CurrentCompany.COMPANY_NAME} 提交截单:{model.MBLNO}|{model.VESSEL}|{etd}|{model.CNTRTOTAL}|{model.PORTDISCHARGE}";
ViewBag.Body = $"订舱公司:{CurrentCompany.COMPANY_NAME}\r\n订舱编号{model.ORDERNO}\r\n提单号{model.MBLNO}\r\nETD{etd}\r\n船公司{model.CARRIER}\r\n箱型箱量{model.CNTRTOTAL}\r\n卸货港{model.PORTDISCHARGE}\r\n操作人{CurrentUser.NAME} {CurrentUser.MOBILE}";
return View("SendMailAfterSubmit");
}
#endregion
#region 确认订舱列表
public ActionResult ConfirmList()
{
var colCfg = bookingDB.ConfigDatas.FirstOrDefault(c => c.Module == ConfigData.ModuleConfirm && c.Category == ConfigData.CateListColumn && c.UserId == CurrentUser.GID);
if (colCfg != null)
{
ViewBag.ColumnConfigData = JsonConvert.DeserializeAnonymousType(colCfg.JsonData, new dynamic[] { new { colName = "", visible = false, sort = 0, width = 0 } }).OrderBy(c => Convert.ToInt32(c.sort)).ToList();
}
ViewBag.ColDic = GetColDicConfirm();
var colCfgOrder = bookingDB.ConfigDatas.FirstOrDefault(c => c.Module == ConfigData.ModuleOrder && c.Category == ConfigData.CateListColumn && c.UserId == CurrentUser.GID);
if (colCfgOrder != null)
{
ViewBag.ColumnConfigDataOrder = JsonConvert.DeserializeAnonymousType(colCfgOrder.JsonData, new dynamic[] { new { colName = "", visible = false, sort = 0, width = 0 } }).OrderBy(c => Convert.ToInt32(c.sort)).ToList();
}
ViewBag.ColDicOrder = GetColDicOrder();
return View();
}
[HttpPost]
public ActionResult ConfirmListData(ReqConfirmList req, int offset = 1, int limit = 10, string sort = "", string order = "asc")
{
var query = bookingDB.Confirms.Where(o => o.CORPID == CurrentCompany.GID);
if (!string.IsNullOrWhiteSpace(req.MBLNO))
{
query = query.Where(o => o.MBLNO == req.MBLNO);
}
#region 条件
if (!string.IsNullOrWhiteSpace(req.ETD_START))
{
var dtStart = DateTime.Parse(req.ETD_START);
query = query.Where(o => o.ETD >= dtStart);
}
if (!string.IsNullOrWhiteSpace(req.ETD_END))
{
var dtEnd = DateTime.Parse(req.ETD_END);
query = query.Where(o => o.ETD >= dtEnd);
}
if (!string.IsNullOrWhiteSpace(req.VESSEL))
{
req.VESSEL = req.VESSEL.ToLower();
query = query.Where(o => o.VESSEL.ToLower().IndexOf(req.VESSEL) > -1);
}
if (!string.IsNullOrWhiteSpace(req.VOYNO))
{
req.VOYNO = req.VOYNO.ToLower();
query = query.Where(o => o.VOYNO.ToLower().IndexOf(req.VOYNO) > -1);
}
if (!string.IsNullOrWhiteSpace(req.BSSTATUS))
{
query = query.Where(o => o.BSSTATUS == req.BSSTATUS);
}
#endregion
#region 排序
if (!string.IsNullOrWhiteSpace(sort) && !string.IsNullOrWhiteSpace(order))
{
if (order.ToLower() == "asc")
{
if (sort.ToUpper() == "CARRIER")
{
query = query.OrderBy(o => o.CARRIER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderBy(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderBy(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderBy(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderBy(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderBy(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderBy(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderBy(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderBy(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderBy(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderBy(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
else
{
if (sort.ToUpper() == "SHIPPER")
{
query = query.OrderByDescending(o => o.SHIPPER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderByDescending(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderByDescending(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderByDescending(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderByDescending(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderByDescending(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderByDescending(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderByDescending(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderByDescending(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderByDescending(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderByDescending(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
#endregion
int count = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
RespPageData resp = new RespPageData();
resp.Total = count;
resp.DataList = list.AsListViewModelList();
return Json(resp);
}
[HttpPost]
public ActionResult ConfirmListByOrder(string ordno)
{
var list = bookingDB.Confirms.Where(c => c.ORDNO == ordno).AsListViewModelList();
return Json(list);
}
#endregion
#region 多品名维护
[HttpGet]
public ActionResult CtnDetail(string sino)
{
var list = bookingDB.Ctns.Where(c => c.ORDNO == sino).ToList().AsCtnListDetailViewModelList();
list.ForEach(c =>
{
c.DetailList = bookingDB.CtnDetails.Where(d => d.CTN_ID == c.CTN_ID).AsEditViewModelList();
});
ViewBag.CtnList = list;
var siObj = bookingDB.Confirms.First(c => c.SINO == sino);
ViewBag.SiObject = JsonConvert.SerializeObject(new { siObj.HSCODE, siObj.MARKS, siObj.DESCRIPTION });
ViewBag.HSCODE = siObj.HSCODE;
ViewBag.MARKS = siObj.MARKS;
ViewBag.DESCRIPTION = siObj.DESCRIPTION;
return View();
}
[HttpPost]
public ActionResult SaveDetailData(List<OpCtnListDetailViewModel> list)
{
RespCommon resp = new RespCommon();
foreach (var ctn in list)
{
bookingDB.CtnDetails.RemoveRange(bookingDB.CtnDetails.Where(d => d.CTN_ID == ctn.CTN_ID));
foreach (var detail in ctn.DetailList)
{
var model = detail.AsModel();
model.GID = Guid.NewGuid().ToString();
model.CTN_ID = ctn.CTN_ID;
bookingDB.CtnDetails.Add(model);
}
}
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgSaveSuccess;
return Json(resp);
}
#endregion
#region 费用
[HttpGet]
public ActionResult OpSeaeList()
{
return View();
}
[HttpPost]
public ActionResult OpSeaeList(string condition, int offset = 0, int limit = 20)
{
var query = jiefengDB.OpSeaes.AsNoTracking().OrderByDescending(s => s.).Where(s => s. == CurrentCompany.INFO_CLIENT);
if (!string.IsNullOrWhiteSpace(condition))
{
var obj = new { VESSEL = "", VOYNO = "", MBLNO = "", INVNO = "", BSNO = "" };
var jsonObj = JsonConvert.DeserializeAnonymousType(condition, obj);
if (!string.IsNullOrWhiteSpace(jsonObj.VESSEL))
{
query = query.Where(s => s..IndexOf(jsonObj.VESSEL) > -1);
}
if (!string.IsNullOrWhiteSpace(jsonObj.VOYNO))
{
query = query.Where(s => s..IndexOf(jsonObj.VOYNO) > -1);
}
if (!string.IsNullOrWhiteSpace(jsonObj.MBLNO))
{
query = query.Where(s => s. == jsonObj.MBLNO);
}
if (!string.IsNullOrWhiteSpace(jsonObj.INVNO))
{
query = query.Where(s => s. == jsonObj.INVNO);
}
if (!string.IsNullOrWhiteSpace(jsonObj.BSNO))
{
query = query.Where(s => s. == jsonObj.BSNO);
}
}
var list = query.Skip(offset).Take(limit).ToList();
var resultList = new List<dynamic>();
list.ForEach(s =>
{
resultList.Add(new
{
BSNO = s.,
VESSEL = s.,
VOYNO = s.,
MBLNO = s.,
INVNO = s.,
CUSTOMNO = s.,
CNTRTOTAL = s.,
ETD = s..HasValue ? s..Value.ToString("yyyy-MM-dd") : string.Empty,
ETA = s..HasValue ? s..Value.ToString("yyyy-MM-dd") : string.Empty,
YARD = s.,
AMOUNT_RMB = jiefengDB.OpChFee.Where(f => f. == s. && f. == "审核通过" && f. == "收" && f. == CurrentCompany.INFO_CLIENT && f. == "RMB").Sum(f => f. * f.),
AMOUNT_USD = jiefengDB.OpChFee.Where(f => f. == s. && f. == "审核通过" && f. == "收" && f. == CurrentCompany.INFO_CLIENT && f. == "USD").Sum(f => f. * f.)
});
});
int count = query.Count();
return Json(new { Data = resultList, Total = count });
}
[HttpGet]
public ActionResult OpFeeList(string BSNO)
{
ViewBag.BSNO = BSNO;
ViewBag.ClientName = ConfigurationManager.AppSettings["ClientName"];
ViewBag.ClientAddress = ConfigurationManager.AppSettings["ClientAddress"];
ViewBag.ClientTel = ConfigurationManager.AppSettings["ClientTel"];
ViewBag.ClientAccountRMB = ConfigurationManager.AppSettings["ClientAccountRMB"];
ViewBag.ClientAccountUSD = ConfigurationManager.AppSettings["ClientAccountUSD"];
return View();
}
[HttpPost]
public ActionResult OpFeeListData(string BSNO, string sort = "", string order = "")
{
var list = jiefengDB.OpChFee.Where(f => f. == "审核通过" && f. == "收" && f. == BSNO && f. == CurrentCompany.INFO_CLIENT).ToList();
var resultList = list.Select(f => new
{
FeeName = f.,
Unit = f.,
UnitPrice = f.,
Quantity = f.,
ExChangerate = f.,
Amount = f.,
IsConfirm = f.IS_CONFIRM
});
return Json(new { Success = true, Data = resultList });
}
[HttpPost]
public ActionResult OpFeeConfirmData(string BSNO)
{
RespCommon resp = new RespCommon();
var list = jiefengDB.OpChFee.Where(f => f. == "审核通过" && f. == "收" && f. == BSNO && f. == CurrentCompany.INFO_CLIENT).ToList();
list.ForEach(f => f.IS_CONFIRM = "1");
jiefengDB.SaveChanges();
resp.Success = true;
resp.Message = "确认成功";
return Json(resp);
}
#endregion
#region 其他
public ActionResult GetYardData(string ordno)
{
RespCtrnData resp = new RespCtrnData();
var order = bookingDB.Orders.FirstOrDefault(o => o.ORDNO == ordno);
if (order == null)
{
resp.Success = false;
resp.Message = "未找到订舱信息";
}
else if (string.IsNullOrEmpty(order.BSNO))
{
resp.Success = false;
resp.Message = "订舱信息中的BSNO为空";
}
else
{
var opseae = jiefengDB.OpSeaes.FirstOrDefault(s => s. == order.BSNO);
if (opseae == null)
{
resp.Success = false;
resp.Message = "委托信息未找到";
}
else
{
var client = jiefengDB.CrmClients.FirstOrDefault(c => c. == true && c. == opseae.);
if (client == null)
{
resp.Success = false;
resp.Message = "client信息未找到";
}
else
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://47.104.90.170:5000/query",//URL 必需项
Encoding = null,//编码格式utf-8,gb2312,gbk 可选项 默认类会自动识别
Host = "47.104.90.170:5000",
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
Accept = "gzip, deflate",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",
Postdata = "webusername=&webuserpass=&mblno=" + order.MBLNO + "&yardid=" + client. + "&isweb=0&custname=JieFeng&psw=JieFeng",
Method = "POST",//URL 可选项 默认为Get
};
HttpResult resulthtml = http.GetHtml(item);
var datahtml = resulthtml.Html;
var objRtn = JsonConvert.DeserializeAnonymousType(datahtml, new { status = "" });
if (objRtn.status == "1")
{
var objRtn2 = JsonConvert.DeserializeObject<YardDataJsonModel>(datahtml);
resp.List = objRtn2.message.Select(x => new OpCtnConfirmEditViewModel
{
CNTRNO = x.CNTRNO,
SEALNO = x.SEALNO,
CTNALL = x.CTNALL,
CTNNUM = x.XiangLiang,
TAREWEIGHT = x.TAREWEIGHT,
KINDPKGS = x.KINDPKGS,
CBM = x.CBM,
PKGS = x.PKGS,
KGS = x.KGS
}).ToList();
resp.Success = true;
}
else
{
var objRtn2 = JsonConvert.DeserializeAnonymousType(datahtml, new { status = "", message = "" });
resp.Success = false;
resp.Message = objRtn2.message;
}
}
}
}
return Json(resp);
}
[HttpPost]
public ActionResult CtrnFromExcel()
{
RespCtrnData resp = new RespCtrnData();
if (Request.Files.Count == 0)
{
resp.Success = false;
resp.Message = LangAll.MsgInvalidParam;
return Json(resp);
}
try
{
var excelfile = Request.Files[0];
string strMsg;
string ext = Path.GetExtension(excelfile.FileName).ToLower();
if (ext != ".xls" && ext != ".xlsx")
{
resp.Success = false;
resp.Message = LangAll.MsgInvalidParam;
return Json(resp);
}
DataTable dt = ExcelHelper.ExcelToDatatable(excelfile.InputStream, ext, out strMsg);
if (!string.IsNullOrEmpty(strMsg))
{
resp.Success = false;
resp.Message = strMsg;
return Json(resp);
}
if (dt.Rows.Count > 0)
{
resp.List = new List<OpCtnConfirmEditViewModel>();
foreach (DataRow row in dt.Rows)
{
OpCtnConfirmEditViewModel item = new OpCtnConfirmEditViewModel();
item.CTNALL = DataFromRowStr(row, "箱型");
item.CNTRNO = DataFromRowStr(row, "箱号");
item.SEALNO = DataFromRowStr(row, "封号");
item.PKGS = DataFromRowInt(row, "件数");
item.KINDPKGS = DataFromRowStr(row, "包装");
item.KGS = DataFromRowDecimal(row, "重量");
item.CBM = DataFromRowDecimal(row, "体积");
//item.TAREWEIGHT = DataFromRowDecimal(row, "皮重");
resp.List.Add(item);
}
resp.Success = true;
}
else
{
resp.Success = false;
resp.Message = "excel无数据";
}
}
catch (Exception ex)
{
resp.Success = false;
resp.Message = ex.Message;
}
return Json(resp);
}
private string GenOrderCode()
{
var codePrefix = ConfigurationManager.AppSettings["orderCodePrefix"];
var prefix = $"{codePrefix}{DateTime.Today.ToString("yyyyMMdd")}";
var maxNO = bookingDB.Orders.Where(o => o.CORPID == CurrentCompany.GID && o.ORDERNO.StartsWith(prefix)).Max(o => o.ORDERNO);
int curr = 0;
if (maxNO != null)
{
curr = int.Parse(maxNO.Substring(maxNO.Length - 4));
}
var code = prefix + (curr + 1).ToString("0000");
return code;
}
[HttpGet]
public ActionResult UpAttach(string ordno)
{
ViewBag.ORDNO = ordno;
return View();
}
[HttpPost]
public ActionResult UpAttachSave(string ordno)
{
RespCommon resp = new RespCommon();
if (Request.Files.Count > 0)
{
var listAtt = bookingDB.Attaches.Where(a => a.RELATIVEID == ordno).ToList();
if (listAtt.Count > 0)
{
listAtt.ForEach(a =>
{
bookingDB.Attaches.Remove(a);
});
}
var attNew = new OP_ATTACH();
attNew.OP_TIME = DateTime.Now;
attNew.OP_USER = CurrentUser.NAME;
attNew.RELATIVEID = ordno;
attNew.TITLE = Path.GetFileNameWithoutExtension(Request.Files[0].FileName);
attNew.GID = Guid.NewGuid().ToString();
attNew.FILETYPE = Path.GetExtension(Request.Files[0].FileName);
string upDir = Server.MapPath($"~/{AttachUpDir}");
if (!Directory.Exists(upDir))
{
Directory.CreateDirectory(upDir);
}
var saveFilePath = Path.Combine(upDir, $"{attNew.GID}{attNew.FILETYPE}");
var recordFilePath = $"~/{AttachUpDir}/{attNew.GID}{attNew.FILETYPE}";
attNew.FILEPATH = recordFilePath;
Request.Files[0].SaveAs(saveFilePath);
bookingDB.Attaches.Add(attNew);
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "上传成功";
}
return Json(resp);
}
[HttpGet]
public ActionResult DownAttach(string attId)
{
var att = bookingDB.Attaches.FirstOrDefault(a => a.GID == attId);
if (att != null)
{
var filePath = Server.MapPath(att.FILEPATH);
if (System.IO.File.Exists(filePath))
{
return File(filePath, "application/octet-stream", att.TITLE);
}
}
return HttpNotFound();
}
[HttpPost, AllowAnonymousAttribute]
public ActionResult ModifyFromDS6(string json, string type = "order")
{
RespCommon resp = new RespCommon();
if (string.IsNullOrEmpty(json))
{
resp.Success = false;
resp.Message = "无效json";
return Json(resp);
}
try
{
JObject jobj = JObject.Parse(json);
JToken jt = null;
if (type.ToLower() == "order")
{
if (jobj.TryGetValue("ORDNO", out jt))
{
var ordno = jt.ToString();
var ord = bookingDB.Orders.FirstOrDefault(o => o.ORDNO == ordno);
var propArr = ord.GetType().GetProperties();
var enumerator = jobj.GetEnumerator();
while (enumerator.MoveNext())
{
var prop = propArr.FirstOrDefault(p => p.Name.ToLower() == enumerator.Current.Key.ToLower());
if (prop != null)
{
var strVal = enumerator.Current.Value.ToString();
if (prop.PropertyType == typeof(string))
{
prop.SetValue(ord, strVal);
}
else if (prop.PropertyType == typeof(DateTime?))
{
DateTime dtTmp = DateTime.MinValue;
if (DateTime.TryParse(strVal, out dtTmp))
{
prop.SetValue(ord, dtTmp);
}
else
{
resp.Success = false;
resp.Message = $"字段 {prop.Name} 的值无效:{strVal}";
return Json(resp);
}
}
else if (prop.PropertyType == typeof(decimal?))
{
prop.SetValue(ord, Convert.ToDecimal(strVal));
}
else if (prop.PropertyType == typeof(int?))
{
prop.SetValue(ord, Convert.ToInt32(strVal));
}
else if (prop.PropertyType == typeof(bool?))
{
prop.SetValue(ord, Convert.ToBoolean(strVal));
}
}
}
var errors = bookingDB.GetValidationErrors();
var viewModel = ord.AsEditViewModel();
OP_LOG log = new OP_LOG();
log.OpTime = DateTime.Now;
log.OpUserId = "";
log.OpUserName = "东胜6";
log.OpCompanyId = "";
log.OpCompanyName = "";
log.Module = OpLogModule.Order.ToString();
log.Type = OpLogType.Save.ToString();
log.BillNO = ordno;
log.MBLNO = ord.MBLNO;
log.JsonValue = JsonConvert.SerializeObject(viewModel);
bookingDB.Logs.Add(log);
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "操作成功";
}
else
{
resp.Success = false;
resp.Message = "未找到ORDNO字段";
return Json(resp);
}
}
else if (type.ToLower() == "confirm")
{
if (jobj.TryGetValue("SINO", out jt))
{
var sino = jt.ToString();
var confirm = bookingDB.Confirms.FirstOrDefault(o => o.SINO == sino);
var propArr = confirm.GetType().GetProperties();
var enumerator = jobj.GetEnumerator();
while (enumerator.MoveNext())
{
var prop = propArr.FirstOrDefault(p => p.Name.ToLower() == enumerator.Current.Key.ToLower());
if (prop != null)
{
prop.SetValue(confirm, enumerator.Current.Value.ToString());
}
}
var viewModel = confirm.AsEditViewModel();
OP_LOG log = new OP_LOG();
log.OpTime = DateTime.Now;
log.OpUserId = "";
log.OpUserName = "东胜6";
log.OpCompanyId = "";
log.OpCompanyName = "";
log.Module = OpLogModule.Confirm.ToString();
log.Type = OpLogType.Save.ToString();
log.BillNO = sino;
log.MBLNO = confirm.MBLNO;
log.JsonValue = JsonConvert.SerializeObject(viewModel);
bookingDB.Logs.Add(log);
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "操作成功";
}
else
{
resp.Success = false;
resp.Message = "未找到SINO字段";
return Json(resp);
}
}
else if (type.ToLower() == "shipping")
{
//暂无需求
}
}
catch (JsonReaderException je)
{
resp.Success = false;
resp.Message = "json格式不正确";
}
catch (Exception ex)
{
resp.Success = false;
resp.Message = ex.Message;
}
return Json(resp);
}
//导入excel数据从datatable获取一行的指定列的数据
private string DataFromRowStr(DataRow row, string name)
{
if (row.Table.Columns.Contains(name))
{
return row[name].ToString();
}
return string.Empty;
}
private int DataFromRowInt(DataRow row, string name)
{
if (row.Table.Columns.Contains(name))
{
if (int.TryParse(row[name].ToString(), out int rtn))
{
return rtn;
}
}
return 0;
}
private decimal DataFromRowDecimal(DataRow row, string name)
{
if (row.Table.Columns.Contains(name))
{
if (decimal.TryParse(row[name].ToString(), out decimal rtn))
{
return rtn;
}
}
return 0;
}
//箱型 Bootstrap Search Suggest (截单界面专用)
public ActionResult SuggestCTN(string keyword)
{
RespSuggest resp = new RespSuggest();
var paraObj = JsonConvert.DeserializeAnonymousType(keyword, new { ord = "", ctn = "" });
var query = bookingDB.Ctns.AsNoTracking().Where(o => o.ORDNO == paraObj.ord);
if (!string.IsNullOrEmpty(paraObj.ctn))
{
query = query.Where(c => c.CTNALL.Contains(paraObj.ctn));
}
resp.value = query.Select(x => new { CTNID = x.CTN_ID, CTN = x.CTNALL }).ToList();
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
#endregion
#region 舱单
[HttpGet]
public ActionResult Shipping(string sino)
{
ShippingEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(sino))
{
var siobj = bookingDB.Confirms.FirstOrDefault(s => s.SINO == sino);
if (siobj == null)
{
return HttpNotFound();
}
viewModel = siobj.AsShippingEditViewModel();
#region 解析shipper、consignee、notifyparty
string[] arrShipper = siobj.SHIPPER.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (int line = 0; line < arrShipper.Length; line++)
{
if (line == 0)
{
viewModel.SHIPPERNAME = arrShipper[line];
}
else if (line == 1)
{
viewModel.SHIPPERADDR1 = arrShipper[line];
}
else
{
int idx = arrShipper[line].IndexOf("TEL:");
if (idx > -1)
{
int idxStart = idx + 4;
int idxEnd = arrShipper[line].LastIndexOf(' ');
int len = 0;
if (idxEnd == -1)
{
len = arrShipper[line].Length - idxStart;
}
else
{
len = idxEnd - idxStart;
}
viewModel.SHIPPERTEL = arrShipper[line].Substring(idxStart, len);
}
}
}
string[] arrConsignee = siobj.CONSIGNEE.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (int line = 0; line < arrConsignee.Length; line++)
{
if (line == 0)
{
viewModel.CONSIGNEENAME = arrConsignee[line];
}
else if (line == 1)
{
viewModel.CONSIGNEEADDR1 = arrConsignee[line];
}
else
{
int idx = arrConsignee[line].IndexOf("TEL:");
if (idx > -1)
{
int idxStart = idx + 4;
int idxEnd = arrConsignee[line].LastIndexOf(' ');
int len = 0;
if (idxEnd == -1)
{
len = arrConsignee[line].Length - idxStart;
}
else
{
len = idxEnd - idxStart;
}
viewModel.CONSIGNEETEL = arrConsignee[line].Substring(idxStart, len);
}
}
}
string[] arrNotifyparty = siobj.NOTIFYPARTY.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (int line = 0; line < arrNotifyparty.Length; line++)
{
if (line == 0)
{
viewModel.NOTIFYPARTYNAME = arrNotifyparty[line];
}
else if (line == 1)
{
viewModel.NOTIFYPARTYADDR1 = arrNotifyparty[line];
}
else
{
int idx = arrNotifyparty[line].IndexOf("TEL:");
if (idx > -1)
{
int idxStart = idx + 4;
int idxEnd = arrNotifyparty[line].LastIndexOf(' ');
int len = 0;
if (idxEnd == -1)
{
len = arrNotifyparty[line].Length - idxStart;
}
else
{
len = idxEnd - idxStart;
}
viewModel.NOTIFYPARTYTEL = arrNotifyparty[line].Substring(idxStart, len);
}
}
}
#endregion
}
else
{
viewModel = new ShippingEditViewModel();
}
viewModel.BSSTATUS = ShippingStatus.Create.ToString();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == sino).AsShippingEditViewModelList();
return View(viewModel);
}
[HttpGet]
public ActionResult ShippingEdit(string shipid)
{
ShippingEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(shipid))
{
var model = bookingDB.Shippings.First(o => o.SHIPPINGNO == shipid);
viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == shipid).AsShippingEditViewModelList();
return View("Shipping", viewModel);
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
[HttpGet]
public ActionResult ShippingCopy(string shipid, bool subFlag = false)
{
ShippingEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(shipid))
{
var model = bookingDB.Shippings.First(o => o.SHIPPINGNO == shipid);
viewModel = model.AsEditViewModel();
viewModel.SHIPPINGNO = string.Empty;
viewModel.BSSTATUS = ShippingStatus.Create.ToString();
viewModel.SUB_FLAG = subFlag;
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == shipid).AsShippingEditViewModelList();
return View("Shipping", viewModel);
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
[HttpGet]
public ActionResult ShippingList()
{
var colCfg = bookingDB.ConfigDatas.FirstOrDefault(c => c.Module == ConfigData.ModuleShipping && c.Category == ConfigData.CateListColumn && c.UserId == CurrentUser.GID);
if (colCfg != null)
{
ViewBag.ColumnConfigData = JsonConvert.DeserializeAnonymousType(colCfg.JsonData, new dynamic[] { new { colName = "", visible = false, sort = 0, width = 0 } }).OrderBy(c => Convert.ToInt32(c.sort)).ToList();
}
ViewBag.ColDic = GetColDicShipping();
return View();
}
[HttpPost]
public ActionResult ShippingList(ReqShippingList req, int offset = 1, int limit = 10, string sort = "", string order = "asc")
{
var query = bookingDB.Shippings.Where(o => o.CORPID == CurrentCompany.GID);
#region 条件
if (!string.IsNullOrWhiteSpace(req.MBLNO))
{
query = query.Where(o => o.MBLNO == req.MBLNO);
}
if (!string.IsNullOrWhiteSpace(req.HBLNO))
{
query = query.Where(o => o.HBLNO == req.HBLNO);
}
if (!string.IsNullOrWhiteSpace(req.ETD_START))
{
var dtStart = DateTime.Parse(req.ETD_START);
query = query.Where(o => o.ETD >= dtStart);
}
if (!string.IsNullOrWhiteSpace(req.ETD_END))
{
var dtEnd = DateTime.Parse(req.ETD_END);
query = query.Where(o => o.ETD >= dtEnd);
}
if (!string.IsNullOrWhiteSpace(req.VESSEL))
{
req.VESSEL = req.VESSEL.ToLower();
query = query.Where(o => o.VESSEL.ToLower().IndexOf(req.VESSEL) > -1);
}
if (!string.IsNullOrWhiteSpace(req.VOYNO))
{
req.VOYNO = req.VOYNO.ToLower();
query = query.Where(o => o.VOYNO.ToLower().IndexOf(req.VOYNO) > -1);
}
#endregion
#region 排序
if (!string.IsNullOrWhiteSpace(sort) && !string.IsNullOrWhiteSpace(order))
{
if (order.ToLower() == "asc")
{
if (sort.ToUpper() == "CARRIER")
{
query = query.OrderBy(o => o.CARRIER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderBy(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderBy(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderBy(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderBy(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderBy(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderBy(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderBy(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderBy(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderBy(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderBy(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
else
{
if (sort.ToUpper() == "SHIPPER")
{
query = query.OrderByDescending(o => o.SHIPPER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderByDescending(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderByDescending(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderByDescending(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderByDescending(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderByDescending(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderByDescending(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderByDescending(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderByDescending(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderByDescending(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderByDescending(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
#endregion
int count = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
RespPageData resp = new RespPageData();
resp.Total = count;
var dataList = list.AsListViewModelList();
resp.DataList = dataList;
return Json(resp);
}
[HttpPost]
public ActionResult ShippingSave(ShippingEditViewModel viewModel)
{
RespRedirect resp = new RespRedirect();
#region 保存
OP_SEAE_SHIPPING model = null;
bool isNew = false;
if (string.IsNullOrWhiteSpace(viewModel.SHIPPINGNO))
{
isNew = true;
viewModel.SHIPPINGNO = Guid.NewGuid().ToString();
model = viewModel.AsModel();
model.CORPID = CurrentCompany.GID;
model.USERID = CurrentUser.GID;
//model.BSSTATUS = OrderConfirmStatus.Create.ToString();
model.BSDATE = DateTime.Today;
model.CREATETIME = DateTime.Now;
model.INPUTBY = CurrentUser.NAME;
if (model.MODIFYTIME == DateTime.MinValue)
{
model.MODIFYTIME = null;
}
bookingDB.Shippings.Add(model);
}
else
{
model = bookingDB.Shippings.First(o => o.SHIPPINGNO == viewModel.SHIPPINGNO);
if (model.MODIFYTIME != null && model.MODIFYTIME.Value.Ticks != viewModel.MODIFYTIME)
{
return Json(new RespCommon() { Success = false, Message = LangAll.MsgDataSaveByOther });
}
viewModel.AsModel(model);
model.MODIFYTIME = DateTime.Now;
}
var dbCtnList = bookingDB.Ctns.Where(c => c.ORDNO == viewModel.SHIPPINGNO).ToList();
dbCtnList.ForEach(dbCtn =>
{
if (viewModel.CtrnList.FirstOrDefault(c => c.CTN_ID == dbCtn.CTN_ID) == null)
{
bookingDB.Ctns.Remove(dbCtn);
}
});
viewModel.CtrnList.ForEach(ctn =>
{
ctn.CTNNUM = 1;//截单的箱量固定为1
//计算teu
var tmpStr = ctn.CTNALL.Substring(0, 2);
if (tmpStr == "20")
{
ctn.TEU = ctn.CTNNUM;
}
else if (tmpStr == "40" || tmpStr == "45")
{
ctn.TEU = ctn.CTNNUM * 2;
}
var dbCtn = dbCtnList.FirstOrDefault(c => c.CTN_ID == ctn.CTN_ID);
if (dbCtn != null)
{
ctn.AsModel(dbCtn);
}
else
{
var saveModel = ctn.AsModel();
saveModel.CTN_ID = Guid.NewGuid().ToString();
saveModel.ORDNO = viewModel.SHIPPINGNO;
bookingDB.Ctns.Add(saveModel);
}
});
var strCtrnList = viewModel.CtrnList.Select(c => $"{c.CTNALL}*{c.CTNNUM}");
model.CNTRTOTAL = string.Join(" / ", strCtrnList);
model.PKGS = viewModel.CtrnList.Sum(c => c.PKGS);
model.KGS = viewModel.CtrnList.Sum(c => c.KGS);
model.CBM = viewModel.CtrnList.Sum(c => c.CBM);
bookingDB.SaveChanges();
var isSubmit = model.BSSTATUS == ShippingStatus.Submit.ToString();
if (isNew || (!isNew && !isSubmit))
{
//日志
LogHelper.Log(OpLogModule.Shipping, OpLogType.Save, model.SHIPPINGNO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
}
#endregion
//日志-提交
if (isSubmit)
{
LogHelper.Log(OpLogModule.Shipping, OpLogType.Submit, model.SHIPPINGNO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
}
//提交时,发送邮件
if (isSubmit)
{
var recMail = ConfigurationManager.AppSettings["shippingRecEmail"];
if (!string.IsNullOrEmpty(recMail))
{
var etd = model.ETD.HasValue ? model.ETD.Value.ToString("yyyy-MM-dd") : string.Empty;
OP_SEND_MAIL sendMail = new OP_SEND_MAIL();
sendMail.GID = Guid.NewGuid().ToString();
sendMail.SEND_TO = recMail;
sendMail.TITLE = $"{CurrentCompany.COMPANY_NAME} 提交舱单:{model.MBLNO}|{etd}|{model.CNTRTOTAL}|{model.PORTDISCHARGE}";
sendMail.BODY = $"订舱公司:{CurrentCompany.COMPANY_NAME}\r\n主提单号{model.MBLNO}\r\nETD{etd}\r\n箱型箱量{model.CNTRTOTAL}\r\n卸货港{model.PORTDISCHARGE}\r\n操作人{CurrentUser.NAME} {CurrentUser.MOBILE}";
sendMail.CREATE_TIME = DateTime.Now;
sendMail.STATUS = SendMailStatus.Create.ToString();
bookingDB.SendMails.Add(sendMail);
bookingDB.SaveChanges();
}
}
bookingDB.SaveChanges();
//DS6任务
if (isSubmit)
{
var sqlDs6 = $@"insert into t_op_task(任务编号,任务类型,任务来源,任务状态,任务说明,发起人,录入日期,任务开始时间,提单号,是否公共,任务相关人员,SEA编号,是否完成,备注)
values(newid(),'','','','{CurrentCompany.INFO_CLIENT}{model.MBLNO};{model.PORTDISCHARGE};{model.DESTINATION}',
'DEMO-SA',GETDATE(),GETDATE(),'{model.MBLNO}',0,'DEMO-SA','{model.SHIPPINGNO}',0,'')";
log.Debug(sqlDs6);
jiefengDB.Database.ExecuteSqlCommand(sqlDs6);
}
//舱单数据插入DS6
if (isSubmit)
{
try
{
var opSeae = jiefengDB.OpSeaes.AsNoTracking().FirstOrDefault(o => o. == model.MBLNO);
var rtn = jiefengDB.Database.SqlQuery<string>(@"DECLARE @return_value int,@str varchar(12)
EXEC @return_value = [dbo].[p_id]
@str = @str OUTPUT
SELECT @str as N'@str'
SELECT 'Return Value' = @return_value").First();
t_op_seae_edi edi = new t_op_seae_edi();
edi. = rtn;
edi.EDI = "CN";
edi.EDI = "未发送";
edi. = CurrentUser.NAME;
edi. = DateTime.Now;
edi. = model.MBLNO;
edi. = model.HBLNO;
edi. = "网上申报";
var crm = jiefengDB.CrmClients.FirstOrDefault(c => c. == model.CARRIER);
edi. = crm == null ? string.Empty : crm.EDI;
if (opSeae != null)
{
edi. = opSeae.;
edi. = opSeae.;
edi. = opSeae.;
}
else
{
edi. = string.Empty;
edi. = string.Empty;
edi. = string.Empty;
}
edi. = model.SHIPPERNAME;
edi.1 = model.SHIPPERADDR1;
edi. = model.SHIPPERCOUNTRY;
edi. = model.SHIPPERTEL;
edi. = model.CONSIGNEENAME;
edi.1 = model.CONSIGNEEADDR1;
edi. = model.CONSIGNEERCOUNTRY;
edi. = model.CONSIGNEETEL;
edi. = model.NOTIFYPARTYNAME;
edi.1 = model.NOTIFYPARTYADDR1;
edi. = model.NOTIFYPARTYCOUNTRY;
edi. = model.NOTIFYPARTYTEL;
edi. = model.PORTLOAD;
edi. = model.PORTLOADID;
edi. = model.PORTDISCHARGEID;
edi. = model.PORTDISCHARGE;
edi. = model.DESTINATIONID;
edi. = model.DESTINATION;
edi. = model.SERVICE;
edi. = model.MARKS;
edi. = model.DESCRIPTION;
edi. = model.PKGS;
edi. = model.KINDPKGS;
edi. = model.KGS;
edi. = model.CBM;
edi. = model.DCLASS;
edi. = model.DUNNO;
edi. = model.TEMPSET;
edi. = model.REEFERF;
edi. = model.CARGOID;
//edi.船公司 = model.CARRIER;
edi. = model.HSCODE;
edi.湿 = model.HUMIDITY;
edi. = model.CHUANDAI;
edi. = "";
edi. = "A";
edi. = "FCL";
edi. = true;
edi. = "Master";
jiefengDB.OpseaeEdis.Add(edi);
var ctnList = bookingDB.Ctns.Where(c => c.ORDNO == model.SHIPPINGNO).ToList();
foreach (var item in ctnList)
{
t_op_ctn_edi ctnEdi = new t_op_ctn_edi();
ctnEdi. = item.CTNNUM.Value;
var ctn = jiefengDB.Ctns.AsNoTracking().FirstOrDefault(c => c.MSC == item.CTNALL);
if (ctn != null)
{
ctnEdi. = ctn.;
ctnEdi. = ctn.;
ctnEdi. = ctn.;
ctnEdi. = ctn.;
}
else
{
ctnEdi. = "";
ctnEdi. = "";
ctnEdi. = "";
ctnEdi. = "";
}
ctnEdi.TEU = item.TEU.Value;
ctnEdi. = item.PKGS;
ctnEdi. = item.KINDPKGS;
ctnEdi. = item.KGS;
ctnEdi. = item.CBM;
ctnEdi. = rtn;
ctnEdi. = item.CNTRNO;
ctnEdi. = item.SEALNO;
jiefengDB.OpCtnEdis.Add(ctnEdi);
}
jiefengDB.SaveChanges();
}
catch (Exception ex)
{
var excep = ex;
while (excep != null)
{
log.Error(excep.Message);
log.Error(excep.StackTrace);
excep = excep.InnerException;
}
}
}
resp.Success = true;
resp.Message = isSubmit ? LangAll.MsgSubmitSuccess : LangAll.MsgSaveSuccess;
resp.Url = Url.Action("ShippingEdit", new { shipid = model.SHIPPINGNO });
return Json(resp);
}
//导入舱单数据
[HttpPost]
public ActionResult ImportShippingFromExcel()
{
RespCtrnData resp = new RespCtrnData();
if (Request.Files.Count == 0)
{
resp.Success = false;
resp.Message = LangAll.MsgInvalidParam;
return Json(resp);
}
try
{
var excelfile = Request.Files[0];
string strMsg;
string ext = Path.GetExtension(excelfile.FileName).ToLower();
if (ext != ".xls" && ext != ".xlsx")
{
resp.Success = false;
resp.Message = LangAll.MsgInvalidParam;
return Json(resp);
}
DataTable dt = ExcelHelper.ExcelToDatatable(excelfile.InputStream, ext, out strMsg);
if (!string.IsNullOrEmpty(strMsg))
{
resp.Success = false;
resp.Message = strMsg;
return Json(resp);
}
if (dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
var mblno = DataFromRowStr(row, "报关提单号");
var shipping = bookingDB.Shippings.FirstOrDefault(s => s.MBLNO == mblno);
if (shipping == null)
{
shipping = new OP_SEAE_SHIPPING();
shipping.SHIPPINGNO = Guid.NewGuid().ToString().Replace("-", "");
shipping.CREATETIME = DateTime.Now;
shipping.USERID = CurrentUser.GID;
shipping.CORPID = CurrentCompany.GID;
shipping.BSSTATUS = ShippingStatus.Create.ToString();
shipping.BSDATE = DateTime.Today;
bookingDB.Shippings.Add(shipping);
}
shipping.VESSEL = DataFromRowStr(row, "船名");
shipping.VOYNO = DataFromRowStr(row, "航次");
shipping.MBLNO = DataFromRowStr(row, "报关提单号");
shipping.CARRIER = DataFromRowStr(row, "船公司");
shipping.BLFRT = DataFromRowStr(row, "付款方式");
shipping.SERVICE = DataFromRowStr(row, "运输条款");
shipping.PORTLOAD = DataFromRowStr(row, "装货港");
shipping.PORTLOADID = DataFromRowStr(row, "装货港代码");
shipping.PORTDISCHARGE = DataFromRowStr(row, "卸货港");
shipping.PORTDISCHARGEID = DataFromRowStr(row, "卸货港代码");
shipping.DESTINATION = DataFromRowStr(row, "目的港");
shipping.DESTINATIONID = DataFromRowStr(row, "目的港代码");
shipping.SHIPPERNAME = DataFromRowStr(row, "发货人公司名");
shipping.SHIPPERADDR1 = DataFromRowStr(row, "发货人地址");
shipping.SHIPPERCOUNTRY = DataFromRowStr(row, "发货人国家代码");
shipping.SHIPPERTEL = DataFromRowStr(row, "发货人联系方式");
shipping.CONSIGNEENAME = DataFromRowStr(row, "收货人公司名");
shipping.CONSIGNEEADDR1 = DataFromRowStr(row, "收货人地址");
shipping.CONSIGNEERCOUNTRY = DataFromRowStr(row, "收货人国家代码");
shipping.CONSIGNEETEL = DataFromRowStr(row, "收货人联系方式");
shipping.NOTIFYPARTYNAME = DataFromRowStr(row, "通知人公司名");
shipping.NOTIFYPARTYADDR1 = DataFromRowStr(row, "通知人地址");
shipping.NOTIFYPARTYCOUNTRY = DataFromRowStr(row, "通知人国家代码");
shipping.NOTIFYPARTYTEL = DataFromRowStr(row, "通知人联系方式");
shipping.PKGS = DataFromRowInt(row, "件数");
shipping.KGS = DataFromRowDecimal(row, "重量");
shipping.CBM = DataFromRowDecimal(row, "体积");
shipping.DESCRIPTION = DataFromRowStr(row, "品名");
shipping.MARKS = DataFromRowStr(row, "唛头");
shipping.HSCODE = DataFromRowStr(row, "HSCODE");
OP_CTN ctn = new OP_CTN();
ctn.CTN_ID = Guid.NewGuid().ToString().Replace("-", "");
ctn.ORDNO = shipping.SHIPPINGNO;
ctn.CTNALL = DataFromRowStr(row, "箱型");
ctn.CNTRNO = DataFromRowStr(row, "箱号");
ctn.SEALNO = DataFromRowStr(row, "铅封号");
ctn.KINDPKGS = DataFromRowStr(row, "包装单位");
bookingDB.Ctns.Add(ctn);
}
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "导入成功!";
}
else
{
resp.Success = false;
resp.Message = "excel无数据";
}
}
catch (Exception ex)
{
resp.Success = false;
resp.Message = ex.Message;
}
return Json(resp);
}
//批量提交
[HttpPost]
public ActionResult SubmitBatch(string idStr)
{
RespCommon resp = new RespCommon();
var arr = idStr.Split(',');
var list = bookingDB.Shippings.Where(s => arr.Contains(s.SHIPPINGNO)).ToList();
#region 校验
StringBuilder builder = new StringBuilder();
var allValid = true;
foreach (var item in list)
{
var checkOk = true;
#region 基本信息
if (string.IsNullOrEmpty(item.MBLNO))
{
builder.AppendLine($"主提单号未填写");
checkOk = false;
continue;
}
if (string.IsNullOrEmpty(item.CARRIER))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写船公司");
checkOk = false;
}
if (!item.ETD.HasValue)
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写ETD");
checkOk = false;
}
if (string.IsNullOrEmpty(item.VESSEL))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写船名");
checkOk = false;
}
if (string.IsNullOrEmpty(item.VOYNO))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写航次");
checkOk = false;
}
if (string.IsNullOrEmpty(item.CHUANDAI))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写船代");
checkOk = false;
}
#endregion
#region 发货人、收货人、通知人
if (string.IsNullOrEmpty(item.SHIPPERNAME))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写发货人");
checkOk = false;
}
if (string.IsNullOrEmpty(item.SHIPPERADDR1))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写发货人地址");
checkOk = false;
}
if (string.IsNullOrEmpty(item.SHIPPERCOUNTRY))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写发货人国家");
checkOk = false;
}
if (string.IsNullOrEmpty(item.SHIPPERTEL))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写发货人电话");
checkOk = false;
}
if (string.IsNullOrEmpty(item.CONSIGNEENAME))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写收货人");
checkOk = false;
}
if (string.IsNullOrEmpty(item.CONSIGNEEADDR1))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写收货人地址");
checkOk = false;
}
if (string.IsNullOrEmpty(item.CONSIGNEERCOUNTRY))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写收货人国家");
checkOk = false;
}
if (string.IsNullOrEmpty(item.CONSIGNEETEL))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写收货人电话");
checkOk = false;
}
if (string.IsNullOrEmpty(item.NOTIFYPARTYNAME))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写通知人");
checkOk = false;
}
if (string.IsNullOrEmpty(item.NOTIFYPARTYADDR1))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写通知人地址");
checkOk = false;
}
if (string.IsNullOrEmpty(item.NOTIFYPARTYCOUNTRY))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写通知人国家");
checkOk = false;
}
if (string.IsNullOrEmpty(item.NOTIFYPARTYTEL))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写通知人电话");
checkOk = false;
}
#endregion
#region 港口信息
if (string.IsNullOrEmpty(item.PORTLOADID))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写装货港");
checkOk = false;
}
if (string.IsNullOrEmpty(item.PORTDISCHARGEID))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写卸货港");
checkOk = false;
}
if (string.IsNullOrEmpty(item.PLACERECEIPTID))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写收货地");
checkOk = false;
}
if (string.IsNullOrEmpty(item.DESTINATIONID))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写目的地");
checkOk = false;
}
#endregion
#region 货物信息
if (string.IsNullOrEmpty(item.MARKS))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写唛头");
checkOk = false;
}
if (string.IsNullOrEmpty(item.DESCRIPTION))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写货描");
checkOk = false;
}
if (string.IsNullOrEmpty(item.CARGOID))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写货物标识");
checkOk = false;
}
if (string.IsNullOrEmpty(item.KINDPKGS))
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写包装");
checkOk = false;
}
if (!item.PKGS.HasValue)
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写件数");
checkOk = false;
}
if (!item.KGS.HasValue)
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写重量");
checkOk = false;
}
if (!item.CBM.HasValue)
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写尺码");
checkOk = false;
}
#endregion
var ctrnCount = bookingDB.Ctns.AsNoTracking().Count(c => c.ORDNO == item.SHIPPINGNO);
if (ctrnCount == 0)
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单未填写箱信息");
checkOk = false;
}
if (item.BSSTATUS != ShippingStatus.Create.ToString())
{
builder.AppendLine($"提单号为{item.MBLNO}的舱单当前状态不可提交");
checkOk = false;
}
if (checkOk)
{
item.BSSTATUS = ShippingStatus.Submit.ToString();
}
else
{
allValid = false;
}
}
#endregion
if (allValid)
{
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "操作成功";
}
else
{
resp.Success = false;
resp.Message = builder.ToString().Replace("\r\n", "<br/>");
}
return Json(resp);
}
#endregion
#region 签单条
[HttpGet]
public ActionResult SignList()
{
return View();
}
[HttpPost]
public ActionResult SignListData(int offset = 0, int limit = 10)
{
RespPageData resp = new RespPageData();
var query = jiefengDB.OpSeaeSignMain.Where(s => s. == CurrentCompany.INFO_CLIENT);
resp.DataList = query.OrderByDescending(s => s.).Skip(offset).Take(limit).AsListViewModelList();
resp.Total = query.Count();
return Json(resp);
}
[HttpGet]
public ActionResult SignView(string signNO)
{
var signObj = jiefengDB.OpSeaeSignMain.FirstOrDefault(s => s. == signNO);
var detailList = jiefengDB.OpSeaeSignDetail.Where(d => d. == signNO).ToList();
var personList = from detail in detailList
join opseae in jiefengDB.OpSeaes on detail. equals opseae.
join emp in jiefengDB.Employee on opseae. equals emp.
select emp;
#region itext7
MemoryStream ms = new MemoryStream();
iText.Kernel.Font.PdfFont fontKai = PdfFontFactory.CreateFont("C:/Windows/Fonts/simkai.TTF", iText.IO.Font.PdfEncodings.IDENTITY_H, true);
iText.Kernel.Font.PdfFont fontSong = PdfFontFactory.CreateFont("C:/Windows/Fonts/STSONG.TTF", iText.IO.Font.PdfEncodings.IDENTITY_H, true);
iText.Kernel.Font.PdfFont fontHei = PdfFontFactory.CreateFont("C:/Windows/Fonts/simhei.TTF", iText.IO.Font.PdfEncodings.IDENTITY_H, true);
const int pageWidth = 842;
const int pageHeight = 595;
const int leftPadding = 40;
DocumentProperties docProp = new DocumentProperties();
PdfWriter writer = new PdfWriter(ms);
iText.Kernel.Pdf.PdfDocument pdf = new iText.Kernel.Pdf.PdfDocument(writer);
pdf.SetDefaultPageSize(new iText.Kernel.Geom.PageSize(pageWidth, pageHeight));
Document document = new Document(pdf);
//LOGO图片
var imgDataLogo = iText.IO.Image.ImageDataFactory.Create(Server.MapPath(@"~/content/img/jiefeng.jpg"));
iText.Layout.Element.Image imgLogo = new iText.Layout.Element.Image(imgDataLogo);
imgLogo.SetFixedPosition(leftPadding, pageHeight - 80);//左、上、右、下
imgLogo.SetWidth(120);
imgLogo.SetHeight(40);
document.Add(imgLogo);
#region 标题
Paragraph textHead = new Paragraph("山 东 捷 丰 国 际 储 运 有 限 公 司");
textHead.SetFont(fontKai);
textHead.SetFontSize(24);
textHead.SetFixedPosition(200, pageHeight - 70, pageWidth);
document.Add(textHead);
Paragraph textSubHead = new Paragraph("SMART INTERNATIONAL LOGISTICS CO.,LTD.");
textSubHead.SetFont(fontHei);
textSubHead.SetFontSize(18);
textSubHead.SetFixedPosition(235, pageHeight - 90, pageWidth);
document.Add(textSubHead);
Paragraph textSubHead2 = new Paragraph("青岛市南京路8号府都大厦1213层 邮编266071");
textSubHead2.SetFont(fontSong);
textSubHead2.SetFontSize(16);
textSubHead2.SetFixedPosition(230, pageHeight - 110, pageWidth);
//textSubHead2.SetUnderline();
document.Add(textSubHead2);
Paragraph line = new Paragraph("".PadLeft(115, '¯'));
line.SetFixedPosition(leftPadding, pageHeight - 130, pageWidth);
document.Add(line);
#endregion
#region 条码、签单表标题、作废日期
Paragraph textNO = new Paragraph("NO:");
textNO.SetFont(fontSong);
textNO.SetFontSize(14);
textNO.SetFixedPosition(leftPadding, pageHeight - 160, pageWidth);
document.Add(textNO);
var barcode = new Barcode()
{
IncludeLabel = true,
Alignment = AlignmentPositions.CENTER,
Width = 180,
Height = 55,
RotateFlipType = RotateFlipType.RotateNoneFlipNone,
BackColor = Color.White,
ForeColor = Color.Black,
LabelFont = new Font("Arial", 8)
};
var imgDataBarcode = iText.IO.Image.ImageDataFactory.Create(barcode.Encode(TYPE.CODE128B, signObj.), null);
iText.Layout.Element.Image imgBarcode = new iText.Layout.Element.Image(imgDataBarcode);
imgBarcode.SetFixedPosition(leftPadding + 30, pageHeight - 190);
document.Add(imgBarcode);
Paragraph textTitle = new Paragraph("签 单 表");
textTitle.SetFont(fontSong);
textTitle.SetFontSize(24);
textTitle.SetBold();
textTitle.SetFixedPosition(350, pageHeight - 180, pageWidth);
document.Add(textTitle);
Paragraph textZuofei = new Paragraph($"作废日期:{(signObj.作废日期.HasValue ? signObj.作废日期.Value.ToString("yyyy-MM-dd") : "")}");
textZuofei.SetFont(fontSong);
textZuofei.SetFontSize(16);
textZuofei.SetBold();
textZuofei.SetUnderline();
textZuofei.SetFixedPosition(520, pageHeight - 175, pageWidth);
document.Add(textZuofei);
#endregion
#region 客户名称等
var empFirst = personList.FirstOrDefault();
Paragraph textCustomer = new Paragraph($"客户名称:{signObj.客户名称}\t客户类型{signObj.客户类型}\t联系人{empFirst.姓名 ?? string.Empty}\t联系电话{empFirst.固定电话 ?? string.Empty}");
textCustomer.SetFont(fontSong);
textCustomer.SetFontSize(14);
textCustomer.SetFixedPosition(leftPadding, pageHeight - 225, pageWidth);
document.Add(textCustomer);
Paragraph textJiefei = new Paragraph(signObj.);
textJiefei.SetFont(fontKai);
textJiefei.SetFontSize(14);
textJiefei.SetFixedPosition(leftPadding, pageHeight - 250, pageWidth);
textJiefei.SetBold();
textJiefei.SetUnderline();
document.Add(textJiefei);
#endregion
#region 数据表
var cellStyle = new Style()
.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER)
.SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE);
Table table = new Table(new float[] { 170, 170, 100, 100, 100, 100 });
string[] headers = new string[] { "提单号", "船名", "航次", "签单方式", "提单签入日期", "二次改单" };
foreach (string h in headers)
{
Paragraph head = new Paragraph(h);
head.SetFont(fontSong);
head.SetFontSize(15);
table.AddCell(new Cell()
.Add(head)
.AddStyle(cellStyle));
}
foreach (var detail in detailList)
{
table.AddCell(new Cell().Add(new Paragraph(detail.).SetFont(fontSong)).AddStyle(cellStyle));
table.AddCell(new Cell().Add(new Paragraph(detail.).SetFont(fontSong)).AddStyle(cellStyle));
table.AddCell(new Cell().Add(new Paragraph(detail.).SetFont(fontSong)).AddStyle(cellStyle));
table.AddCell(new Cell().Add(new Paragraph(detail.).SetFont(fontSong)).AddStyle(cellStyle));
table.AddCell(new Cell().Add(new Paragraph(detail..HasValue ? detail..Value.ToString("yyyy-MM-dd") : string.Empty)).AddStyle(cellStyle));
table.AddCell(new Cell().Add(new Paragraph(detail. ?? string.Empty).SetFont(fontSong)).AddStyle(cellStyle));
}
table.SetMarginTop(230);
document.Add(table);
#endregion
#region 月结提示、签字等
Paragraph textTip = new Paragraph("如果您是我司月结客户,请务必在账期内付款,如有延误,会给您的签单造成不便,敬请谅解。");
textTip.SetFont(fontSong);
textTip.SetFontSize(14);
document.Add(textTip);
Paragraph textSign = new Paragraph("签字:");
textSign.SetFont(fontSong);
textSign.SetFontSize(14);
textSign.SetPaddingLeft(500);
document.Add(textSign);
Paragraph textTime = new Paragraph("时间:");
textTime.SetFont(fontSong);
textTime.SetFontSize(14);
textTime.SetPaddingLeft(500);
document.Add(textTime);
#endregion
document.Close();
pdf.Close();
writer.Close();
byte[] bs = ms.GetBuffer();
pdf.Close();
return File(bs, "application/pdf");
#endregion
}
#endregion
#region 列配置
[HttpGet]
public ActionResult ColumnConfig(string module, string cate)
{
Dictionary<string, string> dicAllCol = null;
if (module == ConfigData.ModuleOrder)
{
dicAllCol = GetColDicOrder();
}
else if (module == ConfigData.ModuleConfirm)
{
dicAllCol = GetColDicConfirm();
}
else if (module == ConfigData.ModuleShipping)
{
dicAllCol = GetColDicShipping();
}
ViewBag.DicCol = dicAllCol;
ViewBag.Module = module;
var colCfg = bookingDB.ConfigDatas.FirstOrDefault(c => c.Module == module && c.Category == cate && c.UserId == CurrentUser.GID);
ViewBag.JsonData = colCfg == null ? null : colCfg.JsonData;
return View();
}
private Dictionary<string, string> GetColDicOrder()
{
Dictionary<string, string> dicAllCol = new Dictionary<string, string>();
dicAllCol.Add("CARRIER", "船公司");
dicAllCol.Add("CNTRTOTAL", "集装箱");
dicAllCol.Add("PORTDISCHARGE", "卸货港");
dicAllCol.Add("CONTRACTNO", "约号");
dicAllCol.Add("VESSEL", "船名");
dicAllCol.Add("VOYNO", "航次");
dicAllCol.Add("MBLNO", "提单号");
dicAllCol.Add("ETD", "开船日期");
dicAllCol.Add("DESTINATION", "目的地");
dicAllCol.Add("PONO", "PO NO.");
dicAllCol.Add("BusinessNO", "业务编号");
dicAllCol.Add("CLOSINGDATE", "截港日期");
dicAllCol.Add("CLOSEDOCDATE", "截单日期");
dicAllCol.Add("YARD", "场站");
dicAllCol.Add("YardContract", "场站联系人");
dicAllCol.Add("BSSTATUS_NAME", "状态");
dicAllCol.Add("SISTATUS_NAME", "截单状态");
return dicAllCol;
}
private Dictionary<string, string> GetColDicConfirm()
{
Dictionary<string, string> dicAllCol = new Dictionary<string, string>();
dicAllCol.Add("CARRIER", "船公司");
dicAllCol.Add("YARD", "场站");
dicAllCol.Add("CNTRTOTAL", "集装箱");
dicAllCol.Add("PORTLOAD", "装货港");
dicAllCol.Add("PORTDISCHARGE", "卸货港");
dicAllCol.Add("CONTRACTNO", "客户合同号");
dicAllCol.Add("VESSEL", "船名");
dicAllCol.Add("VOYNO", "航次");
dicAllCol.Add("MBLNO", "提单号");
dicAllCol.Add("ETD", "开船日期");
dicAllCol.Add("DESTINATION", "目的地");
dicAllCol.Add("PONO", "PO NO.");
dicAllCol.Add("BusinessNO", "业务编号");
dicAllCol.Add("BSSTATUS_NAME", "状态");
return dicAllCol;
}
private Dictionary<string, string> GetColDicShipping()
{
Dictionary<string, string> dicAllCol = new Dictionary<string, string>();
dicAllCol.Add("MBLNO", "主提单号");
dicAllCol.Add("HBLNO", "分提单号");
dicAllCol.Add("ETD", "开船日期");
dicAllCol.Add("CHUANDAI", "船代");
dicAllCol.Add("PORTLOAD", "装货港");
dicAllCol.Add("PORTDISCHARGE", "卸货港");
dicAllCol.Add("BSSTATUS_NAME", "状态");
dicAllCol.Add("SENDSTATUS", "发送状态");
return dicAllCol;
}
[HttpPost]
public ActionResult ColumnConfigSave(string module, string cate, string data)
{
RespCommon resp = new RespCommon();
var colCfg = bookingDB.ConfigDatas.FirstOrDefault(c => c.Module == module && c.Category == cate && c.UserId == CurrentUser.GID);
if (colCfg == null)
{
colCfg = new ConfigData();
colCfg.GID = Guid.NewGuid().ToString();
colCfg.UserId = CurrentUser.GID;
colCfg.CompId = CurrentCompany.GID;
colCfg.Module = module;
colCfg.Category = ConfigData.CateListColumn;
bookingDB.ConfigDatas.Add(colCfg);
}
colCfg.JsonData = data;
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = "保存成功";
return Json(resp);
}
#endregion
#region 测试
//[HttpGet]
//public ActionResult SetOrderConfirm(string ordno)
//{
// bookingDB.Orders.First(o => o.ORDNO == ordno).BSSTATUS = OrderConfirmStatus.Confirm.ToString();
// bookingDB.SaveChanges();
// return Content("1");
//}
#endregion
}
}