123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllDiodesMesDal;
- using DllDiodesMesEntity;
- using DllEapDal;
- using DllEapEntity;
- using Microsoft.Extensions.Logging;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using XiangQi.Mes.Entity;
- namespace DllParamCheckServer
- {
- public class ProcessBusiness
- {
- private IDatabase CurrDb = null;
- //private IDatabase EapDb = null;
- private ILogger loger = null;
- private int CheckTime = 0;
- public ProcessBusiness(IDatabase eapdb,ILogger loger,int checktime)
- {
- this.loger = loger;
- CurrDb = eapdb;
- CheckTime = checktime;
- }
- public int ParamCheck(ref string errorinfo)
- {
- try
- {
- //读取机台
- string condition = " and a.id in(SELECT macid FROM eapappservermac group by macid)";
- List<Machine> steps = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- foreach(var item in steps)
- {
- //单个机台盘点
- CurrDb.BeginTrans();
- errorinfo = "";
- int result = SingleParamCheck(item, ref errorinfo);
- if(result<=0)
- {
- CurrDb.Rollback();
- loger.LogError($"机台编号={item.FCode}参数点检失败:{errorinfo}");
- }
- else
- {
- CurrDb.Commit();
- }
- }
- return 1;
- }
- catch(Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- private int SingleParamCheck(Machine mac,ref string errorinfo)
- {
- try
- {
- //判断盘点时间是否已到
- string sqlstr = $"SELECT ifnull(max(a.id),0) FROM maccheckmst a where a.MacCode='{mac.FCode}' and a.CheckMode=1";
- int maxid = int.Parse(CurrDb.FindObject(sqlstr).ToString());
- if(maxid>0)
- {
- MacCheckMst checkmst = CurrDb.FindEntityFor<MacCheckMst>(maxid);
- long difftime = DateTime.Now.Ticks - checkmst.RecTime.Ticks;
- int mint = (int)(difftime / (10000000 * 60));
- if (mint < CheckTime)//还没到点检时间
- return 1;
- }
- //读取机台点检参数
- string condition = $" and b.MModelCode='{mac.MModeCode}' and a.CheckMode=1";
- List<ModelCheckDetail> details = CurrDb.FindListForCondition<ModelCheckDetail>(condition, ref errorinfo).ToList();
- if (details.Count <= 0)
- return 1;
- List<MacParam> macparams = new List<MacParam>();
- foreach(var item in details)
- {
- MacParam entity = new MacParam();
- entity.FCode = item.ParamCode;
- entity.FNum = item.FNum;
- macparams.Add(entity);
- }
- MacOrderSendDal dal = new MacOrderSendDal(CurrDb);
- macparams = dal.GetParamValue(mac.FCode, macparams, ref errorinfo);
- if (macparams == null)
- {
- return -1;
- }
- //添加点检记录
- List<MacCheckDetail> checkdetails = new List<MacCheckDetail>();
- foreach(var item in macparams)
- {
- MacCheckDetail check = new MacCheckDetail();
- check.FNum = item.FNum;
- check.ParamCode = item.FCode;
- check.ParamVal = item.FValue;
- checkdetails.Add(check);
- }
- MacCheckMstDal checkdal = new MacCheckMstDal(CurrDb);
- return checkdal.AddCheck(mac.FCode, checkdetails, "eap", ref errorinfo);
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- }
- }
|