#984(2)
This commit is contained in:
parent
d0235e0c53
commit
79237c4a7f
1 changed files with 176 additions and 3 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
using Amazon.S3.Model;
|
using Amazon.S3.Model;
|
||||||
// using BMA.EHR.Extensions;
|
using BMA.EHR.MetaData.Service.Models;
|
||||||
|
using BMA.EHR.Profile.Service.Models.HR;
|
||||||
|
|
||||||
|
|
||||||
|
//using BMA.EHR.Extensions;
|
||||||
using BMA.EHR.Recruit.Service.Core;
|
using BMA.EHR.Recruit.Service.Core;
|
||||||
using BMA.EHR.Recruit.Service.Data;
|
using BMA.EHR.Recruit.Service.Data;
|
||||||
using BMA.EHR.Recruit.Service.Extensions;
|
using BMA.EHR.Recruit.Service.Extensions;
|
||||||
|
|
@ -23,6 +27,7 @@ using System.Net;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace BMA.EHR.Recruit.Service.Controllers
|
namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -44,7 +49,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
private readonly PermissionRepository _permission;
|
private readonly PermissionRepository _permission;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly ILogger<RecruitController> _logger;
|
private readonly ILogger<RecruitController> _logger;
|
||||||
|
//private readonly DateTimeExtension;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Constructor and Destructor "
|
#region " Constructor and Destructor "
|
||||||
|
|
@ -56,7 +62,9 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
RecruitService recruitService,
|
RecruitService recruitService,
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ILogger<RecruitController> logger,
|
ILogger<RecruitController> logger,
|
||||||
PermissionRepository permission)
|
PermissionRepository permission
|
||||||
|
//DateTimeExtension extensions
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_contextMetadata = contextMetadata;
|
_contextMetadata = contextMetadata;
|
||||||
|
|
@ -66,6 +74,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_permission = permission;
|
_permission = permission;
|
||||||
|
//_extensions = extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -189,6 +198,15 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ExamInfo
|
||||||
|
{
|
||||||
|
public string PositionName { get; set; }
|
||||||
|
public string Gender { get; set; }
|
||||||
|
public int Age { get; set; }
|
||||||
|
public string Degree { get; set; }
|
||||||
|
public string Result { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Ex. Upload, Download and Delete file "
|
#region " Ex. Upload, Download and Delete file "
|
||||||
|
|
@ -2200,6 +2218,161 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region " Report "
|
||||||
|
/// <summary>
|
||||||
|
/// รายงานจำนวนผู้เข้าสอบแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="year">ปีงบประมาณ</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจำนวนผู้เข้าสอบแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpGet("report1"), DisableRequestSizeLimit]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> report1(string year)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<ExamInfo> header = new List<ExamInfo>();
|
||||||
|
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
cmd.CommandTimeout = 0;
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append(" SELECT * ");
|
||||||
|
sb.Append(" FROM exam_info ");
|
||||||
|
sb.Append(" Where score_year = @year");
|
||||||
|
sb.Append(" ORDER BY Position_name ASC");
|
||||||
|
cmd.CommandText = sb.ToString();
|
||||||
|
cmd.Parameters.Add(new MySqlParameter("@year", MySqlDbType.Int32) { Value = year });
|
||||||
|
_context.Database.OpenConnection();
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var examInfo = new ExamInfo
|
||||||
|
{
|
||||||
|
PositionName = reader["Position_name"].ToString(),
|
||||||
|
Gender = reader["Gender"].ToString(),
|
||||||
|
Age = DateTimeExtension.CalculateAge(Convert.ToDateTime(reader["Dateofbirth"]), 0, 0),
|
||||||
|
Degree = reader["Degree"].ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
header.Add(examInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
var groupedResult = header
|
||||||
|
.GroupBy(x => new
|
||||||
|
{
|
||||||
|
x.PositionName,
|
||||||
|
x.Gender,
|
||||||
|
x.Age,
|
||||||
|
x.Degree
|
||||||
|
})
|
||||||
|
.Select(group => new
|
||||||
|
{
|
||||||
|
Group = group.Key,
|
||||||
|
Amount = group.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
var resultMap = groupedResult.ToDictionary(
|
||||||
|
x => string.Join("_", x.Group.PositionName, x.Group.Gender, x.Group.Age, x.Group.Degree),
|
||||||
|
x => x);
|
||||||
|
|
||||||
|
return Success(resultMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// รายงานจำนวนผู้สอบผ่านแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญ
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="year">ปีงบประมาณ</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจำนวนผู้สอบผ่านแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpGet("report2"), DisableRequestSizeLimit]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> report2(string year)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<ExamInfo> header = new List<ExamInfo>();
|
||||||
|
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
cmd.CommandTimeout = 0;
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append(" SELECT * ");
|
||||||
|
sb.Append(" FROM exam_info ");
|
||||||
|
sb.Append(" Where score_year = @year");
|
||||||
|
sb.Append(" AND result = 'ผ่าน'");
|
||||||
|
sb.Append(" ORDER BY Position_name ASC");
|
||||||
|
cmd.CommandText = sb.ToString();
|
||||||
|
cmd.Parameters.Add(new MySqlParameter("@year", MySqlDbType.Int32) { Value = year });
|
||||||
|
_context.Database.OpenConnection();
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var examInfo = new ExamInfo
|
||||||
|
{
|
||||||
|
PositionName = reader["Position_name"].ToString(),
|
||||||
|
Gender = reader["Gender"].ToString(),
|
||||||
|
Age = DateTimeExtension.CalculateAge(Convert.ToDateTime(reader["Dateofbirth"]), 0, 0),
|
||||||
|
Degree = reader["Degree"].ToString(),
|
||||||
|
Result = reader["Result"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
header.Add(examInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
var groupedResult = header
|
||||||
|
.GroupBy(x => new
|
||||||
|
{
|
||||||
|
x.PositionName,
|
||||||
|
x.Gender,
|
||||||
|
x.Age,
|
||||||
|
x.Degree,
|
||||||
|
x.Result
|
||||||
|
})
|
||||||
|
.Select(group => new
|
||||||
|
{
|
||||||
|
Group = group.Key,
|
||||||
|
Amount = group.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
var resultMap = groupedResult.ToDictionary(
|
||||||
|
x => string.Join("_", x.Group.PositionName, x.Group.Gender, x.Group.Age, x.Group.Degree, x.Group.Result),
|
||||||
|
x => x);
|
||||||
|
|
||||||
|
return Success(resultMap);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue