เตรียม UI รายงานแบบประเมิน
This commit is contained in:
253
ApiControllers/rep_eva_xControllers.cs
Normal file
253
ApiControllers/rep_eva_xControllers.cs
Normal file
@@ -0,0 +1,253 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TTSW.Controllers;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
using TodoAPI2.Models;
|
||||
using System.Data;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text;
|
||||
|
||||
namespace TodoAPI2.Controllers
|
||||
{
|
||||
//[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("api/rep_eva_x")]
|
||||
public class rep_eva_xController : BaseController
|
||||
{
|
||||
#region Private Variables
|
||||
private ILogger<rep_eva_xController> _logger;
|
||||
private Irep_eva_xService _repository;
|
||||
private IConfiguration Configuration { get; set; }
|
||||
private Ieva_create_evaluation_detail_processService _process;
|
||||
private Iexternal_linkageService ext;
|
||||
Iexternal_employeeService emp;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Default constructure for dependency injection
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="process"></param>
|
||||
/// <param name="inext"></param>
|
||||
/// <param name="inemp"></param>
|
||||
/// <param name="logger"></param>
|
||||
public rep_eva_xController(ILogger<rep_eva_xController> logger, Irep_eva_xService repository, IConfiguration configuration,
|
||||
Ieva_create_evaluation_detail_processService process, Iexternal_linkageService inext, Iexternal_employeeService inemp)
|
||||
{
|
||||
_logger = logger;
|
||||
_repository = repository;
|
||||
_process = process;
|
||||
Configuration = configuration;
|
||||
ext = inext;
|
||||
emp = inemp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Blank Item
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <returns>Return a blank item</returns>
|
||||
/// <response code="200">Returns the item</response>
|
||||
/// <response code="500">Error Occurred</response>
|
||||
[HttpGet("GetBlankItem")]
|
||||
[ProducesResponseType(typeof(rep_eva_xWithSelectionViewModel), 200)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public IActionResult GetBlankItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
||||
var result = _repository.GetBlankItem();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception in IActionResult GetBlankItem.", ex);
|
||||
return StatusCode(500, $"{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download Report
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <returns>Return list of items by specifced keyword</returns>
|
||||
/// <response code="200">Returns the item</response>
|
||||
/// <response code="500">Error Occurred</response>
|
||||
[HttpGet("rep_eva_x_report")]
|
||||
[ProducesResponseType(typeof(FileStreamResult), 200)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public IActionResult rep_eva_x_report(rep_eva_xReportRequestModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
||||
|
||||
var p1 = GetParameter(Convert.ToInt16(model.detail_id));
|
||||
|
||||
var httpclient = new WebClient();
|
||||
|
||||
string mainurl = MyHelper.GetConfig(Configuration, "JasperReportServer:MainURL");
|
||||
string reportsite = MyHelper.GetConfig(Configuration, "JasperReportServer:reportsite");
|
||||
string username = MyHelper.GetConfig(Configuration, "JasperReportServer:username");
|
||||
string password = MyHelper.GetConfig(Configuration, "JasperReportServer:password");
|
||||
|
||||
//string url = $"{mainurl}{reportsite}/rep_eva_x1.{model.filetype}?{MyHelper.GetParameterForJasperReport(p1)}&j_username={username}&j_password={password}";
|
||||
|
||||
//var data = httpclient.DownloadData(url);
|
||||
//var stream = new MemoryStream(data);
|
||||
|
||||
//return File(stream, model.contentType);
|
||||
|
||||
var stream = new MemoryStream();
|
||||
Document document = new Document();
|
||||
PdfCopy writer = new PdfCopy(document, stream);
|
||||
document.Open();
|
||||
|
||||
var rep_type = new int[] { 1, 2, 3, 4, 5};
|
||||
|
||||
foreach (var k in rep_type)
|
||||
{
|
||||
string url = $"{mainurl}{reportsite}/rep_eva_x{k}.{model.filetype}?{MyHelper.GetParameterForJasperReport(p1)}&j_username={username}&j_password={password}";
|
||||
|
||||
var data = httpclient.DownloadData(url);
|
||||
|
||||
PdfReader reader = new PdfReader(data);
|
||||
reader.ConsolidateNamedDestinations();
|
||||
|
||||
for (int i = 1; i <= reader.NumberOfPages; i++)
|
||||
{
|
||||
PdfImportedPage page = writer.GetImportedPage(reader, i);
|
||||
writer.AddPage(page);
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
|
||||
writer.Close();
|
||||
document.Close();
|
||||
|
||||
var data2 = stream.ToArray();
|
||||
var stream2 = new MemoryStream(data2);
|
||||
|
||||
return File(stream2, model.contentType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while GetReport.", ex);
|
||||
return StatusCode(500, $"{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private rep_eva_xInputModel2 GetParameter(int detail_id)
|
||||
{
|
||||
var i = new rep_eva_xInputModel2();
|
||||
|
||||
i.create_evaluation_detail_id = detail_id;
|
||||
var p = _process.Get(detail_id, null, null);
|
||||
|
||||
i.employee_fullname = p.employee_fullname;
|
||||
i.employee_code = p.employee_code;
|
||||
i.employee_position_type = p.employee_position_type;
|
||||
i.employee_position_level = p.employee_position_level;
|
||||
i.employee_org = p.employee_org;
|
||||
i.employee_position = p.employee_position;
|
||||
if (!string.IsNullOrEmpty(p.employee_profile_picture))
|
||||
{
|
||||
i.image_url = MyHelper.GetConfig(Configuration, "SiteInformation:mainsite") + "/api/image/" + p.employee_profile_picture;
|
||||
}
|
||||
i.chief_fullname = p.chief_fullname;
|
||||
i.chief_position = p.chief_position;
|
||||
i.supervisor2_fullname = p.supervisor2_fullname;
|
||||
i.supervisor2_position = p.supervisor2_position;
|
||||
i.supervisor1A_fullname = p.supervisor1A_fullname;
|
||||
i.supervisor1A_position = p.supervisor1A_position;
|
||||
i.supervisor2A_fullname = p.supervisor2A_fullname;
|
||||
i.supervisor2A_position = p.supervisor2A_position;
|
||||
i.main_dept = p.employee_main_dept;
|
||||
i.leave_period = MyHelper.GetDateStringForReport(p.start_date) + " ถึง " + MyHelper.GetDateStringForReport(p.end_date);
|
||||
i.selected_round = p.selected_round;
|
||||
|
||||
var context = _process.GetDataContext();
|
||||
var all_eva = (from x in context.eva_performance_plan
|
||||
where x.fiscal_year == p.fiscal_year
|
||||
orderby x.theTime
|
||||
select x).ToList();
|
||||
foreach(var x2 in all_eva)
|
||||
{
|
||||
var start = (from n in context.eva_performance_plan_detail
|
||||
where n.performance_plan_id == x2.id
|
||||
select n.start_date).Min();
|
||||
var end = (from n in context.eva_performance_plan_detail
|
||||
where n.performance_plan_id == x2.id
|
||||
select n.end_date).Min();
|
||||
var text = MyHelper.GetDateStringForReport(start) + " ถึง " + MyHelper.GetDateStringForReport(end);
|
||||
if(x2.theTime == 1)
|
||||
{
|
||||
i.round1_text = text;
|
||||
}
|
||||
if (x2.theTime == 2)
|
||||
{
|
||||
i.round2_text = text;
|
||||
}
|
||||
}
|
||||
|
||||
var detail = (from x in context.eva_create_evaluation_detail
|
||||
where x.id == detail_id
|
||||
select x).FirstOrDefault();
|
||||
if(detail != null)
|
||||
{
|
||||
i.total_summary_supervisor2A = detail.total_summary_supervisor2A;
|
||||
i.Final_summary_supervisor2A = detail.Final_summary_supervisor2A;
|
||||
i.total_summary_competency_supervisor2A = detail.total_summary_competency_supervisor2A;
|
||||
i.Final_summary_competency_supervisor2A = detail.Final_summary_competency_supervisor2A;
|
||||
i.achievement_supervisor2A = detail.achievement_supervisor2A;
|
||||
i.competency_supervisor2A = detail.competency_supervisor2A;
|
||||
i.score_supervisor2A = detail.score_supervisor2A;
|
||||
i.level_score_supervisor2A = detail.level_score_supervisor2A;
|
||||
}
|
||||
|
||||
i.w1 = p.create_evaluation_score1;
|
||||
i.w2 = p.create_evaluation_score2;
|
||||
|
||||
var q = emp.GetLeaveOfEmployee(p.employee_id.Value, p.start_date, p.end_date);
|
||||
i.sum_day_sick_leave = q.sum_day_sick_leave;
|
||||
i.count_sick_leave = q.count_sick_leave;
|
||||
i.sum_day_personal_leave = q.sum_day_personal_leave;
|
||||
i.count_personal_leave = q.count_personal_leave;
|
||||
i.sum_day_vacation_leave = q.sum_day_vacation_leave;
|
||||
i.count_stop_working = q.count_stop_working;
|
||||
i.count_late_tad_processing_time_results = q.count_late_tad_processing_time_results;
|
||||
i.count_absence_tad_processing_time_results = q.count_absence_tad_processing_time_results;
|
||||
i.sum_day_sick_personal_leave = q.sum_day_sick_personal_leave;
|
||||
i.count_sick_personal_leave = q.count_sick_personal_leave;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user