林豪 左 2 years ago
parent
commit
cefc5e8d81

+ 4 - 1
ServiceCenter/ServiceCenter.csproj

@@ -20,10 +20,13 @@
     <PackageReference Include="PlcSiemens" Version="1.0.1" />
     <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
     <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
-    <PackageReference Include="WCS.Core" Version="1.0.2.1" />
     <PackageReference Include="WCS.Entity" Version="1.0.3.2" />
     <PackageReference Include="WCS.Entity.Protocol" Version="1.0.4.2" />
     <PackageReference Include="wms.sqlsugar" Version="1.0.0.2" />
   </ItemGroup>
+  
+  <ItemGroup>
+    <ProjectReference Include="..\WCS.Core\WCS.Core.csproj" />
+  </ItemGroup>
 
 </Project>

+ 10 - 5
WCS.Core/DataBlock.cs

@@ -1,6 +1,7 @@
 using System.Collections;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Text;
 
 namespace WCS.Core
 {
@@ -361,11 +362,15 @@ namespace WCS.Core
             var data = Configs.StringEncoding.GetBytes(value);
             if (data.Length > strLen)
                 throw new Exception("字符串长度超出");
-            if (Entity.PLCInfo.Type == PLCType.Siemens)
-            {
-                var title = new byte[] { (byte)strLen, (byte)data.Length };
-                data = title.Concat(data).ToArray();
-            }
+            //if (Entity.PLCInfo.Type == PLCType.Siemens)
+            //{
+            //    var a = Encoding.UTF8.GetString(data);
+            //    var title = new byte[] { (byte)strLen, (byte)data.Length };
+            //    data = title.Concat(data).ToArray();
+            //    var b = Encoding.UTF8.GetString(data);
+
+            //    var c = 0;
+            //}
             WriteBytes(ref bitStart, data);
         }
 

+ 4 - 33
WCS.Service/Worker.cs

@@ -85,42 +85,13 @@ namespace WCS.Service
             };
             SqlSugarHelper.SetDb(new SqlSugarScope(connectionConfigs));
 
-            //初始化数据库
-            SqlSugarHelper.Do(db =>
-            {
-                foreach (var connectionString in ServiceHub.DbConnectionStrings!)
-                {
-                    var _db = db.Connect.GetConnectionScope(connectionString.Key);
-                    switch (connectionString.Key)
-                    {
-                        case "WCSDB"://WCS基本数据库
-                            SqlSugarHelper.SetDefault(connectionString.Key);
-                            _db.CodeFirst.InitTables(typeof(WCS_PlcData));
-                            _db.CodeFirst.InitTables(typeof(WCS_TaskInfo));
-                            _db.CodeFirst.InitTables(typeof(WCS_TaskDtl));
-                            _db.CodeFirst.InitTables(typeof(WCS_TaskOld));
-                            _db.CodeFirst.InitTables(typeof(WCS_AgvTaskInfo));
-
-                            break;
-
-                        case "WCSDlog"://WCS日志数据库
-                            //SqlSugarHelper.SetDefault(connectionString.Key);
-                            //_db.CodeFirst.InitTables(typeof(w));
-                            //_db.CodeFirst.InitTables(typeof(WCS_TaskInfo));
-                            //_db.CodeFirst.InitTables(typeof(WCS_TaskDtl));
-                            //_db.CodeFirst.InitTables(typeof(WCS_TaskOld));
-                            //_db.CodeFirst.InitTables(typeof(WCS_AgvTaskInfo));
-                            break;
-
-                        default: //其他库
-                            break;
-                    };
-                };
-            });
+            ServiceHub.DbConnectionStrings.InitDB();
+
+
 
             #endregion 初始化数据库连接
 
-         
+
 
             #region 初始化设备信息
 

+ 218 - 7
WCS.WorkEngineering/Extensions/TaskExtension.cs

@@ -1,8 +1,10 @@
-using ServiceCenter.Extensions;
+using Newtonsoft.Json;
+using ServiceCenter.Extensions;
 using ServiceCenter.Logs;
 using ServiceCenter.Redis;
 using ServiceCenter.SqlSugars;
 using WCS.Entity;
