| | |
| | | using AutoMapper.Execution; |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | |
| | | this.BaseDal = BaseDal; |
| | | } |
| | | |
| | | public TRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 |
| | | public TRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 |
| | | |
| | | public ISqlSugarClient Db => BaseDal.Db; |
| | | |
| | |
| | | } |
| | | if (EnableWebOrderBy) |
| | | { |
| | | //获取排序字段 |
| | | //获取排序字段 |
| | | Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties); |
| | | |
| | | foreach (var item in orderbyDic) |
| | |
| | | |
| | | |
| | | parameter = parameter ?? Expression.Parameter(typeof(TEntity), "x"); |
| | | //创建节点的属性p=>p.name 属性name |
| | | //创建节点的属性p=>p.name 属性name |
| | | MemberExpression memberProperty = Expression.PropertyOrField(parameter, propertyName); |
| | | |
| | | if (expressionType == LinqExpressionType.In) |
| | |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("属性值类型不正确"); |
| | | throw new Exception("属性值类型不正确"); |
| | | } |
| | | } |
| | | // |
| | |
| | | |
| | | //if (isStringValue) |
| | | //{ |
| | | // //string 类型的字段,如果值带有'单引号,EF会默认变成''两个单引号 |
| | | // //string 类型的字段,如果值带有'单引号,EF会默认变成''两个单引号 |
| | | // MethodInfo method = typeof(System.Collections.IList).GetMethod("Contains"); |
| | | // //创建集合常量并设置为常量的值 |
| | | // //创建集合常量并设置为常量的值 |
| | | // ConstantExpression constantCollection = Expression.Constant(list); |
| | | // //创建一个表示调用带参数的方法的:new string[]{"1","a"}.Contains("a"); |
| | | // //创建一个表示调用带参数的方法的:new string[]{"1","a"}.Contains("a"); |
| | | // MethodCallExpression methodCall = Expression.Call(constantCollection, method, memberProperty); |
| | | // return Expression.Lambda<Func<TEntity, bool>>(methodCall, parameter); |
| | | //} |
| | | //非string字段,按上面方式处理报异常Null TypeMapping in Sql Tree |
| | | //非string字段,按上面方式处理报异常Null TypeMapping in Sql Tree |
| | | BinaryExpression body = null; |
| | | foreach (var values in list) |
| | | { |
| | |
| | | ConstantExpression constant = proType.ToString() == "System.String" |
| | | ? Expression.Constant(propertyValue) : Expression.Constant(value.ChangeType(proType)); |
| | | |
| | | // DateTime只选择了日期的时候自动在结束日期加一天,修复DateTime类型使用日期区间查询无法查询到结束日期的问题 |
| | | // DateTime只选择了日期的时候自动在结束日期加一天,修复DateTime类型使用日期区间查询无法查询到结束日期的问题 |
| | | if ((proType == typeof(DateTime) || proType == typeof(DateTime?)) && expressionType == LinqExpressionType.LessThanOrEqual && value.Length == 10) |
| | | { |
| | | constant = Expression.Constant(Convert.ToDateTime(value).AddDays(1)); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取排序字段 |
| | | /// 获取排序字段 |
| | | /// </summary> |
| | | /// <param name="pageData"></param> |
| | | /// <param name="propertyInfo"></param> |
| | |
| | | // { |
| | | // UserRole? userRole = PermissionDataHostService.UserRoles.FirstOrDefault(x => x.UserId == App.User.UserId); |
| | | // if (userRole == null) |
| | | // throw new Exception($"无权限"); |
| | | // throw new Exception($"无权限"); |
| | | |
| | | // if (type.IsAssignableFrom(typeof(BaseWarehouseEntity)) || type.GetProperty(nameof(BaseWarehouseEntity.WarehouseId)) != null) |
| | | // { |
| | |
| | | |
| | | // //UserRole? userRole = PermissionDataHostService.UserRoles.FirstOrDefault(x => x.UserId == App.User.UserId); |
| | | // //if (userRole == null) |
| | | // // throw new Exception($"无权限"); |
| | | // // throw new Exception($"无权限"); |
| | | |
| | | // //if (userRole.AuthorityScope == (int)AuthorityScopeEnum.CurrentRole) |
| | | // //{ |
| | |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // throw new Exception($"无权限,{ex.Message}"); |
| | | // throw new Exception($"无权限,{ex.Message}"); |
| | | // } |
| | | //} |
| | | |
| | |
| | | |
| | | if (pageData.Value == null) return new PageGridData<object>(total: 0, null); |
| | | string keyName = t.GetKeyName(); |
| | | ////生成查询条件 |
| | | ////生成查询条件 |
| | | //Expression<Func<TEntity, bool>> whereExpression = keyName.CreateExpression<TEntity>(pageData.Value, LinqExpressionType.Equal); |
| | | int totalCount = 0; |
| | | PropertyInfo propertyInfo = t.GetProperties().FirstOrDefault(x => x.GetCustomAttribute<Navigate>() != null); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加数据 |
| | | /// 添加数据 |
| | | /// </summary> |
| | | /// <param name="entity">单个实体</param> |
| | | /// <param name="entity">单个实体</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent AddData(TEntity entity) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加数据 |
| | | /// 添加数据 |
| | | /// </summary> |
| | | /// <param name="entities">实体集合</param> |
| | | /// <param name="entities">实体集合</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent AddData(List<TEntity> entities) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加数据 |
| | | /// 添加数据 |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | |
| | | { |
| | | try |
| | | { |
| | | if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//判断参数是否传入 |
| | | if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//判断参数是否传入 |
| | | { |
| | | return WebResponseContent.Instance.Error("传参错误,参数不能为空"); |
| | | return WebResponseContent.Instance.Error("传参错误,参数不能为空"); |
| | | } |
| | | string validResult = typeof(TEntity).ValidateDicInEntity(saveModel.MainData, true, TProperties); |
| | | |
| | |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | if (keyPro == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("请先设置主键"); |
| | | return WebResponseContent.Instance.Error("请先设置主键"); |
| | | } |
| | | if (keyPro.PropertyType == typeof(Guid)) |
| | | { |
| | |
| | | |
| | | if (typeof(TEntity).GetNavigatePro() == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("未配置导航属性"); |
| | | return WebResponseContent.Instance.Error("未配置导航属性"); |
| | | } |
| | | |
| | | Type detailType = typeof(TEntity).GetDetailType(); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改数据 |
| | | /// 修改数据 |
| | | /// </summary> |
| | | /// <param name="entity">单个实体</param> |
| | | /// <param name="entity">单个实体</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent UpdateData(TEntity entity) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改数据 |
| | | /// 修改数据 |
| | | /// </summary> |
| | | /// <param name="entities">实体集合</param> |
| | | /// <param name="entities">实体集合</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent UpdateData(List<TEntity> entities) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改数据 |
| | | /// 修改数据 |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | |
| | | try |
| | | { |
| | | List<string>? list = UpdateIgnoreColOnExecute?.Invoke(saveModel); |
| | | if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//判断参数是否传入 |
| | | if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//判断参数是否传入 |
| | | { |
| | | return WebResponseContent.Instance.Error("传参错误,参数不能为空"); |
| | | return WebResponseContent.Instance.Error("传参错误,参数不能为空"); |
| | | } |
| | | string validResult = typeof(TEntity).ValidateDicInEntity(saveModel.MainData, false, TProperties, list?.ToArray() ?? null); |
| | | |
| | |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | if (keyPro == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("请先设置主键"); |
| | | return WebResponseContent.Instance.Error("请先设置主键"); |
| | | } |
| | | |
| | | TEntity entity = saveModel.MainData.DicToModel<TEntity>(); |
| | |
| | | |
| | | if (typeof(TEntity).GetNavigatePro() == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("未配置导航属性"); |
| | | return WebResponseContent.Instance.Error("未配置导航属性"); |
| | | } |
| | | |
| | | Type detailType = typeof(TEntity).GetDetailType(); |
| | |
| | | } |
| | | else |
| | | { |
| | | content = WebResponseContent.Instance.Error("未找到主表主键值"); |
| | | content = WebResponseContent.Instance.Error("未找到主表主键值"); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除数据 |
| | | /// 删除数据 |
| | | /// </summary> |
| | | /// <param name="key">主键</param> |
| | | /// <param name="key">主键</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(object key) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除数据 |
| | | /// 删除数据 |
| | | /// </summary> |
| | | /// <param name="keys">主键数组</param> |
| | | /// <param name="keys">主键数组</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(object[] keys) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("参数错误"); |
| | | return WebResponseContent.Instance.Error("参数错误"); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除数据 |
| | | /// 删除数据 |
| | | /// </summary> |
| | | /// <param name="entity">单个实体</param> |
| | | /// <param name="entity">单个实体</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(TEntity entity) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除数据 |
| | | /// 删除数据 |
| | | /// </summary> |
| | | /// <param name="entities">实体集合</param> |
| | | /// <param name="entities">实体集合</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(List<TEntity> entities) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导出数据 |
| | | /// 导出数据 |
| | | /// </summary> |
| | | /// <param name="pageData"></param> |
| | | /// <returns></returns> |
| | |
| | | string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelExport"; |
| | | IExporter exporter = new ExcelExporter(); |
| | | string wheres = options.ValidatePageOptions(TProperties); |
| | | //获取排序字段 |
| | | //获取排序字段 |
| | | Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(TProperties); |
| | | |
| | | List<TEntity> entities = BaseDal.QueryData(wheres, orderbyDic); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导入数据 |
| | | /// 导入数据 |
| | | /// </summary> |
| | | /// <param name="files"></param> |
| | | /// <returns></returns> |
| | |
| | | try |
| | | { |
| | | if (files == null || files.Count == 0) |
| | | return new WebResponseContent { Status = true, Message = "请选择上传的文件" }; |
| | | return new WebResponseContent { Status = true, Message = "请选择上传的文件" }; |
| | | Microsoft.AspNetCore.Http.IFormFile formFile = files[0]; |
| | | string dicPath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprot/{DateTime.Now.ToString("yyyMMdd")}/{typeof(TEntity).Name}/"; |
| | | if (!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传文件 |
| | | /// 上传文件 |
| | | /// </summary> |
| | | /// <param name="files"></param> |
| | | /// <returns></returns> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 模板下载 |
| | | /// 模板下载 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DownLoadTemplate() |
| | |
| | | SugarTable sugarTable = t.GetCustomAttribute<SugarTable>(); |
| | | if (sugarTable != null) |
| | | { |
| | | fileName = sugarTable.TableDescription + "导入模板.xlsx"; |
| | | fileName = sugarTable.TableDescription + "导入模板.xlsx"; |
| | | } |
| | | else |
| | | { |
| | | fileName = nameof(TEntity) + "导入模板.xlsx"; |
| | | fileName = nameof(TEntity) + "导入模板.xlsx"; |
| | | } |
| | | string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprotTemplate"; |
| | | FileHelper.WriteFile(savePath, fileName, data); |