ทำ Access Matrix

This commit is contained in:
Nakorn Rientrakrunchai
2020-11-17 12:23:25 +07:00
parent 01bebe4549
commit 5ca2b0d53d
5 changed files with 222 additions and 35 deletions

View File

@@ -16,9 +16,12 @@ namespace TodoAPI2.Models
int? GetLeader(int? emp_id);
external_employeeViewModel GetEmployeeForLogin(int? user_id);
external_employeeWithSelectionViewModel GetBlankItem();
employee_leaveViewModel GetLeaveOfEmployee(int employee_id, DateTime? start_date, DateTime? end_date);
List<external_employeeViewModel> GetAllEmployee();
List<external_menu> GetAllMenu();
List<external_menu> GetMenuByUser(int? userid);
List<external_user> GetAllUser();
}
}

View File

@@ -24,7 +24,7 @@ namespace TodoAPI2.Models
public external_employeeService(IMyDatabase mydb)
{
db = mydb;
db = mydb;
}
public int? GetLeader(int? emp_id)
@@ -50,15 +50,15 @@ where ha.employee_id = @emp_id and ha.workingstatus = 'สถานะปฏิ
if (dt.Rows.Count == 1)
{
if(dt.Rows[0]["chief_id"] == DBNull.Value)
if (dt.Rows[0]["chief_id"] == DBNull.Value)
{
return null;
}
else
{
return Convert.ToInt32(dt.Rows[0]["chief_id"]);
}
}
}
}
return null;
}
@@ -127,7 +127,7 @@ order by he.firstname, he.lastname;
i.profile_picture = dr["profile_picture"].ToString();
i.position_number = dr["position_number"].ToString();
i.position_name = dr["position_name"].ToString();
i.fullname= dr["fullname"].ToString();
i.fullname = dr["fullname"].ToString();
i.halfname = dr["halfname"].ToString();
if (dr["employee_type_id"] != DBNull.Value)
{
@@ -158,16 +158,16 @@ order by he.firstname, he.lastname;
i.department_name = dr["department_name"].ToString();
i.department_code = dr["department_code"].ToString();
}
if(dr["employee_no"] != DBNull.Value)
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.position_level_text = dr["position_level_name"].ToString();
}
if(dr["hpl_position_level_id"] != DBNull.Value)
if (dr["hpl_position_level_id"] != DBNull.Value)
{
i.hpl_position_level_id = Convert.ToInt32(dr["hpl_position_level_id"]);
}
@@ -197,10 +197,10 @@ order by he.firstname, he.lastname;
{
i.department_degree_id = Convert.ToInt32(dr["department_degree_id"]);
}
if(dr["remark_hrm_work_record"] != DBNull.Value)
if (dr["remark_hrm_work_record"] != DBNull.Value)
{
i.remark_hrm_work_record = dr["remark_hrm_work_record"].ToString();
}
}
result.Add(i);
}
@@ -584,6 +584,141 @@ select {0}b{0}.{0}employee_id{0}, (
return i;
}
public List<external_menu> GetAllMenu()
{
var sql = string.Format(@"
select cself.icon,cself.id,
case
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
else pmenu2.sort
end as psort,
case
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
end
as pid,cself.display_name
from core_menu as cself
left join core_menu as pmenu on cself.parent_id=pmenu.id
left join core_menu as pmenu2 on pmenu.parent_id=pmenu2.id
where cself.id in (
select model_id from model_has_roles
where model_type='App\Models\Menu'
and role_id in (select id from roles where id in (
select role_id from model_has_roles
where model_type='App\Models\User'
and model_id in (select id from users)
order by model_id
))
) order by
case
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
else pmenu2.sort
end,
case
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
end
", '"'.ToString());
var para = db.GetParameterListNpgsql();
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
var result = new List<external_menu>();
foreach (DataRow dr in dt.Rows)
{
var i = new external_menu();
i.icon = dr["icon"].ToString();
i.id = Convert.ToInt32(dr["id"]);
i.psort = Convert.ToInt32(dr["psort"]);
i.pid = Convert.ToInt32(dr["pid"]);
i.display_name = dr["display_name"].ToString();
result.Add(i);
}
return result;
}
public List<external_menu> GetMenuByUser(int? userid)
{
var sql = string.Format(@"
select cself.icon,cself.id,
case
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
else pmenu2.sort
end as psort,
case
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
end
as pid,cself.display_name
from core_menu as cself
left join core_menu as pmenu on cself.parent_id=pmenu.id
left join core_menu as pmenu2 on pmenu.parent_id=pmenu2.id
where cself.id in (
select model_id from model_has_roles
where model_type='App\Models\Menu'
and role_id in (select id from roles where id in (
select role_id from model_has_roles
where model_type='App\Models\User'
and model_id in ({1})
order by model_id
))
) order by
case
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
else pmenu2.sort
end,
case
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
end
", '"'.ToString(), userid.ToString());
var para = db.GetParameterListNpgsql();
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
var result = new List<external_menu>();
foreach (DataRow dr in dt.Rows)
{
var i = new external_menu();
i.icon = dr["icon"].ToString();
i.id = Convert.ToInt32(dr["id"]);
i.psort = Convert.ToInt32(dr["psort"]);
i.pid = Convert.ToInt32(dr["pid"]);
i.display_name = dr["display_name"].ToString();
result.Add(i);
}
return result;
}
public List<external_user> GetAllUser()
{
var sql = string.Format(@"
select id,name from users
", '"'.ToString());
var para = db.GetParameterListNpgsql();
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
var result = new List<external_user>();
foreach (DataRow dr in dt.Rows)
{
var i = new external_user();
i.id = Convert.ToInt32(dr["id"]);
i.name = dr["name"].ToString();
result.Add(i);
}
return result;
}
public external_employeeWithSelectionViewModel GetBlankItem()
{
var i = new external_employeeWithSelectionViewModel();
@@ -593,5 +728,20 @@ select {0}b{0}.{0}employee_id{0}, (
return i;
}
}
public class external_menu
{
public string icon { get; set; }
public int? id { get; set; }
public int? psort { get; set; }
public int? pid { get; set; }
public string display_name { get; set; }
}
public class external_user
{
public int? id { get; set; }
public string name { get; set; }
}
}