public HttpResponseMessage ModifyReportConfigInfo([FromUri] int id, [FromBody] ReportConfig rptConfig) { HttpResponseMessage response = new HttpResponseMessage(); using (var db = new SecureCloud_Entities()) { var paraShow = new StringBuilder(100); try { var rptConfigEntity = db.T_REPORT_CONFIG.ToList().Find(u => u.Id == id); var intervalCheck = CronExpression.IsValidExpression(rptConfig.CreateInterval); if (!intervalCheck || rptConfigEntity == null || rptConfig.Templates == null) { if (!intervalCheck) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", false), new JProperty("exist", true), new JProperty("template", true) )); } else if (rptConfigEntity == null) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", false), new JProperty("template", true) )); } else if (rptConfig.Templates == null) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", true), new JProperty("template", false) )); } } if (intervalCheck && rptConfigEntity != null && rptConfig.Templates != null) { if (rptConfig.DateType != rptConfigEntity.DateType) { rptConfigEntity.DateType = rptConfig.DateType; paraShow.AppendFormat("报表日期类型改为: {0} ", rptConfig.DateType); } if (rptConfig.CreateInterval != rptConfigEntity.CreateInterval) { rptConfigEntity.CreateInterval = rptConfig.CreateInterval; paraShow.AppendFormat("报表生成周期改为: {0} ", rptConfig.CreateInterval); } if (rptConfig.GetDataTime != default(string) && rptConfig.GetDataTime != rptConfigEntity.GetDataTime) { rptConfigEntity.GetDataTime = rptConfig.GetDataTime; paraShow.AppendFormat("报表数据获取时间改为: {0} ", rptConfig.GetDataTime); } if (rptConfig.IsEnabled != rptConfigEntity.IsEnabled) { rptConfigEntity.IsEnabled = rptConfig.IsEnabled; paraShow.AppendFormat("报表启用状态改为: {0} ", rptConfig.IsEnabled); } if (rptConfig.NeedConfirmed != rptConfigEntity.NeedConfirmed) { rptConfigEntity.NeedConfirmed = rptConfig.NeedConfirmed; paraShow.AppendFormat("报表是否需要确认状态改为: {0} ", rptConfig.NeedConfirmed); } var entry1 = db.Entry(rptConfigEntity); entry1.State = System.Data.EntityState.Modified; var queryTemp = from uo in db.T_REPORT_CONFIG_TEMPLATE where uo.ReportConfigId == id select uo; foreach (var configTemp in queryTemp) { var entry2 = db.Entry(configTemp); entry2.State = System.Data.EntityState.Deleted; } if (rptConfig.Templates.Length != 0) { var templates = rptConfig.Templates.Split(',').Select(o => Convert.ToInt32(o)); var temp = db.T_REPORT_TEMPLATE.Where(o => templates.Contains(o.Id)).Select(o => o.Name); paraShow.AppendFormat("模板改为: {0} ", string.Join(",", temp)); foreach (var tempId in templates) { var uo = new T_REPORT_CONFIG_TEMPLATE { ReportConfigId = id, ReportTemplateId = tempId }; var entry3 = db.Entry(uo); entry3.State = System.Data.EntityState.Added; } } #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(rptConfig); this.Request.Properties["ActionParameterShow"] = paraShow.ToString(); #endregion db.SaveChanges(); response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", true), new JProperty("template", true) )); } return(response); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置信息修改失败"))); } } }
public HttpResponseMessage AddReportConfigInfo([FromBody] ReportConfig rptConfig) { HttpResponseMessage response = new HttpResponseMessage(); using (var db = new SecureCloud_Entities()) { try { var us = new T_REPORT_CONFIG { OrgId = rptConfig.OrgId, StructId = rptConfig.StructId, ReportName = rptConfig.ReportName, DateType = rptConfig.DateType, CreateInterval = rptConfig.CreateInterval, GetDataTime = rptConfig.GetDataTime, NeedConfirmed = rptConfig.NeedConfirmed, IsEnabled = true }; IQueryable <T_REPORT_CONFIG> congigTemp = from q in db.T_REPORT_CONFIG where q.OrgId == rptConfig.OrgId && q.StructId == rptConfig.StructId && q.ReportName == rptConfig.ReportName && q.DateType == rptConfig.DateType && q.CreateInterval == rptConfig.CreateInterval && q.GetDataTime == rptConfig.GetDataTime && q.NeedConfirmed == rptConfig.NeedConfirmed && q.IsEnabled == rptConfig.IsEnabled select q; var stc = db.T_REPORT_CONFIG.Where(s => s.ReportName == rptConfig.ReportName && s.DateType == rptConfig.DateType); var intervalCheck = CronExpression.IsValidExpression(rptConfig.CreateInterval); if (!intervalCheck || congigTemp.Any() || rptConfig.Templates == null || stc.Any()) { if (!intervalCheck) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", false), new JProperty("exist", false), new JProperty("template", true), new JProperty("name", true)//无重名 )); } else if (congigTemp.Any()) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", true), new JProperty("template", true), new JProperty("name", true) )); } else if (rptConfig.Templates == null) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", false), new JProperty("template", false), new JProperty("name", true) )); } else if (stc.Any()) { response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", false), new JProperty("template", true), new JProperty("name", false) )); } } if (intervalCheck && !congigTemp.Any() && rptConfig.Templates != null && !stc.Any()) { db.T_REPORT_CONFIG.Add(us); db.SaveChanges(); int configId = us.Id; string templateStr = string.Empty; if (rptConfig.Templates != null) { var templates = rptConfig.Templates.Split(',').Select(o => Convert.ToInt32(o)); var template = db.T_REPORT_TEMPLATE.Where(o => templates.Contains(o.Id)).Select(o => o.Name); templateStr = string.Join(",", template); foreach (var templateId in templates) { var uo = new T_REPORT_CONFIG_TEMPLATE { ReportConfigId = configId, ReportTemplateId = templateId }; var entry = db.Entry(uo); entry.State = System.Data.EntityState.Added; } } db.SaveChanges(); #region 日志信息 this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(rptConfig); this.Request.Properties["ActionParameterShow"] = string.Format("组织:{0}, 结构物:{1}, 报表名称:{2}, 日期类型:{3}, 生成周期:{4}, 模板: {5}", us.OrgId, us.StructId, us.ReportName, us.DateType, us.CreateInterval, templateStr); #endregion response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject( new JProperty("interval", true), new JProperty("exist", false), new JProperty("template", true), new JProperty("name", true) )); } return(response); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置添加失败"))); } } }