Example #1
0
       /// <summary> 配件信息同步
       /// </summary>
       /// <param name="updateTime">最后更新时间</param>
       /// <returns>返回同步配件信息条数,如为-1,同步失败</returns>
       public static int LoadPart(string updateTime)
       {
           ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;

           QueryPart.clientInfo clientInfo = new QueryPart.clientInfo();
           clientInfo.clientID = GlobalStaticObj_Servier.Instance.ClientID;
           clientInfo.serviceID = "partQuery";
           QueryPart.partQueryService serv = new QueryPart.partQueryService();
           string dtNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
           QueryPart.Result result = serv.partQuery(GlobalStaticObj_Servier.Instance.ClientID, dtNow, "QUERY", updateTime, clientInfo);
           if (result.state == "F")
           {
               return -1;
           }
           QueryPart.part[] partArr = result.Details;
           if (partArr.Length == 0)
           {
               return 0;
           }

           string nowTicks = Common.LocalDateTimeToUtcLong(DateTime.Now).ToString();
           List<SysSQLString> list = new List<SysSQLString>();
           foreach (QueryPart.part item in partArr)
           {
               SysSQLString sysSQLString = new SysSQLString();
               sysSQLString.cmdType = CommandType.Text;
               sysSQLString.Param = new Dictionary<string, string>();
               StringBuilder strSql = new StringBuilder();
               bool isContactExist = DBHelper.IsExist("判断配件信息是否存在", "tb_parts", "car_parts_code='" + item.car_parts_code+ "'");
               if (isContactExist)
               {
                   #region 更新语句
                   strSql.Append(" update tb_parts set ");
                   strSql.Append(" parts_name = @parts_name , ");
                   strSql.Append(" sales_unit_code = @sales_unit_code , ");
                   strSql.Append(" sales_unit_name = @sales_unit_name , ");
                   strSql.Append(" model = @model , ");
                   strSql.Append(" status = @status , ");
                   strSql.Append(" retail = @retail , ");
                   strSql.Append(" price3a = @price3a , ");
                   strSql.Append(" price2a = @price2a , ");
                   strSql.Append(" replaced = @replaced , ");
                   strSql.Append(" base_unit_code = @base_unit_code , ");
                   strSql.Append(" base_unit_name = @base_unit_name , ");
                   strSql.Append(" sales_unit_quantity = @sales_unit_quantity , ");
                   strSql.Append(" base_unit_quantity = @base_unit_quantity , ");
                   strSql.Append(" update_time = @update_time ");
                   strSql.Append(" where car_parts_code=@car_parts_code;  ");
                   #endregion               
               }
               else
               {
                   #region 插入语句
                   strSql.Append(" insert into tb_parts(");
                   strSql.Append("parts_id,parts_name,sales_unit_code,data_source,sales_unit_name,model,retail,price3a,price2a,status,enable_flag,replaced,base_unit_code,base_unit_name,sales_unit_quantity,base_unit_quantity,create_by,create_time,update_by,update_time");
                   strSql.Append(") values (");
                   strSql.Append("@parts_id,@parts_name,@sales_unit_code,@data_source,@sales_unit_name,@model,@retail,@price3a,@price2a,@status,@enable_flag,@replaced,@base_unit_code,@base_unit_name,@sales_unit_quantity,@base_unit_quantity,@create_by,@create_time,@update_by,@update_time");
                   strSql.Append(");  ");
                   #endregion
                   sysSQLString.Param.Add("parts_id", Guid.NewGuid().ToString());
                   sysSQLString.Param.Add("create_by", GlobalStaticObj_Servier.Instance.UserID);
                   sysSQLString.Param.Add("create_time", nowTicks);
               }
               #region 参数项 9
               sysSQLString.sqlString = strSql.ToString();
               sysSQLString.Param.Add("parts_name", item.parts_name);
               sysSQLString.Param.Add("sales_unit_code", item.unit_code);
               sysSQLString.Param.Add("sales_unit_name", item.unit_name);
               sysSQLString.Param.Add("model", item.model);
               sysSQLString.Param.Add("status", item.status);
               sysSQLString.Param.Add("retail", item.retail);
               sysSQLString.Param.Add("price3a", item.price3a);
               sysSQLString.Param.Add("price2a", item.price2a);
               //sysSQLString.Param.Add("replaced", item.partReplace);替代关系处理
               sysSQLString.Param.Add("base_unit_code", item.basic_unit_code);
               sysSQLString.Param.Add("base_unit_name", item.basic_unit_name);
               sysSQLString.Param.Add("sales_unit_quantity", item.unit_name_quantity);
               sysSQLString.Param.Add("base_unit_quantity", item.basic_unit_quantity);
               sysSQLString.Param.Add("enable_flag", ((int)DataSources.EnumEnableFlag.USING).ToString());
               sysSQLString.Param.Add("data_source", ((int)DataSources.EnumDataSources.YUTONG).ToString());
               sysSQLString.Param.Add("update_by", GlobalStaticObj_Servier.Instance.ClientID);
               sysSQLString.Param.Add("update_time", nowTicks);
               #endregion
               list.Add(sysSQLString);

                foreach (QueryPart.replaceDetail item0 in item.partReplace)
                {
                  SysSQLString sysSQLString0 = new SysSQLString();
                  sysSQLString0.cmdType = CommandType.Text;
                  sysSQLString0.Param = new Dictionary<string, string>();
                  StringBuilder strSql0 = new StringBuilder();
                  bool isContactExist0 = DBHelper.IsExist("判断配件替代信息是否存在", "tb_parts_replace", "repl_parts_code='" + item0.repl_parts_code+ "'");
                  if (isContactExist0)
                  {
                      #region 更新语句
                      strSql0.Append(" update tb_parts_replace set ");
                      strSql0.Append(" repl_parts_status = @repl_parts_status , ");
                      strSql0.Append(" repl_remark = @repl_remark , ");
                      strSql0.Append(" change = @change ");                 
                      strSql0.Append(" update_time = @update_time ");
                      strSql0.Append(" where repl_parts_code=@repl_parts_code;  ");
                      #endregion                    
                  }
                  else
                  {
                      #region 插入语句
                      strSql0.Append(" insert into tb_parts_replace(");
                      strSql0.Append("replace_id,repl_parts_status,repl_remark,change,create_by,create_time,update_by,update_time");
                      strSql0.Append(") values (");
                      strSql0.Append("@replace_id,@repl_parts_status,@repl_remark,@change,@create_by,@create_time,@update_by,@update_time");
                      strSql0.Append("); ");
                      #endregion
                      sysSQLString0.Param.Add("replace_id", Guid.NewGuid().ToString());
                      sysSQLString0.Param.Add("create_by", GlobalStaticObj_Servier.Instance.UserID);
                      sysSQLString0.Param.Add("create_time", nowTicks);
                  }
                  #region 
                  sysSQLString0.sqlString = strSql0.ToString();
                  sysSQLString0.Param.Add("repl_parts_status", item0.repl_parts_status);
                  sysSQLString0.Param.Add("repl_remark", item0.repl_remark);
                  sysSQLString0.Param.Add("change", item0.change);
                  sysSQLString0.Param.Add("repl_parts_code", item0.repl_parts_code);
                  sysSQLString0.Param.Add("update_by", GlobalStaticObj_Servier.Instance.ClientID);
                  sysSQLString0.Param.Add("update_time", nowTicks);
                  #endregion
                  list.Add(sysSQLString0);
               }
           }
           bool flag = DBHelper.BatchExeSQLStringMultiByTrans("宇通:同步车型", list);
           if (!flag)
           {
               return -1;
           }
           return partArr.Length;
       }
 /// <summary> 配件信息同步
 /// </summary>
 /// <param name="updateTime">最后更新时间</param>
 /// <returns>返回同步配件信息条数,如为-1,同步失败</returns>
 public static string LoadPart(string updateTime)
 {
     //如果没有接入码或者sap代码,则不调用接口
     if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) ||
         string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode))
     {
         return "";
     }
     ServicePointManager.ServerCertificateValidationCallback = WebServUtil.ValidateServerCertificate;
     QueryPart.clientInfo clientInfo = new QueryPart.clientInfo();
     clientInfo.clientID = GlobalStaticObj_YT.ClientID;
     clientInfo.serviceID = "partQuery";
     QueryPart.partQueryService serv = new QueryPart.partQueryService();
     updateTime = Secret.Encrypt3DES_UTF8(updateTime, GlobalStaticObj_YT.KeySecurity_YT);
     string stationCode = Secret.Encrypt3DES_UTF8(GlobalStaticObj_YT.SAPCode, GlobalStaticObj_YT.KeySecurity_YT);
     string dateStr = Secret.Encrypt3DES_UTF8(GlobalStaticObj_Server.Instance.CurrentDateTime.ToString("yyyy-MM-dd HH:mm:ss"), GlobalStaticObj_YT.KeySecurity_YT);
     string requestType = Secret.Encrypt3DES_UTF8("QUERY", GlobalStaticObj_YT.KeySecurity_YT);
     clientInfo = WebServUtil.EncModel<QueryPart.clientInfo>(clientInfo);
     DateTime dtStart = GlobalStaticObj_Server.Instance.CurrentDateTime;//开始时间
     QueryPart.Result result = new QueryPart.Result();
     string message = string.Empty;//错误消息
     try
     {
         result = serv.partQuery(stationCode, dateStr, requestType, updateTime, clientInfo);
     }
     catch (InvalidOperationException ioe)
     {
         //Utility.Log.Log.writeLineToLog(ioe, "配件信息同步");
         GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("配件信息同步", ioe);
         message = ioe.Message;
         return "配件信息同步超时!";
     }
     catch (TimeoutException te)
     {
         //Utility.Log.Log.writeLineToLog(te, "配件信息同步");
         GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("配件信息同步", te);
         message = te.Message;
         return "配件信息同步出错!";
     }
     string state = Secret.Decrypt3DES_UTF8(result.state, GlobalStaticObj_YT.KeySecurity_YT);
     if (state == "F")
     {
         string errMsg = Secret.Decrypt3DES_UTF8(result.errorMsg, GlobalStaticObj_YT.KeySecurity_YT);
         //Utility.Log.Log.writeLineToLog("【配件信息同步】" + errMsg, "接口");
         GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("配件信息同步", errMsg);
         return "配件接口调用失败!";
     }
     QueryPart.part[] partArr = result.Details;
     //if (partArr.Length == 0)
     //{
     //    return "配件接口没有返回数据";
     //}
     partArr = WebServUtil.DesList<QueryPart.part>(partArr);
     //bool flag = SavePart(partArr);
     int updateCount = 0;
     bool flag = SavePartNotBatch(partArr, ref updateCount);
     if (!flag)
     {
         GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("配件信息同步", "配件更新失败");
         return "配件更新失败!";
     }
     DateTime dtEnd = GlobalStaticObj_Server.Instance.CurrentDateTime;//结束时间
     int totalCount = int.Parse(DBHelper.GetSingleValue("", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "select count(1) from tb_parts where data_source='2'"));
     WebServUtil.WriteInterficeSync(DataSources.EnumInterfaceType.Part, DataSources.EnumExternalSys.YTCRM, totalCount, updateCount, GlobalStaticObj_Server.Instance.CurrentDateTime);
     WebServUtil.WriteInterficeSyncLog(DataSources.EnumInterfaceType.Part, DataSources.EnumExternalSys.YTCRM, DataSources.EnumSyncDirection.DownLoad, "tb_parts", dtStart, dtEnd, updateCount, message);
     return "";
 }