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.

886 lines
31 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity.Migrations;
using System.Data.Entity.Validation;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Security.Permissions;
using System.ServiceModel.Configuration;
using System.Text;
using System.Web;
using System.Windows.Forms;
using DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.MvcShipping.Models.Message.VGM;
using DSWeb.Common.DB;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.MvcShipping.Controllers;
using DSWeb.MvcShipping.Helper;
using HcUtility.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Newtonsoft.Json.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace DSWeb.Areas.CommMng.PublicInterfaceDAL
{
public class InterfaceResult
{
public string errCode { get; set; }
public string errMsg { get; set; }
public InterfaceResult() { }
public InterfaceResult(DBResult dbresult)
{
if (dbresult.Success)
{
errCode = "0";
}
else
{
errCode = "1";
}
errMsg = dbresult.Message + ";Data:" + JsonConvert.Serialize(dbresult.Data);
}
}
public class InterfaceParam
{
public Interface_Header header { get; set; }
public object body { get; set; }
public t_PublicInterface_Log_md getsaverec()
{
var result = new t_PublicInterface_Log_md();
try
{
result.GID = Guid.NewGuid().ToString();
result.Param = body.ToString();
result.PORTNAME = header.serviceCode;
result.CreateTime = DateTime.Now;
}
catch (Exception e) {
}
return result;
}
public void Save()
{
var saverec = getsaverec();
if (!string.IsNullOrWhiteSpace(saverec.Param) && !string.IsNullOrWhiteSpace(saverec.PORTNAME))
{
var cdc = new DS6DataContext();
cdc.t_PublicInterface_Log.Add(saverec);
cdc.SaveChanges();
}
}
}
public class Interface_Header
{
public string serviceCode { get; set; }
}
public static class InterfaceLog {
public static void Save(string PORTNAME,object c) {
var saverec = getsaverec(PORTNAME,c);
if (!string.IsNullOrWhiteSpace(saverec.Param) && !string.IsNullOrWhiteSpace(saverec.PORTNAME))
{
var cdc = new DS6DataContext();
cdc.t_PublicInterface_Log.Add(saverec);
cdc.SaveChanges();
}
}
private static t_PublicInterface_Log_md getsaverec(string PORTNAME, object c)
{
var result = new t_PublicInterface_Log_md();
try
{
result.GID = Guid.NewGuid().ToString();
result.PORTNAME= PORTNAME;
result.Param = JsonConvert.Serialize(c);
result.CreateTime = DateTime.Now;
}
catch (Exception e)
{
}
return result;
}
}
public class InterfaceBase
{
public InterfaceBase() { }
public virtual InterfaceResult DoSet(JObject paramObject)
{
return new InterfaceResult();
}
//public static void SaveParam(InterfaceParam param) {
// param.Save();
//}
}
public class KF_CUST_UPDATE : InterfaceBase
{
public override InterfaceResult DoSet(JObject paramObject)
{
var ds6 = new DS6DataContext();
var result = new DBResult();
var errorstr = "";
try {
#region 从日志中补数据
//从日志中循环读取然后处理
//var LogParamList = ds6.t_PublicInterface_Log.Where(x => x.ID >= 1230).ToList();
//foreach (var LogParam in LogParamList)
//{
// var jsonstr = LogParam.Param;
#endregion
var jsonstr = paramObject.ToString();
errorstr = jsonstr;
csCustHead custhead = JsonConvert.Deserialize<csCustHead>(jsonstr);
var custlist = custhead.csCust;
//解析param.Param
foreach (var cust in custlist)
{
var ds6cust = cust.GetCrmClient();
var currInfoclient = ds6.t_crm_client.Where(x => x. == cust.MDGCustCode).ToList();
//if (currInfoclient == null || currInfoclient.Count == 0)
// currInfoclient=ds6.t_crm_client.Where(x => x.国税登记 == cust.taxpayerIdentificatioNo).ToList();
var io = "";
if (currInfoclient == null || currInfoclient.Count == 0)
{
ds6.t_crm_client.Add(ds6cust);
io = "新增";
}
else
{
//foreach (var oldclient in currInfoclient)
//{
// ds6cust = cust.GetCrmClient(oldclient);
// ds6.t_crm_client.AddOrUpdate(ds6cust);
//}
io = "更新";
}
#region
//var newerror = new t_sys_soft_error_md();
//newerror.针对版本 = 1;
//newerror.升级日期 = DateTime.Now;
//newerror.升级人 = io;
//newerror.执行文件 = $"[{cust.bizCsCustId},{cust.MDGCustCode},{cust.custAlias}]"+ errorstr;
//var ds62 = new DS6DataContext();
//ds62.t_sys_soft_error.Add(newerror);
//ds62.SaveChanges();
#endregion
ds6.CustInfo.AddOrUpdate(cust);
if (cust.csCustOfficeInfo != null && cust.csCustOfficeInfo.Count > 0)
{
var old_csCustOfficeInfo = ds6.CustOfficeInfo.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustOfficeInfo != null && old_csCustOfficeInfo.Count > 0)
{
var newid = cust.csCustOfficeInfo.Select(s => s.bizCsCustOfficeInfoId).ToList();
var delrec = old_csCustOfficeInfo.Where(x => !newid.Contains(x.bizCsCustOfficeInfoId)).ToList();
if (delrec != null && delrec.Count > 0)
ds6.CustOfficeInfo.RemoveRange(delrec);
}
foreach (var item in cust.csCustOfficeInfo)
{
item.SetAllLength();
ds6.CustOfficeInfo.AddOrUpdate(item);
}
}
else
{
var old_csCustOfficeInfo = ds6.CustOfficeInfo.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustOfficeInfo != null && old_csCustOfficeInfo.Count > 0)
{
ds6.CustOfficeInfo.RemoveRange(old_csCustOfficeInfo);
}
}
if (cust.csCustTypes != null && cust.csCustTypes.Count > 0)
{
var old_csCustType = ds6.CustType.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustType != null && old_csCustType.Count > 0)
{
var newid = cust.csCustTypes.Select(s => s.bizCsCustTypeId).ToList();
var delrec = old_csCustType.Where(x => !newid.Contains(x.bizCsCustTypeId)).ToList();
if (delrec != null && delrec.Count > 0)
ds6.CustType.RemoveRange(delrec);
}
foreach (var item in cust.csCustTypes)
{
item.SetAllLength();
ds6.CustType.AddOrUpdate(item);
}
}
else
{
var old_csCustType = ds6.CustType.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustType != null && old_csCustType.Count > 0)
{
ds6.CustType.RemoveRange(old_csCustType);
}
}
if (cust.csCustContacts != null && cust.csCustContacts.Count > 0)
{
var old_csCustContacts = ds6.CustContact.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustContacts != null && old_csCustContacts.Count > 0)
{
var newid = cust.csCustContacts.Select(s => s.bizCsCustContactId).ToList();
var delrec = old_csCustContacts.Where(x => !newid.Contains(x.bizCsCustContactId)).ToList();
if (delrec != null && delrec.Count > 0)
ds6.CustContact.RemoveRange(delrec);
}
foreach (var item in cust.csCustContacts)
{
item.SetAllLength();
ds6.CustContact.AddOrUpdate(item);
}
}
else
{
var old_csCustContacts = ds6.CustContact.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustContacts != null && old_csCustContacts.Count > 0)
{
ds6.CustContact.RemoveRange(old_csCustContacts);
}
}
if (cust.csCustSaless != null && cust.csCustSaless.Count > 0)
{
var old_csCustSales = ds6.CustSales.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustSales != null && old_csCustSales.Count > 0)
{
var newid = cust.csCustSaless.Select(s => s.bizCsCustSalesId).ToList();
var delrec = old_csCustSales.Where(x => !newid.Contains(x.bizCsCustSalesId)).ToList();
if (delrec != null && delrec.Count > 0)
ds6.CustSales.RemoveRange(delrec);
}
foreach (var item in cust.csCustSaless)
{
item.SetAllLength();
ds6.CustSales.AddOrUpdate(item);
}
}
else
{
var old_csCustSales = ds6.CustSales.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustSales != null && old_csCustSales.Count > 0)
{
ds6.CustSales.RemoveRange(old_csCustSales);
}
}
if (cust.csCustAccounts != null && cust.csCustAccounts.Count > 0)
{
var old_csCustAccounts = ds6.CustAccount.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustAccounts != null && old_csCustAccounts.Count > 0)
{
var newid = cust.csCustAccounts.Select(s => s.bizCsCustAccountId).ToList();
var delrec = old_csCustAccounts.Where(x => !newid.Contains(x.bizCsCustAccountId)).ToList();
if (delrec != null && delrec.Count > 0)
ds6.CustAccount.RemoveRange(delrec);
}
foreach (var item in cust.csCustAccounts)
{
item.SetAllLength();
ds6.CustAccount.AddOrUpdate(item);
}
}
else
{
var old_csCustAccounts = ds6.CustAccount.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustAccounts != null && old_csCustAccounts.Count > 0)
{
ds6.CustAccount.RemoveRange(old_csCustAccounts);
}
}
if (cust.csCustInvoices != null && cust.csCustInvoices.Count > 0)
{
var old_csCustInvoice = ds6.CustInvoice.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustInvoice != null && old_csCustInvoice.Count > 0)
{
var newid = cust.csCustInvoices.Select(s => s.bizCsCustInvoiceId).ToList();
var delrec = old_csCustInvoice.Where(x => !newid.Contains(x.bizCsCustInvoiceId)).ToList();
if (delrec != null && delrec.Count > 0)
ds6.CustInvoice.RemoveRange(delrec);
}
foreach (var item in cust.csCustInvoices)
{
item.SetAllLength();
ds6.CustInvoice.AddOrUpdate(item);
}
}
else
{
var old_csCustInvoice = ds6.CustInvoice.Where(x => x.bizCsCustId == cust.bizCsCustId).ToList();
if (old_csCustInvoice != null && old_csCustInvoice.Count > 0)
{
ds6.CustInvoice.RemoveRange(old_csCustInvoice);
}
}
}
if (custlist.Count > 0)
{
ds6.SaveChanges();
}
result.Success = true;
result.Message = "保存成功";
//}
}
catch(Exception ex)
{
var newerror = new t_sys_soft_error_md();
newerror. = 0;
newerror. = DateTime.Now;
newerror. = "管理员";
newerror.=$"[{ex.Message}]"+errorstr;
var ds62= new DS6DataContext();
ds62.t_sys_soft_error.Add(newerror);
ds62.SaveChanges();
result.Success= false;
result.Message=ex.Message;
}
//向数据库保存
return new InterfaceResult(result);
}
}
#region 大简云 数据比对校验
/// <summary>
/// 用于比对大简云和ds6数据之间谁有谁没有的问题
/// </summary>
public class DJYBILLCHECK
{
public DJYCHECK_REPLY DoSet(DJYCHECK_DATA_SEND param)
{
var errorstr = "";
var result = new DBResult();
errorstr = JsonConvert.Serialize(param);
try
{
var resultData = new DJYCHECK_DATA_REPLY();
resultData.Normal = new List<DJYCHECK_BILL_REPLY>();
resultData.Deleted = new List<DJYCHECK_BILL_REPLY>();
var djyidList_have = new List<DJYCHECK_BILL_SEND>();
var djyidList_have_child = new List<long>();
var djyidList_deleted = new List<DJYCHECK_BILL_SEND>();
//大简云已有
if (param.Normal != null && param.Normal.Count > 0)
{
foreach (var head in param.Normal)
{
djyidList_have.Add(head);
if (head.Sub != null && head.Sub.Count > 1)
{
foreach (var child in head.Sub)
{
djyidList_have_child.Add(child.Id);
}
}
}
}
if (param.Deleted != null && param.Deleted.Count > 0)
{
foreach (var head in param.Deleted)
{
djyidList_deleted.Add(head);
}
}
var cdc = new DS6DataContext();
if (djyidList_have.Count > 0)
{
var djyidList_have_id= djyidList_have.Select(s=>s.Id).ToList();
var currList = cdc.t_op_seae.Where(x => djyidList_have_id.Contains((long)x.DJYID)).ToList();
if (currList.Count == djyidList_have.Count)
{
//对应正确
}
else
{
foreach (var item in djyidList_have)
{
if (!currList.Exists(x => x.DJYID == item.Id && x.==item.MBLNO))
{
var senditem = param.Normal.First(x => x.Id == item.Id);
var rec = new DJYCHECK_BILL_REPLY(item.Id, "Normal", item.MBLNO);
resultData.Normal.Add(rec);
}
}
}
}
//分单
if (djyidList_have_child.Count > 0)
{
var currList = cdc.t_op_seae_assistant.Where(x => djyidList_have_child.Contains((long)x.DJYCHILDRENID)).ToList();
if (currList.Count == djyidList_have_child.Count)
{
//对应正确
}
else
{
foreach (var item in djyidList_have_child)
{
if (!currList.Exists(x => x.DJYCHILDRENID == item))
{
//看看返回数据里有没有主单信息 如果没有
var zd = param.Normal.FirstOrDefault(x => x.Sub.Exists(y => y.Id == item));
var hblno = zd.Sub.FirstOrDefault(x => x.Id == item).MBLNO;
var mblno = zd.MBLNO;
var rec = new DJYCHECK_BILL_REPLY(item, "Normal", mblno);
rec.Result = $"分单号[{hblno}]"+ rec.Result;
resultData.Normal.Add(rec);
}
}
}
}
if (djyidList_deleted.Count > 0)
{
var djyidList_deleted_id = djyidList_have.Select(s => s.Id).ToList();
var currList = cdc.t_op_seae.Where(x => djyidList_deleted_id.Contains((long)x.DJYID)).ToList();
if (currList.Count == 0)
{
//对应正确
}
else
{
foreach (var item in djyidList_deleted)
{
if (currList.Exists(x => x.DJYID == item.Id))
{
var currrec = currList.First(x => x.DJYID == item.Id);
var rec = new DJYCHECK_BILL_REPLY(item.Id, "Deleted", currrec.);
resultData.Deleted.Add(rec);
}
}
}
}
result.Success = true;
result.Message = "";
result.Data = resultData;
return new DJYCHECK_REPLY(result);
}
catch (Exception ex) {
var newerror = new t_sys_soft_error_md();
newerror. = 0;
newerror. = DateTime.Now;
newerror. = "管理员";
newerror. = $"[{ex.Message}]" + errorstr;
var ds62 = new DS6DataContext();
ds62.t_sys_soft_error.Add(newerror);
ds62.SaveChanges();
result.Success = false;
result.Message = ex.Message;
return new DJYCHECK_REPLY(result);
}
}
}
public class DJYINFOBASE {
// {
// {
// "Normal": [
// {
// "Id": 0,
// "MBLNO": "",
// "Sub": [
// {
// "Id": 0,
// "MBLNO": ""
// }
// ]
// }
// ],
// "Deleted": [
// {
// "Id": 0,
// "MBLNO": ""
// }
// ]
//}
// {
// {
// "Code": 200,
// "Message": "",
// "Data": {
// "Normal": [
// {
// "Id": 123123,
// "Result": "没有此票业务"
// }
// ],
// "Deleted": [
// {
// "Id": 234234,
// "Result": "此业务未删除"
// }
// ]
// }
//}
public int? Code { get; set; }
public string Message { get; set; }
}
public class DJYCHECK_BILL_SEND {
public long Id { get; set; }
public string MBLNO { get; set; }
public List<DJYCHECK_BILL_SEND> Sub { get; set; }
}
public class DJYCHECK_DATA_SEND
{
public List<DJYCHECK_BILL_SEND> Normal { get; set; }
public List<DJYCHECK_BILL_SEND> Deleted { get; set; }
}
public class DJYCHECK_BILL_REPLY
{
public long Id { get; set; }
public int Code { get; set; } = 200;
public string MBLNO { get; set; }
public string Result { get; set; }
public DJYCHECK_BILL_REPLY() { }
public DJYCHECK_BILL_REPLY(long id,string replytype,string MBLNO)
{
Id = id;
this.MBLNO = MBLNO;
if (replytype == "Normal") Result = "没有此票业务";
if (replytype == "Deleted") Result = "此业务未删除";
}
}
public class DJYCHECK_DATA_REPLY
{
public List<DJYCHECK_BILL_REPLY> Normal { get; set; }
public List<DJYCHECK_BILL_REPLY> Deleted { get; set; }
}
public class DJYCHECK_REPLY : DJYINFOBASE
{
public DJYCHECK_DATA_REPLY Data { get; set; }
public DJYCHECK_REPLY() { }
public DJYCHECK_REPLY(DBResult result)
{
if (result.Success)
{
Code = 200;
}
else { Code = 1; }
Message = result.Message;
Data = (DJYCHECK_DATA_REPLY)(result.Data);
}
}
#endregion
#region 大简云 删除业务
public class DJYBILLDELETE_SEND:t_PublicInterface_Log_md
{
public List<DJYCHECK_BILL_SEND> Delete { get; set; }
public void Save()
{
var saverec = getsaverec();
if (!string.IsNullOrWhiteSpace(saverec.Param) && !string.IsNullOrWhiteSpace(saverec.PORTNAME))
{
var cdc = new DS6DataContext();
cdc.t_PublicInterface_Log.Add(saverec);
cdc.SaveChanges();
}
}
public t_PublicInterface_Log_md getsaverec()
{
var result = new t_PublicInterface_Log_md();
try
{
result.GID = Guid.NewGuid().ToString();
result.Param = JsonConvert.Serialize(Delete);
result.CreateTime = DateTime.Now;
}
catch (Exception e)
{
}
return result;
}
}
public class DJYBILLDELETE_REPLYDATA
{
public List<DJYCHECK_BILL_REPLY> Deleted { get; set; }
public List<DJYCHECK_BILL_REPLY> NoDeleted { get; set; }
public DJYBILLDELETE_REPLYDATA() {
Deleted = new List<DJYCHECK_BILL_REPLY>();
NoDeleted = new List<DJYCHECK_BILL_REPLY>();
}
}
public class DJYBILLDELETE_REPLY: DJYINFOBASE
{
public DJYBILLDELETE_REPLYDATA Data { get; set; }
//public DJYBILLDELETE_REPLY() { }
public DJYBILLDELETE_REPLY() {
Code = 200;
Message = null;
Data = new DJYBILLDELETE_REPLYDATA();
}
public void Deleted(long Id,string MBLNO) {
var newrec = new DJYCHECK_BILL_REPLY() { Id= Id,MBLNO= MBLNO };
Data.Deleted.Add(newrec);
}
public void NoDeleted(long Id, string MBLNO,string Result,int code=200)
{
var newrec = new DJYCHECK_BILL_REPLY() { Id = Id, MBLNO = MBLNO,Result=Result,Code= code };
Data.NoDeleted.Add(newrec);
}
}
/// <summary>
/// 用于删除大简云业务
/// </summary>
public class DJYBILLDELETE
{
public DJYBILLDELETE_REPLY DoSet(DJYBILLDELETE_SEND param)
{
var errorstr = "";
var result = new DJYBILLDELETE_REPLY();
errorstr = JsonConvert.Serialize(param);
var curritem = new DJYCHECK_BILL_SEND();
try
{
//大简云已有
if (param.Delete != null && param.Delete.Count > 0)
{
var DS6Data = new DS6DataContext();
foreach (var item in param.Delete)
{
curritem = item;
var id=item.Id;
//logger.Debug($"删除订舱信息DJYID:{id}");
long idlong = Convert.ToInt64(id);
var currentBillList = DS6Data.t_op_seae.Where(x => x.DJYID == idlong).ToList();
if (currentBillList != null && currentBillList.Count > 0)
{
var delrec = currentBillList[0];
var headid = delrec.;
if (!CanDelete(delrec))
{
result.NoDeleted(item.Id, item.MBLNO, "该业务存在费用,无法删除");
continue;
}
else {
var _r = DoDelete(headid);
if (_r)
{
result.Deleted(item.Id, item.MBLNO);
}
else {
result.NoDeleted(item.Id, item.MBLNO, "查看东胜日志表t_PublicInterface_Log", 500);
}
}
}
else {
result.NoDeleted(item.Id, item.MBLNO, "东胜系统不存在该业务",201);
}
}
}
InterfaceLog.Save("DJYDELETE", result);
return result;
}
catch (Exception ex)
{
//var newerror = new t_sys_soft_error_md();
//newerror.针对版本 = 0;
//newerror.升级日期 = DateTime.Now;
//newerror.升级人 = "管理员";
//newerror.执行文件 = $"[{ex.Message}]" + errorstr;
//var ds62 = new DS6DataContext();
//ds62.t_sys_soft_error.Add(newerror);
//ds62.SaveChanges();
InterfaceLog.Save("DJYDELETE_Error", ex);
result.Code = 0;
result.Message = ex.Message;
result.NoDeleted(curritem.Id, curritem.MBLNO, ex.Message);
return result;
}
}
public bool DoDelete(string ) {
try
{
var DS6Data = new DS6DataContext();
var delrec = DS6Data.t_op_seae.FirstOrDefault(x => x. == );
//20231030 增加删除控制
delrec.1Y = "1";
DS6Data.t_op_seae.AddOrUpdate(delrec);
DS6Data.SaveChanges();
var ctnlist = DS6Data.t_op_ctn.Where(x => x. == ).ToList();
if (ctnlist != null && ctnlist.Count > 0)
{
//logger.Debug($"删除订舱信息ctnlist:{JsonConvert.SerializeObject(ctnlist)}");
DS6Data.t_op_ctn.RemoveRange(ctnlist);
}
var amslist = DS6Data.t_op_ams.Where(x => x. == ).ToList();
if (amslist != null && amslist.Count > 0)
{
//logger.Debug($"删除订舱信息amslist:{JsonConvert.SerializeObject(amslist)}");
DS6Data.t_op_ams.RemoveRange(amslist);
}
var old_assistantList = DS6Data.t_op_seae_assistant.Where(x => x. == ).ToList();
if (old_assistantList != null && old_assistantList.Count > 0)
{
//logger.Debug($"删除订舱信息old_assistantList:{JsonConvert.SerializeObject(old_assistantList)}");
DS6Data.t_op_seae_assistant.RemoveRange(old_assistantList);
}
InterfaceLog.Save("DJYDELETE_DoDelete", delrec);
DS6Data.t_op_seae.Remove(delrec);
//logger.Debug($"删除订舱信息DJYID:{id}");
DS6Data.SaveChanges();
//logger.Debug($"删除订舱信息DJYID:OK");
return true;
}catch(Exception ex)
{
InterfaceLog.Save("DJYDELETE_DoDeleteError", ex);
return false;
}
}
public bool CanDelete(t_op_seae_md opseae)
{
var ds6 = new DS6DataContext();
var chfeeList = ds6.t_ch_fee.Where(x => x. == opseae.).ToList();
if (chfeeList == null || chfeeList.Count == 0)
{
return true;
}
else
{
return false;
}
}
}
#endregion
}