/// <summary> /// 执行同步客户操作 /// </summary> /// <param name="sourceDatas"></param> /// <param name="logs"></param> /// <param name="operationType"></param> /// <returns></returns> public override HttpResponseResult ExecuteSynchro(IEnumerable <AbsSynchroDataInfo> sourceDatas, List <SynchroLog> logs, SynOperationType operationType) { HttpResponseResult result = null; List <K3CustomerInfo> custs = null; JObject bizData = null; string msgs = string.Empty; if (sourceDatas != null && sourceDatas.Count() > 0) { custs = sourceDatas.Select(c => (K3CustomerInfo)c).ToList(); bizData = BuildSynchroDataJsons(sourceDatas, operationType); } try { if (operationType == SynOperationType.SAVE) { if (bizData == null) { return(null); } else { if (bizData["Model"] == null) { return(null); } } //客户地址新增 result = ExecuteOperate(SynOperationType.SAVE, null, null, bizData.ToString()); //客户地址新增成功后返回的单据编码集合 if (result != null && result.Success) { RemoveRedisData(this.K3CloudContext, result.SuccessEntityNos); } } else if (operationType == SynOperationType.UPDATE) { List <SqlObject> sqlObjects = null; List <SqlParam> sqlParams = null; List <string> custNos = new List <string>(); int count = 0; try { if (custs != null && custs.Count > 0) { custNos = new List <string>(); foreach (var cust in custs) { if (cust != null && cust.lstCustCtaInfo != null && cust.lstCustCtaInfo.Count > 0) { foreach (var contact in cust.lstCustCtaInfo) { if (contact != null) { string sql = string.Format(@"/*dialect*/ update a set FNAME = @FNAME,FADDRESS = @FADDRESS,FMOBILE = @FMOBILE,F_HS_POSTCODE = @F_HS_POSTCODE, F_HS_DELIVERYCITY = @F_HS_DELIVERYCITY,F_HS_DELIVERYPROVINCES = @F_HS_DELIVERYPROVINCES ,F_HS_RECIPIENTCOUNTRY = @F_HS_RECIPIENTCOUNTRY,F_HS_DELIVERYNAME = @F_HS_DELIVERYNAME from T_BD_CUSTLOCATION a inner join T_BD_CUSTOMER b on a.FCUSTID = b.FCUSTID where b.FNUMBER = @BFNUMBER and a.FNUMBER = @AFNUMBER and FUSEORGID = 1"); sqlObjects = new List <SqlObject>(); sqlParams = new List <SqlParam>(); sqlParams.Add(new SqlParam("@FNAME", KDDbType.String, SQLUtils.DealQuotes(contact.FNAME1))); sqlParams.Add(new SqlParam("@FADDRESS", KDDbType.String, SQLUtils.DealQuotes(contact.FADDRESS1))); sqlParams.Add(new SqlParam("@FMOBILE", KDDbType.String, SQLUtils.DealQuotes(contact.FMOBILE))); sqlParams.Add(new SqlParam("@F_HS_POSTCODE", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_PostCode))); sqlParams.Add(new SqlParam("@F_HS_DELIVERYCITY", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_DeliveryCity))); sqlParams.Add(new SqlParam("@F_HS_DELIVERYPROVINCES", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_DeliveryProvinces))); sqlParams.Add(new SqlParam("@F_HS_RECIPIENTCOUNTRY", KDDbType.String, SQLUtils.DealQuotes(SQLUtils.GetCountryId(this.K3CloudContext, contact.F_HS_RecipientCountry)))); sqlParams.Add(new SqlParam("@F_HS_DELIVERYNAME", KDDbType.String, SQLUtils.DealQuotes(contact.F_HS_DeliveryName))); sqlParams.Add(new SqlParam("@BFNUMBER", KDDbType.String, contact.FCustNo)); sqlParams.Add(new SqlParam("@AFNUMBER", KDDbType.String, contact.FNUMBER1)); sqlObjects.Add(new SqlObject(sql, sqlParams)); count = DBUtils.ExecuteBatch(this.K3CloudContext, sqlObjects); if (count > 0) { custNos.Add(contact.FCustNo); msgs += string.Format("客户[{0}]地址[{1}]更新成功!", contact.FCustNo, contact.FNUMBER1) + Environment.NewLine; LogUtils.WriteSynchroLog(this.K3CloudContext, SynchroDataType.CustomerAddress, string.Format("客户[{0}]地址[{1}]更新成功!", contact.FCustNo, contact.FNUMBER1)); } } } } } if (!string.IsNullOrWhiteSpace(msgs)) { result = new HttpResponseResult(); result.Success = true; result.SuccessEntityNos = custNos; result.Message = msgs; RemoveRedisData(this.K3CloudContext, custNos); } } } catch (Exception ex) { result = new HttpResponseResult(); result.Success = false; result.Message = "客户地址更新出现异常:" + ex.Message + Environment.NewLine + ex.StackTrace; LogUtils.WriteSynchroLog(this.K3CloudContext, SynchroDataType.CustomerAddress, "客户地址更新出现异常:" + result.Message); } } return(result); } catch (Exception ex) { if (logs != null && logs.Count > 0) { foreach (var log in logs) { log.IsSuccess = 0; log.ErrInfor = ex.Message + System.Environment.NewLine + ex.StackTrace; } } LogUtils.WriteSynchroLog(this.K3CloudContext, this.DataType, ex.Message + System.Environment.NewLine + ex.StackTrace); } if (result == null) { return(null); } if (result.Success == false && result.FailedResult == null && result.Result == null) { //同步出现错误之类:如令牌错误,url错误之类的 if (logs != null && logs.Count > 0) { foreach (var log in logs) { log.IsSuccess = 0; log.ErrInfor = "数据同步失败:" + result.Message == null ? "" : result.Message; } } return(result); } return(result); }