286 lines
9.9 KiB
C#
286 lines
9.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using System.Web;
|
||
using WX.CRM.BLL.Res;
|
||
using WX.CRM.BLL.Soft;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.Model.Enum;
|
||
|
||
|
||
namespace WX.CRM.CRMServices.Res
|
||
{
|
||
public class GetResByAgentId
|
||
{
|
||
ValidationErrors errors = new ValidationErrors();
|
||
public void Execute()
|
||
{
|
||
try
|
||
{
|
||
LogHelper.Error("------GetResByAgentId开始执行-----");
|
||
CACHE_BL _cacheQ = new CACHE_BL();
|
||
SOFT_MODULE_BL sfmd = new SOFT_MODULE_BL();
|
||
string agentId = _cacheQ.GetValue_Parameter(Parameter.ISVR_CN_JMDAgentId);
|
||
agentId = string.Format("{0}", agentId).Trim();
|
||
if (string.IsNullOrEmpty(agentId))
|
||
return;
|
||
DateTime sd = sfmd.GetServiceLastExecTime();
|
||
DateTime ed = sd.AddDays(1);
|
||
|
||
GetDataByUrl(agentId, sd, ed);
|
||
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(string.Concat("GetResByAgentId.Execute():", ex.Message));
|
||
}
|
||
LogHelper.Error("------GetResByAgentId执行END-----");
|
||
}
|
||
|
||
void GetDataByUrl(string AgId, DateTime sd, DateTime ed)
|
||
{
|
||
DateTime? maxD = null;
|
||
SOFT_MODULE_BL sfmd = new SOFT_MODULE_BL();
|
||
try
|
||
{
|
||
string _url = System.Configuration.ConfigurationManager.AppSettings["GetAgentResourceUrl"];
|
||
System.Web.Script.Serialization.JavaScriptSerializer serize = new System.Web.Script.Serialization.JavaScriptSerializer();
|
||
string message = serize.Serialize(new ResModel() { agentId = AgId, bTime = sd.ToString(), eTime = ed.ToString() });
|
||
string clientid = "UPWEBSITE";
|
||
string key = "key={0}&clientId=UPWEBSITE&sign={1}";
|
||
string jiami = new SecurityHelper().encyptData(clientid, message);
|
||
string jiami1 = HttpUtility.UrlEncode(jiami, Encoding.UTF8);
|
||
string jiasuo = new SecurityHelper().signData(clientid, jiami);
|
||
string jiasuo1 = HttpUtility.UrlEncode(jiasuo, Encoding.UTF8);
|
||
key = string.Format(key, jiami1, jiasuo1);
|
||
string str = Utility.HttpPostData(_url, key, Encoding.UTF8);
|
||
str = new SecurityHelper().decyptData("UPWEBSITE", str);
|
||
|
||
//AY.ResourceSystem.Common.LogHelper.Write(str);
|
||
|
||
//处理返回串str
|
||
res info = Utility.JSONToObject<res>(str);
|
||
if (info.result == true && info.data != null)
|
||
{
|
||
foreach (UserApplyModule obj in info.data)
|
||
{
|
||
obj.CTime = obj.CTime.ToLocalTime();
|
||
Insert(obj);
|
||
|
||
DateTime tem = System.DateTime.Now;
|
||
if (obj.CTime != null)
|
||
{
|
||
tem = obj.CTime;
|
||
if (maxD == null)
|
||
maxD = tem;
|
||
else
|
||
maxD = maxD < tem ? tem : maxD;
|
||
}
|
||
else
|
||
{
|
||
tem = System.DateTime.Now;
|
||
}
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error(string.Format("GetResByAgentId.GetDataByUrl({0},{1},{2}),错误原因:{3}", AgId, sd, ed, "抓取数据为空!!"));
|
||
}
|
||
if (maxD != null)
|
||
sfmd.UpdateExecLastTime(maxD.GetValueOrDefault(System.DateTime.Now));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(string.Format("GetResByAgentId.GetDataByUrl({0},{1},{2}),错误原因:{3},{4}"
|
||
, AgId
|
||
, sd
|
||
, ed
|
||
, ex.Message
|
||
, ex.StackTrace));
|
||
}
|
||
}
|
||
|
||
|
||
public void Insert(UserApplyModule info)
|
||
{
|
||
RES_USERAPPLYMODULE_BL resBl = new RES_USERAPPLYMODULE_BL();
|
||
string agentID = new CACHE_BL().GetValue_Parameter(Parameter.ISVR_CN_JMDAgentId);
|
||
|
||
string tag = agentID == "500" ? GetResourceTag(info.ModuleId) : GetResourceTagByModelId(info.ModuleId);
|
||
string resid = string.Empty;
|
||
if (!string.IsNullOrEmpty(info.Mobile))
|
||
{
|
||
resid = ResUtil.CreateResId(info.Mobile);
|
||
if (!resBl.CheckDataByResId(resid))
|
||
{
|
||
new WX.CRM.BLL.Res.RES_CUSTOMER_BL().ResgisterCustomer(info.Mobile, resid, tag);
|
||
new WX.CRM.BLL.Res.RES_CUSTOMERUSER_BL().ContractUser(resid, info.UserName);
|
||
//进入资源系统
|
||
resBl.ImportResApply(errors, info.Mobile, tag, info.UserCardNo, info.UserName, info.CTime);
|
||
}
|
||
|
||
}
|
||
if (!resBl.CheckDataByUserName(info.UserName, info.ModuleId))
|
||
{
|
||
RES_USERAPPLYMODULE thedata = new RES_USERAPPLYMODULE();
|
||
thedata.MODULEID = info.ModuleId;
|
||
thedata.ISAUDITED = Convert.ToInt16(info.IsAudited);
|
||
thedata.CUSTOMERFROM = info.CustomerFrom;
|
||
thedata.RESID = resid;
|
||
thedata.USERCARDNO = info.UserCardNo;
|
||
thedata.USERNAME = info.UserName;
|
||
thedata.CTIME = info.CTime;
|
||
resBl.insertData(thedata);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
#region 辅助类
|
||
|
||
/// <summary>
|
||
/// 根据模块Id选择标签
|
||
/// </summary>
|
||
/// <param name="moduleid"></param>
|
||
/// <returns></returns>
|
||
public string GetResourceTag(int intMoudlueId)
|
||
{
|
||
string resourceTag = string.Empty;
|
||
|
||
if (intMoudlueId < 17 || intMoudlueId == 999)
|
||
{
|
||
resourceTag = "module_HuiYuan";
|
||
}
|
||
else if (intMoudlueId >= 18 && intMoudlueId <= 24 && string.IsNullOrEmpty(resourceTag))
|
||
{
|
||
resourceTag = "module_GJS";
|
||
|
||
}
|
||
else if (intMoudlueId == 25 && string.IsNullOrEmpty(resourceTag))
|
||
{
|
||
resourceTag = "module_QKJCY";
|
||
|
||
}
|
||
else if (intMoudlueId == 26 && string.IsNullOrEmpty(resourceTag))
|
||
{
|
||
resourceTag = "module_T0YYJJ";
|
||
}
|
||
else if (intMoudlueId == 17 && string.IsNullOrEmpty(resourceTag))
|
||
{
|
||
resourceTag = "module_BHZZJJ";
|
||
}
|
||
else
|
||
{
|
||
resourceTag = "module_other";
|
||
}
|
||
|
||
return resourceTag;
|
||
}
|
||
|
||
|
||
public string GetResourceTagByModelId(int id)
|
||
{
|
||
//模块申请_3大特权(module_3DaTeQuan):8,9,10,15,16
|
||
//模块申请_3大驱动(module_3DaQuDong):5,6,7
|
||
//模块申请_乾坤决策眼(module_QKJCY):18,19,20,21,22,23,24,25
|
||
//模块申请_T+0鹰眼狙击(module_T0YYJJ):26
|
||
//模块申请_渤海至尊狙击(module_BHZZJJ):17
|
||
//模块申请_其它(module_other):
|
||
string tag = "module_other";
|
||
switch (id)
|
||
{
|
||
case 8:
|
||
tag = "module_3DaTeQuan";
|
||
break;
|
||
case 9:
|
||
tag = "module_3DaTeQuan";
|
||
break;
|
||
case 10:
|
||
tag = "module_3DaTeQuan";
|
||
break;
|
||
case 15:
|
||
tag = "module_3DaTeQuan";
|
||
break;
|
||
case 16:
|
||
tag = "module_3DaTeQuan";
|
||
break;
|
||
case 5:
|
||
tag = "module_3DaQuDong";
|
||
break;
|
||
case 6:
|
||
tag = "module_3DaQuDong";
|
||
break;
|
||
case 7:
|
||
tag = "module_3DaQuDong";
|
||
break;
|
||
case 18:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 19:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 20:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 21:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 22:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 23:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 24:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 25:
|
||
tag = "module_QKJCY";
|
||
break;
|
||
case 26:
|
||
tag = "module_T0YYJJ";
|
||
break;
|
||
case 17:
|
||
tag = "module_BHZZJJ";
|
||
break;
|
||
}
|
||
return tag;
|
||
}
|
||
public class ResModel
|
||
{
|
||
public string agentId { get; set; }
|
||
public string bTime { get; set; }
|
||
public string eTime { get; set; }
|
||
}
|
||
public class res
|
||
{
|
||
public bool result { get; set; }
|
||
public string retcode { get; set; }
|
||
public List<UserApplyModule> data { get; set; }
|
||
}
|
||
|
||
public class UserApplyModule
|
||
{
|
||
public int pkid { get; set; }
|
||
public string UserCardNo { get; set; }
|
||
public string UserName { get; set; }
|
||
public string Mobile { get; set; }
|
||
public int ModuleId { get; set; }
|
||
public string CustomerId { get; set; }
|
||
public string CustomerFrom { get; set; }
|
||
public int IsAudited { get; set; }
|
||
public DateTime CTime { get; set; }
|
||
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|