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/DSWeb/Areas/MvcShipping/Controllers/MsOpTaskController.cs

483 lines
23 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Models.MsOpTask;
using DSWeb.Areas.MvcShipping.DAL;
using HcUtility.Comm;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.DsSendmail;
using DSWeb.MvcShipping.DAL.MsInfoClientMailProject;
using System.Data;
using DSWeb.MvcShipping.Models.MsOpMailLog;
using HcUtility.Core;
using System.IO;
using CommonTool.MailKit;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsOpTaskController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult PiLiang()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = MsOpTaskDAL.GetDataList(start, limit,condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
int count = MsOpTaskDAL.getTotalCount(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", totalCount = count, data = dataList });//list.ToList()
return new ContentResult() { Content = json };
}
public ContentResult GetTaskTreeRefList(string PARENTID, string condition)
{
var dataList = MsOpTaskDAL.GetTaskTreeRefList(PARENTID, condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string condition)
{
OpTask head = null;
head = MsOpTaskDAL.GetData(condition);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Delete(string bsno, string data)
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
var bodyList = JsonConvert.Deserialize<List<OpTask>>(data);
var result = new DBResult();
if (bodyList != null)
{
result = MsOpTaskDAL.DeleteTask(bodyList);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
/// <summary>
/// optask执行动作
/// </summary>
/// <param name="data"></param>
/// <param name="transstatus"></param>
/// <param name="statusdate"></param>
/// <param name="arriverremark"></param>
/// <returns></returns>
public ContentResult UpTransStatusList(string data, string transstatus, string statusdate = "", string arriverremark = "")
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
if (transstatus == "转发邮件")
{
return UpTaskEmail(data);
} else if (transstatus == "确认并完成")
{
return UpTaskOver(data);
}
else if (transstatus == "取消任务" || transstatus == "PENDING")
{
var bodyList = JsonConvert.Deserialize<List<OpTask>>(data);
var result = MsOpTaskDAL.UpTransStatus(bodyList, transstatus, Convert.ToString(Session["SHOWNAME"]).ToString().Trim());
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var jsonRespose = new JsonResponse
{
Success =false,
Message ="当前状态无法处理!"
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//
}
public ContentResult GetBcRemark(string data)
{
var result = new DBResult();
var bodyList = JsonConvert.Deserialize<List<OpTask>>(data);
if (bodyList != null)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
foreach (var enumValue in bodyList)
{
result = MsOpTaskDAL.GetBcRemark(enumValue);
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetTaskFieldValueDataList( string sort, string condition)
{
var dataList = MsOpTaskDAL.GetTaskFieldValueDataList(condition);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });//list.ToList()
return new ContentResult() { Content = json };
}
public ContentResult updatetaskbs(string bsno, string body)
{
var result = new DBResult();
var bodyList = JsonConvert.Deserialize<List<OpTaskFieldValue>>(body);
if (bodyList != null && bodyList.Count != 0) {
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
foreach (var bill in bodyList) {
if (bill.FEILDNAME == "船名")
{
var blUpSQL = " update OP_SEAE SET VESSEL='" + bill.FEILDVALUE + "' where BSNO='" + bsno + "'";
var bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}else if (bill.FEILDNAME == "航次")
{
var blUpSQL = " update OP_SEAE SET VOYNO='" + bill.FEILDVALUE + "' where BSNO='" + bsno + "'";
var bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
else if (bill.FEILDNAME == "提单号")
{
var blUpSQL = " update OP_SEAE SET MBLNO='" + bill.FEILDVALUE + "' where BSNO='" + bsno + "'";
var bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
else if (bill.FEILDNAME == "卸货港")
{
var blUpSQL = " update OP_SEAE SET PORTDISCHARGE='" + bill.FEILDVALUE + "' where BSNO='" + bsno + "'";
var bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
else if (bill.FEILDNAME == "目的港")
{
var blUpSQL = " update OP_SEAE SET DESTINATION='" + bill.FEILDVALUE + "' where BSNO='" + bsno + "'";
var bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
}
}
result.Success = true;
result.Message = "更新成功!";
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult UpTaskOver(string data)
{
var result = new DBResult();
var bodyList = JsonConvert.Deserialize<List<OpTask>>(data);
if (bodyList != null)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
foreach (var enumValue in bodyList)
{
if (enumValue.TASKTYPE == "INVOIC") {
result=MsOpTaskDAL.ImpInvoice(enumValue, Convert.ToString(Session["SHOWNAME"]).ToString().Trim(), Convert.ToString(Session["USERID"]).ToString().Trim(), Convert.ToString(Session["COMPANYID"]).ToString().Trim());
} else if (enumValue.TASKTYPE == "费用账单")
{
result = MsOpTaskDAL.ImpOrderFee(enumValue, Convert.ToString(Session["SHOWNAME"]).ToString().Trim(), Convert.ToString(Session["USERID"]).ToString().Trim(), Convert.ToString(Session["COMPANYID"]).ToString().Trim());
}
else if (enumValue.TASKTYPE == "报关导入")
{
//20230129 关贸云 报关业务导入
result = MsOpTaskDAL.(enumValue.TASKNO, Convert.ToString(Session["SHOWNAME"]).ToString().Trim());
}
else
{
var blUpSQL = " insert into op_task_state (GID,TASKNO,TASKSTATUS,OP,OPTIME) values (newid(),'" + enumValue.TASKNO + "','已完成','" + Convert.ToString(Session["SHOWNAME"]).ToString().Trim() + "',GETDATE())";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
blUpSQL = " update op_task set ISCOMPLETE=1,TASKSTATUS='已完成',COMPLETETYPE='人工',COMPLETETIME=GETDATE(),OP='" + Convert.ToString(Session["SHOWNAME"]).ToString().Trim() + "' where GID='" + enumValue.GID + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
if (enumValue.ISCOMPLETE != "1" && (enumValue.TASKTYPE == "BA" || enumValue.TASKTYPE == "BC" || enumValue.TASKTYPE == "BCL" || enumValue.TASKTYPE == "ORIGINAL" || enumValue.TASKTYPE == "VC" || enumValue.TASKTYPE == "DRAFT" || enumValue.TASKTYPE == "SEAWAY"))
{
//blUpSQL = "INSERT INTO [Receipt_Doc](GID,BSNO,URL,Driect_URL,MODIFIEDUSER,MODIFIEDTIME,RECEIPTTYPE,DOCUMENTATTACHEDCODE,DOCUMENTATTACHEDNO)"
// + "VALUES(newid(),'" + enumValue.BSNO + "','" + enumValue.TASKTYPE + "','" + enumValue.FILEPATH + "','"+ Convert.ToString(Session["USERID"]).ToString().Trim()+ "',GETDATE(),'入货通知','','');";
// bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
result.Success = true;
result.Message = "确认完成";
}
if (!result.Success) {
var jsonRespose2 = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult UpTaskEmail(string data)
{
var result = new DBResult();
var bodyList = JsonConvert.Deserialize<List<OpTask>>(data);
if (bodyList != null)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var MAILACCOUNT = "admin@dongshengsoft.com";
var PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTONAME'");
if (PARAMVALUE.PARAMVALUE != "") MAILACCOUNT = PARAMVALUE.PARAMVALUE;
var MAILTOPASSWORD = "ds!@#)(*";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOPASSWORD'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOPASSWORD = PARAMVALUE.PARAMVALUE;
var MAILTOSERVER = "smtpcom.263xmail.com";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOSERVER'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOSERVER = PARAMVALUE.PARAMVALUE;
var MAILTOPORT = "465";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOPORT'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOPORT = PARAMVALUE.PARAMVALUE;
var MAILISSSL = false;
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILISSSL'");
if (PARAMVALUE.PARAMVALUE == "1") MAILISSSL = true;
foreach (var enumValue in bodyList)
{
result.Success = false;
if (enumValue.MAILNO != ""&& enumValue.TASKTYPE != "SEAWAY")
{
var mailrec = T_ALL_DA.GetDataSet("select MAILTITILE,MAILDESCRIP from op_mail_recv where MAILID='" + enumValue.MAILNO+"'");
string mailtopic = "";
string mailbody = "";
foreach (DataRow row in mailrec.Tables[0].Rows)
{
mailtopic = Convert.ToString(row["MAILTITILE"]);
mailbody = Convert.ToString(row["MAILDESCRIP"]);
}
var bltype = "";
bltype = enumValue.TASKTYPE;
if (bltype != "运输计划变更")
{
if (bltype == "BA" || bltype == "BC") bltype = "入货通知";
else bltype = "提单留底";
}
var receiver = "";
if (bltype == "运输计划变更") {
mailbody = "";
string filename = Server.MapPath(enumValue.FILEPATH);
FileStream fs = new FileStream(filename, FileMode.Open);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
string line;
while ((line = sr.ReadLine()) != null)
{
mailbody = mailbody + line;
}
sr.Close();
fs.Close();
}
var mailproject = MsInfoClientMailProjectDAL.GetBodyList(" BLTYPE='"+ bltype + "' AND PROJECTID in (select MAILPROJECT from op_seae where BSNO='" + enumValue.BSNO+"' )");
if (mailproject == null || mailproject.Count == 0)
{
result.Message = result.Message + " 提单号:" + enumValue.MBLNO + ",未设置邮件方案!";
var EMAIL = T_ALL_DA.GetStrSQL("EMAIL", "SELECT c.EMAIL EMAIL from info_client_contact c,(select customername,OPERATOR from op_seae where bsno='" + enumValue.BSNO + "') v where c.linkid in (select gid from info_client where shortname = v.customername) and c.showname = v.operator ");
if (EMAIL != "") receiver = EMAIL;
}
else
{
foreach (var mail in mailproject)
{
if (receiver == "")
receiver = mail.RECEIVER;
else receiver = receiver + ";" + mail.RECEIVER;
}
}
if (receiver != "")
{
var email1 = T_ALL_DA.GetStrSQL("email1", "select email1 from VW_user WHERE SHOWNAME='" + Convert.ToString(Session["SHOWNAME"]).ToString().Trim() + "' ");
//SendEmail se = new SendEmail(receiver, MAILTONAME, "", "", "转发:" + mailtopic, mailbody, false);
// SendEmail se = new SendEmail("dev001@dongshengsoft.com", "admin@dongshengsoft.com", "", "", mailtopic, mailbody, false);
string filePath = "";
string fileExt = "";
if (bltype != "运输计划变更")
{
if (enumValue.FILEPATH != "")
{
filePath = Server.MapPath(enumValue.FILEPATH);
var filename = Path.GetFileName(filePath);
fileExt = Path.GetExtension(filename);
}
//se.Attachments(filePath);
}
try
{
var recipients = new List<string>();
var ccList = new List<string>();
string[] emailList = receiver.Split(';');
foreach (var m in emailList)
{
if (m.Trim() != "")
recipients.Add(m);
}
var opmail = "";
if (opmail == "") opmail = email1;
var mailBodyEntity = new MailBodyEntity()
{
Body = mailbody,
Cc = ccList,
//MailBodyType = "html",
MailFiles = new List<MailFile>() {
new MailFile { MailFilePath = filePath, MailFileSubType =fileExt, MailFileType = fileExt}
},
Recipients = recipients,
Sender = opmail,
SenderAddress = opmail,
Subject = mailtopic,
};
var sendServerConfiguration = new SendServerConfigurationEntity()
{
SenderPassword = MAILTOPASSWORD,
SmtpPort = Convert.ToInt32(MAILTOPORT),
IsSsl = MAILISSSL,
MailEncoding = "utf-8",
SenderAccount = MAILACCOUNT,
SmtpHost = MAILTOSERVER,
};
var Mailresult = MailHelper.SendMail(mailBodyEntity, sendServerConfiguration);
result.Success = Mailresult.ResultStatus;
result.Message = Mailresult.ResultInformation;
}
catch (Exception e)
{
//se.SetSmtp(MAILTONAME, MAILTOPASSWORD, MAILTOSERVER, Convert.ToInt32(MAILTOPORT), false, System.Net.Mail.MailPriority.Normal); //必须在所有参数设置完后调用此方法
}
}
if (result.Success) {
var head = new OpMailLog();
head.BSNO = enumValue.BSNO;
head.BLTYPE = enumValue.TASKTYPE;
head.RECEIVER = receiver;
head.SUBJECT = "转发:" + mailtopic;
head.DESCRIPTION = mailbody;
head.ATTACHMENT = enumValue.FILEPATH;
head.SENDER = Convert.ToString(Session["SHOWNAME"]).ToString().Trim();
head.SENDTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
head.DbOperationType = DbOperationType.DbotIns;
var modb = new ModelObjectDB();
modb.Save(head);
}
if (result.Success) {
var blUpSQL = " insert into op_task_state (GID,TASKNO,TASKSTATUS,OP,OPTIME) values (newid(),'" + enumValue.TASKNO+ "','已转发','" + Convert.ToString(Session["SHOWNAME"]).ToString().Trim() + "',GETDATE())";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
blUpSQL = " update op_task set ISCOMPLETE=1,TASKSTATUS='已转发',COMPLETETYPE='人工',COMPLETETIME=GETDATE(),OP='"+ Convert.ToString(Session["SHOWNAME"]).ToString().Trim() + "' where GID='" + enumValue.GID+"'";
bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
if (enumValue.ISCOMPLETE!="1"&&(enumValue.TASKTYPE=="BA"|| enumValue.TASKTYPE=="BC")) {
blUpSQL = "INSERT INTO [Receipt_Doc](GID,BSNO,URL,Driect_URL,MODIFIEDUSER,MODIFIEDTIME,RECEIPTTYPE,DOCUMENTATTACHEDCODE,DOCUMENTATTACHEDNO)"
+ "VALUES(newid(),'"+enumValue.BSNO+"','"+enumValue.TASKTYPE+"','"+enumValue.FILEPATH+"','"+ Convert.ToString(Session["USERID"]).ToString().Trim() + "',GETDATE(),'入货通知','','');";
bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
}
// }
}
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}