210 lines
8.1 KiB
C#
210 lines
8.1 KiB
C#
using AutoMapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using TTSW.EF;
|
|
using TTSW.Utils;
|
|
using TTSW.Constant;
|
|
using TTSW.Common;
|
|
using TodoAPI2.Models;
|
|
using System.IO;
|
|
using System.Web;
|
|
using System.Net;
|
|
using TTSW.Configure;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Data;
|
|
using Npgsql;
|
|
|
|
namespace TodoAPI2.Models
|
|
{
|
|
public class external_employeeService : Iexternal_employeeService
|
|
{
|
|
private IMyDatabase db;
|
|
|
|
public external_employeeService(IMyDatabase mydb)
|
|
{
|
|
db = mydb;
|
|
}
|
|
|
|
public int? GetLeader(int? emp_id)
|
|
{
|
|
var sql = @"
|
|
SELECT ha.employee_id as emp_id,
|
|
CONCAT(hta.title_name,ha.firstname,' ',ha.lastname) as emp_name,
|
|
ha.chief_id,
|
|
CONCAT(htb.title_name,hb.firstname,' ',hb.lastname) as chief_name
|
|
FROM public.hrm_employees as ha
|
|
left join public.hrm_employees as hb on hb.employee_id = ha.chief_id
|
|
left join public.hrm_title_masters as hta on hta.id = ha.prefix_card_name
|
|
left join public.hrm_title_masters as htb on hb.prefix_card_name = htb.id
|
|
where ha.employee_id = @emp_id and ha.workingstatus = 'สถานะปฏิบัติงาน';
|
|
";
|
|
var para = db.GetParameterListNpgsql();
|
|
|
|
var ix = new NpgsqlParameter("emp_id", DbType.Int32);
|
|
ix.Value = emp_id;
|
|
para.Add(ix);
|
|
|
|
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
|
|
|
|
if (dt.Rows.Count == 1)
|
|
{
|
|
if(dt.Rows[0]["chief_id"] == DBNull.Value)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return Convert.ToInt32(dt.Rows[0]["chief_id"]);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public List<external_employeeViewModel> GetListByemployee_type(int? employee_type, int? position_type)
|
|
{
|
|
var sql = string.Format(@"
|
|
select he.employee_id as id, mpn.position_number,he.employee_no,he.position_no,
|
|
CONCAT(htm.title_name,' ',he.firstname,' ',he.lastname) as fullname,opd.position_name,
|
|
orgdata.id as department_id,orgdata.department_name,orgdata.department_code,he.salary,
|
|
he.employee_type_id, het.employee_type_name,opd.position_id as position_id,
|
|
u.email as user_email, u.id as user_id,hpl.position_level_name,he.position_level_id,
|
|
he.position_type_id,hpt.position_type_name,he.packing_date
|
|
from public.hrm_employees as he
|
|
left join public.hrm_position_types as hpt on he.position_type_id=hpt.id
|
|
left join public.hrm_position_levels as hpl on he.position_level_id = hpl.id
|
|
left join public.mpp_position_numbers as mpn on he.position_no = mpn.id
|
|
left join public.org_position_datas as opd on opd.position_id = mpn.position_id
|
|
left join public.hrm_title_masters as htm on htm.id = he.prefix_card_name
|
|
left join public.{0}DepartmentData{0} as orgdata on orgdata.id = he.department_id
|
|
left join public.hrm_employee_types as het on het.id = he.employee_type_id
|
|
left join public.users as u on u.employee_id = he.employee_id
|
|
where he.workingstatus = 'สถานะปฏิบัติงาน' and he.deleted_at is null and mpn.deleted_at is null
|
|
and opd.deleted_at is null and htm.deleted_at is null
|
|
order by he.firstname,he.lastname;
|
|
", '"'.ToString());
|
|
var para = db.GetParameterListNpgsql();
|
|
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
|
|
var result = new List<external_employeeViewModel>();
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
var i = new external_employeeViewModel();
|
|
i.id = Convert.ToInt32(dr["id"]);
|
|
i.position_number = dr["position_number"].ToString();
|
|
i.position_name = dr["position_name"].ToString();
|
|
i.fullname= dr["fullname"].ToString();
|
|
if(dr["employee_type_id"] != DBNull.Value)
|
|
{
|
|
i.employee_type_id = Convert.ToInt32(dr["employee_type_id"]);
|
|
i.employee_type_name = dr["employee_type_name"].ToString();
|
|
}
|
|
|
|
if (dr["position_type_id"] != DBNull.Value)
|
|
{
|
|
i.position_type_id = Convert.ToInt32(dr["position_type_id"]);
|
|
i.position_type_name = dr["position_type_name"].ToString();
|
|
}
|
|
|
|
if (dr["position_id"] != DBNull.Value)
|
|
{
|
|
i.position_id = Convert.ToInt32(dr["position_id"]);
|
|
}
|
|
|
|
if (dr["user_id"] != DBNull.Value)
|
|
{
|
|
i.user_email = dr["user_email"].ToString();
|
|
i.user_id = Convert.ToInt32(dr["user_id"]);
|
|
}
|
|
if (dr["department_id"] != DBNull.Value)
|
|
{
|
|
i.department_id = Convert.ToInt32(dr["department_id"]);
|
|
i.department_name = dr["department_name"].ToString();
|
|
i.department_code = dr["department_code"].ToString();
|
|
}
|
|
if(dr["employee_no"] != DBNull.Value)
|
|
{
|
|
i.employee_no = dr["employee_no"].ToString();
|
|
}
|
|
if (dr["position_level_id"] != DBNull.Value)
|
|
{
|
|
i.position_level_id = Convert.ToInt32(dr["position_level_id"]);
|
|
i.position_level_text = dr["position_level_name"].ToString();
|
|
}
|
|
i.salary = 0;
|
|
if (dr["salary"] != DBNull.Value)
|
|
{
|
|
i.salary = Convert.ToDecimal(dr["salary"]);
|
|
}
|
|
if (dr["packing_date"] != DBNull.Value)
|
|
{
|
|
i.packing_date = Convert.ToDateTime(dr["packing_date"]);
|
|
}
|
|
|
|
result.Add(i);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public external_employeeViewModel GetEmployeeForLogin(int? user_id)
|
|
{
|
|
var sql = @"
|
|
select he.employee_id as id, mpn.position_number, opd.position_name,
|
|
CONCAT(htm.title_name,' ',he.firstname,' ',he.lastname) as fullname,
|
|
u.email as user_email, u.id as user_id,u.name as fullname2
|
|
from public.hrm_employees as he
|
|
left join public.mpp_position_numbers as mpn on he.position_no = mpn.id
|
|
left join public.org_position_datas as opd on opd.position_id = mpn.position_id
|
|
left join public.hrm_title_masters as htm on htm.id = he.prefix_card_name
|
|
left join public.users as u on u.employee_id = he.employee_id
|
|
where he.workingstatus = 'สถานะปฏิบัติงาน' and he.deleted_at is null and mpn.deleted_at is null
|
|
and opd.deleted_at is null and htm.deleted_at is null
|
|
and u.id=@user_id;
|
|
";
|
|
var para = db.GetParameterListNpgsql();
|
|
var ix = new NpgsqlParameter("user_id", DbType.Int32);
|
|
ix.Value = user_id;
|
|
para.Add(ix);
|
|
|
|
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
|
|
var result = new List<external_employeeViewModel>();
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
var i = new external_employeeViewModel();
|
|
i.id = Convert.ToInt32(dr["id"]);
|
|
i.position_number = dr["position_number"].ToString();
|
|
i.position_name = dr["position_name"].ToString();
|
|
i.fullname = dr["fullname2"].ToString();
|
|
i.employee_type_id = null;
|
|
i.position_type_id = null;
|
|
if (dr["user_id"] != DBNull.Value)
|
|
{
|
|
i.user_email = dr["user_email"].ToString();
|
|
i.user_id = Convert.ToInt32(dr["user_id"]);
|
|
}
|
|
|
|
result.Add(i);
|
|
}
|
|
if (result.Count == 1)
|
|
{
|
|
return result[0];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public external_employeeWithSelectionViewModel GetBlankItem()
|
|
{
|
|
var i = new external_employeeWithSelectionViewModel();
|
|
//var j = Mapper.Map<List<eva_performance_criteriaViewModel>>((from x in epc.GetListALLeva_performance_criteria() select x));
|
|
//i.eva_performance_criteria_id = j;
|
|
|
|
return i;
|
|
}
|
|
}
|
|
}
|
|
|