|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
using HslCommunication.Core;
|
|
|
|
|
using Mesnac.Compressor.Entity;
|
|
|
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Models;
|
|
|
|
|
@ -9,6 +10,7 @@ using SlnMesnac.Config;
|
|
|
|
|
using SlnMesnac.Model.domain;
|
|
|
|
|
using SlnMesnac.Plc;
|
|
|
|
|
using SlnMesnac.Repository;
|
|
|
|
|
using SlnMesnac.Repository.service;
|
|
|
|
|
using SlnMesnac.Serilog;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
@ -49,6 +51,8 @@ namespace ConsoleApp
|
|
|
|
|
//PLC支线码2地址
|
|
|
|
|
private string _semiBarcode2;
|
|
|
|
|
|
|
|
|
|
private IDatastationLocalService _datastationLocalService;
|
|
|
|
|
|
|
|
|
|
public MainCentralControl(IHost host)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
@ -59,6 +63,7 @@ namespace ConsoleApp
|
|
|
|
|
SqlSugarClient = host.Services.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
_logger = host.Services.GetRequiredService<SerilogHelper>();
|
|
|
|
|
plcList = host.Services.GetRequiredService<List<PlcAbsractFactory>>();
|
|
|
|
|
_datastationLocalService = host.Services.GetService<IDatastationLocalService>();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
@ -204,21 +209,28 @@ namespace ConsoleApp
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ProductBarCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private Datastation IsExistData(string ProductBarCode)
|
|
|
|
|
private DatastationLocal IsExistData(string ProductBarCode)
|
|
|
|
|
{
|
|
|
|
|
Datastation datastation = null;
|
|
|
|
|
DatastationLocal datastationLocal = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
datastation = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns.Contains(ProductBarCode));
|
|
|
|
|
if (datastation != null)
|
|
|
|
|
partsns partsns = new partsns();
|
|
|
|
|
partsns.sn.Add(ProductBarCode);
|
|
|
|
|
string jsonString = StringChange.ModeToJson(partsns);
|
|
|
|
|
|
|
|
|
|
//查询本地库是否存在该数据
|
|
|
|
|
datastationLocal = _datastationLocalService.GetDatastationLocal("jsonString");
|
|
|
|
|
//datastationLocal = SqlSugarClient.Queryable<DatastationLocal>().First(it => it.Partsns == jsonString);
|
|
|
|
|
//datastation = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns == jsonString);
|
|
|
|
|
if (datastationLocal != null)
|
|
|
|
|
{
|
|
|
|
|
return datastation;
|
|
|
|
|
return datastationLocal;
|
|
|
|
|
}
|
|
|
|
|
return datastation;
|
|
|
|
|
return datastationLocal;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return datastation;
|
|
|
|
|
return datastationLocal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -231,6 +243,26 @@ namespace ConsoleApp
|
|
|
|
|
{ //转子码
|
|
|
|
|
byte[] SemBarCode = Plc.readValueByAddress(_semiBarcode1, 20);
|
|
|
|
|
string barcode = ByteTransform.TransString(SemBarCode, 0, 20, Encoding.ASCII);
|
|
|
|
|
Glbcaldata no = SqlSugarClient.Queryable<Glbcaldata>().First(it => it.Id == 18);
|
|
|
|
|
Dataproduce dataproduce = null;
|
|
|
|
|
if (no != null)
|
|
|
|
|
{
|
|
|
|
|
dataproduce = new Dataproduce()
|
|
|
|
|
{
|
|
|
|
|
Productid = no.ProducePreSn + no.LastProduceId,
|
|
|
|
|
Stime = DateTime.Now,
|
|
|
|
|
Etime = DateTime.Now,
|
|
|
|
|
Currreinstation = StationCode,
|
|
|
|
|
Operseq = StationCode,
|
|
|
|
|
Snlist = barcode,
|
|
|
|
|
Mainsn = barcode,
|
|
|
|
|
Pdtype = 2,
|
|
|
|
|
Status = 2,
|
|
|
|
|
};
|
|
|
|
|
int id = SqlSugarClient.Insertable(dataproduce).ExecuteReturnIdentity();
|
|
|
|
|
no.LastProduceId = no.LastProduceId + 1;
|
|
|
|
|
SqlSugarClient.Updateable(no).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
partsns partsns = new partsns();
|
|
|
|
|
partsns.sn.Add(barcode);
|
|
|
|
|
//数据
|
|
|
|
|
@ -289,7 +321,7 @@ namespace ConsoleApp
|
|
|
|
|
root.d.Add(data5);
|
|
|
|
|
string datastring = StringChange.ModeToJson(root);
|
|
|
|
|
//查询是否已经存在数据,存在则更新不存在则保存
|
|
|
|
|
Datastation datastation = IsExistData(barcode);
|
|
|
|
|
Datastation datastation = null;
|
|
|
|
|
if (datastation != null)
|
|
|
|
|
{
|
|
|
|
|
//更新
|
|
|
|
|
@ -305,11 +337,12 @@ namespace ConsoleApp
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SqlSugarClient.AsTenant().BeginTran();
|
|
|
|
|
//存库
|
|
|
|
|
datastation = new Datastation()
|
|
|
|
|
{
|
|
|
|
|
Stime = DateTime.Now,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
Productid = "",
|
|
|
|
|
Productid = dataproduce.Productid,
|
|
|
|
|
Partid = "",
|
|
|
|
|
Modelid = "",
|
|
|
|
|
Ng = Plc.readInt16ByAddress("D7725").ToString() == "1" ? 0 : 1,
|
|
|
|
|
@ -325,17 +358,40 @@ namespace ConsoleApp
|
|
|
|
|
GroupStationId = "",
|
|
|
|
|
Renum = "0",
|
|
|
|
|
};
|
|
|
|
|
//存盘
|
|
|
|
|
DatastationLocal datastationLocal = new DatastationLocal()
|
|
|
|
|
{
|
|
|
|
|
Stime = DateTime.Now,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
Productid = dataproduce.Productid,
|
|
|
|
|
Partid = "",
|
|
|
|
|
Modelid = "",
|
|
|
|
|
Ng = Plc.readInt16ByAddress("D7725").ToString() == "1" ? 0 : 1,
|
|
|
|
|
Proc = 0,
|
|
|
|
|
Sublinenum = 0,
|
|
|
|
|
Sublinesnnum = 0,
|
|
|
|
|
Partsnnum = 1,
|
|
|
|
|
Sublineids = "",
|
|
|
|
|
Partsns = jsonString,
|
|
|
|
|
Sublinesns = StringChange.ModeToJson(new partsns()),
|
|
|
|
|
Paratemp = datastring,
|
|
|
|
|
Stringtemp = "",
|
|
|
|
|
GroupStationId = "",
|
|
|
|
|
Renum = "0",
|
|
|
|
|
};
|
|
|
|
|
//存盘先报存到本地数据库
|
|
|
|
|
bool insertflag = await _datastationLocalService.AddDatastationLocalAsync(datastationLocal);
|
|
|
|
|
|
|
|
|
|
int id = SqlSugarClient.Insertable(datastation).ExecuteReturnIdentity();
|
|
|
|
|
|
|
|
|
|
Plc.writeInt16ByAddress("D7704", 1);
|
|
|
|
|
//Console.WriteLine(StringChange.ModeToJson(datastation));
|
|
|
|
|
_logger.Info(StringChange.ModeToJson(datastation));
|
|
|
|
|
|
|
|
|
|
var datastationid = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns.Contains(barcode));
|
|
|
|
|
|
|
|
|
|
//var datastationid = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns.Contains(barcode));
|
|
|
|
|
//datastationparam数据存表
|
|
|
|
|
Datastationparam datastationparam1 = new Datastationparam()
|
|
|
|
|
{
|
|
|
|
|
Dsid = datastationid.Id,
|
|
|
|
|
Dsid = id,
|
|
|
|
|
Productid = StationCode,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
N = data1.n,
|
|
|
|
|
@ -349,7 +405,7 @@ namespace ConsoleApp
|
|
|
|
|
};
|
|
|
|
|
Datastationparam datastationparam2 = new Datastationparam()
|
|
|
|
|
{
|
|
|
|
|
Dsid = datastationid.Id,
|
|
|
|
|
Dsid = id,
|
|
|
|
|
Productid = StationCode,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
N = data2.n,
|
|
|
|
|
@ -363,7 +419,7 @@ namespace ConsoleApp
|
|
|
|
|
};
|
|
|
|
|
Datastationparam datastationparam3 = new Datastationparam()
|
|
|
|
|
{
|
|
|
|
|
Dsid = datastationid.Id,
|
|
|
|
|
Dsid = id,
|
|
|
|
|
Productid = StationCode,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
N = data3.n,
|
|
|
|
|
@ -377,7 +433,7 @@ namespace ConsoleApp
|
|
|
|
|
};
|
|
|
|
|
Datastationparam datastationparam4 = new Datastationparam()
|
|
|
|
|
{
|
|
|
|
|
Dsid = datastationid.Id,
|
|
|
|
|
Dsid = id,
|
|
|
|
|
Productid = StationCode,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
N = data4.n,
|
|
|
|
|
@ -391,7 +447,7 @@ namespace ConsoleApp
|
|
|
|
|
};
|
|
|
|
|
Datastationparam datastationparam5 = new Datastationparam()
|
|
|
|
|
{
|
|
|
|
|
Dsid = datastationid.Id,
|
|
|
|
|
Dsid = id,
|
|
|
|
|
Productid = StationCode,
|
|
|
|
|
Stationid = StationCode,
|
|
|
|
|
N = data5.n,
|
|
|
|
|
@ -429,7 +485,7 @@ namespace ConsoleApp
|
|
|
|
|
byte[] SemBarCode = Plc.readValueByAddress(_semiBarcode1, 20);
|
|
|
|
|
string ZZBarCode = ByteTransform.TransString(SemBarCode, 0, 20, Encoding.ASCII);
|
|
|
|
|
_logger.Info("转子码:" + ZZBarCode);
|
|
|
|
|
Datastation datastation = IsExistData(ZZBarCode);
|
|
|
|
|
DatastationLocal datastation = IsExistData(ZZBarCode);
|
|
|
|
|
if (datastation != null)
|
|
|
|
|
{
|
|
|
|
|
if (datastation.Ng != 0)
|
|
|
|
|
@ -448,11 +504,17 @@ namespace ConsoleApp
|
|
|
|
|
#region 根据前盖码查询Productid
|
|
|
|
|
//根据前盖码查询Productid
|
|
|
|
|
var Dipsn = SqlSugarClient.Queryable<Dataproduce>().First(it => it.Mainsn == QGBarCode);
|
|
|
|
|
|
|
|
|
|
if (Dipsn != null)
|
|
|
|
|
{
|
|
|
|
|
Dipsn.Snlist = QGBarCode+","+ZZBarCode;
|
|
|
|
|
Dipsn.Operseq = Dipsn.Operseq+","+StationCode;
|
|
|
|
|
int updateflag = SqlSugarClient.Updateable(Dipsn).ExecuteCommand();
|
|
|
|
|
var ZZBarcide = SqlSugarClient.Queryable<Dataproduce>().First(it => it.Mainsn == ZZBarCode);
|
|
|
|
|
if (ZZBarcide != null)
|
|
|
|
|
{
|
|
|
|
|
ZZBarcide.Sysid = Dipsn.Productid;
|
|
|
|
|
//ZZBarcide.Snlist = QGBarCode + "," + ZZBarCode;
|
|
|
|
|
//ZZBarcide.Operseq = Dipsn.Operseq + "," + StationCode;
|
|
|
|
|
int updateflag = SqlSugarClient.Updateable(Dipsn).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Dipsn dipsn = new Dipsn()
|
|
|
|
|
//{
|
|
|
|
|
@ -465,7 +527,7 @@ namespace ConsoleApp
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 查询datastation表,更新Productid
|
|
|
|
|
var zzdata = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns.Contains(ZZBarCode));
|
|
|
|
|
/* var zzdata = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns.Contains(ZZBarCode));
|
|
|
|
|
if (zzdata != null)
|
|
|
|
|
{
|
|
|
|
|
zzdata.Productid = Dipsn.Productid;
|
|
|
|
|
@ -480,7 +542,7 @@ namespace ConsoleApp
|
|
|
|
|
int updateflag = SqlSugarClient.Ado.ExecuteCommand(sql);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
#endregion
|
|
|
|
|
//下发PLC上工位合格
|
|
|
|
|
Plc.writeInt16ByAddress(_completeAskAddress, 1);
|
|
|
|
|
|