1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using EInk.Dtos;
- using EInk.Models;
- using EInk.Tools;
- using Newtonsoft.Json;
- using SqlSugar;
- namespace EInk.TaskThread
- {
- public class SendColourCastThread
- {
- public void SendThreadStart()
- {
- Thread t = new Thread(SendTask);
- t.Start();
- }
- static void SendTask()
- {
- IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
- ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
- {
- DbType = DbType.PostgreSQL,
- ConnectionString = _configuration.GetValue<string>("LocalDbConnectionString"),
- IsAutoCloseConnection = true
- });
- 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(200);
- }
- }
- }
- catch(Exception ex)
- {
- LogerHelper.RecordLogTxt($"SendColourCastTask, StackTrace:{ex.StackTrace}, Message:{ex.Message}");
- }
- finally
- {
- Thread.Sleep(5000);
- }
- }
- }
- }
- }
|