服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-09-28 0a73b07c5efd882960af101ac8f8e12b8d2f560f
Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
@@ -14,6 +14,8 @@
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
{
@@ -125,7 +127,7 @@
                    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()))
                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>()}],不能下发!");
@@ -226,7 +228,8 @@
                if (_woBatch != null)
                {
                    _woBatch.STATUS = input.Status < 0 ? _woBatch.STATUS : input.Status;
                    if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue()) {
                    if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue())
                    {
                        WoContext.RemoveBatch(input.WoBatch);
                    }
                }
@@ -240,7 +243,7 @@
                var db = Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    db.Updateable(_woBatch, input.UserId).UpdateColumns(x=> new { x.STATUS}).ExecuteCommand();
                    db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS }).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
@@ -272,7 +275,14 @@
                    result.LocaleMsg = new($"工单号不能为空!");
                    return result;
                }
                List<BAS_LABEL_VAR_WO> varWoList = new();
                if (File.Exists(input.LABEL_VIEW_PATH))
                {
                    string imageFileName = Path.GetFileNameWithoutExtension(input.LABEL_VIEW_PATH);
                    string? path = Path.GetDirectoryName(input.LABEL_VIEW_PATH);
                    input.LABEL_VIEW_PATH = $"{path}//Temp//{imageFileName}.png";
                    varWoList = await Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(x => x.LABEL_ID == input.LABEL_ID && x.WORK_ORDER == input.WORK_ORDER).ToListAsync();
                }
                var db = Biz.Db;
                var dbTran = db.UseTran(() =>
                {
@@ -281,6 +291,11 @@
                       .ToStorage();
                    y.AsInsertable.ExecuteCommand();
                    y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                    if (varWoList.Count > 0)
                    {
                        db.Updateable(varWoList).UpdateColumns(q => q.LABEL_VIEW_PATH).ExecuteCommand();
                    }
                });
                if (!dbTran.IsSuccess)
                {
@@ -292,7 +307,7 @@
            {
                result.CatchExceptionWithLog(ex, "更新工单模板变量异常");
            }
            return await Task.FromResult(result);
            return result;
        }
        /// <summary>
@@ -312,13 +327,37 @@
                    result.LocaleMsg = new($"工单号不能为空!");
                    return result;
                }
                query.page = await Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q=>q.WORK_ORDER.Equals(input.WorkOrder) && q.LABEL_ID.Equals(input.LabelId)).ToPageAsync(input.pageIndex, input.pageSize);
                query.Items = query.page.data;
                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(input.LabelId)).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)