Beispiel #1
0
        public async Task <HandleResult> CreateField(ModelField info)
        {
            var model = await _modelTableService.GetByNum(info.ModelNum);

            if (model == null)
            {
                return(HandleResult.Error("模型不存在"));
            }

            var tableName = $"CMS_U_{model.TableName}";

            var count = 0;

            switch (info.OptionType)
            {
            case ReactFormItemType.RangePicker:
                count += await GetDapper().CreateField($"{info.Name}Start", tableName, info.OptionType);

                count += await GetDapper().CreateField($"{info.Name}End", tableName, info.OptionType);

                break;

            default:
                count = await GetDapper().CreateField(info.Name, tableName, info.OptionType);

                break;
            }

            return(new HandleResult
            {
                IsSuccess = count > 0
            });
        }
Beispiel #2
0
        public async Task <HandleResult> GetCascaderData(string columnNum, string labelFieldName,
                                                         string currentFieldName)
        {
            var data = await GetDictionaryDataByColumnNum(columnNum);

            var resData = new List <CascaderDataType>();

            if (data.Count > 0)
            {
                var firstItem = data[0];
                if (!firstItem.ContainsKey(labelFieldName) ||
                    !firstItem.ContainsKey(currentFieldName))
                {
                    return(HandleResult.Error("无效字段"));
                }

                resData = GetCascaderData(data, "", currentFieldName, labelFieldName);
            }

            return(new HandleResult
            {
                IsSuccess = true,
                Data = resData
            });
        }
Beispiel #3
0
        public async Task <HandleResult> GetFields([FromBody] JObject form)
        {
            string columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("请选择栏目"));
            }

            var column = await _columnService.GetByNum(columnNum);

            if (column == null)
            {
                return(HandleResult.Error("栏目不存在"));
            }
            if (column.ModelNum.IsEmpty())
            {
                return(HandleResult.Error("栏目未绑定模型"));
            }

            return(new HandleResult
            {
                IsSuccess = true,
                Data = new
                {
                    fields = await _columnFieldService.GetByColumnNum(columnNum)
                }
            });
        }
Beispiel #4
0
        public async Task <HandleResult> Export([FromBody] JObject form)
        {
            string columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error());
            }


            var fields = await _columnFieldService.GetByColumnNum(columnNum);

            var dataResp = await _service.PageByColumn(columnNum, new SqlServerPageRequest
            {
                Current = 1,
                Size    = 1000
            });

            if (dataResp.Data.Count() <= 0)
            {
                return(HandleResult.Error("未能查询出数据"));
            }

            var fullPath     = Path.GetFullPath("wwwroot/Export.xls");
            var webPath      = $"/temp/数据导出_{DateTime.Now:yyyyMMddHHmmss}.xls";
            var saveFullPath = Path.GetFullPath($"wwwroot/{webPath}");

            using (var excel = new ExcelUtil(fullPath))
            {
                var column = new ExcelRowItem();

                var columnIndex = 0;
                foreach (var columnField in fields)
                {
                    column.Add(columnField.Explain, excel.GetColumnLetter(columnIndex));
                    columnIndex++;
                }
                excel.SetRowValue(0, column);

                var contentData = dataResp.Data.ToList();

                excel.CirculateLetterSetValue(1, (dataIndex, row) =>
                {
                    var item = contentData[dataIndex];
                    var contentDataColumnIndex = 0;

                    foreach (var columnField in fields)
                    {
                        row.Add(item[columnField.Name].ToStr(), excel.GetColumnLetter(contentDataColumnIndex));
                        contentDataColumnIndex++;
                    }

                    return(contentData.Count - 1 > dataIndex);
                });

                excel.Save(saveFullPath);
            }

            return(HandleResult.Success(webPath));
        }
