/// <summary> /// 添加一个AccountantCourse /// </summary> /// <param name="input">实体</param> /// <returns></returns> public async Task <AccountantCourseOutputDto> Create(CreateAccountantCourseInput input) { var parent_Model = await _repository.GetAsync(input.Pid); var updateLeftNodes = _repository.GetAll().Where(r => r.parent_left > parent_Model.parent_left); foreach (var updateLeftNode in updateLeftNodes) { updateLeftNode.parent_left = updateLeftNode.parent_left + 2; } var updateRightNodes = _repository.GetAll().Where(r => r.parent_right > parent_Model.parent_left); foreach (var updateRightNode in updateRightNodes) { updateRightNode.parent_right = updateRightNode.parent_right + 2; } var newmodel = new AccountantCourse() { Id = Guid.NewGuid(), Name = input.Name, Pid = parent_Model.Id, }; newmodel.parent_left = parent_Model.parent_left + 1; newmodel.parent_right = parent_Model.parent_left + 2; await _repository.InsertAsync(newmodel); RefreshCL(); var ret = newmodel.MapTo <AccountantCourseOutputDto>(); return(ret); }
public async Task ImportFile(ImportFileInputDto input) { string filePath = hostingEnv.WebRootPath + $@"/Files/upload/temp/"; string fileFullName = filePath + input.FileRelationPath; var retData = new List <AccountantCourseOutputDto>(); if (System.IO.File.Exists(fileFullName)) { var firstNode = new AccountantCourseOutputDto() { Name = "会计科目", Id = Guid.NewGuid(), parent_left = 0, parent_right = 1, }; var unKnowId = _appConfiguration.GetValue <string>("App:ACOtherId").ToGuid(); using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete)) { _repository.Delete(r => r.Id == unKnowId); } ///增加统一id的未知节点 retData.Add(new AccountantCourseOutputDto() { Id = _appConfiguration.GetValue <string>("App:ACOtherId").ToGuid(), Name = "未知", Pid = firstNode.Id }); DataTable dt = new DataTable(); #region 导入execle using (FileStream stream = System.IO.File.Open(fileFullName, FileMode.Open, FileAccess.Read)) { //创建 XSSFWorkbook和ISheet实例 XSSFWorkbook workbook = new XSSFWorkbook(stream); ISheet sheet = workbook.GetSheetAt(0); //获取sheet的首行 IRow headerRow = sheet.GetRow(0); int cellCount = headerRow.LastCellNum; for (int i = headerRow.FirstCellNum; i < cellCount; i++) { //Column 添加ColumnName var dtColumn = new DataColumn(headerRow.GetCell(i).StringCellValue, typeof(string)); dt.Columns.Add(dtColumn); } int rowCount = sheet.LastRowNum; for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) { object[] valuelist = new object[cellCount]; IRow row = sheet.GetRow(i); var newRow = dt.NewRow(); for (int j = row.FirstCellNum; j < cellCount; j++) { //遍历添加Column的数据 if (row.GetCell(j) != null) { valuelist.SetValue(row.GetCell(j).ToString(), j); newRow[j] = row.GetCell(j).ToString(); } } //遍历将Column的数据添加到Datarow dt.Rows.Add(newRow); } } #endregion var listData = new List <string>(); foreach (DataRow item in dt.Rows) { var rowData = item[0].ToString(); listData.Add(rowData); var arrys = rowData.Split('/'); foreach (var obj in arrys) { if (retData.Any(r => r.Name == obj.ToString())) { continue; } else { var entity = new AccountantCourseOutputDto() { Id = Guid.NewGuid(), Name = obj.ToString(), }; retData.Add(entity); } } } var childData = listData.Where(r => r.Split('/').Count() > 1); foreach (var item in childData) { var arrys = item.Split('/'); var arrysCount = arrys.Count(); for (int i = 0; i < arrysCount - 1; i++) { var childeNode = retData.FirstOrDefault(r => r.Name == arrys[i + 1]); if (!childeNode.Pid.HasValue) { var parentNode = retData.FirstOrDefault(r => r.Name == arrys[i]); childeNode.Pid = parentNode.Id; } } } var levetOneNodes = retData.Where(r => !r.Pid.HasValue); foreach (var item in levetOneNodes) { item.Pid = firstNode.Id; } retData.Add(firstNode); ManagerAC(retData.SingleOrDefault(r => !r.Pid.HasValue), retData); _repository.Delete(r => r.Id != Guid.Empty); foreach (var item in retData) { var entity = new AccountantCourse() { Id = item.Id, Name = item.Name, parent_left = item.parent_left, parent_right = item.parent_right, Pid = item.Pid, }; await _repository.InsertAsync(entity); } RefreshCL(); } }