12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using EInk.Dtos;
- using EInk.Models;
- using EInk.Tools;
- using Newtonsoft.Json;
- using SqlSugar;
- namespace EInk.TaskThread
- {
- public class SendColourCastThread
- {
- private readonly ISqlSugarClient _db;
- public SendColourCastThread(ISqlSugarClient db)
- {
- _db = db;
- }
- public void SendThreadStart()
- {
- Thread t = new Thread(SendTask);
- t.Start(_db);
- }
- static void SendTask(Object db)
- {
- ISqlSugarClient _db = (ISqlSugarClient)db;
- IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
- while (true)
- {
- try
- {
- List<ColourCastModel> unsend_list = _db.Queryable<ColourCastModel>().Where(x => x.is_send == 0).OrderBy(x => x.id).Take(120).ToList();
- if (unsend_list != null && unsend_list.Count > 0)
- {
- foreach (var unsend in unsend_list)
- {
- var (rt_bl, rt_str) = HttpHelper.Post(_configuration.GetValue<string>("MesUrl")+ "/MesApi/LotAoiUpLoad", unsend.content, _configuration.GetValue<int>("MesUrlTime"));
- if (rt_bl && !string.IsNullOrEmpty(rt_str))
- {
- ResultDto rt = JsonConvert.DeserializeObject<ResultDto>(rt_str);
- if (rt.Code == CodeEnum.Ok)
- {
- unsend.is_send = 1;
- unsend.send_time = DateTime.Now;
- _db.Updateable<ColourCastModel>(unsend).WhereColumns(s => s.id).ExecuteCommand();
- }
- else
- {
- LogerHelper.RecordLogTxt("SendColourCastTask,MesApi1," + rt.Code + "," + rt.Message + "," + unsend.content);
- }
- }
- else
- {
- LogerHelper.RecordLogTxt("SendColourCastTask,MesApi2," + rt_bl+ "," + rt_str + "," + unsend.content);
- }
- Thread.Sleep(1000);
- }
- }
- }
- catch(Exception ex)
- {
- LogerHelper.RecordLogTxt("SendLotTask," + ex.Message);
- }
- finally
- {
- Thread.Sleep(5000);
- }
- }
- }
- }
- }
|