满轮主线预写入目标地址.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. using Newtonsoft.Json;
  2. using PlcSiemens.Core.Extension;
  3. using ServiceCenter.Extensions;
  4. using ServiceCenter.Logs;
  5. using ServiceCenter.SqlSugars;
  6. using SqlSugar;
  7. using System.ComponentModel;
  8. using WCS.Core;
  9. using WCS.Entity;
  10. using WCS.Entity.Protocol.BCR;
  11. using WCS.Entity.Protocol.Station;
  12. using WCS.WorkEngineering.Extensions;
  13. using WCS.WorkEngineering.Worlds;
  14. using TaskStatus = WCS.Entity.TaskStatus;
  15. namespace WCS.WorkEngineering.Systems
  16. {
  17. /// <summary>
  18. /// 满轮主线预写入目标地址
  19. /// </summary>
  20. [BelongTo(typeof(SortingMainLineWorld))]
  21. [Description("满轮主线预写入目标地址")]
  22. public class 满轮主线预写入目标地址 : DeviceSystem<Device<IStation523, IBCR83, IStation525>>
  23. {
  24. protected override bool ParallelDo => true;
  25. public override void Do(Device<IStation523, IBCR83, IStation525> obj)
  26. {
  27. try
  28. {
  29. var devCode = obj.Entity.Code switch
  30. {
  31. "18" => "22",
  32. "38" => "41",
  33. "58" => "61",
  34. "118" => "122",
  35. "138" => "141",
  36. "158" => "161",
  37. _ => throw new ArgumentOutOfRangeException()
  38. };
  39. var dev = new Device<IStation520>(Device.All.First(x => x.Code == devCode), World);
  40. dev.Data.Mode = StationMode.Automatic;
  41. //从DB83中获取待处理条码组
  42. var pendingBcrList = obj.Data2.GetBcrCodeList().Where(x => !x.IsNullOrEmpty());
  43. //从DB525获取已处理条码组
  44. var cacheBcrList = obj.Data3.GetBcrCodeList();
  45. //筛选出未处理条码组
  46. var codes = pendingBcrList.Where(x => !cacheBcrList.Contains(x));
  47. World.Log($"扫码器:{JsonConvert.SerializeObject(pendingBcrList)}");
  48. World.Log($"缓存信息:{JsonConvert.SerializeObject(cacheBcrList)}");
  49. //循环处理所有缓存条码组中没有的条码
  50. foreach (var bcrCode in codes)
  51. {
  52. WCS_TaskInfo taskInfo = null;
  53. fjSysConfig config = new fjSysConfig();
  54. SqlSugarHelper.Do(_db =>
  55. {
  56. var db = _db.Default;
  57. var task = db.Queryable<WCS_TaskInfo>().NoLock().First(x => x.BarCode == bcrCode && x.Status == TaskStatus.NewBuild);
  58. if (task == null)
  59. {
  60. World.Log($"{bcrCode}:找不到匹配的任务", LogLevelEnum.High);
  61. return;
  62. }
  63. var config1 = db.Queryable<fjSysConfig>().NoLock().First(x => x.Code == $"{task.WarehouseCode}-Flow");
  64. if (config1 == null)
  65. {
  66. config.Code = "4";
  67. }
  68. config = config1;
  69. taskInfo = task;
  70. });
  71. if (taskInfo == null)
  72. {
  73. continue;
  74. }
  75. var srmCode = taskInfo.WarehouseCode.WarehouseToSrm();
  76. var path = DevicePath.GetPath(obj.Entity.Code, srmCode);
  77. if (path == null || path is { Points.Count: < 2 })
  78. {
  79. World.Log($"{bcrCode}:路径错误,当前位置{obj.Entity.Code},目标位置:{srmCode}", LogLevelEnum.High);
  80. continue;
  81. }
  82. var next = path.Points[1].Code;
  83. #region 计算应该去哪个分拣库
  84. //应该要去的分拣库
  85. if (taskInfo.WarehouseCode.Contains("N"))
  86. {
  87. next = config.SContent switch
  88. {
  89. "1" => "418",
  90. "2" => "818",
  91. "3" => "1218",
  92. _ => next
  93. };
  94. }
  95. else if (taskInfo.WarehouseCode.Contains("S"))
  96. {
  97. next = config.SContent switch
  98. {
  99. "1" => "618",
  100. "2" => "1018",
  101. "3" => "1418",
  102. _ => next
  103. };
  104. }
  105. #endregion 计算应该去哪个分拣库
  106. if (taskInfo == null) continue;
  107. //开始赋值
  108. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
  109. .SetValue(obj.Data3, taskInfo.ID);
  110. obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
  111. .SetValue(obj.Data3, taskInfo.ID);
  112. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
  113. .SetValue(obj.Data3, next.ToShort());
  114. obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
  115. .SetValue(obj.Data3, next.ToShort());
  116. obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
  117. if (obj.Data3.NextIndex >= 49)
  118. {
  119. obj.Data3.NextIndex = 0;
  120. }
  121. else
  122. {
  123. obj.Data3.NextIndex++;
  124. }
  125. }
  126. dev.Data.Mode = StationMode.Automatic;
  127. }
  128. catch (Exception e)
  129. {
  130. World.Log($"{e.Message}:---{e.StackTrace}", LogLevelEnum.High);
  131. }
  132. }
  133. public override bool Select(Device dev)
  134. {
  135. var codes = new List<string>();
  136. if (WorkStart.WareHouses.Contains("FJ1")) codes.AddRange(new List<string>() { "18", "118" });
  137. if (WorkStart.WareHouses.Contains("FJ2")) codes.AddRange(new List<string>() { "38", "58" });
  138. if (WorkStart.WareHouses.Contains("FJ3")) codes.AddRange(new List<string>() { "138", "158" });
  139. return codes.Contains(dev.Code);
  140. return false;
  141. }
  142. }
  143. /// <summary>
  144. /// 主线分流
  145. /// </summary>
  146. public class MainlineDiversion
  147. {
  148. /// <summary>
  149. /// 任务号
  150. /// </summary>
  151. public int TaskId { get; set; }
  152. /// <summary>
  153. /// 仓库号
  154. /// </summary>
  155. public string WarehouseCode { get; set; }
  156. }
  157. /// <summary>
  158. /// 配置信息表
  159. /// </summary>
  160. [Tenant("fj")]
  161. [SugarTable("sys_config", "配置信息表")]
  162. public class fjSysConfig : BaseModel
  163. {
  164. /// <summary>
  165. /// 编号
  166. /// </summary>
  167. [SugarColumn(ColumnName = "code", Length = 100)]
  168. public string Code { get; set; }
  169. /// <summary>
  170. /// 名称
  171. /// </summary>
  172. [SugarColumn(ColumnName = "name", Length = 100)]
  173. public string Name { get; set; }
  174. /// <summary>
  175. /// 内容
  176. /// </summary>
  177. [SugarColumn(ColumnName = "scontent", Length = 100)]
  178. public string SContent { get; set; }
  179. /// <summary>
  180. /// 类型
  181. /// </summary>
  182. [SugarColumn(ColumnName = "stype", Length = 50)]
  183. public string SType { get; set; }
  184. [SugarColumn(ColumnName = "default1", Length = 100, IsNullable = true)]
  185. public string Default1 { get; set; }
  186. [SugarColumn(ColumnName = "default2", Length = 100, IsNullable = true)]
  187. public string Default2 { get; set; }
  188. [SugarColumn(ColumnName = "default3", Length = 100, IsNullable = true)]
  189. public string Default3 { get; set; }
  190. }
  191. /// <summary>
  192. /// 物料表
  193. /// </summary>
  194. [Tenant("fj")]
  195. [SugarTable("Base_MatInfo")]
  196. public partial class BaseMatinfo : BaseModel
  197. {
  198. /// <summary>
  199. /// 仓库ID
  200. /// </summary>
  201. [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
  202. public long WarehouseId { get; set; }
  203. /// <summary>
  204. /// 编码
  205. /// </summary>
  206. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
  207. public string Code { get; set; }
  208. /// <summary>
  209. /// 名称
  210. /// </summary>
  211. [SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = false)]
  212. public string Name { get; set; }
  213. /// <summary>
  214. /// 短描述
  215. /// </summary>
  216. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  217. public string ShortDesc { get; set; }
  218. /// <summary>
  219. /// 长描述
  220. /// </summary>
  221. [SugarColumn(ColumnDataType = "nvarchar", Length = 500, IsNullable = true)]
  222. public string FullDesc { get; set; }
  223. /// <summary>
  224. /// 补充描述
  225. /// </summary>
  226. [SugarColumn(ColumnDataType = "nvarchar", Length = 500, IsNullable = true)]
  227. public string ExtDesc { get; set; }
  228. /// <summary>
  229. /// 英文名
  230. /// </summary>
  231. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  232. public string Enname { get; set; }
  233. /// <summary>
  234. /// 组ID
  235. /// </summary>
  236. [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
  237. public long MatGrpId { get; set; }
  238. /// <summary>
  239. /// 叶类编码
  240. /// </summary>
  241. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  242. public string Leafcode { get; set; }
  243. /// <summary>
  244. /// 叶类名称
  245. /// </summary>
  246. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  247. public string LeafName { get; set; }
  248. /// <summary>
  249. /// 中类编码
  250. /// </summary>
  251. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  252. public string MidCode { get; set; }
  253. /// <summary>
  254. /// 中类名称
  255. /// </summary>
  256. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  257. public string MidName { get; set; }
  258. /// <summary>
  259. /// 大类编码
  260. /// </summary>
  261. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  262. public string HeadCode { get; set; }
  263. /// <summary>
  264. /// 大类名称
  265. /// </summary>
  266. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  267. public string HeadName { get; set; }
  268. /// <summary>
  269. /// 规格型号
  270. /// </summary>
  271. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  272. public string Description { get; set; }
  273. /// <summary>
  274. /// 材质
  275. /// </summary>
  276. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  277. public string Texture { get; set; }
  278. /// <summary>
  279. /// 图号
  280. /// </summary>
  281. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  282. public string FigureNo { get; set; }
  283. /// <summary>
  284. /// 强度
  285. /// </summary>
  286. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  287. public string Strength { get; set; }
  288. /// <summary>
  289. /// 镀层
  290. /// </summary>
  291. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  292. public string Plating { get; set; }
  293. /// <summary>
  294. /// 镀层克重
  295. /// </summary>
  296. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  297. public decimal? PlatingWeight { get; set; }
  298. /// <summary>
  299. /// 镀层主元素含量
  300. /// </summary>
  301. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  302. public decimal? PlatingContQty { get; set; }
  303. /// <summary>
  304. /// 线密度
  305. /// </summary>
  306. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  307. public decimal? Linear { get; set; }
  308. /// <summary>
  309. /// 产品号
  310. /// </summary>
  311. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  312. public string ProCode { get; set; }
  313. /// <summary>
  314. /// 产品描述
  315. /// </summary>
  316. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  317. public string ProName { get; set; }
  318. /// <summary>
  319. /// 产品强度
  320. /// </summary>
  321. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  322. public string ProStre { get; set; }
  323. /// <summary>
  324. /// 线密度上限
  325. /// </summary>
  326. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  327. public decimal? LinearMax { get; set; }
  328. /// <summary>
  329. /// 线密度下限
  330. /// </summary>
  331. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  332. public decimal? LinearMin { get; set; }
  333. /// <summary>
  334. /// 线密度目标值
  335. /// </summary>
  336. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  337. public decimal? LinearTar { get; set; }
  338. /// <summary>
  339. /// 单丝倍数
  340. /// </summary>
  341. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  342. public decimal? Mono { get; set; }
  343. /// <summary>
  344. /// 工字轮型号
  345. /// </summary>
  346. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  347. public string SpoolType { get; set; }
  348. /// <summary>
  349. /// 工字轮料号
  350. /// </summary>
  351. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  352. public string SpoolCode { get; set; }
  353. /// <summary>
  354. /// 单卷长度
  355. /// </summary>
  356. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  357. public decimal? Length { get; set; }
  358. /// <summary>
  359. /// 涂油量
  360. /// </summary>
  361. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  362. public decimal? OilQty { get; set; }
  363. /// <summary>
  364. /// 润滑液种类
  365. /// </summary>
  366. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  367. public string LubType { get; set; }
  368. /// <summary>
  369. /// 排线间距
  370. /// </summary>
  371. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  372. public decimal? LineSpace { get; set; }
  373. /// <summary>
  374. /// 线长度
  375. /// </summary>
  376. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  377. public decimal? LineLength { get; set; }
  378. /// <summary>
  379. /// 捻向
  380. /// </summary>
  381. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  382. public string LayDirect { get; set; }
  383. /// <summary>
  384. /// 客户标准索引号
  385. /// </summary>
  386. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  387. public string CumIndex { get; set; }
  388. /// <summary>
  389. /// 有无焊点
  390. /// </summary>
  391. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  392. public string IsSolder { get; set; }
  393. /// <summary>
  394. /// SKU号
  395. /// </summary>
  396. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  397. public string SkuCode { get; set; }
  398. /// <summary>
  399. /// SKU描述
  400. /// </summary>
  401. [SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)]
  402. public string SkuDesc { get; set; }
  403. /// <summary>
  404. /// 控制扭转
  405. /// </summary>
  406. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  407. public string Tors { get; set; }
  408. /// <summary>
  409. /// 包装组ID
  410. /// </summary>
  411. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  412. public string PackGrpId { get; set; }
  413. /// <summary>
  414. /// 黑盘取样
  415. /// </summary>
  416. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  417. public string BlackSamp { get; set; }
  418. /// <summary>
  419. /// 黑盘检验
  420. /// </summary>
  421. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  422. public string BlackChk { get; set; }
  423. /// <summary>
  424. /// 客户编码
  425. /// </summary>
  426. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  427. public string CustCode { get; set; }
  428. /// <summary>
  429. /// 客户描述
  430. /// </summary>
  431. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  432. public string CustName { get; set; }
  433. /// <summary>
  434. /// 收货地址编码
  435. /// </summary>
  436. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  437. public string AddressCode { get; set; }
  438. /// <summary>
  439. /// 收货地址名称
  440. /// </summary>
  441. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  442. public string AddressName { get; set; }
  443. /// <summary>
  444. /// 生产批次数量(箱/批)
  445. /// </summary>
  446. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  447. public decimal? Qty { get; set; }
  448. /// <summary>
  449. /// 每箱最大焊点盘数(个)
  450. /// </summary>
  451. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  452. public decimal? BoxMaxSolder { get; set; }
  453. /// <summary>
  454. /// 工字轮最大焊点数(个)
  455. /// </summary>
  456. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  457. public decimal? SpoolMaxSolder { get; set; }
  458. /// <summary>
  459. /// OVC比例
  460. /// </summary>
  461. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  462. public decimal? Ovc { get; set; }
  463. /// <summary>
  464. /// 起鼓等级
  465. /// </summary>
  466. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  467. public string DrummLevel { get; set; }
  468. /// <summary>
  469. /// 公司代码
  470. /// </summary>
  471. [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
  472. public string ComCode { get; set; }
  473. /// <summary>
  474. /// 公司名称
  475. /// </summary>
  476. [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
  477. public string ComName { get; set; }
  478. /// <summary>
  479. /// 计量单位
  480. /// </summary>
  481. [SugarColumn(ColumnDataType = "nvarchar", Length = 10, IsNullable = true)]
  482. public string CalcUnit { get; set; }
  483. /// <summary>
  484. /// 库存单位
  485. /// </summary>
  486. [SugarColumn(ColumnDataType = "nvarchar", Length = 10, IsNullable = true)]
  487. public string StockUnit { get; set; }
  488. /// <summary>
  489. /// 单重
  490. /// </summary>
  491. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
  492. public decimal? Weight { get; set; }
  493. /// <summary>
  494. /// 单重单位
  495. /// </summary>
  496. [SugarColumn(ColumnDataType = "nvarchar", Length = 10, IsNullable = true)]
  497. public string WeightUnit { get; set; }
  498. /// <summary>
  499. /// 是否启用时效
  500. /// </summary>
  501. [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
  502. public bool IsHold { get; set; }
  503. /// <summary>
  504. /// 时效时长(小时)
  505. /// </summary>
  506. [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
  507. public decimal HoldDuration { get; set; }
  508. /// <summary>
  509. /// 超时时间-小时
  510. /// </summary>
  511. [SugarColumn(ColumnDataType = "int", IsNullable = true)]
  512. public int TimeOut { get; set; }
  513. }
  514. }