2023-08-04
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
namespace BLL
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public static class DataForJTApiService
|
||||
{
|
||||
public static Model.SGGLDB db = Funs.DB;
|
||||
|
||||
/// <summary>
|
||||
/// 获取接口设置信息
|
||||
/// </summary>
|
||||
/// <param name="InterFaceSetId">设置Id</param>
|
||||
/// <returns>接口设置信息</returns>
|
||||
public static Model.InterFaceSet GetFaceSetById(string InterFaceSetId)
|
||||
{
|
||||
return Funs.DB.InterFaceSet.FirstOrDefault(e => e.InterFaceSetId == InterFaceSetId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加接口设置信息
|
||||
/// </summary>
|
||||
/// <param name="faceset">接口设置</param>
|
||||
public static void AddFaceSet(Model.InterFaceSet faceset)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
string newKeyID = SQLHelper.GetNewID(typeof(Model.InterFaceSet));
|
||||
Model.InterFaceSet newSet = new Model.InterFaceSet
|
||||
{
|
||||
InterFaceSetId = newKeyID,
|
||||
InterFaceName = faceset.InterFaceName,
|
||||
AuthUnitIds = faceset.AuthUnitIds,
|
||||
AuthUnitName = faceset.AuthUnitName,
|
||||
InterFaceUrl = faceset.InterFaceUrl,
|
||||
ValidPeriod = faceset.ValidPeriod,
|
||||
UnitId = faceset.UnitId,
|
||||
TxtRemarks = faceset.TxtRemarks,
|
||||
IsOpen = faceset.IsOpen,
|
||||
};
|
||||
db.InterFaceSet.InsertOnSubmit(newSet);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改接口设置信息
|
||||
/// </summary>
|
||||
/// <param name="user">接口设置实体</param>
|
||||
public static void UpdateFaceSet(Model.InterFaceSet user)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
Model.InterFaceSet newSet = db.InterFaceSet.FirstOrDefault(e => e.InterFaceSetId == user.InterFaceSetId);
|
||||
if (newSet != null)
|
||||
{
|
||||
newSet.InterFaceName = user.InterFaceName;
|
||||
newSet.AuthUnitIds = user.AuthUnitIds;
|
||||
newSet.AuthUnitName = user.AuthUnitName;
|
||||
newSet.InterFaceUrl = user.InterFaceUrl;
|
||||
newSet.UnitId = user.UnitId;
|
||||
newSet.ValidPeriod = user.ValidPeriod;
|
||||
newSet.UnitId = user.UnitId;
|
||||
newSet.TxtRemarks = user.TxtRemarks;
|
||||
newSet.IsOpen = user.IsOpen;
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据Id删除信息
|
||||
/// </summary>
|
||||
/// <param name="SetId"></param>
|
||||
public static void DeleteFaceSet(string SetId)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
Model.InterFaceSet FaceSet = db.InterFaceSet.FirstOrDefault(e => e.InterFaceSetId == SetId);
|
||||
if (FaceSet != null)
|
||||
{
|
||||
var logs = from x in db.Sys_Log where x.UserId == SetId select x;
|
||||
if (logs.Count() > 0)
|
||||
{
|
||||
db.Sys_Log.DeleteAllOnSubmit(logs);
|
||||
}
|
||||
db.InterFaceSet.DeleteOnSubmit(FaceSet);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 保存上报数据记录
|
||||
///// </summary>
|
||||
///// <param name="newItem">上报数据</param>
|
||||
///// <returns></returns>
|
||||
//public static string SaveUpData(Model.InterFaceItem newItem)
|
||||
//{
|
||||
// if (newItem.FaceLogDate.Count() == 0)
|
||||
// return "数据不可为空!";
|
||||
// using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||||
// {
|
||||
// List<string> InterFaceLogIdList=new List<string> ();
|
||||
// List<Model.InterFaceLog> logList = new List<Model.InterFaceLog>();
|
||||
// string message = string.Empty;
|
||||
// var InterFaceSetList = db.InterFaceSet.Where(x => x.InterFaceName != "");
|
||||
// foreach (var item in newItem.FaceLogDate)
|
||||
// {
|
||||
// //如果配置接口名称存在 进行数据保存
|
||||
// var faceset = InterFaceSetList.FirstOrDefault(p => p.InterFaceName == item.InterFaceName);
|
||||
// if (faceset != null)
|
||||
// {
|
||||
// Model.InterFaceLog FaceLog = new Model.InterFaceLog();
|
||||
// FaceLog.InterFaceLogId = Guid.NewGuid().ToString();
|
||||
// FaceLog.TxtContent = item.TxtContent;
|
||||
// FaceLog.InterFaceLogDate = Convert.ToDateTime(item.InterFaceLogDate);
|
||||
// FaceLog.LogSate = false;
|
||||
// FaceLog.CollCropCode = item.CollCropCode;
|
||||
// FaceLog.IP = item.IP;
|
||||
// FaceLog.UnitId = item.UnitId;
|
||||
// FaceLog.InterFaceDetailId ="";
|
||||
// logList.Add(FaceLog);
|
||||
// }
|
||||
// else //配置接口名称不存在 记录反馈给前端提示
|
||||
// {
|
||||
// InterFaceLogIdList.Add(item.InterFaceName);
|
||||
// }
|
||||
// }
|
||||
// db.InterFaceLog.InsertAllOnSubmit(logList);
|
||||
// db.SubmitChanges();
|
||||
// }
|
||||
// return "数据同步成功";
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using FineUIPro;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Printing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
|
||||
public static class InterFaceLogService
|
||||
{
|
||||
public static Model.SGGLDB db = Funs.DB;
|
||||
|
||||
public const string Type1 = "上报";
|
||||
public const string Type2= "下发";
|
||||
public const string Type3 = "回调";
|
||||
|
||||
#region 获取列表
|
||||
/// <summary>
|
||||
/// 记录数
|
||||
/// </summary>
|
||||
public static int count
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public static List<Model.InterFaceLog> GetInterFaceLogByModle(Model.InterFaceLog table)
|
||||
{
|
||||
var q= from x in db.InterFaceLog
|
||||
where
|
||||
( string.IsNullOrEmpty(table.InterFaceLogId)||x.InterFaceLogId.Contains(table.InterFaceLogId)) &&
|
||||
( string.IsNullOrEmpty(table.UserId)||x.UserId.Contains(table.UserId)) &&
|
||||
( string.IsNullOrEmpty(table.UnitId)||x.UnitId.Contains(table.UnitId)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceName)||x.InterFaceName.Contains(table.InterFaceName)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceUrl)||x.InterFaceUrl.Contains(table.InterFaceUrl)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceMehtod)||x.InterFaceMehtod.Contains(table.InterFaceMehtod)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceBody)||x.InterFaceBody.Contains(table.InterFaceBody)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceReturnData)||x.InterFaceReturnData.Contains(table.InterFaceReturnData)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceType)||x.InterFaceType.Contains(table.InterFaceType)) &&
|
||||
( string.IsNullOrEmpty(table.IP)||x.IP.Contains(table.IP))
|
||||
orderby x.InterFaceLogDate descending
|
||||
select x
|
||||
;
|
||||
|
||||
return q.ToList();
|
||||
}
|
||||
|
||||
/// 获取分页列表
|
||||
/// </summary>
|
||||
/// <param name="PageIndex">页码</param>
|
||||
/// <param name="PageSize">每页数量</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable getListData(Model.InterFaceLog table, Grid Grid1)
|
||||
{
|
||||
var q= GetInterFaceLogByModle(table);
|
||||
count = q.Count();
|
||||
if (count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
q = q.Skip(Grid1.PageSize * (Grid1.PageIndex)).Take(Grid1.PageSize).ToList();
|
||||
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
||||
return (from x in q
|
||||
select new
|
||||
{
|
||||
x.InterFaceLogId,
|
||||
x.UserId,
|
||||
x.UnitId,
|
||||
x.InterFaceName,
|
||||
x.InterFaceUrl,
|
||||
x.InterFaceMehtod,
|
||||
x.InterFaceBody,
|
||||
x.InterFaceReturnData,
|
||||
x.InterFaceLogDate,
|
||||
x.InterFaceType,
|
||||
x.LogSate,
|
||||
x.IP,
|
||||
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static Model.InterFaceLog GetInterFaceLogById(string InterFaceLogId)
|
||||
{
|
||||
return db.InterFaceLog.FirstOrDefault(x=>x.InterFaceLogId==InterFaceLogId);
|
||||
}
|
||||
|
||||
|
||||
public static void AddInterFaceLog(Model.InterFaceLog newtable)
|
||||
{
|
||||
|
||||
|
||||
Model.InterFaceLog table = new Model.InterFaceLog{
|
||||
InterFaceLogId=newtable.InterFaceLogId,
|
||||
UserId=newtable.UserId,
|
||||
UnitId=newtable.UnitId,
|
||||
InterFaceName=newtable.InterFaceName,
|
||||
InterFaceUrl=newtable.InterFaceUrl,
|
||||
InterFaceMehtod=newtable.InterFaceMehtod,
|
||||
InterFaceBody=newtable.InterFaceBody,
|
||||
InterFaceReturnData=newtable.InterFaceReturnData,
|
||||
InterFaceLogDate=newtable.InterFaceLogDate,
|
||||
InterFaceType=newtable.InterFaceType,
|
||||
LogSate=newtable.LogSate,
|
||||
IP=newtable.IP,
|
||||
};
|
||||
Funs.DB.InterFaceLog.InsertOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
public static void WriteInterFaceLog(string InterFaceSetlId, string InterFaceBody, string ReturnData, string InterFaceType,bool isSuccess)
|
||||
{
|
||||
var InterfaceSetModel = InterFaceSetService.GetInterFaceSetById(InterFaceSetlId);
|
||||
Model.InterFaceLog table = new Model.InterFaceLog();
|
||||
table.InterFaceLogId = SQLHelper.GetNewID(typeof(Model.InterFaceLog));
|
||||
table.UserId = Const.sysglyId;
|
||||
table.InterFaceLogDate = DateTime.Now;
|
||||
table.IP = "";
|
||||
table.InterFaceName = InterfaceSetModel.InterFaceName;
|
||||
table.InterFaceBody = InterFaceBody;
|
||||
table.InterFaceReturnData = ReturnData;
|
||||
table.InterFaceType = InterFaceType;
|
||||
table.LogSate = isSuccess;
|
||||
switch (InterFaceType)
|
||||
{
|
||||
case Type1:
|
||||
table.UnitId = InterfaceSetModel.UnitId;
|
||||
table.InterFaceUrl = InterfaceSetModel.InterFaceUrl;
|
||||
table.InterFaceMehtod = InterfaceSetModel.UrlReqMethod;
|
||||
|
||||
break;
|
||||
case Type2:
|
||||
table.UnitId = InterfaceSetModel.AuthUnitIds;
|
||||
table.InterFaceUrl = InterfaceSetModel.InterFaceForUrl;
|
||||
table.InterFaceMehtod = InterfaceSetModel.ForUrlReqMethod;
|
||||
break;
|
||||
case Type3:
|
||||
table.UnitId = InterfaceSetModel.UnitId;
|
||||
table.InterFaceUrl = InterfaceSetModel.InterFaceCallBackUrl;
|
||||
table.InterFaceMehtod = InterfaceSetModel.CallBackUrlReqMethod;
|
||||
break;
|
||||
}
|
||||
Funs.DB.InterFaceLog.InsertOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
public static void UpdateInterFaceLog(Model.InterFaceLog newtable)
|
||||
{
|
||||
|
||||
Model.InterFaceLog table = db.InterFaceLog.FirstOrDefault(x=>x.InterFaceLogId==newtable.InterFaceLogId);
|
||||
if (table != null)
|
||||
{
|
||||
table.InterFaceLogId=newtable.InterFaceLogId;
|
||||
table.UserId=newtable.UserId;
|
||||
table.UnitId=newtable.UnitId;
|
||||
table.InterFaceName=newtable.InterFaceName;
|
||||
table.InterFaceUrl=newtable.InterFaceUrl;
|
||||
table.InterFaceMehtod=newtable.InterFaceMehtod;
|
||||
table.InterFaceBody=newtable.InterFaceBody;
|
||||
table.InterFaceReturnData=newtable.InterFaceReturnData;
|
||||
table.InterFaceLogDate=newtable.InterFaceLogDate;
|
||||
table.InterFaceType=newtable.InterFaceType;
|
||||
table.LogSate=newtable.LogSate;
|
||||
table.IP=newtable.IP;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
public static void DeleteInterFaceLogById (string InterFaceLogId)
|
||||
{
|
||||
|
||||
Model.InterFaceLog table =Funs.DB.InterFaceLog.FirstOrDefault(x=>x.InterFaceLogId==InterFaceLogId);
|
||||
if (table != null)
|
||||
{
|
||||
Funs.DB.InterFaceLog.DeleteOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
using FineUIPro;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
|
||||
public static class InterFaceSetService
|
||||
{
|
||||
|
||||
|
||||
#region 获取列表
|
||||
/// <summary>
|
||||
/// 记录数
|
||||
/// </summary>
|
||||
public static int count
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public static List<Model.InterFaceSet> GetInterFaceSetByModle(Model.InterFaceSet table)
|
||||
{
|
||||
var q= from x in Funs.DB.InterFaceSet
|
||||
where
|
||||
( string.IsNullOrEmpty(table.InterFaceSetId)||x.InterFaceSetId.Contains(table.InterFaceSetId)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceName)||x.InterFaceName.Contains(table.InterFaceName)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceUrl)||x.InterFaceUrl.Contains(table.InterFaceUrl)) &&
|
||||
( string.IsNullOrEmpty(table.UnitId)||x.UnitId.Contains(table.UnitId)) &&
|
||||
( string.IsNullOrEmpty(table.AuthUnitIds)||x.AuthUnitIds.Contains(table.AuthUnitIds)) &&
|
||||
( string.IsNullOrEmpty(table.AuthUnitName)||x.AuthUnitName.Contains(table.AuthUnitName)) &&
|
||||
( string.IsNullOrEmpty(table.ValidPeriod)||x.ValidPeriod.Contains(table.ValidPeriod)) &&
|
||||
( string.IsNullOrEmpty(table.TxtRemarks)||x.TxtRemarks.Contains(table.TxtRemarks)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceForUrl)||x.InterFaceForUrl.Contains(table.InterFaceForUrl)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceCallBackUrl)||x.InterFaceCallBackUrl.Contains(table.InterFaceCallBackUrl))
|
||||
select x
|
||||
;
|
||||
|
||||
return q.ToList();
|
||||
}
|
||||
|
||||
/// 获取分页列表
|
||||
/// </summary>
|
||||
/// <param name="PageIndex">页码</param>
|
||||
/// <param name="PageSize">每页数量</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable getListData(Model.InterFaceSet table, Grid Grid1)
|
||||
{
|
||||
var q= GetInterFaceSetByModle(table);
|
||||
count = q.Count();
|
||||
if (count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// q= q.Take(Grid1.PageSize * Grid1.PageIndex).Skip(Grid1.PageSize * (Grid1.PageIndex)).ToList();
|
||||
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
||||
return from x in q
|
||||
select new
|
||||
{
|
||||
x.InterFaceSetId,
|
||||
x.InterFaceName,
|
||||
x.InterFaceUrl,
|
||||
x.UnitId,
|
||||
x.AuthUnitIds,
|
||||
x.AuthUnitName,
|
||||
x.IsOpen,
|
||||
x.ValidPeriod,
|
||||
x.TxtRemarks,
|
||||
x.InterFaceForUrl,
|
||||
x.IsCallBack,
|
||||
x.InterFaceCallBackUrl,
|
||||
x.UrlReqMethod,
|
||||
x.CallBackUrlReqMethod,
|
||||
x.ForUrlReqMethod
|
||||
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static Model.InterFaceSet GetInterFaceSetById(string InterFaceSetId)
|
||||
{
|
||||
return Funs.DB.InterFaceSet.FirstOrDefault(x=>x.InterFaceSetId==InterFaceSetId);
|
||||
}
|
||||
public static List<Model.InterFaceSet> GetInterFaceSets()
|
||||
{
|
||||
var q = (from x in Funs.DB.InterFaceSet select x).ToList();
|
||||
return q;
|
||||
}
|
||||
|
||||
public static void AddInterFaceSet(Model.InterFaceSet newtable)
|
||||
{
|
||||
|
||||
Model.InterFaceSet table = new Model.InterFaceSet{
|
||||
InterFaceSetId=newtable.InterFaceSetId,
|
||||
InterFaceName=newtable.InterFaceName,
|
||||
InterFaceUrl=newtable.InterFaceUrl,
|
||||
UnitId=newtable.UnitId,
|
||||
AuthUnitIds=newtable.AuthUnitIds,
|
||||
AuthUnitName=newtable.AuthUnitName,
|
||||
IsOpen=newtable.IsOpen,
|
||||
ValidPeriod=newtable.ValidPeriod,
|
||||
TxtRemarks=newtable.TxtRemarks,
|
||||
InterFaceForUrl=newtable.InterFaceForUrl,
|
||||
IsCallBack=newtable.IsCallBack,
|
||||
InterFaceCallBackUrl=newtable.InterFaceCallBackUrl,
|
||||
UrlReqMethod=newtable.UrlReqMethod,
|
||||
ForUrlReqMethod=newtable.ForUrlReqMethod,
|
||||
CallBackUrlReqMethod= newtable.CallBackUrlReqMethod,
|
||||
};
|
||||
Funs.DB.InterFaceSet.InsertOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateInterFaceSet(Model.InterFaceSet newtable)
|
||||
{
|
||||
|
||||
Model.InterFaceSet table = Funs.DB.InterFaceSet.FirstOrDefault(x=>x.InterFaceSetId==newtable.InterFaceSetId);
|
||||
if (table != null)
|
||||
{
|
||||
table.InterFaceSetId=newtable.InterFaceSetId;
|
||||
table.InterFaceName=newtable.InterFaceName;
|
||||
table.InterFaceUrl=newtable.InterFaceUrl;
|
||||
table.UnitId=newtable.UnitId;
|
||||
table.AuthUnitIds=newtable.AuthUnitIds;
|
||||
table.AuthUnitName=newtable.AuthUnitName;
|
||||
table.IsOpen=newtable.IsOpen;
|
||||
table.ValidPeriod=newtable.ValidPeriod;
|
||||
table.TxtRemarks=newtable.TxtRemarks;
|
||||
table.InterFaceForUrl=newtable.InterFaceForUrl;
|
||||
table.IsCallBack=newtable.IsCallBack;
|
||||
table.InterFaceCallBackUrl=newtable.InterFaceCallBackUrl;
|
||||
table.UrlReqMethod=newtable.UrlReqMethod;
|
||||
table.ForUrlReqMethod=newtable.ForUrlReqMethod;
|
||||
table.CallBackUrlReqMethod=newtable.CallBackUrlReqMethod;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
public static void DeleteInterFaceSetById (string InterFaceSetId)
|
||||
{
|
||||
|
||||
Model.InterFaceSet table =Funs.DB.InterFaceSet.FirstOrDefault(x=>x.InterFaceSetId==InterFaceSetId);
|
||||
if (table != null)
|
||||
{
|
||||
Funs.DB.InterFaceSet.DeleteOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
public static void InitInterFaceDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
|
||||
{
|
||||
dropName.DataValueField = "InterFaceSetId";
|
||||
dropName.DataTextField = "InterFaceName";
|
||||
dropName.DataSource = GetInterFaceSets();
|
||||
dropName.DataBind();
|
||||
if (isShowPlease)
|
||||
{
|
||||
Funs.FineUIPleaseSelect(dropName);
|
||||
}
|
||||
}
|
||||
public static ListItem[] GetReqMethod()
|
||||
{
|
||||
ListItem[] listItem = new ListItem[2];
|
||||
listItem[0] = new ListItem("Get", "Get");
|
||||
listItem[1] = new ListItem("Post", "Post");
|
||||
return listItem;
|
||||
}
|
||||
public static void InitReqMethodDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
|
||||
{
|
||||
dropName.DataValueField = "Value";
|
||||
dropName.DataTextField = "Text";
|
||||
dropName.DataSource = GetReqMethod();
|
||||
dropName.DataBind();
|
||||
if (isShowPlease)
|
||||
{
|
||||
Funs.FineUIPleaseSelect(dropName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
using FineUIPro;
|
||||
using Model;
|
||||
using Newtonsoft.Json;
|
||||
using Quartz;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
|
||||
public static class InterFaceTaskService
|
||||
{
|
||||
public static Model.SGGLDB db = Funs.DB;
|
||||
|
||||
|
||||
#region 获取列表
|
||||
/// <summary>
|
||||
/// 记录数
|
||||
/// </summary>
|
||||
public static int count
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public static List<Model.InterFaceTask> GetInterFaceTaskByModle(Model.InterFaceTask table)
|
||||
{
|
||||
var q= from x in db.InterFaceTask
|
||||
where
|
||||
( string.IsNullOrEmpty(table.InterFaceTaskId)||x.InterFaceTaskId.Contains(table.InterFaceTaskId)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceName)||x.InterFaceName.Contains(table.InterFaceName)) &&
|
||||
( string.IsNullOrEmpty(table.InterFaceSetLists)||x.InterFaceSetLists.Contains(table.InterFaceSetLists)) &&
|
||||
( string.IsNullOrEmpty(table.Frequency)||x.Frequency.Contains(table.Frequency)) &&
|
||||
(table.Enable ==null|| x.Enable==table.Enable)
|
||||
select x
|
||||
;
|
||||
|
||||
return q.ToList();
|
||||
}
|
||||
|
||||
/// 获取分页列表
|
||||
/// </summary>
|
||||
/// <param name="PageIndex">页码</param>
|
||||
/// <param name="PageSize">每页数量</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable getListData(Model.InterFaceTask table, Grid Grid1)
|
||||
{
|
||||
var q= GetInterFaceTaskByModle(table);
|
||||
count = q.Count();
|
||||
if (count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// q= q.Take(Grid1.PageSize * Grid1.PageIndex).Skip(Grid1.PageSize * (Grid1.PageIndex)).ToList();
|
||||
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
||||
return from x in q
|
||||
select new
|
||||
{
|
||||
x.InterFaceTaskId,
|
||||
x.InterFaceName,
|
||||
x.InterFaceSetLists,
|
||||
x.Frequency,
|
||||
x.CreateTime,
|
||||
x.Enable,
|
||||
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static Model.InterFaceTask GetInterFaceTaskById(string InterFaceTaskId)
|
||||
{
|
||||
return db.InterFaceTask.FirstOrDefault(x=>x.InterFaceTaskId==InterFaceTaskId);
|
||||
}
|
||||
public static void AddInterFaceTask(Model.InterFaceTask newtable)
|
||||
{
|
||||
|
||||
Model.InterFaceTask table = new Model.InterFaceTask{
|
||||
InterFaceTaskId=newtable.InterFaceTaskId,
|
||||
InterFaceName=newtable.InterFaceName,
|
||||
InterFaceSetLists=newtable.InterFaceSetLists,
|
||||
Frequency=newtable.Frequency,
|
||||
CreateTime=newtable.CreateTime,
|
||||
Enable=newtable.Enable,
|
||||
};
|
||||
db.InterFaceTask.InsertOnSubmit(table);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateInterFaceTask(Model.InterFaceTask newtable)
|
||||
{
|
||||
|
||||
Model.InterFaceTask table = db.InterFaceTask.FirstOrDefault(x=>x.InterFaceTaskId==newtable.InterFaceTaskId);
|
||||
if (table != null)
|
||||
{
|
||||
table.InterFaceTaskId=newtable.InterFaceTaskId;
|
||||
table.InterFaceName=newtable.InterFaceName;
|
||||
table.InterFaceSetLists=newtable.InterFaceSetLists;
|
||||
table.Frequency=newtable.Frequency;
|
||||
table.CreateTime=newtable.CreateTime;
|
||||
table.Enable=newtable.Enable;
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
public static void DeleteInterFaceTaskById (string InterFaceTaskId)
|
||||
{
|
||||
|
||||
Model.InterFaceTask table =db.InterFaceTask.FirstOrDefault(x=>x.InterFaceTaskId==InterFaceTaskId);
|
||||
if (table != null)
|
||||
{
|
||||
db.InterFaceTask.DeleteOnSubmit(table);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
#region 执行任务
|
||||
public static void ExecuteTasks(string InterFaceTaskId)
|
||||
{
|
||||
|
||||
var model = GetInterFaceTaskById(InterFaceTaskId);
|
||||
var InterFaceSetlIds = model.InterFaceSetLists.Split(',');
|
||||
foreach (var item in InterFaceSetlIds)
|
||||
{
|
||||
ExecuteTasksByInterFaceSetlId(item);
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行接口
|
||||
/// </summary>
|
||||
/// <param name="InterFaceSetlId">接口id </param>
|
||||
public static void ExecuteTasksByInterFaceSetlId(string InterFaceSetlId)
|
||||
{
|
||||
var InterfaceSetModel = InterFaceSetService.GetInterFaceSetById(InterFaceSetlId);
|
||||
if (InterfaceSetModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
var sourseData = GetSourseData(InterfaceSetModel.InterFaceUrl, InterfaceSetModel.UrlReqMethod);
|
||||
bool sourseisSuccess = false;
|
||||
if (sourseData.code == 1)
|
||||
{
|
||||
sourseisSuccess = true;
|
||||
}
|
||||
InterFaceLogService.WriteInterFaceLog(InterFaceSetlId, "", JsonConvert.SerializeObject(sourseData), InterFaceLogService.Type1, sourseisSuccess);
|
||||
if (sourseData.code == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var TargetData = GetTargetData(InterfaceSetModel.InterFaceForUrl, sourseData, InterfaceSetModel.ForUrlReqMethod);
|
||||
|
||||
bool TargetisSuccess = false;
|
||||
if (TargetData.code == 1)
|
||||
{
|
||||
TargetisSuccess = true;
|
||||
}
|
||||
InterFaceLogService.WriteInterFaceLog(InterFaceSetlId, JsonConvert.SerializeObject(sourseData.data), JsonConvert.SerializeObject(TargetData), InterFaceLogService.Type2, TargetisSuccess);
|
||||
|
||||
if (TargetData.code == 0 || InterfaceSetModel.IsCallBack == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var callbackData = ExecuteCallBack(InterfaceSetModel.InterFaceCallBackUrl, sourseData, InterfaceSetModel.CallBackUrlReqMethod);
|
||||
|
||||
bool CallBackisSuccess = false;
|
||||
if (TargetData.code == 1)
|
||||
{
|
||||
CallBackisSuccess = true;
|
||||
}
|
||||
InterFaceLogService.WriteInterFaceLog(InterFaceSetlId, JsonConvert.SerializeObject(sourseData.data), JsonConvert.SerializeObject(callbackData), InterFaceLogService.Type3, CallBackisSuccess);
|
||||
|
||||
}
|
||||
catch (Exception ex )
|
||||
{
|
||||
Model.InterFaceLog interFaceLog=new InterFaceLog();
|
||||
interFaceLog.InterFaceLogId=Guid.NewGuid().ToString();
|
||||
interFaceLog.InterFaceType = "异常";
|
||||
interFaceLog.LogSate = false;
|
||||
interFaceLog.InterFaceLogDate= DateTime.Now;
|
||||
interFaceLog.InterFaceName = InterfaceSetModel.InterFaceName;
|
||||
interFaceLog.InterFaceReturnData = ex.ToString();
|
||||
InterFaceLogService.AddInterFaceLog(interFaceLog);
|
||||
}
|
||||
|
||||
}
|
||||
public static Model.ReturnData GetSourseData(string baseurl,string ReqMethod)
|
||||
{
|
||||
Model.ReturnData returnData = new ReturnData();
|
||||
string token = "C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0";
|
||||
string Content = "";
|
||||
switch (ReqMethod)
|
||||
{
|
||||
case "Get":
|
||||
Content = Funs.RequestGet(baseurl, token);
|
||||
break;
|
||||
case "Post":
|
||||
Content = Funs.RequestPost(baseurl, token, "");
|
||||
break;
|
||||
}
|
||||
//var client = new RestClient(baseurl);
|
||||
//client.Timeout = -1;
|
||||
//var request = new RestRequest(Method.POST);
|
||||
//request.AddHeader("token", "AF17168B-87BD-4GLY-1111-F0A0A1158F9B");
|
||||
//IRestResponse response = client.Execute(request);
|
||||
//Console.WriteLine(response.Content);
|
||||
try
|
||||
{
|
||||
returnData = JsonConvert.DeserializeObject<Model.ReturnData>(Content);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
returnData.code = 0;
|
||||
returnData.message = "获取数据失败:" + Content;
|
||||
}
|
||||
|
||||
|
||||
return returnData;
|
||||
}
|
||||
public static Model.ResponeData GetTargetData(string baseurl, ReturnData DataInput, string ReqMethod)
|
||||
{
|
||||
Model.ResponeData responeData = new ResponeData();
|
||||
if (DataInput.code == 1)
|
||||
{
|
||||
|
||||
string token = DataInput.token;
|
||||
string returnContent = "";
|
||||
switch (ReqMethod)
|
||||
{
|
||||
case "Get":
|
||||
returnContent = Funs.RequestGet(baseurl, token);
|
||||
break;
|
||||
case "Post":
|
||||
returnContent = Funs.RequestPost(baseurl, token, JsonConvert.SerializeObject(DataInput.data));
|
||||
break;
|
||||
}
|
||||
//var client = new RestClient(baseurl);
|
||||
//client.Timeout = -1;
|
||||
//if (isPost)
|
||||
//{
|
||||
// var request = new RestRequest(Method.POST);
|
||||
// request.AddHeader("token", DataInput.token);
|
||||
// request.AddJsonBody(JsonConvert.SerializeObject(DataInput.data));
|
||||
// IRestResponse response = client.Execute(request);
|
||||
// returnContent = response.Content;
|
||||
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// var request = new RestRequest(Method.GET);
|
||||
// request.AddHeader("token", DataInput.token);
|
||||
// IRestResponse response = client.Execute(request);
|
||||
// returnContent = response.Content;
|
||||
|
||||
//}
|
||||
try
|
||||
{
|
||||
responeData = JsonConvert.DeserializeObject<Model.ResponeData>(returnContent);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "推送数据失败:" + returnContent;
|
||||
|
||||
}
|
||||
return responeData;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
return responeData;
|
||||
}
|
||||
public static ReturnData ExecuteCallBack(string baseurl, ReturnData DataInput,string ReqMethod)
|
||||
{
|
||||
Model.ReturnData returnData = new ReturnData();
|
||||
if (DataInput.code == 1)
|
||||
{
|
||||
string token = "AF17168B-87BD-4GLY-1111-F0A0A1158F9B";
|
||||
string Content = "";
|
||||
switch (ReqMethod)
|
||||
{
|
||||
case "Get":
|
||||
Content = Funs.RequestGet(baseurl, token);
|
||||
break;
|
||||
case "Post":
|
||||
Content = Funs.RequestPost(baseurl, token, JsonConvert.SerializeObject(DataInput.data));
|
||||
break;
|
||||
}
|
||||
|
||||
//var client = new RestClient(baseurl);
|
||||
//client.Timeout = -1;
|
||||
//var request = new RestRequest(Method.POST);
|
||||
//request.AddHeader("token", "AF17168B-87BD-4GLY-1111-F0A0A1158F9B");
|
||||
//request.AddJsonBody(JsonConvert.SerializeObject(DataInput.data));
|
||||
//IRestResponse response = client.Execute(request);
|
||||
//returnContent = response.Content;
|
||||
try
|
||||
{
|
||||
returnData = JsonConvert.DeserializeObject<Model.ReturnData>(Content);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
returnData.code = 0;
|
||||
returnData.message = "回调失败:" + Content;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user