Exemplo n.º 1
0
       /// <summary> 产品改进号信息同步
       /// </summary>
       /// <param name="updateTime">最后更新时间</param>
       /// <returns>返回产品改进号条数,如为-1,同步失败</returns>
       public static int LoadProdImprovement(string updateTime)
       {
           ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;

           QueryProdImprovement.clientInfo clientInfo = new QueryProdImprovement.clientInfo();
           clientInfo.clientID = GlobalStaticObj_Servier.Instance.ClientID;
           clientInfo.serviceID = "prodImprovementQuery";
           QueryProdImprovement.prodImprovementQueryService serv = new  QueryProdImprovement.prodImprovementQueryService();
           QueryProdImprovement.Result result = serv.prodImprovementQuery(GlobalStaticObj_Servier.Instance.ClientID, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "QUERY", updateTime, clientInfo);
           if (result.state == "F")
           {
               return -1;
           }
           QueryProdImprovement.prodImprovement[] ProdArr = result.Details;
           if (ProdArr.Length == 0)
           {
               return 0;
           }

           string nowTicks = Common.LocalDateTimeToUtcLong(DateTime.Now).ToString();
           List<SysSQLString> list = new List<SysSQLString>();
           foreach (QueryProdImprovement.prodImprovement item in ProdArr)
           {
               SysSQLString sysSQLString = new SysSQLString();
               sysSQLString.cmdType = CommandType.Text;
               sysSQLString.Param = new Dictionary<string, string>();
               StringBuilder strSql = new StringBuilder();
               bool isContactExist = DBHelper.IsExist("判断产品改进号是否存在", "tb_product_no", "service_code='" + item.service_code+ "'");
               if (isContactExist)
               {
                   #region 更新语句
                   strSql.Append(" update tb_product_no set ");
                   strSql.Append(" activities = @activities , ");
                   strSql.Append(" service_type = @service_type , ");
                   strSql.Append(" sart_date = @sart_date , ");
                   strSql.Append(" begin_date = @begin_date , ");
                   strSql.Append(" end_date = @end_date , ");
                   strSql.Append(" service_memo = @service_memo , ");
                   strSql.Append(" update_time = @update_time ");
                   strSql.Append(" where service_code=@service_code;  ");
                   #endregion               
               }
               else
               {
                   #region 插入语句
                   strSql.Append(" insert into tb_product_no(");
                   strSql.Append("p_no_id,activities,service_type,sart_date,begin_date,end_date,service_memo,service_code,create_by,create_time,update_by,update_time");
                   strSql.Append(") values (");
                   strSql.Append("@p_no_id,@activities,@service_type,@sart_date,@begin_date,@end_date,@service_memo,@service_code,@create_by,@create_time,@update_by,@update_time");
                   strSql.Append(");  ");
                   #endregion
                   sysSQLString.Param.Add("p_no_id", Guid.NewGuid().ToString());
                   sysSQLString.Param.Add("create_by", GlobalStaticObj_Servier.Instance.ClientID);
                   sysSQLString.Param.Add("create_time", nowTicks);
               }
               #region 参数项 9
               sysSQLString.sqlString = strSql.ToString();
               sysSQLString.Param.Add("activities", item.activities);
               sysSQLString.Param.Add("service_code", item.service_code);
               sysSQLString.Param.Add("service_type", item.service_type);
               sysSQLString.Param.Add("sart_date", Common.LocalDateTimeToUtcLong(DateTime.Parse(string.IsNullOrEmpty(item.sart_date) ? DateTime.MinValue.ToString() : item.sart_date.ToString())).ToString());
               sysSQLString.Param.Add("begin_date",  Common.LocalDateTimeToUtcLong(DateTime.Parse(item.begin_date)).ToString());
               sysSQLString.Param.Add("end_date", Common.LocalDateTimeToUtcLong(DateTime.Parse(item.end_date)).ToString());
               sysSQLString.Param.Add("service_memo", item.service_memo);
               sysSQLString.Param.Add("update_by", GlobalStaticObj_Servier.Instance.ClientID);
               sysSQLString.Param.Add("update_time", nowTicks);
               #endregion
               list.Add(sysSQLString);

               foreach (QueryProdImprovement.BusDetail item0 in item.BusDetails)
                {
                  SysSQLString sysSQLString0 = new SysSQLString();
                  sysSQLString0.cmdType = CommandType.Text;
                  sysSQLString0.Param = new Dictionary<string, string>();
                  StringBuilder strSql0 = new StringBuilder();
                  bool isContactExist0 = DBHelper.IsExist("判断产品改进号车辆信息是否存在", "tb_product_no_vehicle", "vehicle_code='" + item0.vehicle_code + "'");
                  if (isContactExist0)
                  {
                      #region 更新语句
                      strSql0.Append(" update tb_product_no_vehicle set ");
                      strSql0.Append(" account_code = @account_code , ");
                      strSql0.Append(" server_station = @server_station , ");                
                      strSql0.Append(" update_time = @update_time ");
                      strSql0.Append(" where vehicle_code=@vehicle_code;  ");
                      #endregion                    
                  }
                  else
                  {
                      #region 插入语句
                      strSql0.Append(" insert into tb_product_no_vehicle(");
                      strSql0.Append("p_no_v_id,account_code,server_station,create_by,create_time,update_by,update_time");
                      strSql0.Append(") values (");
                      strSql0.Append("@p_no_v_id,@account_code,@server_station,@create_by,@create_time,@update_by,@update_time");
                      strSql0.Append("); ");
                      #endregion
                      sysSQLString0.Param.Add("p_no_v_id", Guid.NewGuid().ToString());
                      sysSQLString0.Param.Add("create_by", GlobalStaticObj_Servier.Instance.ClientID);
                      sysSQLString0.Param.Add("create_time", nowTicks);
                  }
                  #region 
                  sysSQLString0.sqlString = strSql0.ToString();
                  sysSQLString0.Param.Add("account_code", item0.account_code);
                  sysSQLString0.Param.Add("server_station", item0.server_station);            
                  sysSQLString0.Param.Add("update_by", GlobalStaticObj_Servier.Instance.ClientID);
                  sysSQLString0.Param.Add("update_time", nowTicks);
                  #endregion
                  list.Add(sysSQLString0);
               }

               foreach (QueryProdImprovement.PartDetail item1 in item.PartDetails)
               {
                   SysSQLString sysSQLString1 = new SysSQLString();
                   sysSQLString1.cmdType = CommandType.Text;
                   sysSQLString1.Param = new Dictionary<string, string>();
                   StringBuilder strSql1 = new StringBuilder();
                   bool isContactExist1 = DBHelper.IsExist("判断产品改进号配件信息是否存在", "tb_product_no_part", "part_code='" + item1.part_code + "'");
                   if (isContactExist1)
                   {
                       #region 更新语句
                       strSql1.Append(" update tb_product_no_part set ");
                       strSql1.Append(" quantity = @quantity , ");
                       strSql1.Append(" uint = @uint , ");
                       strSql1.Append(" update_time = @update_time ");
                       strSql1.Append(" where part_code=@part_code;  ");
                       #endregion
                   }
                   else
                   {
                       #region 插入语句
                       strSql1.Append(" insert into tb_product_no_part(");
                       strSql1.Append("p_no_part_id,part_code,quantity,uint,create_by,create_time,update_by,update_time");
                       strSql1.Append(") values (");
                       strSql1.Append("@p_no_part_id,@part_code,@quantity,@uint,@create_by,@create_time,@update_by,@update_time");
                       strSql1.Append("); ");
                       #endregion
                       sysSQLString1.Param.Add("p_no_part_id", Guid.NewGuid().ToString());
                       sysSQLString1.Param.Add("create_by", GlobalStaticObj_Servier.Instance.ClientID);
                       sysSQLString1.Param.Add("create_time", nowTicks);
                   }
                   #region
                   sysSQLString1.sqlString = strSql1.ToString();
                   sysSQLString1.Param.Add("part_code", item1.part_code);
                   sysSQLString1.Param.Add("quantity", item1.quantity);
                   sysSQLString1.Param.Add("uint", item1.@uint);
                   sysSQLString1.Param.Add("update_by", GlobalStaticObj_Servier.Instance.ClientID);
                   sysSQLString1.Param.Add("update_time", nowTicks);
                   #endregion
                   list.Add(sysSQLString1);
               }
           }
           bool flag = DBHelper.BatchExeSQLStringMultiByTrans("宇通:同步车型", list);
           if (!flag)
           {
               return -1;
           }
           return ProdArr.Length;
       }
 /// <summary> 产品改进号信息同步
 /// </summary>
 /// <param name="updateTime">最后更新时间</param>
 /// <returns>返回产品改进号条数,如为-1,同步失败</returns>
 public static string LoadProdImprovement(string updateTime)
 {
     //如果没有接入码或者sap代码,则不调用接口
     if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) ||
         string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode))
     {
         return "";
     }
     ServicePointManager.ServerCertificateValidationCallback = WebServUtil.ValidateServerCertificate;
     QueryProdImprovement.clientInfo clientInfo = new QueryProdImprovement.clientInfo();
     clientInfo.clientID = GlobalStaticObj_YT.ClientID;
     clientInfo.serviceID = "prodImprovementQuery";
     QueryProdImprovement.prodImprovementQueryService serv = new QueryProdImprovement.prodImprovementQueryService();
     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<QueryProdImprovement.clientInfo>(clientInfo);
     DateTime dtStart = GlobalStaticObj_Server.Instance.CurrentDateTime;//开始时间
     QueryProdImprovement.Result result = new QueryProdImprovement.Result();
     string message = string.Empty;//错误消息
     try
     {
         result = serv.prodImprovementQuery(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 "产品改进号接口调用失败!";
     }
     QueryProdImprovement.prodImprovement[] ProdArr = result.Details;
     //if (ProdArr.Length == 0)
     //{
     //    return "产品改进号接口没有返回数据";
     //}
     int updateCount = 0;//更新条数
     ProdArr = WebServUtil.DesList<QueryProdImprovement.prodImprovement>(ProdArr);
     string nowTicks = Common.LocalDateTimeToUtcLong(GlobalStaticObj_Server.Instance.CurrentDateTime).ToString();
     List<SysSQLString> list = new List<SysSQLString>();
     DataTable dtProduct = DBHelper.GetTable("判断产品改进号是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_product_no", "service_code", "", "", "");
     foreach (QueryProdImprovement.prodImprovement item in ProdArr)
     {
         SysSQLString sysSQLString = new SysSQLString();
         sysSQLString.cmdType = CommandType.Text;
         sysSQLString.Param = new Dictionary<string, string>();
         StringBuilder strSql = new StringBuilder();
         //bool isContactExist = DBHelper.IsExist("判断产品改进号是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_product_no", "service_code='" + item.service_code + "'");
         bool isContactExist = false;
         DataRow[] drsProcuct = dtProduct.Select("service_code='" + item.service_code + "'");
         if (drsProcuct.Count() > 0)
         {
             isContactExist = true;
         }
         if (isContactExist)
         {
             #region 更新语句
             strSql.Append(" update tb_product_no set ");
             strSql.Append(" activities = @activities , ");
             strSql.Append(" service_type = @service_type , ");
             strSql.Append(" sart_date = @sart_date , ");
             strSql.Append(" begin_date = @begin_date , ");
             strSql.Append(" end_date = @end_date , ");
             strSql.Append(" service_memo = @service_memo , ");
             strSql.Append(" update_time = @update_time ");
             strSql.Append(" where service_code=@service_code;  ");
             #endregion
         }
         else
         {
             #region 插入语句
             strSql.Append(" insert into tb_product_no(");
             strSql.Append("p_no_id,activities,service_type,sart_date,begin_date,end_date,service_memo,service_code,create_by,create_time,update_by,update_time");
             strSql.Append(") values (");
             strSql.Append("@p_no_id,@activities,@service_type,@sart_date,@begin_date,@end_date,@service_memo,@service_code,@create_by,@create_time,@update_by,@update_time");
             strSql.Append(");  ");
             #endregion
             sysSQLString.Param.Add("p_no_id", Guid.NewGuid().ToString());
             sysSQLString.Param.Add("create_by", GlobalStaticObj_Server.Instance.UserID);
             sysSQLString.Param.Add("create_time", nowTicks);
         }
         #region 参数项 9
         sysSQLString.sqlString = strSql.ToString();
         sysSQLString.Param.Add("activities", item.activities);
         sysSQLString.Param.Add("service_code", item.service_code);
         sysSQLString.Param.Add("service_type", WebServUtil.GetLocalDicID("service_type", item.service_type));
         sysSQLString.Param.Add("sart_date", Common.LocalDateTimeToUtcLong(DateTime.Parse(string.IsNullOrEmpty(item.sart_date) ? DateTime.MinValue.ToString() : item.sart_date.ToString())).ToString());
         sysSQLString.Param.Add("begin_date", Common.LocalDateTimeToUtcLong(DateTime.Parse(item.begin_date)).ToString());
         sysSQLString.Param.Add("end_date", Common.LocalDateTimeToUtcLong(DateTime.Parse(item.end_date)).ToString());
         sysSQLString.Param.Add("service_memo", item.service_memo);
         sysSQLString.Param.Add("update_by", GlobalStaticObj_Server.Instance.UserID);
         sysSQLString.Param.Add("update_time", nowTicks);
         #endregion
         list.Add(sysSQLString);
         item.BusDetails = WebServUtil.DesList(item.BusDetails);
         foreach (QueryProdImprovement.BusDetail item0 in item.BusDetails)
         {
             SysSQLString sysSQLString0 = new SysSQLString();
             sysSQLString0.cmdType = CommandType.Text;
             sysSQLString0.Param = new Dictionary<string, string>();
             StringBuilder strSql0 = new StringBuilder();
             bool isContactExist0 = DBHelper.IsExist("判断产品改进号车辆信息是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_product_no_vehicle", "vehicle_code='" + item0.vehicle_code + "'");
             if (isContactExist0)
             {
                 #region 更新语句
                 strSql0.Append(" update tb_product_no_vehicle set ");
                 strSql0.Append(" account_code = @account_code , ");
                 strSql0.Append(" server_station = @server_station , ");
                 strSql0.Append(" update_time = @update_time ");
                 strSql0.Append(" where vehicle_code=@vehicle_code;  ");
                 #endregion
             }
             else
             {
                 #region 插入语句
                 strSql0.Append(" insert into tb_product_no_vehicle(");
                 strSql0.Append("p_no_v_id,account_code,server_station,create_by,create_time,update_by,update_time");
                 strSql0.Append(") values (");
                 strSql0.Append("@p_no_v_id,@account_code,@server_station,@create_by,@create_time,@update_by,@update_time");
                 strSql0.Append("); ");
                 #endregion
                 sysSQLString0.Param.Add("p_no_v_id", Guid.NewGuid().ToString());
                 sysSQLString0.Param.Add("create_by", GlobalStaticObj_Server.Instance.UserID);
                 sysSQLString0.Param.Add("create_time", nowTicks);
             }
             #region
             sysSQLString0.sqlString = strSql0.ToString();
             sysSQLString0.Param.Add("account_code", item0.account_code);
             sysSQLString0.Param.Add("server_station", item0.server_station);
             sysSQLString0.Param.Add("update_by", GlobalStaticObj_Server.Instance.UserID);
             sysSQLString0.Param.Add("update_time", nowTicks);
             #endregion
             list.Add(sysSQLString0);
         }
         item.PartDetails = WebServUtil.DesList(item.PartDetails);
         foreach (QueryProdImprovement.PartDetail item1 in item.PartDetails)
         {
             SysSQLString sysSQLString1 = new SysSQLString();
             sysSQLString1.cmdType = CommandType.Text;
             sysSQLString1.Param = new Dictionary<string, string>();
             StringBuilder strSql1 = new StringBuilder();
             bool isContactExist1 = DBHelper.IsExist("判断产品改进号配件信息是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_product_no_part", "part_code='" + item1.part_code + "'");
             if (isContactExist1)
             {
                 #region 更新语句
                 strSql1.Append(" update tb_product_no_part set ");
                 strSql1.Append(" quantity = @quantity , ");
                 strSql1.Append(" uint = @uint , ");
                 strSql1.Append(" update_time = @update_time ");
                 strSql1.Append(" where part_code=@part_code;  ");
                 #endregion
             }
             else
             {
                 #region 插入语句
                 strSql1.Append(" insert into tb_product_no_part(");
                 strSql1.Append("p_no_part_id,part_code,quantity,uint,create_by,create_time,update_by,update_time");
                 strSql1.Append(") values (");
                 strSql1.Append("@p_no_part_id,@part_code,@quantity,@uint,@create_by,@create_time,@update_by,@update_time");
                 strSql1.Append("); ");
                 #endregion
                 sysSQLString1.Param.Add("p_no_part_id", Guid.NewGuid().ToString());
                 sysSQLString1.Param.Add("create_by", GlobalStaticObj_Server.Instance.UserID);
                 sysSQLString1.Param.Add("create_time", nowTicks);
             }
             #region
             sysSQLString1.sqlString = strSql1.ToString();
             sysSQLString1.Param.Add("part_code", item1.part_code);
             sysSQLString1.Param.Add("quantity", Convert.ToDecimal(item1.quantity).ToString());
             sysSQLString1.Param.Add("uint", item1.@uint);
             sysSQLString1.Param.Add("update_by", GlobalStaticObj_Server.Instance.UserID);
             sysSQLString1.Param.Add("update_time", nowTicks);
             #endregion
             list.Add(sysSQLString1);
         }
     }
     bool flag = true;
     if (list.Count > 0)
     {
         flag = DBHelper.BatchExeSQLStrMultiByTransNoLogNoBackup("宇通:产品改进号", GlobalStaticObj_Server.Instance.MainAccCode, list);
     }
     updateCount = ProdArr.Count();
     SysConfig sysConfig = new SysConfig();
     sysConfig.UpdateLastTime("ProdImprovement");
     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.ProdImprovement, DataSources.EnumExternalSys.YTCRM, totalCount, updateCount, GlobalStaticObj_Server.Instance.CurrentDateTime);
     WebServUtil.WriteInterficeSyncLog(DataSources.EnumInterfaceType.ProdImprovement, DataSources.EnumExternalSys.YTCRM, DataSources.EnumSyncDirection.DownLoad, "tb_parts", dtStart, dtEnd, updateCount, message);
     return "";
 }