From 4b3263a99724c161d4848d44cb7b6ac7e0bb12b7 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期二, 24 九月 2024 23:33:52 +0800
Subject: [PATCH] 修复了一些已知问题

---
 Tiger.Business.MES/BIZ/BIZ_MES_WO.cs |  155 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 153 insertions(+), 2 deletions(-)

diff --git a/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs b/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
index 59cd2ad..b225414 100644
--- a/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
+++ b/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
@@ -13,6 +13,9 @@
 using Microsoft.AspNetCore.Http;
 using Tiger.Model.Entitys.MES.BizMesWoBatch;
 using Tiger.Model.Entitys.MES.BizMesWo;
+using Tiger.Model.Entitys.MES.Position;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using System.Drawing.Printing;
 
 namespace Tiger.Business.MES
 {
@@ -103,7 +106,6 @@
             var result = new ApiAction();
             try
             {
-                WoContext.RemoveBatch(input.WoBatch.BATCH_NO);
                 //淇濆瓨鍓嶇殑鍒ゆ柇,骞剁敓鎴愭壒娆″彿
                 var _wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO).FirstAsync();
                 //if (_wo.STATUS > (int)BIZ_MES_WO.STATUSs.Init)
@@ -125,6 +127,14 @@
                     result.LocaleMsg = new($"宸ュ崟涓嬪彂鐨勬暟閲忚秴杩囧伐鍗曡鍒掓暟閲忥紝涓嶈兘涓嬪彂锛�");
                     return result;
                 }
+                if (Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Any(x => x.ORDER_NO == input.Wo.ORDER_NO && x.ACT_LINE == input.WoBatch.ACT_LINE && x.STATUS> BIZ_MES_WO.STATUSs.Imported.GetValue() && x.STATUS< BIZ_MES_WO.STATUSs.Closed.GetValue()))
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"宸ュ崟鎵规鍦ㄧ嚎浣揫{input.WoBatch.ACT_LINE}]涓姸鎬佷负[{input.WoBatch.STATUS.GetEnumDesc<BIZ_MES_WO.STATUSs>()}]锛屼笉鑳戒笅鍙戯紒");
+                    return result;
+                }
+                WoContext.RemoveBatch(input.WoBatch.BATCH_NO);
+
                 var _batchWos = await Biz.Db.Queryable<V_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.WoBatch.ORDER_NO).ToListAsync();
                 if (_batchWos.Count > 0)
                 {
@@ -187,7 +197,7 @@
                 var db = Biz.Db;
                 var dbTran = db.UseTran(() =>
                 {
-                    db.Updateable(_wo, input.UserId).ExecuteCommand();
+                    db.Updateable(_wo, input.UserId).UpdateColumns(x => new { x.STATUS }).ExecuteCommand();
                 });
                 if (!dbTran.IsSuccess)
                 {
@@ -201,5 +211,146 @@
             }
             return result;
         }
