using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsOpVgmSend; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using DSWeb.Areas.CommMng.DAL; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.MvcShipping.Helper; using DSWeb.Areas.MvcShipping.Comm; using System.Collections.Specialized; using DSWeb.Common.DB; using System.Linq; using DSWeb.Areas.MvcShipping.Models.Message.VGM; using HcUtility.Core; using System.Data.Entity.Migrations; using DSWeb.MvcShipping.Models.MsOpSeae; using NPOI.SS.Formula.Functions; using Quartz.Util; using DSWeb.MvcShipping.DAL.MsSysThirdPartyAccount; namespace DSWeb.MvcShipping.DAL.MsOpVgmSendDAL { public class MsOpVgmSendDAL { #region Inquery DataList static public List GetDataList(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } // String strSql = "SELECT *,(select top 1 showname from [user] where GID=op_seae_vgm_send.SENDERUSER) as SENDERUSERREF FROM op_seae_vgm_send "; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by ETD desc"; } return SetData(strSql); } static public string GetDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } // String strSql = "SELECT *,(select top 1 showname from [user] where GID=op_seae_vgm_send.SENDERUSER) as SENDERUSERREF FROM op_seae_vgm_send "; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by ETD desc"; } return strSql.ToString(); } static public MsOpVgmSend GetData(string condition) { String strSql = "SELECT *,(select top 1 showname from [user] where GID=op_seae_vgm_send.SENDERUSER) as SENDERUSERREF FROM op_seae_vgm_send "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } var list = SetData(strSql); if (list.Count > 0) { return list[0]; } return new MsOpVgmSend(); } private static List SetData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpVgmSend data = new MsOpVgmSend(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.VGMSTATUS = Convert.ToString(reader["VGMSTATUS"]); data.MFNO = Convert.ToString(reader["MFNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.CARRIER = Convert.ToString(reader["CARRIER"]); data.LOADPORT = Convert.ToString(reader["LOADPORT"]); data.MATOU = Convert.ToString(reader["MATOU"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.CARRIERSTATUS = Convert.ToString(reader["CARRIERSTATUS"]); data.YGTSTATUS = Convert.ToString(reader["YGTSTATUS"]); data.YARDSTATUS = Convert.ToString(reader["YARDSTATUS"]); data.VGM_TIME = Convert.ToString(reader["VGM_TIME"]); data.SENDERUSER = Convert.ToString(reader["SENDERUSER"]); data.SENDERUSERREF = Convert.ToString(reader["SENDERUSERREF"]); if (reader["CTNNUM"] != DBNull.Value) data.CTNNUM = Convert.ToInt16(reader["CTNNUM"]); if (reader["ISCARRIER"] != DBNull.Value) data.ISCARRIER = Convert.ToBoolean(reader["ISCARRIER"]); if (reader["ISYGT"] != DBNull.Value) data.ISYGT = Convert.ToBoolean(reader["ISYGT"]); if (reader["SENDTIME"] != DBNull.Value) data.SENDTIME = Convert.ToDateTime(reader["SENDTIME"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.LINKURL = Convert.ToString(reader["LINKURL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 明细表 static public List GetVgmCtnList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("*"); strSql.Append(" from op_seae_vgm_ctn "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" WHERE " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CTNALL "); } return SetVgmCtnData(strSql); } private static List SetVgmCtnData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpVgmCtn data = new MsOpVgmCtn(); #region Set DB data to Object data.CTN_ID = Convert.ToString(reader["CTN_ID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.SENDGID = Convert.ToString(reader["SENDGID"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.SEALNO = Convert.ToString(reader["SEALNO"]); data.WEIGHTYPE = Convert.ToString(reader["WEIGHTYPE"]); data.YARD = Convert.ToString(reader["YARD"]); data.WEIGHDATE = Convert.ToString(reader["WEIGHDATE"]); if (reader["KGS"] != DBNull.Value) data.KGS = Convert.ToDecimal(reader["KGS"]);// if (reader["TAREWEIGHT"] != DBNull.Value) data.TAREWEIGHT = Convert.ToDecimal(reader["TAREWEIGHT"]);// if (reader["VGMKGS"] != DBNull.Value) data.VGMKGS = Convert.ToDecimal(reader["VGMKGS"]);// data.carrierSendFlag = Convert.ToInt32(reader["carrierSendFlag"]); data.ygtSendFlag = Convert.ToInt32(reader["ygtSendFlag"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveDetail(string LE_ID, List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmddelete = db.GetSqlStringCommand(@"delete from op_seae_vgm_ctn where SENDGID='" + LE_ID + "'"); db.ExecuteNonQuery(cmddelete, tran); var cntr = ""; if (bodyList != null) { foreach (var enumValue in bodyList) { var cmdInsert = db.GetSqlStringCommand(@"insert into op_seae_vgm_ctn ([CTN_ID],[BSNO],[SENDGID],[CTNALL],[CNTRNO],[SEALNO],[KGS],[TAREWEIGHT],[WEIGHTYPE],[VGMKGS],[YARD],[WEIGHDATE],[carrierSendFlag],[ygtSendFlag]) values (NEWID(),'" + enumValue.BSNO + "','" + LE_ID + "','" + enumValue.CTNALL + "','" + enumValue.CNTRNO + "','" + enumValue.SEALNO + "'," + enumValue.KGS + "," + enumValue.TAREWEIGHT + ",'" + enumValue.WEIGHTYPE + "'," + enumValue.VGMKGS + ",'" + enumValue.YARD + "','" + enumValue.WEIGHDATE + "',"+enumValue.carrierSendFlag.ToString()+ ","+enumValue.ygtSendFlag.ToString()+")"); db.ExecuteNonQuery(cmdInsert, tran); } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = $"保存出现错误:{JsonConvert.Serialize(e)},请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } public static DsVgm CreateDjyVgm(MsOpVgmSend headData, List bodyList, MsOpSeae OpSeaehead) { var cdc = new CommonDataContext(); var DsVgm = new DsVgm(); DsVgm.mfno = headData.MFNO; DsVgm.mblno = headData.MBLNO; DsVgm.carrier = BasicDataRefDAL.GetCustEdiCodeByName2(headData.CARRIER, "DJY"); //DsVgm.carrier = headData.CARRIER; DsVgm.etd = OpSeaehead.ETD; DsVgm.weiTuoFaSongFang = "QDDS";//BasicDataRefDAL.GetCustEdiCodeByName2(OpSeaehead.CUSTOMERNAME, "DJY"); DsVgm.chuanMing = headData.VESSEL; DsVgm.vsid = OpSeaehead.VESSELID; DsVgm.hangCi = headData.VOYNO; DsVgm.beiZhu = headData.REMARK; //var 装货港 = OpSeaehead.PORTLOAD; var 装货港代码 = headData.LOADPORT; //BasicDataRefDAL.GetPORTInfoByEDICODEAndEDIName("DJY", headData.LOADPORT, OpSeaehead.PORTLOAD, ref 装货港代码, ref 装货港); var 口岸 = cdc.tSysEnumValue.Where(x => x.EnumTypeID == 96303 && x.EnumValueID == 装货港代码).FirstOrDefault(); if (口岸 != null) { DsVgm.zhuangHuoGang = 口岸.EnumValueName; DsVgm.zhuangHuoGangDaiMa = 口岸.EnumValueID; } else { DsVgm.zhuangHuoGang = "QINGDAO,CHINA"; DsVgm.zhuangHuoGangDaiMa = "CNTAO"; } //DsVgm.yard = BasicDataRefDAL.GetCustEdiCodeByName2(ctn.YARD, "DJY");//BasicDataRefDAL.GetCustEdiCodeByName2(OpSeaehead.YARD, "DJY"); DsVgm.orderno = headData.ORDERNO; DsVgm.vgmclosetime = headData.VGM_TIME; DsVgm.vgmclosetime = string.IsNullOrWhiteSpace(DsVgm.vgmclosetime) ? null : DsVgm.vgmclosetime; DsVgm.wharf = headData.MATOU; DsVgm.sendType = Convert.ToInt32(headData.SENDTYPE); DsVgm.sendCarr = headData.ISCARRIER; DsVgm.sendYGT = headData.ISYGT; var cntrlist = new List(); foreach (var ctn in bodyList) { var cntr = new Ctn(); cntr.ctn_id = ctn.CTN_ID; cntr.ctnall = ctn.CTNALL; cntr.cntrno = ctn.CNTRNO; cntr.sealno = ctn.SEALNO; cntr.chengZhongFangShi = ctn.WEIGHTYPE; cntr.kgs = ctn.KGS; cntr.pizhong = ctn.TAREWEIGHT; cntr.chengZhongZhongLiang = ctn.KGS + ctn.TAREWEIGHT; //cntr.yard = ctn.YARD; cntr.yard = BasicDataRefDAL.GetCustEdiCodeByName2(ctn.YARD, "DJY"); if (!string.IsNullOrWhiteSpace(ctn.WEIGHDATE)) cntr.chengZhongShiJian = ctn.WEIGHDATE.Replace("T", " "); else cntr.chengZhongShiJian = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //20240906 判断发船公司/云港通 和箱明细是否已发船公司云港通之间的关系 cntr.sendFlag = true; cntrlist.Add(cntr); DsVgm.yard = BasicDataRefDAL.GetCustEdiCodeByName2(ctn.YARD, "DJY"); } DsVgm.ctnList = cntrlist; return DsVgm; } static public List GetVgmHistoryList(string BSNO) { var result = new List(); var cdc = new CommonDataContext(); result = cdc.op_seae_vgm_history .Where(x => x.BSNO == BSNO) .OrderByDescending(o=>o.SENDTIME).ToList(); if (result != null && result.Count > 0) { var useridlist= result.Select(x => x.SENDERUSER).Distinct().ToList(); var userlist = cdc.VW_user.Where(x => useridlist.Contains(x.USERID)).ToList(); foreach (var item in result) { item.SENDERNAME = userlist.FirstOrDefault(x => x.USERID == item.SENDERUSER).SHOWNAME; } } return result; } #endregion static public List GetStatusList(string BSNO,string type) { var result = new List(); var cdc = new CommonDataContext(); result = cdc.op_seae_vgm_state .Where(x => x.mfno==BSNO&& x.Type==type) .OrderByDescending(o => o.statustime).ToList(); return result; } #region 发送vgm至大简云 public static DBResult CanSend(ref MsOpVgmSend headData,ref List bodyList,string SendType) { var result = new DBResult(); result.OK(); if (headData.ISCARRIER == false && headData.ISYGT == false) { result.SetErrorInfo("不能 船公司和云港通 都不选择"); } var _iscarrier = headData.ISCARRIER; var _isygt = headData.ISYGT; if (string.IsNullOrWhiteSpace(headData.MBLNO)) { result.SetErrorInfo("提单号不能为空"); } if (headData.SENDTYPE == "0") { return result; } if (string.IsNullOrWhiteSpace(headData.CARRIER)) { result.SetErrorInfo($"船公司{headData.CARRIER}不能为空"); } var 船公司= BasicDataRefDAL.GetCustEdiCodeByName2(headData.CARRIER, "DJY"); if (string.IsNullOrWhiteSpace(船公司)) { result.SetErrorInfo($"船公司{headData.CARRIER}未配置大简云代码"); } //var 场站 = BasicDataRefDAL.GetCustEdiCodeByName2(headData.CARRIER, "DJY"); //if (string.IsNullOrWhiteSpace(船公司)) //{ // result.SetErrorInfo("船公司未配置大简云代码"); //} foreach (var ctn in bodyList) { if (string.IsNullOrWhiteSpace(ctn.YARD)) { result.SetErrorInfo($"场站{ctn.YARD}不能为空"); } var _yard= BasicDataRefDAL.GetCustEdiCodeByName2(ctn.YARD, "DJY"); if (string.IsNullOrWhiteSpace(_yard)) { result.SetErrorInfo($"场站{ctn.YARD}未配置大简云代码"); } } //如果所有这些箱 船公司状态都为已发 而且此次选择了 发送船公司+sendtype=新增 则取消头表的发送船公司 if (headData.SENDTYPE == "9") { if (headData.ISCARRIER == true) { if (bodyList.Exists(x => x.carrierSendFlag != 1)) { if (bodyList.Exists(x => x.carrierSendFlag == 1)) { //var ctn = bodyList.FirstOrDefault(x => x.carrierSendFlag == 1); //result.SetErrorInfo($"箱号{ctn.CNTRNO}已发船公司,不能再次发送新增"); } } else { if (!bodyList.Exists(x => x.carrierSendFlag != 1)) { headData.ISCARRIER = false; } } } if (headData.ISYGT == true) { if (bodyList.Exists(x => x.ygtSendFlag != 1)) { if (bodyList.Exists(x => x.ygtSendFlag == 1)) { var ctn = bodyList.FirstOrDefault(x => x.ygtSendFlag == 1); result.SetErrorInfo($"箱号{ctn.CNTRNO}已发云港通,不能再次发送新增"); } } else { if (!bodyList.Exists(x => x.ygtSendFlag != 1)) { headData.ISYGT = false; } } } if (headData.ISCARRIER == false && headData.ISYGT == false) { var msg = ""; if (_iscarrier) msg = "船公司"; if (_isygt) msg = "云港通"; result.SetErrorInfo($"你选择的集装箱军已发({msg})"); } } if ( headData.ISCARRIER && ( 船公司 == "HLC" || 船公司 == "WHL")) { if (headData.ORDERNO == null || headData.ORDERNO == "") { result.SetErrorInfo("HLC/WHL船公司的订舱编号不能为空"); } } if (headData.ISCARRIER ) { var cdc = new CommonDataContext(); var 可用船公司 = cdc.tSysEnumValue.Where(x => x.EnumTypeID == 96306).ToList(); if (!可用船公司.Any(x => x.EnumValueID == 船公司)) { result.SetErrorInfo($"船公司{船公司}暂时没有船公司VGM通道"); } } //if (headData.ISYGT) //{ // if (string.IsNullOrWhiteSpace(headData.MATOU)) // { // result.SetErrorInfo($"发送云港通时码头不能为空"); // } //} if (bodyList == null || bodyList.Count == 0) { result.SetErrorInfo("集装箱信息不能为空"); } var firstctn=new MsOpVgmCtn(); foreach (var ctnitems in bodyList) { //MsOpSeaVgmCtn OpSeaVgmCtn = new MsOpSeaVgmCtn(); if (ctnitems.CNTRNO == "") result.SetErrorInfo("箱号不能为空"); if (ctnitems.CTNALL == "") result.SetErrorInfo("箱型不能为空"); if (ctnitems.SEALNO == "") result.SetErrorInfo("封号不能为空"); if ((ctnitems.KGS+ctnitems.TAREWEIGHT) <= 0 ) result.SetErrorInfo("称重重量不能为空或小于零"); if (string.IsNullOrWhiteSpace( ctnitems.WEIGHDATE)) { //result.SetErrorInfo("称重时间不能为空"); } } if (result.Success) { //根据head的iscarrier和isygt 以及 } return result; } public static DBResult SendDjyVgm(MsOpVgmSend headData, List bodyList,string userid,string companyid, string SendType = "") { var result = new DBResult(); result.OK(); var _cansend = CanSend(ref headData,ref bodyList, SendType ); if (!_cansend.Success) { return _cansend; } var DsVgmUrl = MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024URL'").PARAMVALUE; var headers = new NameValueCollection(); var userkey = ""; var usersecret = ""; var userkeyinfo = MsSysThirdPartyAccountDAL.GetData($"USERID ='{userid}' and THIRDPARTY='大简云用户userkey' "); { if (userkeyinfo != null && !string.IsNullOrWhiteSpace(userkeyinfo.ACCOUNT)) { userkey = userkeyinfo.ACCOUNT; usersecret = userkeyinfo.ACCOUNTPSW; } } if (string.IsNullOrWhiteSpace(userkey)) { var companykeyinfo = MsSysThirdPartyAccountDAL.GetData($"USERID in(select USERID from user_company where companyid='{companyid}') and THIRDPARTY='大简云用户userkey' "); if (companykeyinfo != null && !string.IsNullOrWhiteSpace(companykeyinfo.ACCOUNT)) { userkey = companykeyinfo.ACCOUNT; usersecret = companykeyinfo.ACCOUNTPSW; } } if (string.IsNullOrWhiteSpace(userkey)) { userkey = MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024_Key'").PARAMVALUE; usersecret = MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024_Secret'").PARAMVALUE; } if (string.IsNullOrWhiteSpace(userkey) || string.IsNullOrWhiteSpace(usersecret)) { result.SetErrorInfo("请配置大简云VGM的key和secret"); return result; } headers["USER_KEY"] = userkey; headers["USER_SECRET"] = usersecret; var OpSeaehead = MsOpSeaeDAL.MsOpSeaeDAL.GetData("BSNO='" + headData.BSNO + "'"); headData.MBLNO = OpSeaehead.MBLNO; if (!string.IsNullOrWhiteSpace(SendType)) { //临时性修改 不记录 headData.SENDTYPE = SendType; } var sendinfo = CreateDjyVgm(headData, bodyList, OpSeaehead); BasicDataRefDAL.SaveLog(JsonConvert.Serialize(DsVgmUrl) + "////" + userkey + "////"+ usersecret + "////"+JsonConvert.Serialize(sendinfo), "", "DJYVGM2024", "发送"); var rtn = WebRequestHelper.DoPost_JSON_Header(DsVgmUrl, JsonConvert.Serialize(sendinfo), 10000,headers); BasicDataRefDAL.SaveLog(rtn, "", "DJYVGM2024", "返回"); var _r = JsonConvert.Deserialize(rtn); if (_r.statusCode == 200) { //20240904 然后判断 CarrierSendFlag 或 YGTSendFlag 中有-1的 对应发送失败 var cdc = new CommonDataContext(); var updrec = cdc.op_seae_vgm_send.FirstOrDefault(x => x.BSNO == OpSeaehead.BSNO); updrec.MFNO = _r.data.mfno; updrec.LINKURL = _r.data.linkUrl; //updrec.VGMSTATUS = _r.data.sendstatus; updrec.VGMSTATUS = ""; if (_r.data.carrierSendFlag == -1) { updrec.VGMSTATUS = "船公司发送失败"; } if (_r.data.carrierSendFlag == 1) { updrec.VGMSTATUS = "船公司发送成功"; } if (_r.data.ygtSendFlag == -1) { updrec.VGMSTATUS += " 云港通发送失败"; } if (_r.data.ygtSendFlag == 1) { updrec.VGMSTATUS += " 云港通发送成功"; } if (string.IsNullOrWhiteSpace(updrec.VGMSTATUS)) { updrec.VGMSTATUS = _r.data.sendstatus; } if (_r.data.ctnList != null && _r.data.ctnList.Count > 0) { var returnCtnList = _r.data.ctnList; var currctnlist = cdc.op_seae_vgm_ctn.Where(p => p.BSNO == OpSeaehead.BSNO).ToList(); foreach (var ctn in currctnlist) { if (returnCtnList.Exists(x => x.cntrno == ctn.CNTRNO)) { ctn.ygtSendFlag = returnCtnList.FirstOrDefault(x => x.cntrno == ctn.CNTRNO).ygtSendFlag; ctn.carrierSendFlag = returnCtnList.FirstOrDefault(x => x.cntrno == ctn.CNTRNO).carrierSendFlag; cdc.op_seae_vgm_ctn.AddOrUpdate(ctn); } } } cdc.op_seae_vgm_send.AddOrUpdate(updrec); //cdc.SaveChanges(); result.OK("上传成功",updrec); //记录日志 //var cdc = new DSWeb.Common.DB.CommonDataContext(); var newrec = new op_seae_vgm_history_md(); newrec.BSNO = updrec.BSNO; newrec.SENDERUSER = updrec.SENDERUSER; newrec.SENDTIME = updrec.SENDTIME; newrec.CTNNUM = updrec.CTNNUM; newrec.REMARK = updrec.REMARK; if (!string.IsNullOrEmpty(_r.data.sendRltMsg)) { newrec.REMARK += " " + _r.data.sendRltMsg; } newrec.SENDTYPE = updrec.SENDTYPE; cdc.op_seae_vgm_history.Add(newrec); cdc.SaveChanges(); } else { result.Success = false; result.Message = _r.errors; } return result; } #endregion #region 从大简云获取VGM链接 public class getlinkparam { public string mfno { get; set; } public bool sendCarr { get; set; } = false; public bool sendYGT { get; set; } = false; } public static DBResult GetDjyVgmLink(getlinkparam sendparam) { var result = new DBResult(); result.OK(); var cdc = new CommonDataContext(); var _head = cdc.op_seae_vgm_send.Where(p => p.BSNO == sendparam.mfno||p.MFNO==sendparam.mfno).FirstOrDefault(); //var head = MsOpVgmSendDAL.GetData("BSNO='" + sendparam.mfno + "'"); var DsVgmUrl = MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024GetUrl'").PARAMVALUE; var headers = new NameValueCollection(); var key = MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024_GetUrl_Key'").PARAMVALUE; var secret = MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024_GetUrl_Secret'").PARAMVALUE; //测试数据 //sendparam.mfno = "585399286181957"; headers["USER_KEY"] = key;// MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024_GetUrl_Key'").PARAMVALUE; headers["USER_SECRET"] = secret;// MsSysParamSetDAL.GetData("PARAMNAME='DJYVGM2024_GetUrl_Secret'").PARAMVALUE; var sendstr= JsonConvert.Serialize(sendparam); var dic = new Dictionary { { "mfno", sendparam.mfno }, { "sendCarr", sendparam.sendCarr.ToString().ToLower() }, { "sendYGT", sendparam.sendYGT.ToString().ToLower() } }; BasicDataRefDAL.SaveLog(JsonConvert.Serialize(DsVgmUrl) + "////" + key +"//"+ secret + "////" + JsonConvert.Serialize(sendstr), "", "DJYVGM2024GetUrl", "发送"); var rtn = WebRequestHelper.DoGet_Param_Header(DsVgmUrl, dic, 10000, headers); BasicDataRefDAL.SaveLog(rtn, "", "DJYVGM2024GetUrl", "返回"); 获取vgm链接Result rp = JsonConvert.Deserialize<获取vgm链接Result>(rtn); if (rp.statusCode == 200) { var _str = rp.data; _head.LINKURL = BasicDataRefDAL.Unicode2String(_str); _head.ISCARRIER = sendparam.sendCarr; _head.ISYGT = sendparam.sendYGT; cdc.op_seae_vgm_send.AddOrUpdate(_head); cdc.SaveChangesAsync(); result.OK("获取成功"); result.Data = _head.LINKURL; } else { result.SetErrorInfo(BasicDataRefDAL.Unicode2String(rp.errors)); } return result; } #endregion #region 判断编码是否有重复 static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" Count(BSNO) AS CT "); strSql.Append(" from op_seae_pre "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var ct=0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ct = Convert.ToInt16(reader["CT"]); } reader.Close(); } return ct; } #endregion #region Rang权限范围 public static string GetRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT"); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID"); strSql.Append(" from VW_User_Authority"); strSql.Append(" where [NAME]='modSaleRptList' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); break; } reader.Close(); } if (visiblerange == "4") { str = " SALE='" + username + "'"; } else if (visiblerange == "3") { str = " SALE='" + username + "'"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"; } else if (visiblerange == "1") { str = " SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') "; } else if (visiblerange == "5") { if (tb == "index") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "') "; } else { str = str + " or SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "')"; }; } str = str + ")"; reader.Close(); } } else { str = " SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') "; } } else if (visiblerange == "6") { if (tb == "index") { var opstr = ""; var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { while (reader.Read()) { if (opstr == "") { opstr = " ('" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { opstr = opstr + ",'" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } if (opstr != "") opstr = opstr + ")"; reader.Close(); } if (opstr == "") opstr = "('" + username + "')"; str = " (OP in " + opstr + " )"; } else { str = " (UPPER(op_other.Corpid)='" + companyid + "') "; } } else if (visiblerange == "0") { str = " 1=1 "; } return str; } #endregion } }