ปรับปรุง API ให้รับรูปภาพจากการสแกนได้ด้วย
This commit is contained in:
@@ -16,9 +16,17 @@ using Microsoft.Extensions.Options;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Odbc;
|
using System.Data.Odbc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace TodoAPI2.Models
|
namespace TodoAPI2.Models
|
||||||
{
|
{
|
||||||
|
public class upload_result
|
||||||
|
{
|
||||||
|
public string path { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class eva_temp_fingerscanService : Ieva_temp_fingerscanService
|
public class eva_temp_fingerscanService : Ieva_temp_fingerscanService
|
||||||
{
|
{
|
||||||
private IBaseRepository2<eva_temp_fingerscanEntity, string> _repository;
|
private IBaseRepository2<eva_temp_fingerscanEntity, string> _repository;
|
||||||
@@ -170,13 +178,48 @@ namespace TodoAPI2.Models
|
|||||||
.Replace("ผศ.ดร.", "");
|
.Replace("ผศ.ดร.", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string PostAttachment(byte[] data, string filename)
|
||||||
|
{
|
||||||
|
HttpContent content = new ByteArrayContent(data);
|
||||||
|
|
||||||
|
content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
|
||||||
|
|
||||||
|
using (var form = new MultipartFormDataContent())
|
||||||
|
{
|
||||||
|
form.Add(content, "file", filename);
|
||||||
|
|
||||||
|
using (var client = new HttpClient())
|
||||||
|
{
|
||||||
|
var url = MyHelper.GetConfig(Configuration, "SiteInformation:hr_upload_api");
|
||||||
|
var response = client.PostAsync(url, form).Result;
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
var json = response.Content.ReadAsStringAsync().Result;
|
||||||
|
upload_result u = JsonConvert.DeserializeObject<upload_result>(json);
|
||||||
|
return u.path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string RecieveFingerScanFromLocal(List<fingerscanDataModel> model)
|
public string RecieveFingerScanFromLocal(List<fingerscanDataModel> model)
|
||||||
{
|
{
|
||||||
var all_emp = emp.GetListByemployee_type(null, null);
|
var all_emp = emp.GetListByemployee_type(null, null);
|
||||||
|
|
||||||
var result = (from i in model
|
//var result = (from i in model
|
||||||
join e in all_emp on ClearName(i.fullname) equals ClearName(e.halfname)
|
// join e in all_emp on ClearName(i.fullname) equals ClearName(e.halfname)
|
||||||
select e.id.ToString() + "#" + GetDateStringForDB(i.checktime) + "#" + GetTimeStringForDB(i.checktime)).ToList();
|
// select e.id.ToString() + "#" + GetDateStringForDB(i.checktime) + "#" + GetTimeStringForDB(i.checktime)).ToList();
|
||||||
|
|
||||||
|
var result = new List<string>();
|
||||||
|
|
||||||
|
foreach (var i in model)
|
||||||
|
{
|
||||||
|
var id = (from e in all_emp
|
||||||
|
where ClearName(i.fullname) == ClearName(e.halfname)
|
||||||
|
select e.id.ToString()).FirstOrDefault().ToString();
|
||||||
|
byte[] imageBytes = Convert.FromBase64String(i.base64img);
|
||||||
|
var r = PostAttachment(imageBytes, "jk" + i.image_id + ".jpg");
|
||||||
|
var r2 = id + "#" + GetDateStringForDB(i.checktime) + "#" + GetTimeStringForDB(i.checktime) + "#" + r;
|
||||||
|
result.Add(r2);
|
||||||
|
}
|
||||||
|
|
||||||
return InsertFingerScanToHR(result);
|
return InsertFingerScanToHR(result);
|
||||||
}
|
}
|
||||||
@@ -190,14 +233,14 @@ namespace TodoAPI2.Models
|
|||||||
string employee_id = data[0];
|
string employee_id = data[0];
|
||||||
string date = data[1];
|
string date = data[1];
|
||||||
string time = data[2];
|
string time = data[2];
|
||||||
|
string picture = data[3];
|
||||||
|
|
||||||
string sql_checking = $"select employee_id,date,time from tad_time_attendances where employee_id={employee_id} and date='{date}' and time='{time}' ";
|
string sql_checking = $"select employee_id,date,time from tad_time_attendances where employee_id={employee_id} and date='{date}' and time='{time}' ";
|
||||||
|
|
||||||
|
|
||||||
DataTable dt = db.ExecuteDataTableNpgsql(sql_checking, null);
|
DataTable dt = db.ExecuteDataTableNpgsql(sql_checking, null);
|
||||||
if (dt.Rows.Count == 0)
|
if (dt.Rows.Count == 0)
|
||||||
{
|
{
|
||||||
string sql_insert = $"insert into tad_time_attendances(employee_id,date,time) values({employee_id},'{date}','{time}')";
|
string sql_insert = $"insert into tad_time_attendances(employee_id,date,time,picture) values({employee_id},'{date}','{time}','{picture}')";
|
||||||
db.ExecuteNonQueryNpgsql(sql_insert, null);
|
db.ExecuteNonQueryNpgsql(sql_insert, null);
|
||||||
count_insert++;
|
count_insert++;
|
||||||
}
|
}
|
||||||
@@ -228,6 +271,10 @@ namespace TodoAPI2.Models
|
|||||||
public DateTime checktime { get; set; }
|
public DateTime checktime { get; set; }
|
||||||
|
|
||||||
public string fullname { get; set; }
|
public string fullname { get; set; }
|
||||||
|
|
||||||
|
public string device_id { get; set; }
|
||||||
|
public string image_id { get; set; }
|
||||||
|
public string base64img { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
"mainsite": "http://tb320dev.zd.co.th",
|
"mainsite": "http://tb320dev.zd.co.th",
|
||||||
"modulesite": "http://tb320dev.zd.co.th/menu/evaluation",
|
"modulesite": "http://tb320dev.zd.co.th/menu/evaluation",
|
||||||
"sitename": "เนติบัณฑิตยสภา ในพระบรมราชูปถัมภ์",
|
"sitename": "เนติบัณฑิตยสภา ในพระบรมราชูปถัมภ์",
|
||||||
"modulename": "ระบบประวัติเงินเดือนและการเลื่อนเงินเดือน"
|
"modulename": "ระบบประวัติเงินเดือนและการเลื่อนเงินเดือน",
|
||||||
|
"hr_upload_api": "http://tb-320.zd.co.th/api/file/upload"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
"mainsite": "http://tb320.zd.co.th",
|
"mainsite": "http://tb320.zd.co.th",
|
||||||
"modulesite": "http://tb320.zd.co.th/menu/evaluation",
|
"modulesite": "http://tb320.zd.co.th/menu/evaluation",
|
||||||
"sitename": "เนติบัณฑิตยสภา ในพระบรมราชูปถัมภ์",
|
"sitename": "เนติบัณฑิตยสภา ในพระบรมราชูปถัมภ์",
|
||||||
"modulename": "ระบบประวัติเงินเดือนและการเลื่อนเงินเดือน"
|
"modulename": "ระบบประวัติเงินเดือนและการเลื่อนเงินเดือน",
|
||||||
|
"hr_upload_api": "http://tb-320.zd.co.th/api/file/upload"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
"mainsite": "http://tb320dev.zd.co.th",
|
"mainsite": "http://tb320dev.zd.co.th",
|
||||||
"modulesite": "http://tb320dev.zd.co.th/menu/evaluation",
|
"modulesite": "http://tb320dev.zd.co.th/menu/evaluation",
|
||||||
"sitename": "เนติบัณฑิตยสภา ในพระบรมราชูปถัมภ์",
|
"sitename": "เนติบัณฑิตยสภา ในพระบรมราชูปถัมภ์",
|
||||||
"modulename": "ระบบประวัติเงินเดือนและการเลื่อนเงินเดือน"
|
"modulename": "ระบบประวัติเงินเดือนและการเลื่อนเงินเดือน",
|
||||||
|
"hr_upload_api": "http://tb-320.zd.co.th/api/file/upload"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user