+using wms.sqlsugar.model.fj;
 
 namespace WCS.WorkEngineering.Extensions
 {
@@ -140,12 +142,82 @@ namespace WCS.WorkEngineering.Extensions
 
         #region 工字轮支线分流
 
-        ///// <summary>
-        /////  初始化码垛信息
-        ///// </summary>
-        //public static void InitStackStructure()
-        //{
-        //}
+        /// <summary>
+        ///  初始化码垛信息
+        /// </summary>
+        /// <param name="stackId"> 垛形ID</param>
+        public static void InitStackStructure(long stackId)
+        {
+            SqlSugarHelper.Do(_db =>
+            {
+                var db = _db.Default;
+                //TODO:获取对应的垛形主表信息,暂时直接使用垛形ID获取,后续需要更新使用订单号
+                BillBomsetgrp billBomsetgrp = db.Queryable<BillBomsetgrp>().Single(x => x.Id == stackId);
+                var billBomsetinfos = db.Queryable<BillBomsetinfo>().Where(x => x.BomSetHdrId == billBomsetgrp.Id).ToList();
+
+                //开始构造垛形信息
+                StackInfo stackInfo = new StackInfo()
+                {
+                    Code = billBomsetgrp.Code,
+                    ShortCode = billBomsetgrp.ShortCode,
+                    ProMaterCode = billBomsetgrp.ProMaterCode,
+                    TpTypeCode = billBomsetgrp.TpTypeCode,
+                    LayerCountQty = 2,
+                    LayerInfos = new List<StackLayerInfo>()
+                    {
+                        new StackLayerInfo()
+                        {
+                          LayerNo=1,
+                          RowInfos=new List<StackRowInfo>(),
+            },
+                        new StackLayerInfo()
+                        {
+                            LayerNo=2,
+                            RowInfos=new List<StackRowInfo>()
+                        }
+                    },
+                    StampType = billBomsetgrp.StampType
+                };
+
+                foreach (var item in billBomsetinfos.GroupBy(x => x.Row).OrderBy(x => x.Key))
+                {
+                    //获取层信息
+                    StackLayerInfo layerInfo = new StackLayerInfo();
+                    if (item.Key <= 6) layerInfo = stackInfo.LayerInfos.Single(x => x.LayerNo == 1);
+                    else layerInfo = stackInfo.LayerInfos.Single(x => x.LayerNo == 2);
+
+                    //构造行信息
+                    var rowInfo = new StackRowInfo()
+                    {
+                        RowNo = item.Key,
+                        PosInfos = new List<StackPosInfo>()
+                    };
+
+                    //构造位信息
+                    foreach (var item1 in item)
+                    {
+                        rowInfo.PosInfos.Add(new StackPosInfo()
+                        {
+                            IsEmpty = item1.IsEmpty == 0 ? false : true,
+                            XYNo = item1.XYNo,
+                            MatCode = item1.MatCode,
+                            SideNum = item1.SideNum,
+                            SpoolType = item1.SpoolType,
+                            TaskNumber = 0
+                        });
+                        //同步是否混合料行
+                        rowInfo.IsMixRow = item1.IsMixRow == 0 ? false : true;
+                    }
+                    rowInfo.QtyMaxCount = rowInfo.PosInfos.Count;
+                    rowInfo.IsEmpty = rowInfo.QtyMaxCount > 0 ? false : true;
+                    layerInfo.RowInfos.Add(rowInfo);
+                    var count = layerInfo.RowInfos.Count(x => !x.IsEmpty); //计算所有不空数量
+                    layerInfo.IsEmpty = count <= 0 ? true : false;
+                }
+
+                RedisHub.Default.Set("", JsonConvert.SerializeObject(stackInfo));
+            });
+        }
 
         ////获取目标地址
         //public static string GetNextAdd(this WCS_TaskInfo task)
@@ -155,4 +227,143 @@ namespace WCS.WorkEngineering.Extensions
 
         #endregion 工字轮支线分流
     }
+
+    /// <summary>
+    ///  垛形信息
+    /// </summary>
+    public class StackInfo
+    {
+        /// <summary>
+        /// 垛型编码
+        /// </summary>
+        public string Code { get; set; }
+
+        /// <summary>
+        ///  短垛型编码
+        /// </summary>
+        public short ShortCode { get; set; }
+
+        /// <summary>
+        ///  帘线物料编码
+        /// </summary>
+        public string ProMaterCode { get; set; }
+
+        /// <summary>
+        ///  产品总数
+        /// </summary>
+        public int CountQty { get; set; }
+
+        /// <summary>
+        ///  托盘类型
+        /// </summary>
+        public string TpTypeCode { get; set; }
+
+        /// <summary>
+        ///  层数
+        /// </summary>
+        public int LayerCountQty { get; set; }
+
+        /// <summary>
+        ///  层信息
+        /// </summary>
+        public List<StackLayerInfo> LayerInfos { get; set; }
+
+        /// <summary>
+        ///  垛型大类
+        /// </summary>
+        public int StampType { get; set; }
+    }
+
+    /// <summary>
+    ///  垛形层信息
+    /// </summary>
+    public class StackLayerInfo
+    {
+        /// <summary>
+        /// 是否空置
+        /// </summary>
+        public bool IsEmpty { get; set; }
+
+        /// <summary>
+        ///  层号
+        /// </summary>
+        public int LayerNo { get; set; }
+
+        /// <summary>
+        ///  行数
+        /// </summary>
+        public int RowCountQty { get; set; }
+
+        /// <summary>
+        ///  行信息
+        /// </summary>
+        public List<StackRowInfo> RowInfos { get; set; }
+    }
+
+    /// <summary>
+    ///  垛形行信息
+    /// </summary>
+    public class StackRowInfo
+    {
+        /// <summary>
+        /// 是否空置
+        /// </summary>
+        public bool IsEmpty { get; set; }
+
+        /// <summary>
+        /// 数量上限
+        /// </summary>
+        public int QtyMaxCount { get; set; }
+
+        /// <summary>
+        ///  行号
+        /// </summary>
+        public int RowNo { get; set; }
+
+        /// <summary>
+        ///  是否混合料行
+        /// </summary>
+        public bool IsMixRow { get; set; }
+
+        /// <summary>
+        ///  表示每一个具体位置的商品信息
+        /// </summary>
+        public List<StackPosInfo> PosInfos { get; set; }
+    }
+
+    /// <summary>
+    ///  垛形位信息
+    /// </summary>
+    public class StackPosInfo
+    {
+        /// <summary>
+        ///  任务号
+        /// </summary>
+        public int TaskNumber { get; set; }
+
+        /// <summary>
+        /// 是否空置
+        /// </summary>
+        public bool IsEmpty { get; set; }
+
+        /// <summary>
+        /// 坐标号
+        /// </summary>
+        public string XYNo { get; set; }
+
+        /// <summary>
+        /// 物料编码
+        /// </summary>
+        public string MatCode { get; set; }
+
+        /// <summary>
+        /// 正反面
+        /// </summary>
+        public int SideNum { get; set; }
+
+        /// <summary>
+        /// 工字轮类型
+        /// </summary>
+        public string SpoolType { get; set; }
+    }
 }

