162 lines
6.6 KiB
C#
162 lines
6.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.OracleClient;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using CRM.Core.DTO;
|
||
using Newtonsoft.Json;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Ww;
|
||
using WX.CRM.BLL.Wx;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.DAL;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.IBLL.WeWork;
|
||
using WX.CRM.IBLL.Ww;
|
||
using WX.CRM.IBLL.Wx;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.Model.Ww;
|
||
|
||
namespace WX.CRM.CRMServices.WeiXin
|
||
{
|
||
/// <summary>
|
||
/// 自动绑定
|
||
/// </summary>
|
||
public static class GetAutoBound
|
||
{
|
||
//更新参数
|
||
//工作内容
|
||
//get wework.ww_extuser json
|
||
//手机号转 resid
|
||
//insert Orcl_TG.ww_extuser_resid
|
||
//update Orcl_TG.res_customerdetail isbound
|
||
|
||
private static BAS_PARAMETER_BL paramter_bl = new BAS_PARAMETER_BL();
|
||
private static IWX_SZZYORDER _wxSzzyorder = new WX_SZZYORDER_BL();
|
||
private static IWw_huser _iww_hhuser_service = new Ww_huser_BL();
|
||
public static void Bound()
|
||
{
|
||
|
||
var syskey = paramter_bl.GetModel_Patameter("WW_Extuser_MAXID");//获取系统上次同步最后更新时间
|
||
var MaxId = Convert.ToInt64(syskey.PARAVALUE);//上次同步的最大id
|
||
LogHelper.Info("拉取加好友信息:" + MaxId);
|
||
var companycode = Utility.GetSettingOrNullByKey("DataClientCode");
|
||
Dictionary<string, List<int>> dicDept = _iww_hhuser_service.GetAllCorpDept(companycode);
|
||
|
||
List<WW_EXTUSER_PARES> logs = new List<WW_EXTUSER_PARES>();
|
||
|
||
//读取投顾 WW_EXTUSER_PARES 表
|
||
OracleParameter[] p =
|
||
{
|
||
new OracleParameter(":ID",MaxId)
|
||
};
|
||
string sql = $@"select rownum,ID,RESID,EXTERNAL_USERID,USERID,UNIONID,REMARK,CORPID,CTIME,ISINNERDEPT from WW_EXTUSER_PARES where ID>:ID and rownum <= 1000 order by ID";//=必要:保证 一个客户多个用户电话信息在插入时其中一条插入失败,下次能被获取到
|
||
DataSet table = OracleHelper.DataQueray(OracleHelper.TGConn, CommandType.Text, sql, p);
|
||
|
||
//处理外部联系人关系数据
|
||
foreach (DataRow row in table.Tables[0].Rows)
|
||
{
|
||
var id = Convert.ToInt64(row["ID"].ToString());
|
||
MaxId = id > MaxId ? id : MaxId;//更新最大id
|
||
WW_EXTUSER_PARES wep = new WW_EXTUSER_PARES();
|
||
wep.RESID = row["RESID"].ToString();
|
||
wep.EXTERNAL_USERID = row["EXTERNAL_USERID"].ToString();
|
||
wep.USERID = row["USERID"].ToString();
|
||
wep.UNIONID = row["UNIONID"].ToString();
|
||
wep.REMAKE = row["REMARK"].ToString();
|
||
wep.CORPID = row["CORPID"].ToString();
|
||
logs.Add(wep);
|
||
|
||
}
|
||
|
||
//时间由远到近 避免中途出错漏掉数据
|
||
//按照顺序 处理获取到的数据
|
||
foreach (var item in logs.OrderBy(m => m.CTIME))
|
||
{
|
||
try
|
||
{
|
||
var hhuser = _iww_hhuser_service.HHuser_Get(item.USERID, item.CORPID);
|
||
if (hhuser != null && hhuser.deptid.HasValue && dicDept.ContainsKey(hhuser.corpid) && dicDept[hhuser.corpid].Contains(hhuser.deptid.Value))
|
||
{
|
||
item.ISINNERDEPT = 1;//是内部资源
|
||
var res = _wxSzzyorder.UpdateResIdByWwUserName(item.RESID, item.EXTERNAL_USERID, item.USERID, item.CORPID);
|
||
if (!res)
|
||
{
|
||
continue;//处理失败时跳出
|
||
}
|
||
else
|
||
{
|
||
//_wxSzzyorder.UpdateIsBoundByResId(resId);
|
||
var host = Utility.GetSettingOrNullByKey("DataSyncApiUrl");
|
||
var url = host + "/api/DataSync";
|
||
var data = new { resid = item.RESID, userid = item.EXTERNAL_USERID, deptcode = companycode };
|
||
var para = new SYNC_PUSH_DTO()
|
||
{
|
||
bidatatype = "Server_WwextUserResid",
|
||
deptcode = companycode,
|
||
jsontext = data.ToJson()
|
||
};
|
||
var rep = Utility.PostAjaxData(url, para.ToJson(), Encoding.UTF8);
|
||
var ret2 = Utility.JSONToObject<retMsg>(rep);
|
||
if (!ret2.result)
|
||
{
|
||
LogHelper.Info("同步到中心点异常:" + para.ToJson());
|
||
//message = "关联成功!同步到总部失败!";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
item.ISINNERDEPT = 0;
|
||
var logRes = _wxSzzyorder.InsertWW_EXTUSER_PARES(item);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
|
||
LogHelper.Error(e.ToString());
|
||
LogHelper.Error("异常JSON:"+item.ToJson());
|
||
continue;//处理失败时跳出
|
||
}
|
||
|
||
|
||
if (logs.Any())
|
||
{
|
||
//处理到数据才修改配置
|
||
syskey.PARAVALUE = MaxId.ToString();
|
||
//更新系统变量 最后处理数据时间
|
||
Common.ValidationErrors errors = new Common.ValidationErrors();
|
||
paramter_bl.Update_Parameter(ref errors, syskey);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//public class WwExtUserView
|
||
//{
|
||
// public External_Contact external_contact { get; set; }
|
||
// public List<Follow_User> follow_user { get; set; }
|
||
// public string corpid { get; set; }
|
||
//}
|
||
//public class External_Contact
|
||
//{
|
||
// public string external_userid { get; set; }
|
||
// public string name { get; set; }
|
||
// public int type { get; set; }
|
||
// public string avatar { get; set; }
|
||
// public int gender { get; set; }
|
||
// public string unionid { get; set; }
|
||
//}
|
||
//public class Follow_User
|
||
//{
|
||
// public string saleeid { get; set; }
|
||
// public string userid { get; set; }
|
||
// public string remark { get; set; }
|
||
// public string description { get; set; }
|
||
// public long createtime { get; set; }
|
||
// public string bindtime { get; set; }
|
||
// public List<string> remark_mobiles { get; set; }
|
||
// public string uname { get; set; }
|
||
//}
|
||
}
|