TG.WXCRM.V4/Core.WxYunService/WxMessageSvr.svc.cs

142 lines
6.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Core.WxYunService.Model;
using CRM.Core.BLL.Yun;
using CRM.Core.Model.Enum;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Configuration;
using System.Web.Script.Serialization;
using WX.CRM.Common;
namespace Core.WxYunService
{
// 注意: 使用“重构”菜单上的“重命名”命令可以同时更改代码、svc 和配置文件中的类名“WxMessageSvr”。
// 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 WxMessageSvr.svc 或 WxMessageSvr.svc.cs然后开始调试。
public class WxMessageSvr : IWxMessageSvr
{
private static Dictionary<string, UpgradeVersion> upgradeappVersionList;
private static DateTime Uptime = new DateTime(2000, 1, 1);
public JsonResult<UpgradeVersion> UpgradeVersionGet(string code)
{
UpgradeVersion nversion = new UpgradeVersion();
try
{
DateTime now = DateTime.Now;
TimeSpan timespan = now - Uptime;
if (timespan.TotalMinutes > 5 && (upgradeappVersionList == null || upgradeappVersionList.Count == 0))
{
Uptime = now;
LogHelper.Error("初始化数据!");
upgradeappVersionList = new Dictionary<string, UpgradeVersion>();
DataTable tab = new Yun_UPGradeVersion_BL().YunVersionGet();
foreach (DataRow item in tab.Rows)
{
UpgradeVersion woc = new UpgradeVersion();
woc.code = item["code"].ToString();
woc.saledepart = item["saledepart"].ToString();
woc.type = item["type"].ToString();
string urlcode = HttpUtility.UrlEncode(item["url"].ToString());
woc.url = urlcode;
woc.version = item["version"].ToString();
if (!upgradeappVersionList.ContainsKey(woc.code))
{
upgradeappVersionList.Add(woc.code, woc);
}
}
}
if (upgradeappVersionList == null || !upgradeappVersionList.ContainsKey(code))
{
return new JsonResult<UpgradeVersion> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
else
{
nversion = upgradeappVersionList[code];
return new JsonResult<UpgradeVersion> { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
return new JsonResult<UpgradeVersion> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = nversion };
}
}
private static ConfigSet allconfig = null;//全局的config
private static Dictionary<string, ConfigSet> dptconfig;//不买内部的config内部的config会继承掉all立马的config
public JsonResult<string> ConfigSetGet(string code)
{
List<ConfigSet> nversion = new List<ConfigSet>();
try
{
int count = 0;
if (allconfig == null)
{
count = 0;
}
if (dptconfig != null)
{
count += dptconfig.Count;
}
if (count == 0)
{
dptconfig = new Dictionary<string, ConfigSet>();
DataTable tab = new Yun_UPGradeVersion_BL().YunSettingGet();
foreach (DataRow item in tab.Rows)
{
ConfigSet woc = new ConfigSet();
woc.code = item["code"].ToString();
woc.jsontext = item["jsontext"].ToString();
woc.status = Convert.ToInt32(item["status"]);
woc.version = item["version"].ToString();
if (woc.code == "SystemConfig")
{
allconfig = new ConfigSet();
allconfig = woc;
}
else if (!dptconfig.ContainsKey(woc.code))
{
dptconfig.Add(woc.code, woc);
}
}
}
if (dptconfig.ContainsKey(code))
{
nversion.Add(dptconfig[code]);
}
if (allconfig != null)
{
nversion.Add(allconfig);
}
if (nversion.Count > 0)
{
string jsontext = ObjDivertToJson(nversion);
jsontext = HttpUtility.UrlEncode(jsontext);
return new JsonResult<string> { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = jsontext };
}
else
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = null };
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
return new JsonResult<string> { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = null };
}
}
public static string ObjDivertToJson(object obj)
{
ScriptingJsonSerializationSection section = ConfigurationManager.GetSection("system.web.extensions/scripting/webServices/jsonSerialization") as ScriptingJsonSerializationSection;
JavaScriptSerializer script = new JavaScriptSerializer();
script.MaxJsonLength = section != null ? section.MaxJsonLength : int.MaxValue;
string json = script.Serialize(obj);
return json;
}
}
}