kingno
2025-04-01 2120c4a86e6b7bfe2b8e27f79c0ebe2efddbc0e0
src/Bro.M141.Process/M141Process.cs
@@ -97,6 +97,7 @@
            _positionCheckTimeDict.Clear();
            _positionSpecHeads.Clear();
            mysqlhelper.IniDBIP(M141Config.IPforall);
            if (ThHeartPlc == null)
            {
@@ -263,6 +264,15 @@
            if (isSaveDB)
            {
                if (M141Config.Isreadbasketcode)
                {
                    p.BasketCode = M141Config.basketcode;
                }
                else
                {
                    p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE);
                }
                mysqlhelper.NewProduct(p);
            }
@@ -294,7 +304,7 @@
                    p.PID = p.PID + "_" + sequence.Split('_')[sequence.Split('_').Length - 1];
                    p.Initial(M141Config.StationCode, M141Config.WorkPositionCollection.Where(u => u.IsEnabled).Select(u => u.PositionName).ToList());
                    //LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"未能从数据库获取产品对象,使用临时新建产品对象");
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"未能从数据库获取产品对象,使用临时新建产品对象");
                }
                NewProductIntoList(p, false);
@@ -704,6 +714,7 @@
            try
            {
                ConcurrentDictionary<MeasureBind, IImageSet> imgSetDicts = new ConcurrentDictionary<MeasureBind, IImageSet>();
                var positionSet = M141Config.WorkPositionCollection.Where(u => u.IsEnabled).FirstOrDefault(u => u.TriggerValue == triggerDatas[0]);
                measureBinds.AsParallel().ForAll(b =>
                {
@@ -715,6 +726,10 @@
                        try
                        {
                            imgSetDicts[b] = CollectHImage(camera, b.SnapshotOpConfig);
                            if (positionSet.ispiccover)
                            {
                                Plc1.WriteSingleAddress(positionSet.plcover,1,out _);
                            }
                        }
                        catch (Exception ea)
                        {
@@ -930,10 +945,8 @@
                        plcresult.Add(isOK);
                        List<string> specHeads = new List<string>();
                        string head = p.GetCSVHead(ref specHeads, positionName);
                        if (!_positionSpecHeads.ContainsKey(positionName))
                        {
                            _positionSpecHeads[positionName] = specHeads;
                        }
                        string data = p.GetCSVData(_positionSpecHeads[positionName], positionName);
                        CSVRecordAsync($"{positionName}_Record_{DateTime.Now.ToString("yyyyMMdd")}.csv", data, head);
@@ -941,10 +954,15 @@
                        //UpdatePositionResultToDB(detail);
                        var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        mysqlhelper.UpdateProduct(p);
                        if (positionSet.IsLastPosition)
                        {
                            UpdateProductResultAsync(p);
                            mysqlhelper.NewForAll(p, M141Config.StationCode);
                            if (M141Config.IsfinDevice)
                            {
                                SummaryAllprodata(p);
                            }
                        }
                    });
                    ReplyPlcData(positionSet, plcresult);
@@ -993,6 +1011,53 @@
        }
        public void SummaryAllprodata(ProductModel p)
        {
            _taskFactory.StartNew(() =>
            {
                try
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = p.SEQUENCE;
                    newp.PID = p.PID;
                    newp.BasketCode = p.BasketCode;
                    newp.Result = p.Result;
                    newp.SN = p.SN;
                    newp.Details.AddRange(p.Details);
                    var plist = mysqlhelper.GetProductList(p.SEQUENCE);
                    if (plist != null)
                    {
                        foreach (var item in plist)
                        {
                            newp.Details.AddRange(item.Details);
                        }
                    }
                    List<string> specHeadListforall = new List<string>();
                    List<string> positionListforall = new List<string>();
                    string csvHeadforall = p.GetCSVHead(ref specHeadListforall, ref positionListforall);
                    CSVRecordAsync($"AllDeviceProductRecord.csv", p.GetCSVData(specHeadListforall, positionListforall), csvHeadforall);
                }
                catch(Exception exx)
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, "AllDeviceProductRecord数据汇总异常  " + exx.ToString());
                }
            });
        }
        #endregion
    }