123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
-
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Logging;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using WebApplet.Models;
- using DllEapDal.OFILM;
- using Newtonsoft.Json;
- using DllEapEntity.Dtos;
- using Cksoft.Unity.Log4NetConfig;
- namespace WebApplet.Controllers
- {
- /// <summary>
- /// EAP 辅助应用sample校验调用的api接口
- /// </summary>
- [Route("eap/api/[controller]/[action]")]
- public class ParamsController : ControllerBase
- {
- IDatabase db;
- public IConfiguration Configuration { get; set; }
- public ParamsController(IConfiguration configuration)
- {
- Configuration = configuration;
-
- }
- /// <summary>
- /// 机台的机种,机台编号获取
- /// </summary>
- /// <param name="MId"></param>
- /// <returns></returns>
- [HttpGet]
- public SampleStandard Get(string MId)
- {
- SampleStandard sample = new SampleStandard();
- string type = string.Empty;
- string macNum = string.Empty;
- using (db = DbFactory.Base("eapslave"))
- {
- var dal = new SampleDal(db);
- type = dal.Get(MId);
- LogHelper<MachineMaterialService>.LogError(type, "DA sample 校验", string.Empty);
- macNum = dal.GetMacNumber(MId);
-
- }
- if (!string.IsNullOrEmpty(type))
- {
- using (db = DbFactory.Base("qis"))
- {
- var dal = new SampleDal(db);
- return dal.MesGet(MId, type, macNum);
- }
- }
- else
- {
- sample.code = "0";
- sample.msg = "未查询到机种信息,暂不支持Sample校验";
- return sample;
- }
- }
-
- /// <summary>
- /// 获取Sample校验参数
- /// </summary>
- /// <param name="paramModel"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<object> GetParams([FromBody] ParamModel paramModel)
- {
- var dal = new SampleDal();
- DateTime time = DateTime.Now;
- var result = dal.GetParamsAsync(paramModel);
- var s = result.Result;
- LayuiModel<Sample> sample = new LayuiModel<Sample>();
- if (s.code == "ok")
- {
- sample.code = 1;
- sample.msg = s.massage;
- Sample ss = new Sample();
- ss.sTime = time.ToString("yyyy-MM-dd HH:mm:ss");
- ss.macId = s.data.equipmentID;
- foreach (var item in s.data.parameters)
- {
- if (item.paramName == "560")
- {
- ss.xOffset = Math.Round(Convert.ToDouble(item.paramValue), 1).ToString();
- }
- if (item.paramName == "561")
- {
- ss.yOffset = Math.Round(Convert.ToDouble(item.paramValue), 1).ToString(); ;
- }
- if (item.paramName == "562")
- {
- ss.tOffset = Math.Round(Convert.ToDouble(item.paramValue), 2).ToString(); ;
- }
- }
- List<Sample> li = new List<Sample>();
- li.Add(ss);
- sample.data = li;
- }
- else
- {
- sample.code = 0;
- sample.msg = s.code;
- }
- return sample;
- }
- /// <summary>
- /// 命令调用
- /// </summary>
- /// <param name="paramModel"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<object> post([FromBody] ParamModell paramModel)
- {
- try
- {
- string str = string.Empty;
- string url = AppConfigurtaionServices.Configuration["url"]; ;
- foreach (var item in paramModel.MacCode)
- {
- Stopwatch sw = new Stopwatch();
- sw.Reset();
- sw.Start();
- var paras = paramModel.Paras;//new string[] { "283" };
- var obj = new Models.MachineInfo { EquipmentID = item, ParamsList = paras };
- HttpClient client = new HttpClient(new HttpClientHandler
- {
- AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
- });
- client.DefaultRequestHeaders.Add("Method", "POST");
- client.DefaultRequestHeaders.Add("ContentType", "multipart/form-data; charset=utf-8");
- var content = new MultipartFormDataContent();
- var uri = new Uri(url);
- var equipmentId = new ByteArrayContent(Encoding.UTF8.GetBytes(obj.EquipmentID));
- content.Add(equipmentId, "EquipmentID");
- for (int i = 0; i < obj.ParamsList.Count(); i++)
- {
- var temp = new ByteArrayContent(Encoding.UTF8.GetBytes(obj.ParamsList.ElementAt(i)));
- content.Add(temp, $"ParamsList[{i}]");
- }
- client.Timeout = new TimeSpan(0, 0, 600);
- LogHelper<MachineMaterialService>.LogError("请求地址: " + url + "请求内容: " + content.ToJson(), "DA sample 校验", string.Empty);
- var result = await client.PostAsync(uri, content);
- DateTime time = DateTime.Now;
- sw.Stop();
- // Console.WriteLine("请求用时:" + sw.ElapsedMilliseconds / 1000);
- if (result == null || result.IsSuccessStatusCode == false)
- {
- Console.WriteLine("----------------");
- LogHelper<MachineMaterialService>.LogError("请求返回的结果" + result.ToJson(), "DA sample 校验", string.Empty);
- Console.WriteLine(result);
- Console.WriteLine("----------------");
- }
- if (result != null && result.IsSuccessStatusCode)
- {
- var bytes = result.Content.ReadAsByteArrayAsync().Result;
- str+= Encoding.UTF8.GetString(bytes);
- }
-
- }
- return str;
- }
- catch (Exception ex)
- {
- return "请求超时";
- }
- }
- /// <summary>
- /// 数据上传接口
- /// </summary>
- /// <param name="sample"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<object> GetMesInfo([FromBody] Sample sample)
- {
- try
- {
- LogHelper<MachineMaterialService>.LogError("GetMesInfo: " + sample.ToJson(), "DA sample 校验", string.Empty);
- DASampleService.EapSampleServiceClient client = new DASampleService.EapSampleServiceClient();
- string x = JsonConvert.SerializeObject(sample);
- string result = client.checkSample(x);
- var temp = JsonConvert.DeserializeObject<Response>(result);
- LogHelper<MachineMaterialService>.LogError("返回值: " + result, "DA sample 校验", string.Empty);
- using (db = DbFactory.Base("eap"))
- {
- SampleDal dal = new SampleDal(db);
- dal.Set(sample, temp.message/*"test"*/);
- }
- return temp.message;
- /*return "TEST";*/
- #region 没有用
- //string url = "";
- //string macCode = paramModel.MacCode;
- //Stopwatch sw = new Stopwatch();
- //sw.Reset();
- //sw.Start();
- //var paras = paramModel.Paras;//new string[] { "283" };
- //var obj = new MachineInfo { EquipmentID = macCode, ParamsList = paras };
- //HttpClient client = new HttpClient(new HttpClientHandler
- //{
- // AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
- //});
- //client.DefaultRequestHeaders.Add("Method", "POST");
- //client.DefaultRequestHeaders.Add("ContentType", "multipart/form-data; charset=utf-8");
- //var content = new MultipartFormDataContent();
- //var uri = new Uri(url);
- //var equipmentId = new ByteArrayContent(Encoding.UTF8.GetBytes(obj.EquipmentID));
- //content.Add(equipmentId, "EquipmentID");
- //for (int i = 0; i < obj.ParamsList.Count(); i++)
- //{
- // var temp = new ByteArrayContent(Encoding.UTF8.GetBytes(obj.ParamsList.ElementAt(i)));
- // content.Add(temp, $"ParamsList[{i}]");
- //}
- //client.Timeout = new TimeSpan(0, 0, 600);
- //var result = await client.PostAsync(uri, content);
- //sw.Stop();
- //// Console.WriteLine("请求用时:" + sw.ElapsedMilliseconds / 1000);
- //if (result == null || result.IsSuccessStatusCode == false)
- //{
- // Console.WriteLine("----------------");
- // Console.WriteLine(result);
- // Console.WriteLine("----------------");
- //}
- //if (result != null && result.IsSuccessStatusCode)
- //{
- // var bytes = result.Content.ReadAsByteArrayAsync().Result;
- // return Encoding.UTF8.GetString(bytes);
- //}
- /* return "请求Mes接口返回信息";
- */
- #endregion
- }
- catch (Exception ex)
- {
- return ex;
- }
-
- }
- }
- }
|