Beispiel #5
0
        public async Task <HandleResult> FormFields([FromBody] JObject form)
        {
            string columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            string parentNum = form["parentNum"].ToStr();
            int    id        = form["id"].ToInt();
            var    data      = id > 0
                ? await _service.GetById(columnNum, id)
                : new Category
            {
                ParentNum = parentNum,
            };

            if (data == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            return(new HandleResult
            {
                IsSuccess = true,
                Data = new
                {
                    EditData = data,
                    Field = ReactForm.ToFormFields <Category>(data.Id > 0)
                }
            });
        }
Beispiel #6
0
        public async Task <HandleResult> Upload(IFormFile file, IFormCollection form = null)
        {
            string folderPath = Path.GetFullPath($"wwwroot{GetSaveWebFolderPath()}");

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            string fileName = file.FileName;
            string fileExt  = Path.GetExtension(fileName);

            if (ExistBack(fileExt))
            {
                return(HandleResult.Error("非法文件,无法上传"));
            }
            if (!ExistWhite(fileExt))
            {
                return(HandleResult.Error("文件后缀不在可信范围内"));
            }

            string savePath = GetSavePath(folderPath, fileName, fileExt);

            await using (var stream = File.Create(savePath))
            {
                await file.CopyToAsync(stream);
            }

            return(UploadSuccessAfter(savePath, form));
        }
Beispiel #7
0
        public async Task <HandleResult> Edit([FromBody] Site model)
        {
            var info = model.Id > 0 ? await _service.GetById(model.Id) : new Site();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            info.Init();
            ReactForm.SetEditModelValue(info, model, info.Id > 0);

            var res = info.Id > 0 ? await _service.Update(info) : await _service.Add(info);

            if (res.IsSuccess)
            {
                if (info.IsDefault)
                {
                    await _service.RemoveOtherDefault(info.Id);
                }

                string siteFolderPath = Path.GetFullPath($"./Views/{info.SiteFolder}");
                if (!Directory.Exists(siteFolderPath))
                {
                    Directory.CreateDirectory(siteFolderPath);
                }
            }


            return(res);
        }
Beispiel #8
0
        public async Task <HandleResult> Edit([FromBody] ModelTable model)
        {
            var info = model.Id > 0 ? await _service.GetById(model.Id) : new ModelTable();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            bool isUpdate = info.Id > 0;

            if (!isUpdate)
            {
                var verify = await _service.GetByTableName(model.TableName);

                if (verify != null && verify.Id != info.Id)
                {
                    return(HandleResult.Error("表名已存在"));
                }
            }

            info.Init();
            ReactForm.SetEditModelValue(info, model, isUpdate);

            var res = isUpdate
                ? await _service.Update(info)
                : await _service.Add(info);

            if (res.IsSuccess && !isUpdate)
            {
                _service.CreateTable(info);
            }

            return(res);
        }
Beispiel #9
0
        public async Task <HandleResult> Edit([FromBody] Column model)
        {
            var info = model.Id > 0 ? await _service.GetById(model.Id) : new Column();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }
            if (model.ParentNum.IsNotEmpty() &&
                string.Equals(info.Num, model.ParentNum, StringComparison.OrdinalIgnoreCase))
            {
                return(HandleResult.Error("无效数据"));
            }

            info.Init();
            ReactForm.SetEditModelValue(info, model, info.Id > 0);

            info.SiteNum = model.SiteNum;
            if (info.ParentNum.IsEmpty())
            {
                info.ParentNum = "";
            }

            var res = info.Id > 0
                ? await _service.Update(info)
                : await _service.Add(info);

            return(res);
        }
