123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- using SysBaseLibs;
- using SysDataLibs.TableClass;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- namespace GSMarketSys.WS
- {
- /// <summary>
- /// GetCheckDataService 的摘要说明
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
- // [System.Web.Script.Services.ScriptService]
- public class GetCheckDataService : System.Web.Services.WebService
- {
- public GetCheckDataService()
- {
- //如果使用设计的组件,请取消注释以下行
- //InitializeComponent();
- }
- /// <summary>
- /// [],[],[]
- /// </summary>
- /// <param name="jsonFile"></param>
- /// <returns></returns>
- [WebMethod]
- public string GetCheckData(string jsonFile)
- {
- string AllResult = "";
- string reIP = Context.Request.ServerVariables["REMOTE_HOST"];
- // string reIP = "123.89.1.1";
- SysBaseLibs.ThreadLog.LogInfo("GetCheckData :" + reIP + " " + jsonFile);
- string[] arrRemoteIPs = SysDataLibs.AppEnv.SysSetObj.GetString("GetCheckDataRemoteIP").Split('@');
- //string lcWhereSql = "";
- string testIP = arrRemoteIPs[arrRemoteIPs.Length - 1];
- arrRemoteIPs[arrRemoteIPs.Length - 1] = "";
- DBConnSql loConn = new DBConnSql();
- loConn.Open();
- if (arrRemoteIPs.Contains(reIP) || reIP == "127.0.0.1")
- {
- if (isCanGetCheckData(reIP, loConn))
- {
- List<string> loJsonPara = new List<string>();
- Sys_AttachTables_info laTab = new Sys_AttachTables_info(reIP, "ForGetCheckData", "GetCheckDataMan", loConn);
- string lcLastGetDatTime = "";
- if (!string.IsNullOrWhiteSpace(laTab.SourceKey))
- lcLastGetDatTime = laTab.ActionTime;
- if (!CheckSearchTimeNot(jsonFile, loJsonPara, lcLastGetDatTime))
- {
- return "输入为不正确的时间格式!";
- }
- AllResult = GetCheckDataByWhere(GetWhereSqlByJsonFile(loJsonPara), reIP, loConn);
- }
- else
- {
- AllResult = "距离上次查询时间不到" + SysDataLibs.AppEnv.SysSetObj.GetString("GetCDataFrequency") + "分钟,限制访问!";
- }
- }
- else if (reIP == testIP)
- {
- AllResult = @"<Records>
- <RemoteIP>测试IP</RemoteIP>
- <ResultSet>
- <Result>
- <BigKindOfFood>---</BigKindOfFood>
- <SmallKindOfFood>葱蒜类</SmallKindOfFood>
- <SampleFoodName>大葱</SampleFoodName>
- <TestMan>DefaultUser</TestMan>
- <TestTime>2010-01-01 00:00:00</TestTime>
- <ProduceUnit>---</ProduceUnit>
- <CheckTypeName>甲醛</CheckTypeName>
- <CheckResult>合格</CheckResult>
- <CheckRate>0.0000</CheckRate>
- <CheckNo>WB967197</CheckNo>
- </Result>
- </ResultSet>
- </Records>";
- }
- else
- {
- AllResult = reIP + "是非约定的IP!";
- }
- return AllResult;
- }
- /// <summary>
- /// 校验输入的第一个日期格式是否正确
- /// </summary>
- /// <param name="pJsonFile"></param>
- /// <returns>false:正确;true:错误</returns>
- private bool CheckSearchTimeNot(string pJsonFile, List<string> poParas, string pcLastGetDatTime)
- {
- bool lbRetval = false;
- if (!string.IsNullOrEmpty(pJsonFile))
- {
- Array loPara = SysBaseLibs.UtilStr.StrToArrayEx(pJsonFile, ",");
- if (loPara != null && loPara.Length > 0)
- {
- if (loPara != null && loPara.Length == 2)
- {
- lbRetval = CheckDateTime(loPara.GetValue(1));
- if (lbRetval)
- {
- poParas.Add(loPara.GetValue(1).ToString());
- }
- }
- lbRetval = CheckDateTime(loPara.GetValue(0));
- if (lbRetval)
- {
- poParas.Add(loPara.GetValue(0).ToString());
- if (SysDataLibs.AppEnv.SysSetObj.GetBool("CheckLastGetDatTime") && !string.IsNullOrWhiteSpace(pcLastGetDatTime))
- {
- try
- {
- if (DateTime.Parse(pcLastGetDatTime).CompareTo(DateTime.Parse(loPara.GetValue(0).ToString())) > 0)
- {
- poParas.RemoveAt(poParas.Count - 1);
- poParas.Add(pcLastGetDatTime);
- }
- }
- catch { }
- }
- }
- }
- poParas.Reverse();
- }
- return lbRetval;
- }
- private bool CheckDateTime(object poDateTime)
- {
- bool lbRetval = false;
- try
- {
- DateTime loTime = DateTime.Parse(SysBaseLibs.UtilStr.StrFromObj(poDateTime));
- lbRetval = true;
- }
- catch { }
- return lbRetval;
- }
- /// <summary>
- /// 根据输入条件生成对应的Sql条件
- /// </summary>
- /// <param name="pJsonFile"></param>
- /// <returns></returns>
- private string GetWhereSqlByJsonFile(List<string> poJsonParas)
- {
- string lcWhereSql = "";
- if (poJsonParas.Count > 0)
- {
- lcWhereSql = " and UploadTime >= '" + CompareEarilyTime(poJsonParas[0]) + "'";
- if (poJsonParas.Count == 2)
- {
- lcWhereSql += " and UploadTime < '" + poJsonParas[1] + "'";
- }
- }
- else
- {
- lcWhereSql = " and UploadTime >= '" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "'"; ; //DateTime.Now.ToString("yyyy/MM/dd 00:00:00") + "'";
- }
- return lcWhereSql;
- }
- private string GetCheckDataByWhere(string poWhereSql, string pRemoteIP, DBConnSql poDBConn)
- {
- string lcSql = SysDataLibs.AppEnv.SysSetObj.GetString("GetCheckDataViewSql") + " where 1=1 " + poWhereSql + " order by UploadTime Asc";
- rsQuery loQuery = poDBConn.OpenQuery(lcSql);
- rsXmlNode rsAll = rsXmlNode.ParseGenericXml("<Records><RemoteIP>" + pRemoteIP + "</RemoteIP></Records>");
- if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
- {
- loQuery.MoveFirst();
- rsXmlNode snResultsNodes = rsXmlNode.ParseGenericXml("<ResultSet></ResultSet>");
- rsXmlNode snNodes = SysBaseLibs.rsXmlNode.ParseGenericXml(SysDataLibs.AppEnv.SysSetObj.GetString("GetCheckDataXml"));
- for (int i = 0; i < loQuery.RecCount; i++)
- {
- rsXmlNode loResultNode = snNodes.Clone() as rsXmlNode;
- foreach (rsXmlNode loNode in loResultNode.Nodes)
- {
- loNode.Value = loQuery.GetString(loNode.Name);
- }
- snResultsNodes.AddChild(loResultNode);
- loQuery.MoveNext();
- }
- rsAll.AddChild(snResultsNodes);
- AddOrUpdateGetDataTimes(pRemoteIP, poDBConn);
- }
- return rsAll.ToXmlString();
- //return sb.ToString();
- }
- /// <summary>
- /// 判断是否小于或等于最早的查询时间
- /// </summary>
- /// <param name="pTime">输入的查询时间</param>
- /// <returns></returns>
- private string CompareEarilyTime(string pTime)
- {
- string lbRetval = pTime;
- DateTime loTime = DateTime.Parse(pTime);
- DateTime loEarliestTime;
- string lcSqlTime = SysDataLibs.AppEnv.SysSetObj.GetString("GetCheckDataEarliest");
- if (!string.IsNullOrEmpty(lcSqlTime))
- {
- if (DateTime.TryParse(lcSqlTime, out loEarliestTime))
- {
- if (loTime.CompareTo(loEarliestTime) < 0)
- {
- lbRetval = loEarliestTime.ToString("yyyy/MM/dd 00:00:00");
- }
- }
- }
- return lbRetval;
- }
- /// <summary>
- /// 判断当前访问的主机IP是不是可以获取数据
- /// </summary>
- /// <param name="remoteIP"></param>
- /// <returns>true:可以获取</returns>
- private bool isCanGetCheckData(string remoteIP, DBConnSql poDBConn)
- {
- bool lbRetval = true;
- Sys_AttachTables_info laTab = new Sys_AttachTables_info(remoteIP, "ForGetCheckData", "GetCheckDataMan", poDBConn);
- if (laTab != null && !string.IsNullOrEmpty(laTab.SourceKey))
- {
- TimeSpan ts = DateTime.Now - DateTime.Parse(laTab.ActionTime);
- string GetCDataFrequency = SysDataLibs.AppEnv.SysSetObj.GetString("GetCDataFrequency");
- if (ts.Minutes < Utils.ValI(GetCDataFrequency))
- {
- lbRetval = false;
- }
- }
- return lbRetval;
- }
- /// <summary>
- /// 更改查询的操作次数
- /// </summary>
- /// <param name="remoteIP"></param>
- /// <param name="poDBConn"></param>
- private void AddOrUpdateGetDataTimes(string remoteIP, DBConnSql poDBConn)
- {
- Sys_AttachTables_info laTab = new Sys_AttachTables_info(remoteIP, "ForGetCheckData", "GetCheckDataMan", poDBConn);
- if (laTab != null && !string.IsNullOrEmpty(laTab.SourceKey))
- {
- laTab.ActionTime = DateTime.Now.ToString();
- laTab.ActionTimes = UtilStr.StrFromObj(Utils.ValI(laTab.ActionTimes) + 1);
- if (poDBConn.ExcuteSqlTran(laTab.UpdateSql()))
- {
- }
- }
- else
- {
- Sys_AttachTables_info laTabNew = new Sys_AttachTables_info();
- laTabNew.TableId = "ForGetCheckData";
- laTabNew.SourceKey = remoteIP;
- laTabNew.UserID = "GetCheckDataMan";
- laTabNew.ColumnId = "RemoteIP";
- laTabNew.ActionTime = DateTime.Now.ToString();
- laTabNew.ActionTimes = "1";
- laTabNew.Actiion = "已查询";
- if (poDBConn.ExcuteSqlTran(laTabNew.InsertSql()))
- {
- //SysBaseLibs.ThreadLog.SysLog.WriteInfor(laTabNew.DataXMLNode.ToXmlString());
- }
- }
- }
- }
- }
|