// POST: api/IndexManager public StandardJsonResult PostIndex([FromBody] IndexAddParam param) { string errorMsg = string.Empty; bool isSuccess = false; var standardJsonResult = StandardAction(() => { isSuccess = this.IndexManagerService.AddIndex(param, ref errorMsg); }); standardJsonResult.Success = isSuccess; if (string.IsNullOrEmpty(standardJsonResult.Message)) { standardJsonResult.Message = isSuccess ? "添加成功" : (string.IsNullOrEmpty(errorMsg) ? "添加失败" : errorMsg); } return(standardJsonResult); }
public bool AddIndex(IndexAddParam param, ref string errorMsg) { if (this.IsIndexExist(param.ServiceNumber, param.IndexName)) { errorMsg = $"该服务已存在名称为{param.IndexName}的索引"; return(false); } var entity = new IndexManager { ServiceNumber = param.ServiceNumber, ServiceSign = param.ServiceSign, ShardNumber = param.ShardNum, Size = param.Size, Status = IndexStatus.NotStarted, ExpensionNum = 0, MaxExpensionNum = param.MaxExpensionNum, ReplicasNumber = param.ReplicasNum, IndexName = param.IndexName, IndexNumber = Guid.NewGuid().ToString("N"), IsDeleted = false, CreatedTime = DateTime.Now, CreatedBy = "admin", ModifiedTime = DateTime.Now, ModifiedBy = "admin" }; return(this.IndexManagerRepository.AddWithTransection(entity, () => { var key = IndexNameHelper.GetIndexMappingName(entity.ServiceSign, entity.IndexName); var isSucess = this.CacheClient.SetCache(key, entity.Status, 173000); if (!isSucess) { throw new Exception("缓存更新失败"); } })); }