59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using NPOI.SS.Formula.Functions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BLL.APIService
|
|
{
|
|
|
|
public class SyncContractorService
|
|
{
|
|
private const string GETAPIUrl = "https://reportserver.basf-ypc.net.cn:3033/api/query";
|
|
public static void GetSyncContractor()
|
|
{
|
|
//string file = System.Web.HttpContext.Current.Server.MapPath("~/ContractorData.txt");
|
|
//string result = System.IO.File.ReadAllText(file);
|
|
|
|
string username = "EpermitContractor_EFC";
|
|
string password = "nM3#yU5$pO8%aZ6";
|
|
string result = BLL.Common.HttpHelper.HttpGetRequest(GETAPIUrl, username, password);
|
|
//BLL.ErrLogInfo.WriteLog($"请求API Result={result}");
|
|
|
|
var data = JsonHelper.DeserializeJsonToObject<List<ContractorInfo>>(result);
|
|
List<Model.EMC_Contractor> conList = new List<Model.EMC_Contractor>();
|
|
foreach (var item in data)
|
|
{
|
|
var conModel = new Model.EMC_Contractor();
|
|
conModel.ContractorId = SQLHelper.GetNewID(typeof(Model.EMC_Contractor));
|
|
conModel.ContractorCN = item.accepter_basf_dep;
|
|
conModel.WorkDate = item.WorkDate;
|
|
conModel.SyncTime = DateTime.Now;
|
|
conList.Add(conModel);
|
|
}
|
|
AddSyncContractor(conList);
|
|
}
|
|
|
|
private static void AddSyncContractor(List<Model.EMC_Contractor> cons)
|
|
{
|
|
string sql = "delete from EMC_Contractor";
|
|
SQLHelper.ExecutSql(sql);
|
|
|
|
Funs.DB.EMC_Contractor.InsertAllOnSubmit(cons);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
|
|
}
|
|
#region 内部类
|
|
[Serializable]
|
|
internal class ContractorInfo
|
|
{
|
|
public string accepter_basf_dep { get; set; }
|
|
public string WorkDate { get; set; }
|
|
}
|
|
#endregion
|
|
|
|
}
|