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 |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 108 insertions(+), 9 deletions(-)

diff --git a/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs b/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
index e4039bb..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
 {
@@ -124,10 +127,10 @@
                     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==(int)BIZ_MES_WO_BATCH.STATUSs.Closed))
+                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}]鏈夋病瀹屽伐鐨勫伐鍗曟壒娆★紝涓嶈兘涓嬪彂锛�");
+                    result.LocaleMsg = new($"宸ュ崟鎵规鍦ㄧ嚎浣揫{input.WoBatch.ACT_LINE}]涓姸鎬佷负[{input.WoBatch.STATUS.GetEnumDesc<BIZ_MES_WO.STATUSs>()}]锛屼笉鑳戒笅鍙戯紒");
                     return result;
                 }
                 WoContext.RemoveBatch(input.WoBatch.BATCH_NO);
@@ -194,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)
                 {
@@ -220,12 +223,12 @@
             var result = new ApiAction();
             try
             {
-                //淇濆瓨鍓嶇殑鍒ゆ柇,骞剁敓鎴愭壒娆″彿
-                var _wo = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.BATCH_NO == input.WoBatch).FirstAsync();
-                if (_wo != null)
+                //淇濆瓨鍓嶇殑鍒ゆ柇
+                var _woBatch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.BATCH_NO == input.WoBatch).FirstAsync();
+                if (_woBatch != null)
                 {
-                    _wo.STATUS = input.Status < 0 ? _wo.STATUS : input.Status;
-                    if (input.Status == (int) BIZ_MES_WO_BATCH.STATUSs.Paused) {
+                    _woBatch.STATUS = input.Status < 0 ? _woBatch.STATUS : input.Status;
+                    if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue()) {
                         WoContext.RemoveBatch(input.WoBatch);
                     }
                 }
@@ -239,7 +242,7 @@
                 var db = Biz.Db;
                 var dbTran = db.UseTran(() =>
                 {
-                    db.Updateable(_wo, input.UserId).ExecuteCommand();
+                    db.Updateable(_woBatch, input.UserId).UpdateColumns(x=> new { x.STATUS}).ExecuteCommand();
                 });
                 if (!dbTran.IsSuccess)
                 {
@@ -253,5 +256,101 @@
             }
             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