chore: 初始化合力差速器MES采集程序
This commit is contained in:
76
Common/02WebApiCall/WebApi/Helpers/LogHelper.cs
Normal file
76
Common/02WebApiCall/WebApi/Helpers/LogHelper.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DataLinkMesWork;
|
||||
|
||||
|
||||
namespace WebApi.Helpers
|
||||
{
|
||||
public class LogHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// UUID生成
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string UuidUtil()
|
||||
{
|
||||
string result = Guid.NewGuid().ToString();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void ShowMsg(string msg)
|
||||
{
|
||||
MyLog4Net.MyLogHelper.Error("WebApi", msg);
|
||||
}
|
||||
|
||||
public static int SaveWebApiReqLogo(string url, string JSON)
|
||||
{
|
||||
int AID = -1;
|
||||
try
|
||||
{
|
||||
//存储日志
|
||||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
|
||||
string procedureName = "接口_IOT接口交互日志_请求记录";
|
||||
SqlParameter[] thisParms = new SqlParameter[4];
|
||||
thisParms[0] = new System.Data.SqlClient.SqlParameter("@接口地址", url);
|
||||
thisParms[1] = new System.Data.SqlClient.SqlParameter("@接口类型", 2);
|
||||
thisParms[2] = new System.Data.SqlClient.SqlParameter("@请求内容", JSON);
|
||||
thisParms[3] = new System.Data.SqlClient.SqlParameter("@请求时间", CreateTime);
|
||||
SQLCommon.ExecuteStoredProcedure(procedureName, ApplicationConfig.ConnectionString_MES, out DataTable dt, out string errorMessage);
|
||||
// DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out DataTable dt);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
AID = Convert.ToInt32(dt.Rows[0]["AID"]);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return AID;
|
||||
}
|
||||
|
||||
public static void SaveWebApiResLogo(int AID, string JSON)
|
||||
{
|
||||
try
|
||||
{
|
||||
//存储日志
|
||||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
string procedureName = "接口_IOT接口交互日志_响应记录";
|
||||
SqlParameter[] thisParms = new SqlParameter[3];
|
||||
thisParms[0] = new System.Data.SqlClient.SqlParameter("@AID", AID);
|
||||
thisParms[1] = new System.Data.SqlClient.SqlParameter("@响应时间", CreateTime);
|
||||
thisParms[2] = new System.Data.SqlClient.SqlParameter("@响应内容", JSON);
|
||||
DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out DataTable dt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
98
Common/02WebApiCall/WebApi/Helpers/ValidationHelper.cs
Normal file
98
Common/02WebApiCall/WebApi/Helpers/ValidationHelper.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace WebApi.Helpers
|
||||
{
|
||||
public class ValidationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证对象的必填字段
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要验证的对象类型</typeparam>
|
||||
/// <param name="obj">要验证的对象</param>
|
||||
/// <param name="errorMessage">错误信息</param>
|
||||
/// <returns>验证是否通过</returns>
|
||||
public static bool ValidateRequired<T>(T obj, out string errorMessage)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
if (obj == null)
|
||||
{
|
||||
errorMessage = "对象不能为空";
|
||||
return false;
|
||||
}
|
||||
|
||||
var properties = typeof(T).GetProperties();
|
||||
foreach (var prop in properties)
|
||||
{
|
||||
var value = prop.GetValue(obj);
|
||||
if (value == null)
|
||||
{
|
||||
errorMessage = $"【{prop.Name}不能为空】";
|
||||
return false;
|
||||
}
|
||||
//else if (prop.PropertyType == typeof(int) && (int)value == 0)
|
||||
//{
|
||||
// errorMessage = $"【{prop.Name}不能为0】";
|
||||
// return false;
|
||||
//}
|
||||
else if (prop.PropertyType == typeof(string) && string.IsNullOrEmpty((string)value))
|
||||
{
|
||||
errorMessage = $"【{prop.Name}不能为空】";
|
||||
return false;
|
||||
}
|
||||
else if (prop.PropertyType == typeof(object) && (object)value == null)
|
||||
{
|
||||
errorMessage = $"【{prop.Name}不能为空】";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证对象的指定字段
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要验证的对象类型</typeparam>
|
||||
/// <param name="obj">要验证的对象</param>
|
||||
/// <param name="propertyNames">要验证的属性名列表</param>
|
||||
/// <param name="errorMessage">错误信息</param>
|
||||
/// <returns>验证是否通过</returns>
|
||||
public static bool ValidateProperties<T>(T obj, string[] propertyNames, out string errorMessage)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
if (obj == null)
|
||||
{
|
||||
errorMessage = "对象不能为空";
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var propName in propertyNames)
|
||||
{
|
||||
var prop = typeof(T).GetProperty(propName);
|
||||
if (prop == null) continue;
|
||||
|
||||
var value = prop.GetValue(obj);
|
||||
if (value == null)
|
||||
{
|
||||
errorMessage = $"【{propName}不能为空】";
|
||||
return false;
|
||||
}
|
||||
//else if (prop.PropertyType == typeof(int) && (int)value == 0)
|
||||
//{
|
||||
// errorMessage = $"【{propName}不能为0】";
|
||||
// return false;
|
||||
//}
|
||||
else if (prop.PropertyType == typeof(string) && string.IsNullOrEmpty((string)value))
|
||||
{
|
||||
errorMessage = $"【{propName}不能为空】";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user