2025-03-05 11:31:36 +09:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
|
|
public class WorkTimeRequesttBody
|
|
|
|
|
{
|
|
|
|
|
public string startDate;
|
|
|
|
|
public string endDate;
|
|
|
|
|
public string MCHCD;
|
|
|
|
|
public string WO;
|
|
|
|
|
}
|
|
|
|
|
public class WorkConditionsRequestBody
|
|
|
|
|
{
|
|
|
|
|
public string startDate;
|
|
|
|
|
public string endDate;
|
|
|
|
|
public string MCHCD;
|
|
|
|
|
public string WO;
|
|
|
|
|
}
|
|
|
|
|
public class HTTPTest : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public string apiKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiZW1haWwiOiJ1dmMiLCJncm91cElkIjoyLCJncm91cENvZGUiOiJjaHVuaWxlbmciLCJyb2xlIjoiVGVuYW50QWRtaW4iLCJuYW1lIjoi7Jyg67mE7JSoIiwibGljZW5zZSI6ImJ1c2luZXNzIiwicGhvbmUiOiIiLCJpYXQiOjE3NDA1MzY0NzUsImV4cCI6NDg5NDEzNjQ3NX0.hr4D0bOA4K09Vhp12itiJgd-nVDQ3VZO8D7MVP5Ltw0";
|
|
|
|
|
public string httpServer = "http://220.90.135.112:3100";
|
|
|
|
|
public string facilityAPI = "/api/workConditionAnalysis/facilityCode";
|
|
|
|
|
public string workingConditionsAPI = "/api/workConditionAnalysis/analyze";
|
|
|
|
|
public string workingTimeAPI = "/api/workTimeAnalysis/analyze";
|
|
|
|
|
|
|
|
|
|
public string startDate;
|
|
|
|
|
public string endDate;
|
|
|
|
|
|
|
|
|
|
public WorkConditionsRequestBody testWorkConditionRequest;
|
|
|
|
|
public WorkTimeRequesttBody testWorkTimeRequest;
|
|
|
|
|
|
2025-03-05 15:22:39 +09:00
|
|
|
public WorkConditionFacilityData workConditionFacilityData;
|
2025-03-05 11:31:36 +09:00
|
|
|
public WorkConditionsData workConditionsData;
|
|
|
|
|
public WorkTimeData workTimeData;
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(HTTPWebRequest());
|
|
|
|
|
}
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.K))
|
|
|
|
|
{
|
|
|
|
|
WorkConditionInQuiry();
|
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyDown(KeyCode.J))
|
|
|
|
|
{
|
|
|
|
|
WorkTimeInQuiry();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator HTTPWebRequest()
|
|
|
|
|
{
|
|
|
|
|
var path = httpServer + facilityAPI;
|
|
|
|
|
var query = $"?startDate={startDate}&endDate={endDate}";
|
|
|
|
|
|
|
|
|
|
string url = path + query;
|
|
|
|
|
|
|
|
|
|
UnityWebRequest www = UnityWebRequest.Get(url);
|
|
|
|
|
www.SetRequestHeader("access-token", apiKey);
|
|
|
|
|
|
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (www.error == null)
|
|
|
|
|
{
|
2025-03-05 15:22:39 +09:00
|
|
|
var payload = Encoding.UTF8.GetString(www.downloadHandler.data);
|
|
|
|
|
var response = JsonConvert.DeserializeObject<WorkConditionFacilityData>(payload);
|
|
|
|
|
workConditionFacilityData = response;
|
2025-03-05 11:31:36 +09:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log(www.error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WorkConditionInQuiry()
|
|
|
|
|
{
|
|
|
|
|
var path = httpServer + workingConditionsAPI;
|
|
|
|
|
|
|
|
|
|
testWorkConditionRequest = TestWorkConditionSetting();
|
|
|
|
|
var json = JsonUtility.ToJson(testWorkConditionRequest);
|
|
|
|
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
StartCoroutine(WorkConditionsPost(path, json));
|
|
|
|
|
}
|
|
|
|
|
IEnumerator WorkConditionsPost(string url, string jsonData)
|
|
|
|
|
{
|
|
|
|
|
var request = new UnityWebRequest(url, "POST");
|
|
|
|
|
byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(jsonData);
|
|
|
|
|
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
|
|
|
|
request.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
|
request.SetRequestHeader("access-token", apiKey);
|
|
|
|
|
request.SetRequestHeader("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Error: " + request.error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var payload = Encoding.UTF8.GetString(request.downloadHandler.data);
|
|
|
|
|
var response = JsonConvert.DeserializeObject<WorkConditionsData>(payload);
|
|
|
|
|
|
|
|
|
|
workConditionsData = response;
|
|
|
|
|
Debug.Log("Received: " + request.downloadHandler.text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WorkTimeInQuiry()
|
|
|
|
|
{
|
|
|
|
|
var path = httpServer + workingTimeAPI;
|
|
|
|
|
|
|
|
|
|
testWorkTimeRequest = TestWorkTimeSetting();
|
|
|
|
|
var json = JsonUtility.ToJson(testWorkTimeRequest);
|
|
|
|
|
|
|
|
|
|
StopAllCoroutines();
|
|
|
|
|
StartCoroutine(WorkTimePost(path, json));
|
|
|
|
|
}
|
|
|
|
|
IEnumerator WorkTimePost(string url, string jsonData)
|
|
|
|
|
{
|
|
|
|
|
var request = new UnityWebRequest(url, "POST");
|
|
|
|
|
byte[] bodyRaw = new UTF8Encoding().GetBytes(jsonData);
|
|
|
|
|
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
|
|
|
|
request.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
|
request.SetRequestHeader("access-token", apiKey);
|
|
|
|
|
request.SetRequestHeader("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Error: " + request.error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var payload = Encoding.UTF8.GetString(request.downloadHandler.data);
|
|
|
|
|
var response = JsonConvert.DeserializeObject<WorkTimeData>(payload);
|
|
|
|
|
|
|
|
|
|
workTimeData = response;
|
|
|
|
|
|
|
|
|
|
Debug.Log("Received: " + request.downloadHandler.text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#region TestJson
|
|
|
|
|
WorkTimeRequesttBody TestWorkTimeSetting()
|
|
|
|
|
{
|
|
|
|
|
WorkTimeRequesttBody request = new WorkTimeRequesttBody
|
|
|
|
|
{
|
|
|
|
|
startDate = "2025-01-10T00:00:00Z",
|
|
|
|
|
endDate = "2025-02-20T00:00:00Z",
|
|
|
|
|
MCHCD = "IJ01",
|
|
|
|
|
WO = "WO202502170014"
|
|
|
|
|
};
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
WorkConditionsRequestBody TestWorkConditionSetting()
|
|
|
|
|
{
|
|
|
|
|
WorkConditionsRequestBody request = new WorkConditionsRequestBody
|
|
|
|
|
{
|
|
|
|
|
startDate = "2025-01-10T00:00:00Z",
|
|
|
|
|
endDate = "2025-02-20T00:00:00Z",
|
|
|
|
|
MCHCD = "IJ01",
|
|
|
|
|
WO = "WO202502170014"
|
|
|
|
|
};
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|