2024-05-28 14:36:38 +00:00
|
|
|
|
using DeviceRepair.Models;
|
2024-05-30 15:52:57 +00:00
|
|
|
|
using DeviceRepair.Models.Common;
|
2024-07-22 07:50:10 +00:00
|
|
|
|
using NLog;
|
2024-05-28 14:36:38 +00:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace DeviceRepair.DataAccess
|
|
|
|
|
{
|
|
|
|
|
public class SystemUtil : DbContext<SysConfigInfo>
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
private static readonly Logger log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2024-05-28 14:36:38 +00:00
|
|
|
|
private static SystemUtil manager;
|
|
|
|
|
public static SystemUtil Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (manager == null)
|
|
|
|
|
manager = new SystemUtil();
|
|
|
|
|
return manager;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取附件信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="TableName"></param>
|
|
|
|
|
/// <param name="PrimaryKey"></param>
|
|
|
|
|
/// <param name="PrimaryValue"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public APIResponseData GetAttachment(string TableName, string PrimaryKey, string PrimaryValue)
|
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"获取数据失败!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(TableName))
|
|
|
|
|
throw new Exception("参数TableName的值不能为空!");
|
|
|
|
|
if (string.IsNullOrWhiteSpace(PrimaryKey))
|
|
|
|
|
throw new Exception("参数PrimaryKey的值不能为空!");
|
|
|
|
|
if (string.IsNullOrWhiteSpace(PrimaryValue))
|
|
|
|
|
throw new Exception("参数PrimaryValue的值不能为空!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.db.ChangeDatabase("main");
|
|
|
|
|
List<AttachmentInfo> lst = db.Queryable<AttachmentInfo>().Where(x =>
|
|
|
|
|
x.TableName == TableName && x.PrimaryKey == PrimaryKey && x.PrimaryValue == PrimaryValue && x.Status)?.ToList();
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = lst;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取图片
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="AutoId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public APIResponseData GetAttachmentImg(int AutoId)
|
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"获取数据失败!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
base.db.ChangeDatabase("main");
|
|
|
|
|
AttachmentInfo Data = db.Queryable<AttachmentInfo>().Single(x => x.AutoID == AutoId && x.Status);
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = Data;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取全部数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public APIResponseData GetAll()
|
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"获取数据失败!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
base.db.ChangeDatabase("main");
|
|
|
|
|
List<SysConfigInfo> lst = db.Queryable<SysConfigInfo>()?.ToList();
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Data = lst;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量编辑配置
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Datas"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public APIResponseData EditConfigs(List<SysConfigInfo> Datas)
|
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"获取数据失败!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if ((Datas?.Count ?? 0) == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"未能获取到待修改的配置信息!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.db.ChangeDatabase("main");
|
|
|
|
|
|
|
|
|
|
if (Datas.Count != db.Updateable(Datas).UpdateColumns(x => new { x.Value }).ExecuteCommand())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("修改的配置信息出错!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-28 14:36:38 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
2024-05-30 15:52:57 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取邮箱配置
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ModuleCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public APIResponseData sysEmailConfigByModuleCode(string ModuleCode)
|
|
|
|
|
{
|
|
|
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"获取数据失败!" };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ModuleCode))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"邮件模块编码不能为空!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.db.ChangeDatabase("main");
|
|
|
|
|
SysEmailConfigInfo config = db.Queryable<SysEmailConfigInfo>().First(x => x.MuduleCode == ModuleCode);
|
|
|
|
|
apiResponseData.Code = 1;
|
|
|
|
|
apiResponseData.Message = "";
|
|
|
|
|
apiResponseData.Data = config;
|
|
|
|
|
}
|
|
|
|
|
catch (SqlSugarException ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-30 15:52:57 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-07-22 07:50:10 +00:00
|
|
|
|
log.Error(ex);
|
2024-05-30 15:52:57 +00:00
|
|
|
|
apiResponseData.Code = -1;
|
|
|
|
|
apiResponseData.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return apiResponseData;
|
|
|
|
|
}
|
2024-05-28 14:36:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|