ComplianceServer/oldcode/CRMServices/SoftUser/GetSoftCustomer.cs

95 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using WX.CRM.BLL.Base;
using WX.CRM.BLL.Soft;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.CRMServices.ServicesModel;
using WX.CRM.Model.Entity;
namespace WX.CRM.CRMServices.SoftUser
{
public class GetSoftCustomer
{
public void getCustomer()
{
SOFT_CUSTOMER_BL soft_customer = new SOFT_CUSTOMER_BL();
List<SOFT_CUSTOMER> softCustomerList = this.getSoftCustomerByUrl();
if (softCustomerList.Count > 0)
{
decimal impid = 0;
DataTable dt = SetImportDataTable(softCustomerList, out impid);
ValidationErrors erros = new ValidationErrors();
bool result = new OracleBulk_BL().OracleBulkInsert(ref erros, "SOFT_IMPORT_CUSTOMER", dt);
if (!result)
throw new Exception(erros.Error);
soft_customer.ComputeSoftCustomer(impid);
BAS_PARAMETER_BL para = new BAS_PARAMETER_BL();
para.Update_ParameterValueByKey("CleanSoftCustomer", DateTime.Now.ToString());
}
}
string clientid = WX.CRM.Common.Utility.GetSettingByKey("CRMClientKey");
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new WX.CRM.BLL.Util.SecurityHelper();
/// <summary>
/// 获取数据
/// </summary>
/// <returns></returns>
private List<SOFT_CUSTOMER> getSoftCustomerByUrl()
{
BAS_PARAMETER_BL para = new BAS_PARAMETER_BL();
string getvalue = DateTime.Now.ToString(); ;
var param = para.GetModel_Patameter("CleanSoftCustomer");
if (param != null)
getvalue = param.PARAVALUE;
string url = para.GetModel_Patameter("getSoftCustomerUrl").PARAVALUE;
returnResult result = new returnResult();
result = result.getResult(getvalue, url);
if (result.result)
{
List<SOFT_CUSTOMER> softCustomerList = Utility.MAXJSONToObject<List<SOFT_CUSTOMER>>(result.retMessage);
List<SOFT_CUSTOMER> list = new List<SOFT_CUSTOMER>();
softCustomerList = softCustomerList.Where(p => p.SOFTTYPE == 1).ToList();
foreach (SOFT_CUSTOMER item in softCustomerList)
{
item.Mobile = sHelper.decyptData(clientid, item.Mobile);
}
return softCustomerList;
}
else
{
LogHelper.Error("接口抓取错误" + result.retcode + result.retMessage);
return new List<SOFT_CUSTOMER>();
}
}
private DataTable SetImportDataTable(List<SOFT_CUSTOMER> list, out decimal impid)
{
DataTable dt = Utility.ToOracleDataTable<SOFT_CUSTOMER>(list);
dt.Columns.Remove("CUSTOMERID");
DataColumn column = new DataColumn("PKID");
column.Caption = "键id";
column.DataType = typeof(System.Decimal);
dt.Columns.Add(column);
DataColumn column2 = new DataColumn("IMPORPTID");
column2.Caption = "导入批次";
column2.DataType = typeof(System.Decimal);
dt.Columns.Add(column2);
SEQUENCES_BL seqId = new SEQUENCES_BL();
decimal importId = seqId.Seq_base_get(WX.CRM.Model.Enum.PKIDType.LargeTable);
impid = importId;
foreach (DataRow row in dt.Rows)
{
row["IMPORPTID"] = importId;
row["PKID"] = seqId.Seq_base_get(WX.CRM.Model.Enum.PKIDType.LargeTable);
}
return dt;
}
}
}