200 lines
8.3 KiB
C#
200 lines
8.3 KiB
C#
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Model.Enum;
|
||
using WX.CRM.Model.Entity;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using WX.CRM.BLL.Quality;
|
||
|
||
namespace WX.CRM.CRMServices.CustomerCheck
|
||
{
|
||
public class CustomerCheck
|
||
{
|
||
public void GetData()
|
||
{
|
||
try
|
||
{
|
||
LogHelper.Error("质检抓取开始" + DateTime.Now.ToString());
|
||
string stime, etime, checkTime = "NA";
|
||
stime = DateTime.Now.Date.ToString();
|
||
etime = DateTime.Now.AddDays(1).Date.ToString();
|
||
BAS_PARAMETER_BL cacheQ = new BAS_PARAMETER_BL();
|
||
string key = Parameter.CustomerCheckData.ToString();
|
||
var patamerter = cacheQ.GetModel_Patameter(key);
|
||
if (patamerter != null)
|
||
{
|
||
checkTime = patamerter.map_PARAVALUE;
|
||
}
|
||
if (checkTime != "NA")
|
||
{
|
||
string[] checkArr = checkTime.Split('#');
|
||
stime = checkArr[0];
|
||
etime = checkArr[1];
|
||
}
|
||
string deptCode = Utility.GetSettingByKey("UpReportCode");
|
||
GetCustomerCheckHandler(stime, etime, deptCode);
|
||
GetTvCheck(stime, etime, deptCode);
|
||
GetUserCheck(stime, etime, deptCode);
|
||
if (checkTime != "NA")
|
||
{
|
||
new BAS_PARAMETER_BL().Update_ParameterValueByKey(Parameter.CustomerCheckData.ToString(), "NA");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("CustomerCheck服务出错!" + ex.Message + ex.StackTrace);
|
||
}
|
||
}
|
||
private void GetCustomerCheckHandler(string stime, string etime, string deptCode)
|
||
{
|
||
try
|
||
{
|
||
string str = "";
|
||
string url = Utility.GetSettingByKey("CheckCustomer");
|
||
string key = "stime=" + stime + "&etime=" + etime + "&deptCode=" + deptCode;
|
||
str = Utility.HttpPostData(url, key, Encoding.UTF8);
|
||
GJS_CUSTOMERCHECK_BL customerCheck = new GJS_CUSTOMERCHECK_BL();
|
||
|
||
List<QC_GJS_CUSTOMERCHECK> bck = new List<QC_GJS_CUSTOMERCHECK>();
|
||
ReslueMsg<QC_GJS_CUSTOMERCHECK> rmsg = Utility.JSONToObject<ReslueMsg<QC_GJS_CUSTOMERCHECK>>(str);
|
||
if (rmsg.result)
|
||
{
|
||
DateTime startTime = Convert.ToDateTime(stime);
|
||
DateTime endTime = Convert.ToDateTime(etime);
|
||
bck = rmsg.retdata;
|
||
List<QC_GJS_CUSTOMERCHECK> bckAdd = new List<QC_GJS_CUSTOMERCHECK>();
|
||
List<QC_GJS_CUSTOMERCHECK> bckUpdate = new List<QC_GJS_CUSTOMERCHECK>();
|
||
foreach (var model in bck)
|
||
{
|
||
if (string.IsNullOrEmpty(model.TRADECODE))
|
||
{
|
||
bckAdd.Add(model);
|
||
}
|
||
else if (model.TRADECODE.Length > 3 && (model.TRADECODE.Substring(0, 3) == "231" || model.TRADECODE.Substring(0, 3) == "086" || model.TRADECODE.Substring(0, 3) == "222"))
|
||
{
|
||
if (model.QUALITYTYPE == 20)
|
||
{
|
||
bckUpdate.Add(model);
|
||
if (model.QUALITYSTATUS == 60)
|
||
{
|
||
try
|
||
{
|
||
//质检未通过生成规则
|
||
customerCheck.GenCommissionByUNQCCheck(model.TRADECODE, "质检数据抓取");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("质检未通过生成规则:" + model.TRADECODE + "。" + ex.ToString());
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bckAdd.Add(model);
|
||
}
|
||
}
|
||
|
||
}
|
||
string[] tradecodes = bckUpdate.Select(m => m.TRADECODE).ToArray();
|
||
var existModels = customerCheck.getUpdateCustomerChecks(tradecodes);
|
||
bckAdd.AddRange(bckUpdate);
|
||
customerCheck.AddCustomerChecks(startTime, endTime, bckAdd, existModels);
|
||
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error("CustomerCheck接口出错!" + rmsg.retcode.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("CustomerCheck方法出错!" + ex.Message + ex.StackTrace);
|
||
}
|
||
}
|
||
|
||
public void GetTvCheck(string stime, string etime, string deptCode)
|
||
{
|
||
try
|
||
{
|
||
string str = "";
|
||
string url = Utility.GetSettingByKey("CheckData");
|
||
string key = "stime=" + stime + "&etime=" + etime + "&deptCode=" + deptCode + "&businessCode=checktv";
|
||
str = Utility.HttpPostData(url, key, Encoding.UTF8);
|
||
|
||
List<QC_USERTVCHECK> bck = new List<QC_USERTVCHECK>();
|
||
ReslueMsg<QC_USERTVCHECK> rmsg = Utility.JSONToObject<ReslueMsg<QC_USERTVCHECK>>(str);
|
||
if (rmsg.result)
|
||
{
|
||
DateTime startTime = Convert.ToDateTime(stime);
|
||
DateTime endTime = Convert.ToDateTime(etime);
|
||
bck = rmsg.retdata;
|
||
new QC_USERTVCHECK_BL().AddUserChecks(startTime, endTime, bck);
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error("GetTvCheck接口出错!" + rmsg.retcode.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("GetTvCheck方法出错!" + ex.Message + ex.StackTrace);
|
||
}
|
||
}
|
||
|
||
public void GetUserCheck(string stime, string etime, string deptCode)
|
||
{
|
||
try
|
||
{
|
||
|
||
string masterStr = "", detailStr = "";
|
||
string url = Utility.GetSettingByKey("CheckData");
|
||
|
||
string masterkey = "stime=" + stime + "&etime=" + etime + "&deptCode=" + deptCode + "&businessCode=usermaster";
|
||
string detailkey = "stime=" + stime + "&etime=" + etime + "&deptCode=" + deptCode + "&businessCode=userdetail";
|
||
|
||
masterStr = Utility.HttpPostData(url, masterkey, Encoding.UTF8);
|
||
detailStr = Utility.HttpPostData(url, detailkey, Encoding.UTF8);
|
||
|
||
List<QC_USERCHECKMASTER> master = new List<QC_USERCHECKMASTER>();
|
||
List<QC_USERCHECKDETAIL> detail = new List<QC_USERCHECKDETAIL>();
|
||
|
||
ReslueMsg<QC_USERCHECKMASTER> masterrmsg = Utility.JSONToObject<ReslueMsg<QC_USERCHECKMASTER>>(masterStr);
|
||
ReslueMsg<QC_USERCHECKDETAIL> detailrmsg = Utility.JSONToObject<ReslueMsg<QC_USERCHECKDETAIL>>(detailStr);
|
||
if (masterrmsg.result && detailrmsg.result)
|
||
{
|
||
DateTime startTime = Convert.ToDateTime(stime);
|
||
DateTime endTime = Convert.ToDateTime(etime);
|
||
master = masterrmsg.retdata;
|
||
detail = detailrmsg.retdata;
|
||
new QC_USERCHECK_BL().AddUserChecks(startTime, endTime, master, detail);
|
||
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error("GetUserCheckMaster接口出错!master:" + masterrmsg.retcode.ToString() + ".detail:" + detailrmsg.retcode.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("GetUserCheckMaster方法出错!" + ex.Message + ex.StackTrace);
|
||
}
|
||
}
|
||
}
|
||
|
||
public class ReslueMsg<T>
|
||
where T : class
|
||
{
|
||
public ReslueMsg()
|
||
{
|
||
|
||
}
|
||
public bool result { get; set; }
|
||
public int retcode { get; set; }
|
||
public List<T> retdata { get; set; }
|
||
}
|
||
}
|