服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-09-27 053f992298073d2b0dcbeca564451fa6d1b36ea0
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,13 @@
            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 +243,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 +257,114 @@
            }
            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;
                }
                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(() =>
                {
                    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 (varWoList.Count > 0)
                    {
                        db.Updateable(varWoList).UpdateColumns(q => q.LABEL_VIEW_PATH).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<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;
        }
    }
}