+ 8 - 5
WCS.WorkEngineering/Systems/SrmSystems.cs

@@ -6,6 +6,7 @@ using System.ComponentModel;
 using WCS.Core;
 using WCS.Entity;
 using WCS.WorkEngineering.Extensions;
+using WCS.WorkEngineering.Protocol.BCR;
 using WCS.WorkEngineering.Protocol.SRM;
 using WCS.WorkEngineering.Protocol.Station;
 using WCS.WorkEngineering.WebApi.Controllers;
@@ -58,13 +59,15 @@ namespace WCS.WorkEngineering.Systems
         {
             #region 处理完成任务
 
-            SqlSugarHelper.Do(db =>
+            var bcr = Device.All.Where(x => x.Code == "1").Select(x => new Device<IBCR83>(x, World));
+            foreach (var item in bcr)
             {
-                var a = db.Default.Queryable<WCS_TaskInfo>().ToSql();
-                var c = db.Default.CurrentConnectionConfig.ConnectionString;
-                var b = db.Default.Queryable<WCS_TaskInfo>().ToList();
-            });
+                var bb = "ZTGT11111111111111";
+                item.Data.BcrCode1 = "ZTGT11111111111111";
+                var aa = item.Data.BcrCode;
+            }
 
+            //TaskExtension.InitStackStructure(1689817060395323392);
             //判断DB520 完成任务确认清除信号 是否为1
             if (obj.Data.OkAck == 1) throw new KnownException($"WCS任务完成确认信号[DB520.OkAck]未清除,请检查堆垛机处理异常原因", LogLevelEnum.Mid);
 

+ 5 - 1
WCS.WorkEngineering/WCS.WorkEngineering.csproj

@@ -22,11 +22,15 @@
   <ItemGroup>
     <PackageReference Include="MessagePack" Version="2.5.108" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
+    <PackageReference Include="wms.sqlsugar" Version="1.0.0.3" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\ServiceCenter\ServiceCenter.csproj" />
-    <ProjectReference Include="..\WCS.Entity\WCS.Entity.csproj" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <Folder Include="Modes\" />
   </ItemGroup>
 
 </Project>

+ 37 - 0
WCS.WorkEngineering/WorkStart.cs

@@ -1,6 +1,8 @@
 using PlcSiemens.Core.Extension;
 using ServiceCenter;
+using ServiceCenter.SqlSugars;
 using WCS.Core;
+using WCS.Entity;
 using WCS.WorkEngineering.Extensions;
 using WCS.WorkEngineering.Protocol.BCR;
 using WCS.WorkEngineering.Protocol.RGV;
@@ -415,5 +417,40 @@ namespace WCS.WorkEngineering
 
             #endregion 标签配置
         }
+
+        /// <summary>
+        ///  初始化数据库连接
+        /// </summary>
+        /// <param name="datas"></param>
+        public static void InitDB(this List<DataBaseConnectionString> datas)
+        {
+            //初始化数据库
+            SqlSugarHelper.Do(db =>
+            {
+                foreach (var connectionString in datas!)
+                {
+                    var _db = db.Connect.GetConnectionScope(connectionString.Key);
+                    switch (connectionString.Key)
+                    {
+                        case "WCSDB"://WCS基本数据库
+                            SqlSugarHelper.SetDefault(connectionString.Key);
+                            _db.CodeFirst.InitTables(typeof(WCS_PlcData));
+                            _db.CodeFirst.InitTables(typeof(WCS_TaskInfo));
+                            _db.CodeFirst.InitTables(typeof(WCS_TaskDtl));
+                            _db.CodeFirst.InitTables(typeof(WCS_TaskOld));
+                            _db.CodeFirst.InitTables(typeof(WCS_AgvTaskInfo));
+
+                            break;
+
+                        case "WCSDlog"://WCS日志数据库
+
+                            break;
+
+                        default: //其他库
+                            break;
+                    };
+                };
+            });
+        }
     }
 }