123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- 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
- {
- /// <summary>
- /// Service类下的Extensions
- /// </summary>
- public static class ServiceBaseExtensions
- {
- /// <summary>
- /// 获取DB仓储仓储
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="dataRepositoryContext"></param>
- /// <returns></returns>
- public static IDataRepository<T> GetDataRepository<T>(this IDataRepositoryContext dataRepositoryContext) where T : class
- {
- return new DataRepository<T>(dataRepositoryContext);
- }
- /// <summary>
- /// 获取服务时间
- /// </summary>
- /// <returns></returns>
- public static DateTime GetServiceNowTime(this IDataRepositoryContext dataRepositoryContext)
- {
- var result = dataRepositoryContext.GetDataRepository<NowTimeModel>().
- Query("select Now=getdate()").FirstOrDefault();
- return result.Now;
- }
- #region FieldKeyInfo
- /// <summary>
- /// 新增字段信息T
- /// </summary>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo> AddFieldKeyInfo(this List<FieldKeyInfo> 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;
- }
- /// <summary>
- /// 新增字段信息T
- /// </summary>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo> AddFieldKeyInfo(this List<FieldKeyInfo> 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;
- }
- /// <summary>
- /// 新增字段信息T
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <param name="operation"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo<T>> AddFieldKeyInfo<T>(this List<FieldKeyInfo<T>> fieldKeyList, string key, object value,
- EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal) where T : class
- {
- fieldKeyList.Add(new FieldKeyInfo<T>
- {
- FieldName = key,
- Value = value,
- Operation = operation,
- FileType = cSharpPropertyType,
- WhereItemType = EnumSelectWhereType.And
- });
- return fieldKeyList;
- }
- /// <summary>
- /// 追加字段Key信息T
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <param name="operation"></param>
- /// <param name="isToAdd"></param>
- /// <param name="groupIndex"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo<T>> AddFieldKeyInfo<T>(this List<FieldKeyInfo<T>> fieldKeyList, string key, object value,
- EnumCSharpPropertyType cSharpPropertyType, string operation = DBOperationString._Equal, bool isToAdd = true) where T : class
- {
- if (isToAdd)
- fieldKeyList.Add(new FieldKeyInfo<T>
- {
- FieldName = key,
- Value = value,
- Operation = operation,
- FileType = cSharpPropertyType,
- WhereItemType = EnumSelectWhereType.And
- });
- return fieldKeyList;
- }
- /// <summary>
- /// 追加字段Key信息T
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <param name="operation"></param>
- /// <param name="selectWhereType"></param>
- /// <param name="isToAdd"></param>
- /// <param name="groupIndex"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo<T>> AddFieldKeyInfo<T>(this List<FieldKeyInfo<T>> 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<T>
- {
- FieldName = key,
- Value = value,
- Operation = operation,
- GroupIndex = groupIndex,
- FileType = cSharpPropertyType,
- WhereItemType = selectWhereType
- });
- return fieldKeyList;
- }
- /// <summary>
- /// 追加字段Key信息T
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <param name="operation"></param>
- /// <param name="selectWhereType"></param>
- /// <param name="isToAdd"></param>
- /// <param name="groupIndex"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo<T>> AddFieldKeyInfo<T>(this List<FieldKeyInfo<T>> 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<T>
- {
- FieldName = key,
- Value = value,
- Operation = operation,
- GroupIndex = groupIndex,
- FileType = cSharpPropertyType,
- WhereItemType = selectWhereType
- });
- return fieldKeyList;
- }
- /// <summary>
- /// 追加字段Key信息
- /// </summary>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <param name="operation"></param>
- /// <param name="isToAdd"></param>
- /// <param name="groupIndex"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo> AddFieldKeyInfo(this List<FieldKeyInfo> 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;
- }
- /// <summary>
- /// 追加字段Key信息
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <param name="value"></param>
- /// <param name="cSharpPropertyType"></param>
- /// <param name="operation"></param>
- /// <param name="isToAdd"></param>
- /// <param name="groupIndex"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo> AddFieldKeyInfo(this List<FieldKeyInfo> 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;
- }
- /// <summary>
- /// 移除字段Key信息
- /// </summary>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo> RemoveFieldKeyInfo(this List<FieldKeyInfo> fieldKeyList, string key)
- {
- var result = fieldKeyList.Where(m => m.FieldName == key).FirstOrDefault();
- fieldKeyList.Remove(result);
- return fieldKeyList;
- }
- /// <summary>
- /// 移除字段Key信息T
- /// </summary>
- /// <param name="fieldKeyList"></param>
- /// <param name="key"></param>
- /// <returns></returns>
- public static List<FieldKeyInfo<T>> RemoveFieldKeyInfo<T>(this List<FieldKeyInfo<T>> fieldKeyList, string key) where T : class
- {
- var result = fieldKeyList.Where(m => m.FieldName == key).FirstOrDefault();
- fieldKeyList.Remove(result);
- return fieldKeyList;
- }
- #endregion
- }
- }
|