+
+        /// <summary>
+        /// 鏇存柊宸ュ崟鎵规鐘舵��
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<ApiAction> UpdateWoBatchStatus(BizMesWoInput input)
+        {
+            var result = new ApiAction();
+            try
+            {
+                //淇濆瓨鍓嶇殑鍒ゆ柇
+                var _woBatch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.BATCH_NO == input.WoBatch).FirstAsync();
+                if (_woBatch != null)
+                {
+                    _woBatch.STATUS = input.Status < 0 ? _woBatch.STATUS : input.Status;
+                    if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue()) {
+                        WoContext.RemoveBatch(input.WoBatch);
+                    }
+                }
+                else
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"宸ュ崟鎵规[{input.WoBatch}]涓嶅瓨鍦�");
+                    return result;
+                }
+
+                var db = Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    db.Updateable(_woBatch, input.UserId).UpdateColumns(x=> new { x.STATUS}).ExecuteCommand();
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏇存柊宸ュ崟鎵规鐘舵�佸紓甯�");
+                }
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "鏇存柊宸ュ崟鎵规鐘舵�佸紓甯�");
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 宸ュ崟妯℃澘鍙橀噺淇敼
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<ApiAction> AddOrEditLabelVarByWorkOrder(BAS_LABEL_VAR_WO input)
+        {
+            var result = new ApiAction();
+            try
+            {
+                //淇濆瓨鍓嶇殑鍒ゆ柇
+                if (input.WORK_ORDER.IsNullOrEmpty())
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"宸ュ崟鍙蜂笉鑳戒负绌猴紒");
+                    return result;
+                }
+
+                var db = Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    var y = db.Storageable(input)
+                       .WhereColumns(t => new { t.LABEL_ID, t.WORK_ORDER, t.VAR_NAME, t.GHOST_ROW })
+                       .ToStorage();
+                    y.AsInsertable.ExecuteCommand();
+                    y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏇存柊宸ュ崟妯℃澘鍙橀噺寮傚父");
+                }
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "鏇存柊宸ュ崟妯℃澘鍙橀噺寮傚父");
+            }
+            return await Task.FromResult(result);
+        }
+
+        /// <summary>
+        /// 鑾峰彇宸ュ崟妯℃澘鍙橀噺
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<ApiAction<QueryAble<BAS_LABEL_VAR_WO>>> GetLabelVarByWorkOrder(BizLabelVarWoInput input)
+        {
+            var result = new ApiAction<QueryAble<BAS_LABEL_VAR_WO>>();
+            try
+            {
+                QueryAble<BAS_LABEL_VAR_WO> query = new();
+                if (input.WorkOrder.IsNullOrEmpty())
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"宸ュ崟鍙蜂笉鑳戒负绌猴紒");
+                    return result;
+                }
+                var labeltemp = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE.Equals(input.LabelId) || q.ID.Equals(input.LabelId)).First();
+                if (labeltemp == null) {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"妯℃澘涓嶅瓨鍦紒");
+                    return result;
+                }
+                var lableVars = await Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q => SqlFunc.IsNullOrEmpty(q.WORK_ORDER) && q.LABEL_ID.Equals(labeltemp.ID)).ToListAsync();
+                var queryable = Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q => q.WORK_ORDER.Equals(input.WorkOrder) && q.LABEL_ID.Equals(labeltemp.ID));
+                query.page = await queryable.ToPageAsync(input.pageIndex, input.pageSize);
+                //濡傛灉涓嶅瓨鍦紝鍒欒繑鍥炲垵濮嬫暟鎹�
+                if (query.page.totals == 0)
+                {
+                    query.page = await Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q => SqlFunc.IsNullOrEmpty(q.WORK_ORDER) && q.LABEL_ID.Equals(labeltemp.ID)).ToPageAsync(input.pageIndex, input.pageSize);
+                    query.Items = query.page.data;
+                }
+                //濡傛灉鍒濆鍙橀噺鏁板ぇ浜庡伐鍗曡缃殑鍙橀噺鏁�
+                if (lableVars.Count > query.page.totals)
+                {
+                    foreach (var item in lableVars)
+                    {
+                        if (queryable.ToList().Any(q => q.VAR_NAME == item.VAR_NAME))
+                        {
+                            item.WORK_ORDER = input.WorkOrder;
+                            item.VAR_VALUE = queryable.ToList().Where(q => q.VAR_NAME == item.VAR_NAME).First()?.VAR_VALUE;
+                        }
+                    }
+                    query.Items = lableVars.Skip((input.pageIndex - 1) * input.pageSize).Take(input.pageSize).ToList();
+                    query.page.totals = lableVars.Count;
+                    query.page.data = query.Items;
+                }
+                result.Data = query;
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "鑾峰彇宸ュ崟妯℃澘鍙橀噺寮傚父");
+            }
+            return result;
+        }
     }
 }

--
Gitblit v1.9.3