Beispiel #10
0
        public async Task <HandleResult> GetSeo([FromBody] JObject form)
        {
            string num       = form["num"].ToStr();
            string columnNum = form["columnNum"].ToStr();

            if (num.IsEmpty() || columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            var data = await _service.GetByNumAndColumn(columnNum, num);

            if (data == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            var content = new ContentData(data);

            return(HandleResult.Success(new
            {
                content.SeoTitle,
                content.SeoKeyword,
                content.SeoDesc
            }));
        }
Beispiel #11
0
 public async Task <HandleResult> Clear([FromBody] JArray nums)
 {
     if (nums == null || nums.Count <= 0)
     {
         return(HandleResult.Error("请选择要清空的数据"));
     }
     return(await _service.Clear(nums.Select(temp => temp.ToStr()).ToArray()));
 }
Beispiel #12
0
        public async Task <HandleResult> Edit(JObject form, string accountNum)
        {
            var num       = form["num"].ToStr();
            var columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效的提交数据"));
            }

            var cm = await _columnService.GetModelByNum(columnNum);

            if (cm == null)
            {
                return(HandleResult.Error("无效的提交数据"));
            }

            var column = cm?.Column;
            var model  = cm?.ModelTable;

            var oldData = num.IsEmpty() ? null : await _dapper.GetByNum(model.SqlCategoryTableName, num);

            var id        = oldData?.Id ?? 0;
            var parentNum = form["parentNum"].ToStr();

            if (oldData != null && oldData.Num == parentNum)
            {
                return(HandleResult.Error("父类别不能是自身"));
            }

            var contentEdit = new DynamicTableSqlHelper(model.SqlCategoryTableName);

            contentEdit.AddFieldAndValue("Name", form["name"].ToStr());
            contentEdit.AddFieldAndValue("ParentNum", parentNum);

            if (id > 0)
            {
                contentEdit.AddFieldAndValue("UpdateAccountNum", accountNum);
                contentEdit.AddFieldAndValue("UpdateDate", DateTime.Now);
            }
            else
            {
                contentEdit.AddFieldAndValue("Num", RandomHelper.CreateNum());
                contentEdit.AddFieldAndValue("CreateDate", DateTime.Now);
                contentEdit.AddFieldAndValue("UpdateDate", DateTime.Now);
                contentEdit.AddFieldAndValue("CreateAccountNum", accountNum);
                contentEdit.AddFieldAndValue("UpdateAccountNum", accountNum);
                contentEdit.AddFieldAndValue("IsDel", false);
                contentEdit.AddFieldAndValue("Status", 0);
                contentEdit.AddFieldAndValue("SiteNum", column.SiteNum);
                contentEdit.AddFieldAndValue("ColumnNum", columnNum);
            }

            var sql = id > 0 ? contentEdit.GetUpdateSql(id) : contentEdit.GetAddSql();
            var res = await _dapper.Execute(sql, contentEdit.GetValue());

            return(res > 0 ? HandleResult.Success() : HandleResult.Error("操作失败"));
        }
Beispiel #13
0
        public async Task <HandleResult> BraftEditor(IFormFile file, IFormCollection form)
        {
            if (file.FileName.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            string ext = Path.GetExtension(file.FileName);

            return(ext.IsImage() ? await _uploadImageUtil.Upload(file, form) : await _uploadFileUtil.Upload(file, form));
        }
Beispiel #14
0
        public async Task <HandleResult> MoveModelField([FromBody] JObject form)
        {
            string columnNum = form["columnNum"].ToStr(true);

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("请选择栏目"));
            }
            if (!(form["fieldNums"] is JArray jFieldNums) || jFieldNums.Count <= 0)
            {
                return(HandleResult.Error("请选择字段"));
            }

            var fields = await _modelFieldService.GetByNum(jFieldNums.Select(temp => temp.ToStr()).ToArray());

            var columnNumStrings = columnNum.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            var modelFieldNum = new List <string>();
            var columnFields  = new List <ColumnField>();

            foreach (var field in fields)
            {
                foreach (var columnNumString in columnNumStrings)
                {
                    var info = new ColumnField
                    {
                        ColumnNum     = columnNumString,
                        Name          = field.Name,
                        ModelFieldNum = field.Num,
                        Explain       = field.Explain,
                        OptionType    = field.OptionType,
                        DataType      = field.DataType,
                        Options       = field.Options,
                    };

                    info.Init();

                    columnFields.Add(info);
                    modelFieldNum.Add(field.Num);
                }
            }

            if (columnNumStrings.Length <= 1)
            {
                var verify = await _service.GetByModelFieldNum(columnNumStrings[0], modelFieldNum);

                if (verify.Any())
                {
                    return(HandleResult.Error("选择的字段有的已存在"));
                }
            }

            return(await _service.Add(columnFields));
        }
Beispiel #15
0
        public async Task <HandleResult> Delete([FromBody] JObject form)
        {
            string ids       = form["ids"].ToStr();
            string columnNum = form["columnNum"].ToStr();

            if (ids.IsEmpty() || columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效参数"));
            }

            return(await _service.Delete(columnNum, ids));
        }
