123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using DllEapDal;
- using DllEapEntity;
- using DllEapEntity.Dtos;
- using DllEapEntity.Rms;
- using DllHsms;
- using DllStatusShowDal;
- using Newtonsoft.Json;
- using RabbitMQ.Client;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- namespace DllStatusShowBll
- {
- public class StatusShowBll : IDisposable
- {
- private string CurrDbCode = "sqlconn";
- private IDatabase CurrDb = null;
- public StatusShowBll(string dbcode)
- {
- CurrDbCode = dbcode;
- CurrDb = DbFactory.Base(CurrDbCode);
- }
- public StatusShowBll()
- {
- }
- public void Dispose()
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- public Hashtable IUTLcd(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- TLcd entity = JsonConvert.DeserializeObject<TLcd>((string)imputds[nameof(TLcd)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- TLcdDal tempdal = new TLcdDal(CurrDb);
- entity = tempdal.IUTLcd(entity, order.usercode, ref errorinfo);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(TLcd), JsonConvert.SerializeObject(entity));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable DelTLcd(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- List<TLcd> entity = JsonConvert.DeserializeObject<List<TLcd>>((string)imputds[nameof(TLcd)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- TLcdDal tempdal = new TLcdDal(CurrDb);
- TLcd result = tempdal.DelTLcd(entity, order.usercode, ref errorinfo);
- if (result == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(TLcd), JsonConvert.SerializeObject(result));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable IUTEntity(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- TEntity entity = JsonConvert.DeserializeObject<TEntity>((string)imputds[nameof(TEntity)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- TEntityDal tempdal = new TEntityDal(CurrDb);
- entity = tempdal.IUTEntity(entity, order.usercode, ref errorinfo);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(TEntity), JsonConvert.SerializeObject(entity));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable DelTEntity(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- List<TEntity> entity = JsonConvert.DeserializeObject<List<TEntity>>((string)imputds[nameof(TEntity)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- TEntityDal tempdal = new TEntityDal(CurrDb);
- TEntity result = tempdal.DelTEntity(entity, order.usercode, ref errorinfo);
- if (result == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(TEntity), JsonConvert.SerializeObject(result));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable IULayoutMst(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- LayoutMst entity = JsonConvert.DeserializeObject<LayoutMst>((string)imputds[nameof(LayoutMst)]);
- List<LayoutDetail> details = JsonConvert.DeserializeObject<List<LayoutDetail>>((string)imputds[nameof(LayoutDetail)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- LayoutMstDal tempdal = new LayoutMstDal(CurrDb);
- entity = tempdal.IULayoutMst(entity, details, order.usercode, ref errorinfo);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(LayoutMst), JsonConvert.SerializeObject(entity));
- CurrDb.Commit();
- //广播layout改变
- BroadcastLayout(entity, ref errorinfo);
- errorinfo = "";
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- private int BroadcastLayout(LayoutMst mst, ref string errorinfo)
- {
- IConnection connection = null;
- try
- {
- List<MQServer> mqserver = CurrDb.FindListForCondition<MQServer>("", ref errorinfo).ToList();
- if (mqserver == null)
- return -1;
- foreach (var item in mqserver)
- {
- var factory = new ConnectionFactory();
- factory.HostName = item.IpAddress;
- factory.UserName = item.FUser;
- factory.Password = item.FPasswd;
- connection = factory.CreateConnection();
- var channel = connection.CreateModel();
- byte[] queuedata = EntityHelper.SerializeBytes<LayoutMst>(mst);
- if (queuedata == null)
- return -1;
- string LayoutExchange = AppConfigurtaionServices.Configuration["rabbitmq:LayoutExchange"];
- channel.ExchangeDeclare(exchange: LayoutExchange, type: "fanout", durable: false, autoDelete: true);
- channel.BasicPublish(LayoutExchange, "", null, queuedata); //开始传递
- channel.Close();
- connection.Close();
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public Hashtable DelLayoutMst(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- List<LayoutMst> entity = JsonConvert.DeserializeObject<List<LayoutMst>>((string)imputds[nameof(LayoutMst)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- LayoutMstDal tempdal = new LayoutMstDal(CurrDb);
- LayoutMst result = tempdal.DelLayoutMst(entity, order.usercode, ref errorinfo);
- if (result == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(LayoutMst), JsonConvert.SerializeObject(result));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable IMacStatus(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- MacStatus entity = JsonConvert.DeserializeObject<MacStatus>((string)imputds[nameof(MacStatus)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- MacStatusDal tempdal = new MacStatusDal(CurrDb);
- entity = tempdal.IMacStatus(entity, order.usercode, ref errorinfo);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- //将状态广播到消息队列里
- string temperrorinfo = "";
- BroadcastStatus(entity, ref temperrorinfo);
- Hashtable reds = new Hashtable();
- reds.Add(nameof(MacStatus), JsonConvert.SerializeObject(entity));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- /// <summary>
- /// 广播状态
- /// </summary>
- /// <param name="status"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private int BroadcastStatus(MacStatus status, ref string errorinfo)
- {
- IConnection connection = null;
- try
- {
- var factory = new ConnectionFactory();
- factory.HostName = AppConfigurtaionServices.Configuration["rabbitmq:IPAddress"];// "127.0.0.1";// System.Configuration.ConfigurationManager.AppSettings["mqaddress"].ToString();
- factory.UserName = AppConfigurtaionServices.Configuration["rabbitmq:UserName"];// "admin";// System.Configuration.ConfigurationManager.AppSettings["mquser"].ToString();
- factory.Password = AppConfigurtaionServices.Configuration["rabbitmq:Password"];// "admin";// System.Configuration.ConfigurationManager.AppSettings["mqpassword"].ToString();
- connection = factory.CreateConnection();
- var channel = connection.CreateModel();
- byte[] queuedata = EntityHelper.SerializeBytes<MacStatus>(status);
- if (queuedata == null)
- return -1;
- string StatusExchange = AppConfigurtaionServices.Configuration["rabbitmq:StatusExchange"];
- channel.ExchangeDeclare(exchange: StatusExchange, type: "fanout", durable: false, autoDelete: true);
- channel.BasicPublish(StatusExchange, "", null, queuedata); //开始传递
- channel.Close();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- finally
- {
- if (connection != null)
- connection.Close();
- }
- }
- public Hashtable BatUpdatePreStatus(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- List<LayoutDetail> entity = JsonConvert.DeserializeObject<List<LayoutDetail>>((string)imputds[nameof(LayoutDetail)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- MacStatusDal tempdal = new MacStatusDal(CurrDb);
- LayoutDetail result = tempdal.BatUpdatePreStatus(entity, order.usercode, ref errorinfo);
- if (result == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(LayoutDetail), JsonConvert.SerializeObject(result));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable ReadOrderMst(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- LayoutMst entity = JsonConvert.DeserializeObject<LayoutMst>((string)imputds[nameof(LayoutMst)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- List<MacOrder> macorders = new List<MacOrder>();
- List<OrderStatus> orderstatus = new List<OrderStatus>();
- LayoutMstDal tempdal = new LayoutMstDal(CurrDb);
- entity = tempdal.ReadOrderMst(entity, macorders, orderstatus, ref errorinfo);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(MacOrder), JsonConvert.SerializeObject(macorders));
- reds.Add(nameof(OrderStatus), JsonConvert.SerializeObject(orderstatus));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable SynchronousMac(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- //TEntity entity = JsonConvert.DeserializeObject<TEntity>((string)imputds[nameof(TEntity)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- TEntityDal tempdal = new TEntityDal(CurrDb);
- int result = tempdal.SynchronousMac(order.usercode, ref errorinfo);
- if (result <= 0)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(ConstOrder), JsonConvert.SerializeObject(order));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- /// <summary>
- /// 读取状态信息
- /// </summary>
- /// <param name="imputds"></param>
- /// <param name="errorinfo"></param>
- /// <param name="error"></param>
- /// <returns></returns>
- public Hashtable ReadStatusInfo(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- LayoutDetail entity = JsonConvert.DeserializeObject<LayoutDetail>((string)imputds[nameof(LayoutDetail)]);
- //MacStatus status = JsonConvert.DeserializeObject<MacStatus>((string)imputds[nameof(MacStatus)]);
- //string usercode = order.usercode;
- ////CurrDb.BeginTrans();
- //List<MacOrder> macorders = new List<MacOrder>();
- //List<OrderStatus> orderstatus = new List<OrderStatus>();
- //LayoutMstDal tempdal = new LayoutMstDal(CurrDb);
- ////entity = tempdal.ReadOrderMst(entity, macorders, orderstatus, ref errorinfo);
- ////if (entity == null)
- ////{
- //// CurrDb.Rollback();
- //// return null;
- ////}
- //从MES系统里读取数据
- StatusEntityInfo result = ReadStatusInfoFromMes(entity.FCode);
- Hashtable reds = new Hashtable();
- reds.Add(nameof(StatusEntityInfo), JsonConvert.SerializeObject(result));
- //reds.Add(nameof(OrderStatus), JsonConvert.SerializeObject(orderstatus));
- //CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- }
- private StatusEntityInfo ReadStatusInfoFromMes(string maccode)
- {
- StatusEntityInfo entity = new StatusEntityInfo();
- IDatabase sqldb = DbFactory.Base("sqlconn");
- //查找机台正在进行中的lot
- string sqlstr = $@"select a.ID,b.PoCode,c.PartCode,d.FName partname from JobBooking a
- inner join LotMst b on a.LotNo = b.LotNo
- inner join ProductOrder c on b.PoCode = c.FCode
- inner join Part d on c.PartCode=d.Fcode
- where a.MacCode = '{maccode}' and a.StatusID = 1";
- DataTable jbdt = sqldb.FindTableFor(sqlstr, "JobBooking");
- if (jbdt.Rows.Count <= 0)
- return entity;
- entity.PartCode = jbdt.Rows[0]["PartCode"].ToString();
- entity.PkgModel = jbdt.Rows[0]["partname"].ToString();
- //读取报工记录
- sqlstr = $@"select b.FName from JbStaff a
- inner join Staff b on a.StaffCode = b.FCode
- where a.JbID = '{jbdt.Rows[0]["ID"].ToString()}' and a.StatusID = 1";
- DataTable tempdt = sqldb.FindTableFor(sqlstr, "JbStaff");
- if (tempdt.Rows.Count > 0)
- entity.OperUser = tempdt.Rows[0]["FName"].ToString();
- //读取材料信息
- sqlstr = $@"select a.PtCode,b.FName from PoPart a
- inner join Part b on a.PtCode=b.FCode
- where a.PoCode='{jbdt.Rows[0]["PoCode"].ToString()}'";
- tempdt = sqldb.FindTableFor(sqlstr, "PoPart");
- if (tempdt.Rows.Count > 0)
- {
- int row = tempdt.Rows.Count < 4 ? tempdt.Rows.Count : 4;
- for (int i = 0; i < row; i++)
- {
- EntityHelper.SetPropertyValue(entity, "MaterialModel" + i.ToString(), tempdt.Rows[i]["PtCode"].ToString());
- EntityHelper.SetPropertyValue(entity, "MaterialName" + i.ToString(), tempdt.Rows[i]["FName"].ToString());
- }
- }
- sqldb.Close();
- return entity;
- }
- /// <summary>
- /// 读取状态统计
- /// </summary>
- /// <param name="imputds"></param>
- /// <param name="errorinfo"></param>
- /// <param name="error"></param>
- /// <returns></returns>
- public Hashtable ReadStatusTotal(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- //LayoutDetail entity = JsonConvert.DeserializeObject<LayoutDetail>((string)imputds[nameof(LayoutDetail)]);
- //MacStatus status = JsonConvert.DeserializeObject<MacStatus>((string)imputds[nameof(MacStatus)]);
- //string usercode = order.usercode;
- ////CurrDb.BeginTrans();
- //List<MacOrder> macorders = new List<MacOrder>();
- //List<OrderStatus> orderstatus = new List<OrderStatus>();
- //LayoutMstDal tempdal = new LayoutMstDal(CurrDb);
- ////entity = tempdal.ReadOrderMst(entity, macorders, orderstatus, ref errorinfo);
- ////if (entity == null)
- ////{
- //// CurrDb.Rollback();
- //// return null;
- ////}
- //从MES系统里读取数据
- StatusTotal result = ReadStatusTotalFromMes();
- Hashtable reds = new Hashtable();
- reds.Add(nameof(StatusTotal), JsonConvert.SerializeObject(result));
- //reds.Add(nameof(OrderStatus), JsonConvert.SerializeObject(orderstatus));
- //CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- }
- public StatusTotal ReadStatusTotalFromMes()
- {
- StatusTotal entity = new StatusTotal();
- entity.Mtbfs = new List<MTBFDto>();
- IDatabase sqldb = DbFactory.Base("eap");
- McaEventStatisticByDayDal totaldal = new McaEventStatisticByDayDal(sqldb);
- //string condition = $" and StartTime>='2019-03-31 00:00:00'";
- DateTime dateStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
- DateTime dateEnd = DateTime.Now;
- string condition = $" and StartTime>='{DateTime.Now.ToString("yyyy-MM-dd")} 00:00:00'";
- List<MTBFDto> mtbfs = totaldal.GetMTBFs(condition, string.Empty, "machine").ToList();
- var pcode = mtbfs.GroupBy(t => t.pcode).Where(p => p.Key != null).ToList();
- if (pcode.Count <= 0)
- {
- }
- else
- {
- foreach (var item in pcode)
- {
- MTBFDto tempentity = new MTBFDto();
- tempentity.pcode = item.Key;
- tempentity.MTBF = item.Sum(t => t.MTBF);
- entity.Mtbfs.Add(tempentity);
- }
- }
- List<MachineEfficiency> effics = totaldal.GetMachineEfficienciesGroupByPcode(condition, string.Empty, dateStart, dateEnd).ToList();
- entity.Effics = effics == null ? new List<MachineEfficiency>() : effics;
- // var efficsgroupby = effics.GroupBy(t => t.PCode).Where(p => p.Key != null).ToList();
- //if (efficsgroupby.Count <= 0)
- //{
- //}
- //else
- //{
- // foreach (var item in efficsgroupby)
- // {
- // MachineEfficiency tempentity = item;
- // tempentity.PCode = item.Key;
- // tempentity.OverallEfficiency = item.Sum(t => t.OverallEfficiency) / item.Count();
- // entity.Effics.Add(tempentity);
- // }
- //}
- //entity.TotalMtbf = mtbfs.Sum(t => t.MTBF).Value;
- //entity.DieMtbf = mtbfs.Where(t => t.pcode == "DB").Sum(t => t.MTBF).Value;
- //entity.WireMtbf = mtbfs.Where(t => t.pcode == "WB").Sum(t => t.MTBF).Value;
- //List<MachineEfficiency> effics = totaldal.GetMachineEfficienciesGroupByMacModel(condition).ToList();
- //if(effics.Count>0)
- // entity.TotalEfficiency = (double)effics.Sum(t => t.OverallEfficiency)/effics.Count;
- //effics = effics.Where(t => t.PCode == "DB").ToList();
- //if (effics.Count > 0)
- // entity.DieEfficiency = (double)effics.Sum(t => t.OverallEfficiency)/ effics.Count;
- //effics = effics.Where(t => t.PCode == "WB").ToList();
- //if (effics.Count > 0)
- // entity.WireEfficiency = (double)effics.Sum(t => t.OverallEfficiency) / effics.Count;
- sqldb.Close();
- return entity;
- }
- public Hashtable UStandardStatus(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- List<StandardStatus> entitys = JsonConvert.DeserializeObject<List<StandardStatus>>((string)imputds[nameof(StandardStatus)]);
- string usercode = order.usercode;
- CurrDb.BeginTrans();
- int result = CurrDb.UpdateFor<StandardStatus>(entitys, usercode);
- if (result < 0)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add(nameof(StandardStatus), JsonConvert.SerializeObject(entitys[0]));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- /// <summary>
- /// 上传程序文件
- /// </summary>
- /// <param name="imputds"></param>
- /// <param name="errorinfo"></param>
- /// <param name="error"></param>
- /// <returns></returns>
- //public Hashtable UpProgram(Hashtable imputds, ref string errorinfo, ref int error)
- //{
- // try
- // {
- // if (imputds == null)
- // {
- // errorinfo = "传入数据不能为空,请确认";
- // error = 1;
- // return null;
- // }
- // ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- // OrderBlock entitys = JsonConvert.DeserializeObject<OrderBlock>((string)imputds[nameof(OrderBlock)]);
- // string usercode = order.usercode;
- // CurrDb.BeginTrans();
- // //上传文件
- // int result = UpProgram(CurrDb, entitys, usercode, ref errorinfo);
- // if(result==-100)
- // {
- // CurrDb.Commit();
- // return null;
- // }
- // else if(result<=0)
- // {
- // CurrDb.Rollback();
- // return null;
- // }
- // Hashtable reds = new Hashtable();
- // reds.Add(nameof(McaSecVMst), JsonConvert.SerializeObject(entitys.MainMsg));
- // CurrDb.Commit();
- // return reds;
- // }
- // catch (Exception ex)
- // {
- // errorinfo = ex.Message.ToString();
- // error = 1;
- // CurrDb.Rollback();
- // return null;
- // }
- //}
- //private int UpProgram(IDatabase db,OrderBlock entity,string usercode,ref string errorinfo)
- //{
- // try
- // {
- // string filedir = AppConfigurtaionServices.Configuration["ProgramDir"];
- // List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
- // int parentid = datas[0].ID;//获取L的ID值
- // datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
- // string programname = datas[0].FContent;
- // string programdata = datas[1].FContent;
- // byte[] filedatas = datas[1].OrgDatas;
- // //查找程序表,是否存在此程序名称的记录
- // string condition = $" and {EntityAttribute.GetPropertyCondition<ProgramMst>(nameof(ProgramMst.FName))}='{programname}'";
- // List<ProgramMst> programmst = db.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
- // ProgramMst programentity = null;
- // if(programmst.Count<=0)
- // {
- // //添加程序记录
- // programentity = new ProgramMst();
- // errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。";
- // return -1;
- // }
- // else
- // {
- // programentity = programmst[0];
- // }
- // //比对参数,并保存比对结果
- // ParamsComMstDal comparedal = new ParamsComMstDal(db);
- // ParamsComMst commst = comparedal.CompareParams(entity.MainMsg.McaCode, programentity.ID, ref errorinfo);
- // if (commst == null)
- // return -1;
- // //if(commst.IsPass<=0)
- // //{
- // // errorinfo = "参数比对没有通过。";
- // // return -100;
- // //}
- // commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo);
- // if (commst == null)
- // return -1;
- // if (commst.IsPass <= 0)
- // {
- // errorinfo = "参数比对没有通过。";
- // return -100;
- // }
- // programentity.ServerPath = filedir + $"\\{programentity.ID}";
- // int result = UnityHelper.WriteFile(programentity.ServerPath, filedatas, ref errorinfo);
- // if (result <= 0)
- // return -1;
- // //更新服务器程序路径
- // result=db.UpdateFor<ProgramMst>(programentity, usercode);
- // if (result <= 0)
- // return -1;
- // return 1;
- // }
- // catch(Exception ex)
- // {
- // errorinfo = ex.Message.ToString();
- // return -1;
- // }
- //}
- /// <summary>
- /// 参数比对
- /// </summary>
- /// <param name="imputds"></param>
- /// <param name="errorinfo"></param>
- /// <param name="error"></param>
- /// <returns></returns>
- public Hashtable CompareParams(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- string maccode = (string)imputds["maccode"];
- CurrDb.BeginTrans();
- //读取机台信息
- string condition = $" and a.FCode='{maccode}'";
- Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
- if (mac.IsControl <= 0)
- {
- //说明此机台没有开启参数比对功能,无需比对
- CurrDb.Commit();
- Hashtable tempreds = new Hashtable();
- tempreds.Add("result", "1");
- return tempreds;
- }
- //string programname = (string)imputds["programname"];
- ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
- //string programname = comdal.GetMacProgram(maccode, ref errorinfo);
- //if(string.IsNullOrEmpty(programname))
- //{
- // CurrDb.Rollback();
- // return null;
- //}
- ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo);
- if (programmst == null)
- {
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"查找程序错误:{errorinfo}", ref logerrorinfo);
- CurrDb.Rollback();
- return null;
- }
- ParamsComMst mst = comdal.CompareParams(mac, programmst, ref errorinfo);
- if (mst == null)
- {
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对发生错误:{errorinfo}", ref logerrorinfo);
- CurrDb.Rollback();
- return null;
- }
- //插入比对记录
- mst = comdal.IUParamsComMst(mst, order.usercode, ref errorinfo);
- if (mst == null)
- {
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"添加比对记录发生错误:{errorinfo}", ref logerrorinfo);
- CurrDb.Rollback();
- return null;
- }
- CurrDb.Commit();
- //如果参数不对,就发送停机指令
- if (mst.IsPass <= 0)
- {
- MacOrderSendDal tempdal = new MacOrderSendDal(CurrDb);
- int result = tempdal.SendStopMac(maccode, ref errorinfo);
- if (result <= 0)
- {
- return null;
- }
- }
- Hashtable reds = new Hashtable();
- reds.Add("result", "1");
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable DownloadProgram(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- string maccode = (string)imputds["maccode"];
- string partcode = (string)imputds["partcode"];
- string pcode = (string)imputds["pcode"];
- //string programname = (string)imputds["programname"];
- CurrDb.BeginTrans();
- ProgramDal programdal = new ProgramDal(CurrDb);
- Machine mac = programdal.ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- {
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
- CurrDb.Rollback();
- return null;
- }
- ProgramMst mst = programdal.FindProgram(mac, partcode, pcode, ref errorinfo);
- if (mst == null)
- {
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"查找程序错误:{errorinfo}", ref logerrorinfo);
- CurrDb.Rollback();
- return null;
- }
- ProgramDal dal = new ProgramDal(CurrDb);
- int result = dal.DownloadProgram(maccode, mst.FName, ref errorinfo);
- if (result <= 0)
- {
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"调程发生错误:{errorinfo}", ref logerrorinfo);
- CurrDb.Rollback();
- return null;
- }
- ////读取程序数据
- //string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
- //MacProgramDal macprogramdal = new MacProgramDal(CurrDb);
- //int filelen = 0;
- //string filepath = "";
- //string programid = "";
- //int result = macprogramdal.ReadMacProgram(mac.FCode, mst.FName, programdir, ref filelen, ref filepath, ref errorinfo);
- //if (result <= 0)
- //{
- // CurrDb.Rollback();
- // return null;
- //}
- //switch (mac.SupplierFCode)
- //{
- // case "ASM":
- // AsmProgramDal comdal = new AsmProgramDal(CurrDb);
- // mst = comdal.DownloadProgram(maccode, partcode, pcode, filelen, filepath, ref errorinfo);
- // if (mst == null)
- // {
- // string logerrorinfo = "";
- // WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"下载程序错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return null;
- // }
- // break;
- // case "KNS":
- // KnsProgramDal comdal1 = new KnsProgramDal(CurrDb);
- // mst = comdal1.DownloadProgram(mac, mst, filelen, filepath, ref errorinfo);
- // if (mst == null)
- // {
- // string logerrorinfo = "";
- // WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"下载程序错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return null;
- // }
- // //选择程序
- // int res = comdal1.SelectProgram(mac, mst.FName, ref errorinfo);
- // if (res <= 0)
- // {
- // string logerrorinfo = "";
- // WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"选择程序错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return null;
- // }
- // break;
- //}
- Hashtable reds = new Hashtable();
- reds.Add(nameof(ProgramMst), JsonConvert.SerializeObject(mst));
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- {
- CurrDb.Close();
- }
- }
- }
- public Hashtable GetQuality(Hashtable imputds, ref string errorinfo, ref int error)
- {
- try
- {
- if (imputds == null)
- {
- errorinfo = "传入数据不能为空,请确认";
- error = 1;
- return null;
- }
- ConstOrder order = JsonConvert.DeserializeObject<ConstOrder>((string)imputds[nameof(ConstOrder)]);
- string maccode = (string)imputds["maccode"];
- //string programname = (string)imputds["programname"];
- CurrDb.BeginTrans();
- ProgramDal programdal = new ProgramDal(CurrDb);
- Machine mac = programdal.ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- {
- CurrDb.Rollback();
- return null;
- }
- MacCountDal dal = new MacCountDal(CurrDb);
- int result = dal.IMacCount(mac, order.usercode, ref errorinfo);
- if (result < 0)
- {
- CurrDb.Rollback();
- return null;
- }
- Hashtable reds = new Hashtable();
- reds.Add("result", result);
- CurrDb.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- error = 1;
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if(CurrDb!=null)
- {
- CurrDb.Close();
- }
- }
- }
- public List<MacStatus> ReadLastStatus(ref string errorinfo)
- {
- string condition = $@" and {EntityAttribute.GetPropertyCondition<MacStatus>(nameof(MacStatus.ETime))}<date_format('2008-01-01 00:00:00', '%Y%m%d%H%i%s')";
- // string condition = string.Empty;
- List<MacStatus> laststatus = CurrDb.FindListForCondition<MacStatus>(condition, ref errorinfo).ToList();
- List<MacStatus> result = new List<MacStatus>();
- MacStatus entity = new MacStatus();
- entity.StatusID = MacStatusVal.Run;
- entity.StatusFName = "运行";
- entity.FLen = laststatus.Where(t => t.StatusID == entity.StatusID).Count();
- result.Add(entity);
- entity = new MacStatus();
- entity.StatusID = MacStatusVal.Error;
- entity.StatusFName = "故障";
- entity.FLen = laststatus.Where(t => t.StatusID == entity.StatusID).Count();
- result.Add(entity);
- entity = new MacStatus();
- entity.StatusID = MacStatusVal.Pause;
- entity.StatusFName = "暂停";
- entity.FLen = laststatus.Where(t => t.StatusID == entity.StatusID).Count();
- result.Add(entity);
- entity = new MacStatus();
- entity.StatusID = MacStatusVal.Idle;
- entity.StatusFName = "空闲";
- entity.FLen = laststatus.Where(t => t.StatusID == entity.StatusID).Count();
- result.Add(entity);
- entity = new MacStatus();
- entity.StatusID = MacStatusVal.Pending;
- entity.StatusFName = "待料";
- entity.FLen = laststatus.Where(t => t.StatusID == entity.StatusID).Count();
- result.Add(entity);
- return result.Where(c => c.FLen > 0).ToList();
- }
- public List<ParamsComMst> ReadParamsComMst(ref string errorinfo)
- {
- string condition = $@" and a.IsPass<=0 and a.rectime between date_format('{DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd")} 00:00:00', '%Y%m%d%H%i%s')
- and date_format('{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '%Y%m%d%H%i%s')";
- // string condition = $@" and a.IsPass<=0 ";
- List<ParamsComMst> mts = CurrDb.FindListForCondition<ParamsComMst>(condition, ref errorinfo).Where(c => !string.IsNullOrEmpty(c.ProgramFName))
- .OrderByDescending(c => c.RecTime).Take(5).ToList();
- return mts;
- }
- }
- }
|