SendBendsInfoService.cs 5.4 KB
using Autofac.Core;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.Service.Repository;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Hh.Mes.Service.QuartzJobService
{
    public class SendBendsInfoService : RepositorySqlSugar<bus_pipebends_job>
    {
        public void Execute()
        {
            List<bus_pipebends_job> bends = Context.Queryable<bus_pipebends_job>().Where(x => x.state == "0").Take(30).ToList();

            if (bends != null && bends.Count > 0)
            {
                Log4NetHelper.Instance.Info("开始发送弯管数据,数量:" + bends.Count);
                PDAService service = new PDAService(null);
                //获取工位
                List<base_work_station> stations = Context.Queryable<base_work_station>().Where(x => x.workStationCode.Contains("BentPipe") && !string.IsNullOrEmpty(x.monitorIP)).ToList();

                foreach (bus_pipebends_job pipe in bends)
                {
                    try
                    {
                        pipe.state = "1";
                        pipe.updateTime = DateTime.Now;
                        pipe.msg = "";
                        // List<base_work_station> stations2 = stations.Where(x => x.lineCode.ToUpper() == pipe.lineCode.ToUpper()).ToList();
                        foreach (base_work_station station in stations)
                        {
                            POJO.Response.Response result = service.InBentPipeTask(pipe.workPieceNo, station.workStationCode);
                            if (result.Code == 200)
                            {
                                pipe.msg += $"{station.workStationCode} 处理成功";
                            }
                            else
                            {
                                pipe.state = "2";
                                pipe.msg += $"{station.workStationCode} 处理失败,错误信息{result.Message}";
                            }
                        }
                        if (pipe.msg.Length > 500)
                        {
                            pipe.msg = pipe.msg.Substring(0, 500);
                        }
                        Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
                    }
                    catch (Exception x)
                    {
                        pipe.msg += x.Message;
                        if (pipe.msg.Length > 500)
                        {
                            pipe.msg = pipe.msg.Substring(0, 500);
                        }
                        pipe.state = "2";
                        Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
                    }
                }

            }
            else
            {

                bends = Context.Queryable<bus_pipebends_job>().Where(x => x.state == "2").Take(30).ToList();

                Log4NetHelper.Instance.Info("开始重新发送弯管数据,数量:" + bends.Count);
                PDAService service = new PDAService(null);
                //获取工位
                List<base_work_station> stations = Context.Queryable<base_work_station>().Where(x => x.workStationCode.Contains("BentPipe") && !string.IsNullOrEmpty(x.monitorIP)).ToList();
                foreach (bus_pipebends_job pipe in bends)
                {
                    try
                    {
                        pipe.state = "1";
                        pipe.updateTime = DateTime.Now;
                        pipe.msg = "";
                        //List<base_work_station> stations2 = stations.Where(x => x.lineCode.ToUpper() == pipe.lineCode.ToUpper()).ToList();
                        foreach (base_work_station station in stations)
                        {
                            POJO.Response.Response result = service.InBentPipeTask(pipe.workPieceNo, station.workStationCode);
                            if (result.Code == 200)
                            {
                                pipe.msg += $"{station.workStationCode} 处理成功";
                            }
                            else
                            {
                                pipe.state = "2";
                                pipe.msg += $"{station.workStationCode} 处理失败,错误信息{result.Message}";
                            }
                        }
                        if (pipe.msg.Length > 500)
                        {
                            pipe.msg = pipe.msg.Substring(0, 500);
                        }
                        Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
                    }
                    catch (Exception x)
                    {
                        pipe.msg += x.Message;
                        if (pipe.msg.Length > 500)
                        {
                            pipe.msg = pipe.msg.Substring(0, 500);
                        }
                        pipe.state = "2";
                        Context.Updateable(pipe).UpdateColumns(t => new { t.state, t.updateby, t.updateTime, t.msg }).ExecuteCommand();
                    }
                }


            }
        }
    }
}