Beispiel #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public async Task <HandleResult> SelectData([FromBody] JObject form)
        {
            string columnNum      = form["columnNum"].ToStr();
            string labelFieldName = form["labelFieldName"].ToStr();
            string valueFieldName = form["valueFieldName"].ToStr();

            if (columnNum.IsEmpty() || labelFieldName.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            List <SelectDataType> resData = new List <SelectDataType>();

            var data = await _service.GetByColumnNum(columnNum);

            var enumerable = data as dynamic[] ?? data.ToArray();

            if (enumerable.Any())
            {
                if (enumerable[0] is IDictionary <string, object> firstItem)
                {
                    if (!firstItem.ContainsKey(labelFieldName))
                    {
                        return(HandleResult.Error("无效的显示列名"));
                    }

                    valueFieldName = valueFieldName.IsNotEmpty() ? valueFieldName : "Num";
                    if (!firstItem.ContainsKey(valueFieldName))
                    {
                        return(HandleResult.Error("无效的值列名"));
                    }

                    foreach (var o in enumerable)
                    {
                        if (o is IDictionary <string, object> item)
                        {
                            resData.Add(new SelectDataType
                            {
                                Label = item[labelFieldName].ToStr(),
                                Value = item[valueFieldName]
                            });
                        }
                    }
                }
            }


            return(new HandleResult
            {
                IsSuccess = true,
                Data = resData
            });
        }
Beispiel #17
0
        /// <summary>
        ///     更新是否置顶
        /// </summary>
        /// <param name="columnNum"></param>
        /// <param name="num"></param>
        /// <param name="isTop"></param>
        /// <returns></returns>
        public async Task <HandleResult> UpdateIsTop(string columnNum, string num, bool isTop)
        {
            var cm = await _columnService.GetModelByNum(columnNum);

            if (cm == null || cm?.ModelTable == null)
            {
                return(HandleResult.Error());
            }

            var count = await _dapper.UpdateIsTop(cm?.ModelTable.SqlTableName, num, isTop);

            return(count > 0 ? HandleResult.Success() : HandleResult.Error(""));
        }
Beispiel #18
0
        public async Task <HandleResult> UpdateTopStatus([FromBody] JObject form)
        {
            string num       = form["num"].ToStr();
            string columnNum = form["columnNum"].ToStr();
            bool   isTop     = form["isTop"].ToBoolean();

            if (num.IsEmpty() || columnNum.IsEmpty())
            {
                return(HandleResult.Error("参数错误"));
            }

            return(await _service.UpdateIsTop(columnNum, num, isTop));
        }
Beispiel #19
0
        public async Task <HandleResult> CascaderData([FromBody] JObject form)
        {
            string columnNum        = form["columnNum"].ToStr();
            string labelFieldName   = form["labelFieldName"].ToStr();
            string currentFieldName = form["currentFieldName"].ToStr();

            if (columnNum.IsEmpty() || labelFieldName.IsEmpty() || currentFieldName.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            return(await _service.GetCascaderData(columnNum, labelFieldName, currentFieldName));
        }
Beispiel #20
0
        public async Task <HandleResult> Delete([FromBody] JArray form)
        {
            if (form == null || form.Count <= 0)
            {
                return(HandleResult.Error("请选择要删除的数据"));
            }

            var deleteModels = form.Select(temp => new Site {
                Id = temp.ToInt()
            }).ToList();

            return(await _service.Delete(deleteModels));
        }
Beispiel #21
0
        public async Task <HandleResult> Add(DynamicTableSqlHelper form)
        {
            var sql = form.GetAddSql();

            if (sql.IsEmpty())
            {
                return(HandleResult.Error());
            }

            var res = await _dapper.Execute(sql, form.GetValue());

            return(res > 0 ? HandleResult.Success() : HandleResult.Error("操作失败"));
        }
Beispiel #22
0
        public async Task <HandleResult> FieldEdit([FromBody] ModelField model)
        {
            if (model.Id <= 0)
            {
                if (model.ModelNum.IsEmpty())
                {
                    return(HandleResult.Error("请选择模型"));
                }
                if (model.Name.IsEmpty())
                {
                    return(HandleResult.Error("请填写名称"));
                }
            }

            var isUpdate = model.Id > 0;
            var info     = isUpdate ? await _modelFieldService.GetById(model.Id) : new ModelField();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            info.Init();
            if (info.Id <= 0)
            {
                info.ModelNum   = model.ModelNum;
                info.Name       = model.Name;
                info.OptionType = model.OptionType;

                var oldInfo = await _modelFieldService.GetByName(model.Name, model.ModelNum);

                if (oldInfo != null && oldInfo.Id != info.Id)
                {
                    return(HandleResult.Error("名称已存在"));
                }
            }

            info.Explain = model.Explain;
            info.Options = model.Options;

            var res = isUpdate
                ? await _modelFieldService.Update(info)
                : await _modelFieldService.Add(info);

            if (res.IsSuccess && !isUpdate)
            {
                await _modelFieldService.CreateField(info);
            }

            return(res);
        }
Beispiel #23
0
        public async Task <HandleResult> Delete(string columnNum, string ids)
        {
            var cm = await _columnService.GetModelByNum(columnNum);

            if (cm == null)
            {
                return(HandleResult.Error());
            }

            var count = await _dapper.Delete(cm?.ModelTable.SqlCategoryTableName,
                                             ids.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));

            return(count > 0 ? HandleResult.Success() : HandleResult.Error(""));
        }
Beispiel #24
0
        public async Task <HandleResult> UpdateSeo([FromBody] Site site)
        {
            var edit = await _service.GetByNum(site.Num);

            if (edit == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            edit.SeoTitle   = site.SeoTitle;
            edit.SeoKeyword = site.SeoKeyword;
            edit.SeoDesc    = site.SeoDesc;
            return(await _service.Update(edit));
        }
Beispiel #25
0
        public async Task <HandleResult> Edit([FromBody] Administrator model)
        {
            var info = model.Id > 0 ? await _adminService.GetById(model.Id) : new Administrator();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            info.Init();
            ReactForm.SetEditModelValue(info, model, info.Id > 0);

            return(info.Id > 0 ? await _adminService.Update(info) : await _adminService.Add(info));
        }
Beispiel #26
0
        public async Task <HandleResult> CascaderData([FromBody] JObject form)
        {
            string columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            return(new HandleResult
            {
                IsSuccess = true,
                Data = await _service.GetCascaderData(columnNum)
            });
        }
Beispiel #27
0
        public async Task <HandleResult> Delete([FromBody] JArray form)
        {
            if (form == null || form.Count <= 0)
            {
                return(HandleResult.Error("请选择要删除的数据"));
            }

            //todo 模型删除需要删除对应的实体表,不允许轻易删除,需要判断有没有栏目再使用该模型

            var deleteModels = form.Select(temp => new ModelTable {
                Id = temp.ToInt()
            }).ToList();

            return(await _service.Delete(deleteModels));
        }
Beispiel #28
0
        public async Task <HandleResult> FormFields([FromBody] JObject form)
        {
            var id   = form["id"].ToInt();
            var role = id > 0 ? await _service.GetById(id) : new Role();

            if (role == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            return(HandleResult.Success(new
            {
                EditData = role,
                Field = ReactForm.ToFormFields <Role>(role.Id > 0)
            }));
        }
Beispiel #29
0
        public async Task <HandleResult> GetEdit([FromBody] JObject form)
        {
            var itemNum   = form["itemNum"].ToStr();
            var columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            var column = await _columnService.GetByNum(columnNum);

            if (column == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            var model = await _modelTableService.GetByNum(column.ModelNum);

            if (model == null)
            {
                return(HandleResult.Error("栏目未绑定模型"));
            }

            ContentData editValue = null;

            if (column.IsSingle)
            {
                editValue = await _service.GetFirstByColumnNum(model.SqlTableName, column.Num);
            }
            else
            {
                if (itemNum.IsEmpty())
                {
                    return(HandleResult.Error("无效数据"));
                }
                editValue = await _service.GetByItem(model.SqlTableName, itemNum);
            }

            return(new HandleResult
            {
                IsSuccess = true,
                Data = editValue.ToDictionary()
            });
        }
Beispiel #30
0
        /// <summary>
        /// 移出回收站
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public async Task <HandleResult> RemovedRecycle([FromBody] JObject form)
        {
            string columnNum = form["columnNum"].ToStr();

            if (!(form["ids"] is JArray ids) || ids.Count <= 0 || columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            var cm = await _columnService.GetModelByNum(columnNum);

            if (cm == null || cm?.ModelTable == null)
            {
                return(HandleResult.Error("无效参数"));
            }

            return(await _service.Removed(cm?.ModelTable.SqlTableName,
                                          ids.Select(temp => temp.ToInt()).ToList()));
        }