id生成方式改为注入方式
This commit is contained in:
parent
a1dbd33400
commit
6eee371cdf
|
|
@ -1,12 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Nirvana.Common
|
||||
{
|
||||
public static partial class Ext
|
||||
{
|
||||
#region 数值转换
|
||||
|
||||
/// <summary>
|
||||
/// 转换为整型
|
||||
/// </summary>
|
||||
|
|
@ -68,6 +67,7 @@ namespace Nirvana.Common
|
|||
double result;
|
||||
return double.TryParse(data.ToString(), out result) ? result : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为float
|
||||
/// </summary>
|
||||
|
|
@ -176,9 +176,10 @@ namespace Nirvana.Common
|
|||
return Math.Round(result.Value, digits);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion 数值转换
|
||||
|
||||
#region 日期转换
|
||||
|
||||
/// <summary>
|
||||
/// 转换为日期
|
||||
/// </summary>
|
||||
|
|
@ -205,6 +206,7 @@ namespace Nirvana.Common
|
|||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 时间格式化,带时分,如果同一年则不显示年,否则显示年份
|
||||
/// </summary>
|
||||
|
|
@ -240,9 +242,11 @@ namespace Nirvana.Common
|
|||
return result.ToString("M-d");
|
||||
return result.ToString("yyyy-M-d");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion 日期转换
|
||||
|
||||
#region 布尔转换
|
||||
|
||||
/// <summary>
|
||||
/// 转换为布尔值
|
||||
/// </summary>
|
||||
|
|
@ -267,16 +271,22 @@ namespace Nirvana.Common
|
|||
{
|
||||
case "0":
|
||||
return false;
|
||||
|
||||
case "1":
|
||||
return true;
|
||||
|
||||
case "是":
|
||||
return true;
|
||||
|
||||
case "否":
|
||||
return false;
|
||||
|
||||
case "yes":
|
||||
return true;
|
||||
|
||||
case "no":
|
||||
return false;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
@ -300,9 +310,46 @@ namespace Nirvana.Common
|
|||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion 布尔转换
|
||||
|
||||
#region Guid转换
|
||||
|
||||
/// <summary>
|
||||
/// 转换为Guid
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static Guid ToGuid(this object data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
Guid result;
|
||||
bool isValid = Guid.TryParse(data.ToString(), out result);
|
||||
if (isValid)
|
||||
return result;
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为Guid
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static Guid ToGuid(this Guid? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
return data.Value;
|
||||
}
|
||||
|
||||
#endregion Guid转换
|
||||
|
||||
#region 字符串转换
|
||||
|
||||
/// <summary>
|
||||
/// 转换为字符串
|
||||
/// </summary>
|
||||
|
|
@ -311,6 +358,7 @@ namespace Nirvana.Common
|
|||
{
|
||||
return data == null ? string.Empty : data.ToString().Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 针对可能为空的字符串处理
|
||||
/// </summary>
|
||||
|
|
@ -318,7 +366,7 @@ namespace Nirvana.Common
|
|||
/// <returns></returns>
|
||||
public static string ToStr(this string data)
|
||||
{
|
||||
return string.IsNullOrEmpty(data) ? string.Empty : data.Replace(" ","");
|
||||
return string.IsNullOrEmpty(data) ? string.Empty : data.Replace(" ", "");
|
||||
}
|
||||
|
||||
public static string ToStrEmpty(this string data)
|
||||
|
|
@ -326,7 +374,7 @@ namespace Nirvana.Common
|
|||
return string.IsNullOrEmpty(data) ? string.Empty : data.Trim();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion 字符串转换
|
||||
|
||||
/// <summary>
|
||||
/// 安全返回值
|
||||
|
|
@ -336,6 +384,7 @@ namespace Nirvana.Common
|
|||
{
|
||||
return value ?? default(T);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为空
|
||||
/// </summary>
|
||||
|
|
@ -344,6 +393,7 @@ namespace Nirvana.Common
|
|||
{
|
||||
return string.IsNullOrWhiteSpace(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为空
|
||||
/// </summary>
|
||||
|
|
@ -354,6 +404,7 @@ namespace Nirvana.Common
|
|||
return true;
|
||||
return IsEmpty(value.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为空
|
||||
/// </summary>
|
||||
|
|
@ -364,6 +415,7 @@ namespace Nirvana.Common
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为空
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using Microsoft.Extensions.Caching.Distributed;
|
|||
using Nirvana.Common;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -33,8 +32,9 @@ namespace Waste.Application.ThirdApiInfo
|
|||
private readonly ICapPublisher _capBus;
|
||||
private readonly IDistributedCache _cahce;
|
||||
private readonly IResultService _resultService;
|
||||
private readonly IDistributedIDGenerator _idgen;
|
||||
|
||||
public OpenService(ISqlSugarRepository<W_Device> sqlSugarRepository, ISuZhouService suZhouService, ILoggerService loggerService, ICapPublisher capPublisher, IDistributedCache distributedCache, IResultService resultService)
|
||||
public OpenService(ISqlSugarRepository<W_Device> sqlSugarRepository, ISuZhouService suZhouService, ILoggerService loggerService, ICapPublisher capPublisher, IDistributedCache distributedCache, IResultService resultService, IDistributedIDGenerator distributedIDGenerator)
|
||||
{
|
||||
repository = sqlSugarRepository;
|
||||
dbClient = repository.Context;
|
||||
|
|
@ -43,6 +43,7 @@ namespace Waste.Application.ThirdApiInfo
|
|||
_capBus = capPublisher;
|
||||
_cahce = distributedCache;
|
||||
_resultService = resultService;
|
||||
_idgen = distributedIDGenerator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -68,7 +69,7 @@ namespace Waste.Application.ThirdApiInfo
|
|||
{
|
||||
var insertdata = new W_ResultExt
|
||||
{
|
||||
Id = IDGen.NextID(),
|
||||
Id = _idgen.Create().ToGuid(),
|
||||
Status = data.status,
|
||||
CreateTime = DateTime.Now,
|
||||
ResultId = resultid
|
||||
|
|
@ -146,7 +147,7 @@ namespace Waste.Application.ThirdApiInfo
|
|||
}
|
||||
var returndata = new GetDevInfoResponseDto
|
||||
{
|
||||
ResultId = IDGen.NextID(),
|
||||
ResultId = _idgen.Create().ToGuid(),
|
||||
UserId = UserId,
|
||||
PostUrl = ApiUrl
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue