using DapperORMCore.Context.DataContext; using DapperORMCore.Dapper; using DapperORMCore.Dapper.BaseModel; using DapperORMCore.Model.BaseModel; using DapperORMCore.Repository.IRepositories; using DapperORMCore.String.Consts; using DapperORMCore.String.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using WestDistance.DapperORM.Repository.Repositorys; namespace NXWMS.Code { /// /// Service类下的Extensions /// public static class ServiceBaseExtensions { /// /// 获取DB仓储仓储 /// /// /// /// public static IDataRepository GetDataRepository(this IDataRepositoryContext dataRepositoryContext) where T : class { return new DataRepository(dataRepositoryContext); } /// /// 获取服务时间 /// /// public static DateTime GetServiceNowTime(this IDataRepositoryContext dataRepositoryContext) { var result = dataRepositoryContext.GetDataRepository(). Query("select Now=getdate()").FirstOrDefault(); return result.Now; } #region FieldKeyInfo /// /// 新增字段信息T /// /// /// /// /// public static List AddFieldKeyInfo(this List fieldKeyList, string key, object value) { var type = EnumCSharpPropertyType.STRING; switch (value.GetType().Name) { case "System.String": break; case "System.Int32": type = EnumCSharpPropertyType.INT; break; case "System.Double": type = EnumCSharpPropertyType.DOUBLE; break; case "System.Single": type = EnumCSharpPropertyType.FLOAT; break; case "System.Boolean": type = EnumCSharpPropertyType.BOOL; break; case "System.DateTime": type = EnumCSharpPropertyType.DATE; break; case "System.Decimal": type = EnumCSharpPropertyType.DECIMAL; break; } fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = DBOperationString._Equal, FileType = type, WhereItemType = EnumSelectWhereType.And }); return fieldKeyList; } /// /// 新增字段信息T /// /// /// /// /// /// public static List AddFieldKeyInfo(this List fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType) { fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = DBOperationString._Equal, FileType = cSharpPropertyType, WhereItemType = EnumSelectWhereType.And }); return fieldKeyList; } /// /// 新增字段信息T /// /// /// /// /// /// /// /// public static List> AddFieldKeyInfo(this List> fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal) where T : class { fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = operation, FileType = cSharpPropertyType, WhereItemType = EnumSelectWhereType.And }); return fieldKeyList; } /// /// 追加字段Key信息T /// /// /// /// /// /// /// /// /// /// public static List> AddFieldKeyInfo(this List> fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal, bool isToAdd = true) where T : class { if (isToAdd) fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = operation, FileType = cSharpPropertyType, WhereItemType = EnumSelectWhereType.And }); return fieldKeyList; } /// /// 追加字段Key信息T /// /// /// /// /// /// /// /// /// /// /// public static List> AddFieldKeyInfo(this List> fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal, EnumSelectWhereType selectWhereType = EnumSelectWhereType.And, int groupIndex = -1) where T : class { fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = operation, GroupIndex = groupIndex, FileType = cSharpPropertyType, WhereItemType = selectWhereType }); return fieldKeyList; } /// /// 追加字段Key信息T /// /// /// /// /// /// /// /// /// /// /// public static List> AddFieldKeyInfo(this List> fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal, EnumSelectWhereType selectWhereType = EnumSelectWhereType.And, int groupIndex = -1, bool isToAdd = true) where T : class { if (isToAdd) fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = operation, GroupIndex = groupIndex, FileType = cSharpPropertyType, WhereItemType = selectWhereType }); return fieldKeyList; } /// /// 追加字段Key信息 /// /// /// /// /// /// /// /// /// public static List AddFieldKeyInfo(this List fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal, EnumSelectWhereType selectWhereType = EnumSelectWhereType.And, int groupIndex = -1, bool isToAdd = true) { if (isToAdd) fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = operation, GroupIndex = groupIndex, FileType = cSharpPropertyType, WhereItemType = selectWhereType }); return fieldKeyList; } /// /// 追加字段Key信息 /// /// /// /// /// /// /// /// /// /// public static List AddFieldKeyInfo(this List fieldKeyList, string key, object value, EnumCSharpPropertyType cSharpPropertyType, string operation, bool isToAdd) { if (isToAdd) fieldKeyList.Add(new FieldKeyInfo { FieldName = key, Value = value, Operation = operation, FileType = cSharpPropertyType, WhereItemType = EnumSelectWhereType.And }); return fieldKeyList; } /// /// 移除字段Key信息 /// /// /// /// public static List RemoveFieldKeyInfo(this List fieldKeyList, string key) { var result = fieldKeyList.Where(m => m.FieldName == key).FirstOrDefault(); fieldKeyList.Remove(result); return fieldKeyList; } /// /// 移除字段Key信息T /// /// /// /// public static List> RemoveFieldKeyInfo(this List> fieldKeyList, string key) where T : class { var result = fieldKeyList.Where(m => m.FieldName == key).FirstOrDefault(); fieldKeyList.Remove(result); return fieldKeyList; } #endregion } }