From db6156a92cc59467bde608a00c76952ebc75e488 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 05 三月 2024 09:51:05 +0800
Subject: [PATCH] 优化代码
---
代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs | 250 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 179 insertions(+), 71 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs"
index e9ff5f8..33de533 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs"
@@ -9,14 +9,15 @@
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Comm;
+using static System.Collections.Specialized.BitVector32;
namespace WIDESEA_WCS.JobsPart.Common
{
public class StationTask
{
- FreeDB freeDB = new FreeDB();
- public void CreateTask()
+ static FreeDB freeDB = new FreeDB();
+ public static void CreateTask()
{
VOLContext context = new VOLContext();
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
@@ -27,8 +28,11 @@
foreach (var item in stationinfos)
{
//鏍规嵁涓嬫枡鍙g殑缁戝畾淇℃伅鏌ヨ瀵瑰簲宸ュ崟锛屾娴嬫宸ュ崟鏄惁宸插畬鎴� 瀹屾垚鍗冲彲灏嗗叾閫佸叆搴�
- dt_Workinfo workinfo = workinfoRepository.FindFirst(x => x.WorkNumber == item.Number);
- int CompeletedNum = Convert.ToInt32(workinfo.PlannedQuantity) - Convert.ToInt32(workinfo.QuantityCompletion);
+
+ dt_mes_head mesinfo = freeDB.Select<dt_mes_head>().Where(x => x.jobID == item.Number).First();
+ dt_geometry_data dt_Geometry_Data = freeDB.Select<dt_geometry_data>().Where(x => x.Description == mesinfo.drawingNo).First();
+ int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum);
+
//鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪
if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0)
@@ -36,11 +40,12 @@
if (item.quantity == 5 || CompeletedNum == 0) //寰幆璇诲彇杞﹁疆鏁颁负5鎴栬�呰鍗曞凡瀹屾垚鏁伴噺鐨勪笅鏂欏彛 鈫掑伐鍗曚汉宸ュ叧闂殑宸ュ崟
{
- dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, workinfo, item);
- if (TargetLocation != null)
+
+ if (mesinfo.quantity <= 50 || item.stationCode.Contains("3")) //灏忎簬50浠剁洿鎺ュ嚭搴�
{
- //todo: 璋冪敤WMS鎺ュ彛鍒涘缓浠诲姟
+ //var station =
+ //todo 瀵绘壘鍙斁璐у鍗忔斁璐у彴
dt_agvtask agvtask = new dt_agvtask()
{
agv_fromaddress = item.stationCode,
@@ -49,16 +54,35 @@
agv_barcode = "",
agv_createtime = DateTime.Now,
agv_taskstate = TaskStatus.Created.ToString(),
- agv_toaddress = TargetLocation.stationCode,
+ //agv_toaddress = ,
};
-
freeDB.Add(agvtask);
- TargetLocation.location_state = LocationStateEnum.Busy.ToString();
- freeDB.Update(TargetLocation);
+ }
+ else
+ {
+ dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data.e);
+
+ if (TargetLocation != null)
+ {
+ //todo: 璋冪敤WMS鎺ュ彛鍒涘缓浠诲姟
+ dt_agvtask agvtask = new dt_agvtask()
+ {
+ agv_fromaddress = item.stationCode,
+ agv_id = Guid.NewGuid(),
+ agv_grade = 0,
+ agv_barcode = "",
+ agv_createtime = DateTime.Now,
+ agv_taskstate = TaskStatus.Created.ToString(),
+ agv_toaddress = TargetLocation.stationCode,
+ };
+
+ freeDB.Add(agvtask);
+ TargetLocation.location_state = LocationStateEnum.Busy.ToString();
+ freeDB.Update(TargetLocation);
+ }
}
}
-
}
}
@@ -69,68 +93,66 @@
/// <param name="workinfo">璁㈠崟</param>
/// <param name="stationinfo">涓嬫枡鍙d俊鎭�</param>
/// <returns></returns>
- private dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_Workinfo workinfo, dt_stationinfo stationinfo)
+ private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo, int CompeletedNum, float e)
{
//鏀捐揣浣�
dt_stationinfo TargetLocation = null;
- //鏍规嵁璁㈠崟鏁伴噺鏉ュ鎵惧搴斿簱鍖轰笖鍚岀墿鏂欑被鍨嬪簱浣�
+ #region 鏍规嵁璁㈠崟鏁伴噺鏉ュ鎵惧搴斿簱鍖轰笖鍚岀墿鏂欑被鍨嬪簱浣�
+ //if (workinfo.PlannedQuantity < 50) //搴撳尯1 鐗╂枡绫诲瀷澶�
+ //{
+ // dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == "1").OrderByDescending(x => x.lastUpdateTime).FirstOrDefault();
+ // if (station != null)
+ // {
+ // //濡傚瓨鍦ㄥ悓鐗╂枡绫诲瀷涓斿湪1琛岀殑搴撳瓨鍒欐柊鍏ュ簱鐨勭墿鏂欐斁鑷冲悓鍒� 涓嶅瓨鍦ㄥ垯瀵绘壘鏂拌搴撲綅
+ // if (station.line == 1)
+ // {
+ // TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.column == station.column && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+ // }
+ // TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+ // }
+ // else
+ // {
+ // TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+ // }
+ //}
+ //else
+ //{
+ //int quantity = Convert.ToInt32(workinfo.PlannedQuantity);
+ //string area = GetArea(quantity);
- if (workinfo.PlannedQuantity < 50) //搴撳尯1 鐗╂枡绫诲瀷澶�
- {
- dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == "1").OrderByDescending(x => x.lastUpdateTime).FirstOrDefault();
- if (station != null)
- {
- //濡傚瓨鍦ㄥ悓鐗╂枡绫诲瀷涓斿湪1琛岀殑搴撳瓨鍒欐柊鍏ュ簱鐨勭墿鏂欐斁鑷冲悓鍒� 涓嶅瓨鍦ㄥ垯瀵绘壘鏂拌搴撲綅
- if (station.line == 1)
- {
- TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.column == station.column && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
- }
- TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
- }
- else
- {
- TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.line == 1 && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
- }
- }
- else
- {
- //int quantity = Convert.ToInt32(workinfo.PlannedQuantity);
- //string area = GetArea(quantity);
+ //dt_materielinfo materielinfo = freeDB.Select<dt_materielinfo>().Where(x => x.materiel_id == stationinfo.stationType).First();
- dt_materielinfo materielinfo = freeDB.Select<dt_materielinfo>().Where(x => x.materiel_id == stationinfo.stationType).First();
+ //if (materielinfo == null)
+ // throw new Exception($"鏃犳鐗╂枡绫诲瀷{stationinfo.stationType}搴撳尯");
- if (materielinfo == null)
- throw new Exception($"鏃犳鐗╂枡绫诲瀷{stationinfo.stationType}搴撳尯");
+ //string area = materielinfo.materiel_areaid.ToString();
- string area = materielinfo.materiel_areaid.ToString();
+ //濡傚瓨鍦ㄥ悓绫诲瀷鐗╂枡鍒欐斁缃悓琛屽簱浣� 涓嶅瓨鍦ㄥ垯鏀剧疆鏂拌鐨勭涓�鍒椾腑
+ //dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == area).OrderBy(x => x.lastUpdateTime).FirstOrDefault();
+ //if (station != null)
+ //{
+ // TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.line == station.line).OrderBy(x => x.column).FirstOrDefault();
+ // if (TargetLocation == null)
+ // {
+ // TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault();
+ // }
+ //}
+ //else
+ //{
+ // TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault();
+ //}
- //濡傚瓨鍦ㄥ悓绫诲瀷鐗╂枡鍒欐斁缃悓琛屽簱浣� 涓嶅瓨鍦ㄥ垯鏀剧疆鏂拌鐨勭涓�鍒椾腑
- dt_stationinfo station = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.area == area).OrderBy(x => x.lastUpdateTime).FirstOrDefault();
- if (station != null)
- {
- TargetLocation = stationinfoRepository.Find(x => x.area == station.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.line == station.line).OrderBy(x => x.column).FirstOrDefault();
- if (TargetLocation == null)
- {
- TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault();
- }
- }
- else
- {
- TargetLocation = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault();
- }
-
- //todo 濡傜墿鏂欏凡婊″垯鏀剧疆鍏朵粬搴撳尯
- //if (TargetLocation == null)
- //{
- // stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault();
- //}
- }
-
- if (TargetLocation == null)
- {
- throw new Exception("搴撲綅宸叉弧");
- }
+ //todo 濡傜墿鏂欏凡婊″垯鏀剧疆鍏朵粬搴撳尯
+ //if (TargetLocation == null)
+ //{
+ // stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.column == '1').OrderBy(x => x.line).FirstOrDefault();
+ //}
+ //}
+ //if (TargetLocation == null)
+ //{
+ // throw new Exception("搴撲綅宸叉弧");
+ //}
//else if (workinfo.PlannedQuantity >= 50 && workinfo.PlannedQuantity < 110) //搴撳尯2
//{
@@ -148,7 +170,81 @@
//else if(workinfo.PlannedQuantity >= 110 && workinfo.PlannedQuantity < 180)
//{
+ //}
+ #endregion
+
+ var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First();
+ dt_inventory inventory = null;
+ if (detail.heatID != null)
+ {
+ inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First();
+ }
+ else
+ {
+ inventory = freeDB.Select<dt_inventory>().Where(x => x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First();
+ }
+
+ if (inventory != null)
+ {
+ var station = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode);
+ if (CompeletedNum <= 15 || station.area == "1")
+ {
+ TargetLocation = stationinfoRepository.Find(x => x.column == station.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.line).FirstOrDefault();
+ }
+ else
+ {
+ TargetLocation = stationinfoRepository.Find(x => x.line == station.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault();
+ }
+ if (TargetLocation != null) return TargetLocation;
+ }
+
+ if (CompeletedNum <= 15)
+ {
+ TargetLocation = stationinfoRepository.Find(x => x.line == 1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault();
+ }
+ else
+ {
+ //if (50 < mesinfo.quantity && mesinfo.quantity <= 180 && e < 1100)
+ // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+ //else if (180 < mesinfo.quantity && mesinfo.quantity <= 225 && e < 1100)
+ // TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "3" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+ //if (50 < mesinfo.quantity && e > 1100 || TargetLocation == null)
+ var area = GetArea(mesinfo.quantity, e);
+ TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+ if (TargetLocation == null)
+ TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "4" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+ }
+
+ #region
+
+ //鏍规嵁璁㈠崟鐐夊彿/宸ュ崟鍙�/绫诲瀷
+ //if (mesinfo.quantity >= 180)
+ //{
+ // //鏌ヨ搴撳瓨璁板綍涓槸鍚﹀瓨鍦ㄥ悓绫诲瀷/宸ュ崟/鐐夊彿鐨勮褰� 濡傛湁鍒欐斁缃悓涓�琛岋紝鏃犲垯瀵绘壘鏂板簱浣�
+ // var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First();
+ // var inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First();
+ // if (inventory != null)
+ // {
+ // //int line = Convert.ToInt16(inventory.stationCode.Split("-")[0]);
+ // var line = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode).line;
+ // TargetLocation = stationinfoRepository.Find(x => x.line == line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault();
+ // if (TargetLocation == null && CompeletedNum <= 15)
+ // {
+ // TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+ // }
+ // }
+ // else
+ // {
+ // TargetLocation = stationinfoRepository.Find(x => x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+
+ // }
//}
+ #endregion
+
+ if (TargetLocation == null)
+ {
+ throw new Exception("搴撲綅宸叉弧");
+ }
return TargetLocation;
}
@@ -157,14 +253,26 @@
/// </summary>
/// <param name="quantity"></param>
/// <returns></returns>
- private string GetArea(int quantity)
+ private static string GetArea(int quantity, float e)
{
- if (quantity >= 50 && quantity < 180)
- return "2";
- else if (quantity >= 180 && quantity < 180)
- return "3";
- else if (quantity >= 180 && quantity < 220)
+ if (e < 1100)
+ {
+ if (quantity <= 180)
+ return "2";
+ else if (quantity <= 225)
+ return "3";
+ }
+ else
+ {
return "4";
+ }
+
+ //if (quantity > 50 && quantity <= 180 && e < 1100)
+ // return "2";
+ //else if (quantity > 180 && quantity <= 225 && e < 1100)
+ // return "3";
+ //else if (quantity > 50 && e > 1100)
+ // return "4";
return null;
}
}
--
Gitblit v1.9.3