public async Task <JsonResult> InitZookeeper(int id, string appName) { try { TemplateCondition condition = new TemplateCondition { AppId = id }; var temList = await _templateService.GetList(condition); if (temList != null && temList.Count() != 0) { var configList = await _configService.GetConfigsByTemplateIds(string.Join(",", temList.Select(s => s.Id))); foreach (var item in configList) { var tem = temList.Where(s => s.Id == item.TemplateId).FirstOrDefault(); var envName = await _envService.GetEnvNameById(item.EnvId); var path = DisconfWatcher.GetPath(tem.Name, appName, tem.Version, envName, tem.Type); DisconfWatcher.AddOrSetData(path); } } } catch (Exception ex) { return(Json(false, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 更新条件{条件}对象(即:一条记录 /// </summary> public int Update(TemplateCondition templateCondition) { using (var dbContext = UnitOfWork.Get(Unity.ContainerName)) { return(new TemplateConditionRepository(dbContext).Update(templateCondition)); } }
public List <ZZTemplate> SearchTemplateByCondistion2(TemplateCondition condition) { var templatePred = PredicateBuilder.New <ZZ_Template>(x => !x.IsDeleted); if (condition.Category.HasValue) { templatePred = templatePred.And(x => x.Category == condition.Category.Value); } if (condition.Sex.HasValue) { templatePred = templatePred.And((x => x.Sex == condition.Sex.Value)); } if (!string.IsNullOrEmpty(condition.Color)) { templatePred = templatePred.And(x => x.Color == condition.Color); } using (var db = GetDbContext()) { var tmp = from t in db.ZZ_Template.AsExpandable().Where(templatePred) join c in db.ZZ_Category on t.Category equals c.CategoryId select new ZZTemplate() { TemplateId = t.TemplateId, BackImg = t.BackImg, Category = t.Category, Color = t.Color, ColorCode = t.ColorCode, FrontImg = t.FrontImg, IsDeleted = t.IsDeleted, Sex = t.Sex, UnitPrice = c.UnitPrice }; return(tmp.OrderByDescending(x => x.Category).ThenBy(x => x.Sex).ThenBy(x => x.ColorCode).ToList()); } }
public async Task <JsonResult> GetTemplateList() { var condition = new TemplateCondition(); condition.AppId = AppId; condition.EnvId = EnvId; var list = await _templateService.GetTemplateList(condition); var appName = await _appService.GetAppNameById(AppId); var envName = await _envService.GetEnvNameById(EnvId); foreach (var s in list) { try { var path = DisconfWatcher.GetPath(s.Name, appName, s.Version, envName, s.Type); s.ZookeeperChildren = string.Join("<br>", DisconfWatcher.GetChildren(path)); } catch (Exception ex) { } } var vmModel = list.OrderBy(s => s.Version).GroupBy(s => s.Version).Select(t => new TemplateView { List = t.ToList(), Version = t.FirstOrDefault().Version, }).ToList(); return(Json(vmModel, JsonRequestBehavior.AllowGet)); }
public async Task <IEnumerable <Templates> > GetTemplateList(TemplateCondition condition) { string sql = $@"SELECT tem.id, tem.name,tem.description,tem.default_value as defaultvalue,tem.type,tem.version,con.id as ConfigId, con.value as configvalue From templates as tem LEFT JOIN configs as con ON tem.id = con.template_id AND con.env_id = @envId {GetSqlWhere(condition)}"; return(await ExecuteWithConditionAsync(async s => await s.QueryAsync <Templates>(sql, GetSqlParameter(condition)))); }
private object GetSqlParameter(TemplateCondition condition) { return(new { appId = condition.AppId, envId = condition.EnvId, type = condition.Type, version = condition.Version, name = condition.Name.Trim() }); }
public async Task <IEnumerable <Templates> > GetList(TemplateCondition condition) { var pg = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List <IPredicate>() }; if (condition.AppId.HasValue) { pg.Predicates.Add(Predicates.Field <Templates>(l => l.AppId, Operator.Eq, condition.AppId.Value)); } return(await _templateRepository.GetListWithCondition <Templates>(pg)); }
public async Task <JsonResult> GetVersion() { var condition = new TemplateCondition(); condition.AppId = AppId; var model = await _templateService.GetList(condition); var list = model.GroupBy(s => s.Version).Select(s => s.FirstOrDefault()).Select(s => new { Id = s.Id, Version = s.Version, }).ToList(); return(Json(list, JsonRequestBehavior.AllowGet)); }
public ActionResult GetTemplates(TemplateCondition condition) { var templates = BS.SearchTemplateByCondistion(condition); return(new JsonResult() { Data = templates.Select(x => new { x.TemplateId, x.FrontImg, x.BackImg, x.Category, x.Sex, x.Color }) }); }
public async Task <ActionResult> DownloadZip(string version) { var condition = new TemplateCondition { AppId = AppId, EnvId = EnvId, Type = (int)ConfigType.File, Version = version }; await _templateService.BatchCreateFile(condition); var fileName = DateTime.Now.ToString("yyMMddHHmmssff"); string[] files = Directory.GetFiles(AppSettingHelper.Get <string>("FilePath")); //返回指定目录下的文件名 Zip(files, fileName); return(File(AppSettingHelper.Get <string>("ZipPath") + fileName + ".zip", "application/zip", fileName + ".zip")); }
public ActionResult GetAllTemplates(TemplateCondition condition) { var templates = BS.SearchTemplateByCondistion2(condition); return(new JsonResult() { Data = templates //.Select(x => // new // { // x.TemplateId, // x.FrontImg, // x.BackImg, // x.Category, // x.Sex, // x.Color // }) }); }
public async Task <JsonResult> GetList() { var condition = new TemplateCondition(); condition.AppId = AppId; var model = await _templateService.GetList(condition); var list = model.Select(s => new { Id = s.Id, Name = s.Name, Description = s.Description, DefaultValue = s.DefaultValue, Version = s.Version, Type = s.Type }).ToList(); return(Json(list, JsonRequestBehavior.AllowGet)); }
public List <ZZ_Template> SearchTemplateByCondistion(TemplateCondition condition) { var templatePred = PredicateBuilder.New <ZZ_Template>(x => !x.IsDeleted); if (condition.Category.HasValue) { templatePred = templatePred.And(x => x.Category == condition.Category.Value); } if (condition.Sex.HasValue) { templatePred = templatePred.And((x => x.Sex == condition.Sex.Value)); } if (!string.IsNullOrEmpty(condition.Color)) { templatePred = templatePred.And(x => x.Color == condition.Color); } using (var db = GetDbContext()) { return(db.ZZ_Template.AsExpandable().Where(templatePred).ToList()); } }
public async Task <JsonResult> Delete(long id) { var result = new BaseResult(); TemplateCondition condition = new TemplateCondition { AppId = id }; var temList = await _templateService.GetList(condition); if (temList.Count() > 0) { result.IsSuccess = false; result.ErrorMsg = "该App下存在模板,请先删除模板"; } else { await _permissionService.BatchDeleteByAppId(id); result.IsSuccess = await _appService.Delete(id); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> Update(Templates model) { var result = new BaseResult(); var condition = new TemplateCondition(); condition.Name = model.Name; condition.Version = model.Version; condition.AppId = AppId; var list = await _templateService.GetTemplateList(condition); if (list.Count() > 0 && list.FirstOrDefault().Id != model.Id) { result.IsSuccess = false; result.ErrorMsg = "该App下同版本名称已经存在"; } else { model.AppId = AppId; result.IsSuccess = await _templateService.Update(model); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <bool> BatchCreateFile(TemplateCondition condition) { var list = await GetTemplateList(condition); FormatFolder(AppSettingHelper.Get <string>("FilePath")); FormatFolder(AppSettingHelper.Get <string>("ZipPath")); foreach (var item in list) { FileStream myFs = new FileStream(AppSettingHelper.Get <string>("FilePath") + item.Name, FileMode.Create); StreamWriter mySw = new StreamWriter(myFs); if (string.IsNullOrWhiteSpace(item.ConfigValue)) { mySw.Write(item.DefaultValue); } else { mySw.Write(item.ConfigValue); } mySw.Close(); myFs.Close(); } return(true); }
private string GetSqlWhere(TemplateCondition condition) { StringBuilder sb = new StringBuilder(); sb.Append(" WHERE 1=1 "); if (condition.AppId.HasValue) { sb.Append(" AND tem.app_id = @appId "); } if (condition.Type.HasValue) { sb.Append(" AND tem.type = @type "); } if (!string.IsNullOrWhiteSpace(condition.Version)) { sb.Append(" AND tem.version = @version "); } if (!string.IsNullOrWhiteSpace(condition.Name)) { sb.Append(" AND tem.name = @name "); } return(sb.ToString()); }
public async Task <IEnumerable <Templates> > GetTemplateList(TemplateCondition condition) { return(await _templateRepository.GetTemplateList(condition)); }
/// <summary> /// 添加条件{条件}对象(即:一条记录 /// </summary> public long Add(TemplateCondition templateCondition) { return(Add <TemplateCondition>(templateCondition)); }
/// <summary> /// 更新条件{条件}对象(即:一条记录 /// </summary> public int Update(TemplateCondition templateCondition) { return(Update <TemplateCondition>(templateCondition)); }