diff --git a/Controllers/Graph.Controller.cs b/Controllers/Graph.Controller.cs new file mode 100644 index 0000000..daa4547 --- /dev/null +++ b/Controllers/Graph.Controller.cs @@ -0,0 +1,186 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using FastReport; +using FastReport.Export.Csv; +using FastReport.Export.Mht; +using FastReport.Export.OoXML; +using FastReport.Export.Pdf; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using rmutr_report.Models; +using rmutr_report.Models.Graph; +using rmutr_report.Models.Hr; +using rmutr_report.Models.HrDevelopment; +using Swashbuckle.AspNetCore.Annotations; + +namespace rmutr_report.Controllers +{ + [SwaggerTag("สำหรับรายงานแบบกราฟ งานพัฒนา")] + public class Graph: Controller + { + readonly Setting _setting; + + public Graph(Setting setting) + { + this._setting = setting; + } + + [HttpPost, Route("graph/passer_join_project_graph/{type}")] + [ApiExplorerSettings(GroupName = "graph")] + public IActionResult GetSum1Report([FromRoute] string type, [FromBody] List reports) + { + Report report = new Report(); + report.Load(_setting.report_path + "passer_join_project_graph_year.frx"); + report.RegisterData(reports, "passer_join_project_graph"); + report.Prepare(); + + MemoryStream stream = new MemoryStream(); + switch (type) + { + case "pdf": + PDFExport pdf = new PDFExport(); + report.Export(pdf, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "application/pdf"); + + case "xls": + Excel2007Export excel = new Excel2007Export(); + report.Export(excel, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "application/vnd.ms-excel"); + break; + case "mht": + MHTExport mht = new MHTExport(); + report.Export(mht, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "multipart/related"); + break; + case "csv": + CSVExport csv = new CSVExport(); + report.Export(csv, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "text/csv"); + break; + } + + return Ok(); + } + [HttpPost, Route("graph/train_graph/{type}")] + [ApiExplorerSettings(GroupName = "graph")] + public IActionResult GetSum2Report([FromRoute] string type, [FromBody] List graph) + { + + //var graph = new List() {reports}; + Report report = new Report(); + report.Load(_setting.report_path + "train_graph.frx"); + report.RegisterData(graph, "train_graph"); + report.Prepare(); + + MemoryStream stream = new MemoryStream(); + switch (type) + { + case "pdf": + PDFExport pdf = new PDFExport(); + report.Export(pdf, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "application/pdf"); + + case "xls": + Excel2007Export excel = new Excel2007Export(); + report.Export(excel, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "application/vnd.ms-excel"); + break; + case "mht": + MHTExport mht = new MHTExport(); + report.Export(mht, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "multipart/related"); + break; + case "csv": + CSVExport csv = new CSVExport(); + report.Export(csv, stream); + stream.Seek(0, SeekOrigin.Begin); + return File(stream, "text/csv"); + break; + } + + return Ok(); + } + // [HttpPost, Route("graph/passer_join_project_person_graph/{type}")] + // [ApiExplorerSettings(GroupName = "graph")] + // public IActionResult GetSum3Report([FromRoute] string type, [FromBody] List graph) + // { + // var a = graph.ToArray(); + // foreach (var v in a) + // { + // foreach (var vv in v.data) + // { + // if (vv.pertype != null) + // { + // v.pertype = vv.pertype; + // v.count_person_pertype = vv.data_detail.Select(g => g.display_name_th).Count(); + // } + // else + // { + // return null; + // } + // foreach (var detail in vv.data_detail) + // { + // if (detail.quantity_project != null) + // { + // v.quantity_project = detail.quantity_project; + // } + // if (detail.registration_fee != null) + // { + // v.registration_fee = detail.registration_fee; + // } + // else + // { + // return null; + // } + // } + // } + // + // } + // //var graph = new List() {reports}; + // Report report = new Report(); + // report.Load(_setting.report_path + "passer_join_project_person_graph.frx"); + // report.RegisterData(graph, "passer_join_project_agency_graph"); + // report.Prepare(); + // + // MemoryStream stream = new MemoryStream(); + // switch (type) + // { + // case "pdf": + // PDFExport pdf = new PDFExport(); + // report.Export(pdf, stream); + // stream.Seek(0, SeekOrigin.Begin); + // return File(stream, "application/pdf"); + // + // case "xls": + // Excel2007Export excel = new Excel2007Export(); + // report.Export(excel, stream); + // stream.Seek(0, SeekOrigin.Begin); + // return File(stream, "application/vnd.ms-excel"); + // break; + // case "mht": + // MHTExport mht = new MHTExport(); + // report.Export(mht, stream); + // stream.Seek(0, SeekOrigin.Begin); + // return File(stream, "multipart/related"); + // break; + // case "csv": + // CSVExport csv = new CSVExport(); + // report.Export(csv, stream); + // stream.Seek(0, SeekOrigin.Begin); + // return File(stream, "text/csv"); + // break; + // } + // + // return Ok(); + // } + } +} \ No newline at end of file diff --git a/Models/Graph/graph.cs b/Models/Graph/graph.cs new file mode 100644 index 0000000..a442a76 --- /dev/null +++ b/Models/Graph/graph.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; + +namespace rmutr_report.Models.Graph +{ + public class passer_join_project_graph + { + public string year { get; set; } + + public string agency_name_th { get; set; } + + //public int? quantity_person { get; set; } + public int? quantity_trained { get; set; } + } + public class train_graph + { + public string year { get; set; } + //public string agency_name_th { get; set; } + public int? quantity_trained_pass { get; set; } + public int? quantity_trained_notpass { get; set; } + } +} +// public class passer_join_project_agency_graph + // { + // public string agency_name_th { get; set; } + // public int? count_person { get; set; } + // public string pertype { get; set; } + // public int? count_person_pertype { get; set; } + // public int? quantity_project { get; set; } + // public decimal? registration_fee { get; set; } + // public List data { get; set; } + // } + // public class passer_join_project_agency_graph_detail + // { + // public string pertype { get; set; } + // public int? count_person_pertype { get; set; } + // public List data_detail { get; set; } + // } + // + // public class passer_join_project_agency_graph_data_detail + // { + // public string display_name_th { get; set; } + // public int? quantity_project { get; set; } + // // public string project_name { get; set; } + // // public string course_organizer { get; set; } + // // public string project_date { get; set; } + // // public string project_time { get; set; } + // // public string location { get; set; } + // public decimal? registration_fee { get; set; } + // //public string complete_date { get; set; } + // } + // public class person_academic_and_supportlines_detail + // { + // public string agency_name_th { get; set; } + // public decimal? quantity_person { get; set; } + // public decimal? percentage_1 { get; set; } + // public decimal? percentage_2 { get; set; } + // public decimal? percentage_3 { get; set; } + // public decimal? percentage_4 { get; set; } + // public decimal? percentage_5 { get; set; } + // public decimal? total { get; set; } + // } diff --git a/Startup.cs b/Startup.cs index 8f19839..81fc16d 100644 --- a/Startup.cs +++ b/Startup.cs @@ -41,7 +41,7 @@ namespace rmutr_report services.AddSwaggerGen(c => { c.SwaggerDoc("reports", new OpenApiInfo {Title = "Reports API", Version = "v1"}); - + c.SwaggerDoc("graph", new OpenApiInfo {Title = "Graph API", Version = "v1"}); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); @@ -90,6 +90,7 @@ namespace rmutr_report app.UseSwaggerUI(c => { c.SwaggerEndpoint("reports/swagger.json", "Reports API v1"); + c.SwaggerEndpoint("graph/swagger.json", "Graph API v1"); c.DefaultModelExpandDepth(0); c.DefaultModelsExpandDepth(-1); diff --git a/wwwroot/reports/passer_join_project_agency_graph.frx b/wwwroot/reports/passer_join_project_agency_graph.frx new file mode 100644 index 0000000..67df1ba --- /dev/null +++ b/wwwroot/reports/passer_join_project_agency_graph.frx @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/passer_join_project_graph.frx b/wwwroot/reports/passer_join_project_graph.frx new file mode 100644 index 0000000..782433b --- /dev/null +++ b/wwwroot/reports/passer_join_project_graph.frx @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/passer_join_project_graph_year.frx b/wwwroot/reports/passer_join_project_graph_year.frx new file mode 100644 index 0000000..188ab29 --- /dev/null +++ b/wwwroot/reports/passer_join_project_graph_year.frx @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/passer_join_project_person_graph.frx b/wwwroot/reports/passer_join_project_person_graph.frx new file mode 100644 index 0000000..56eaf77 --- /dev/null +++ b/wwwroot/reports/passer_join_project_person_graph.frx @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/person_academic_supportlines_graph.frx b/wwwroot/reports/person_academic_supportlines_graph.frx new file mode 100644 index 0000000..4fe17a5 --- /dev/null +++ b/wwwroot/reports/person_academic_supportlines_graph.frx @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/train_graph.frx b/wwwroot/reports/train_graph.frx new file mode 100644 index 0000000..cf44a1e --- /dev/null +++ b/wwwroot/reports/train_graph.frx @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +