服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-05-29 d27b448ee5b4d0b63c7d2955a62155995328c83d
Tiger.Business/MES/Transaction/LoadingMaterial.cs
@@ -34,8 +34,8 @@
        public string UserCode { get; set; }
        public long UserId { get; set; }
        public string OrgCode { get; set; }
        public bool his_isComplete { get; set; }
        public bool isManual { get; set; }
        public string CurrSmtCode { get; set; }
        public string CurrSlotNo { get; set; }
        /// <summary>
        /// 步骤类型
        /// </summary>
@@ -63,6 +63,43 @@
            SN,
        }
        /// <summary>
        /// 完成状态
        /// </summary>
        public enum Statuss
        {
            /// <summary>
            /// 扫描机器编码完成
            /// </summary>
            [Description("机器编码完成")]
            SmtCodeOK,
            /// <summary>
            /// 扫描槽位完成
            /// </summary>
            [Description("槽位完成")]
            SlotNoOK,
            /// <summary>
            /// 扫描飞达完成
            /// </summary>
            [Description("Feeder完成")]
            FeederOK,
            /// <summary>
            /// 扫描料盘SN完成
            /// </summary>
            [Description("料盘码完成")]
            SnOK,
            /// <summary>
            /// 当前机器完成
            /// </summary>
            [Description("当前机器完成")]
            CurrCompleted,
            /// <summary>
            /// 全部完成
            /// </summary>
            [Description("全部完成")]
            Completed,
        }
        #endregion Propertys & Variables
        #region Functions
@@ -72,9 +109,9 @@
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<ProdReqOutput>> ScanItem(SmtLoadingInput input)
        public async Task<ApiAction<SmtLoadingReturn>> ScanItem(SmtLoadingInput input)
        {
            var action = new ApiAction<ProdReqOutput>();
            var action = new ApiAction<SmtLoadingReturn>();
            try
            {
                if (input.Code.IsNullOrEmpty())
@@ -84,20 +121,57 @@
                    return action;
                }
                //01根据上料步骤执行相应方法
                switch (EnumHelper.GetEnum<Step_Types>(input.Step))
                {
                    case Step_Types.SmtCode:
                        ExecuteSmtCode();
                        action = ExecuteSmtCode(input);
                        break;
                    case Step_Types.SlotNo:
                        ExecuteSlotNo();
                        action = ExecuteSlotNo(input);
                        break;
                    case Step_Types.Feeder:
                        ExecuteFeeder();
                        action = ExecuteFeeder(input);
                        break;
                    case Step_Types.SN:
                        ExecuteSN();
                        action = ExecuteSN(input);
                        break;
                }
                if (!action.IsSuccessed) { return action; }
                //02保存上料数据
                //03查看未上料列表
                Biz.SmtTool smtTool = new();
                var actionSmtTool = await smtTool.GetNotLoadingMaterial(input);
                if (actionSmtTool.IsSuccessed)
                {
                    //带入机器编码查询,如果没有未上料的项,说明当前机器所有槽位均已完成上料!
                    if (actionSmtTool.Data.Count == 0)
                    {
                        var _input = input.Clone();
                        _input.machineCode = "";
                        action.LocaleMsg = Biz.L($"当前机器所有槽位均已完成上料!");
                        var _actionSmtTool = await smtTool.GetNotLoadingMaterial(_input);
                        if (_actionSmtTool.IsSuccessed)
                        {
                            //不带入机器编码查询,如果没有未上料的项,说明当前线别所有机器均已完成上料!
                            if (_actionSmtTool.Data.Count == 0)
                            {
                                action.LocaleMsg = Biz.L($"当前线别所有机器均已完成上料");
                            }
                        }
                        else
                        {
                            action.IsSuccessed = false;
                            action.LocaleMsg = Biz.L($"获取未上料列表失败!");
                        }
                    }
                }
                else
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"获取未上料列表失败!");
                }
                //action.Data = new ProdReqOutput()
@@ -120,11 +194,31 @@
            return action;
        }
        private ApiAction ExecuteSmtCode() {
            var action = new ApiAction();
        /// <summary>
        /// 01扫描机器编码操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteSmtCode(SmtLoadingInput input) {
            var action = new ApiAction<SmtLoadingReturn>();
            SmtLoadingReturn loadingReturn = new();
            try
            {
                if (Biz.Db.Queryable<SMT_WO_TABLE>().Where(x => x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == input.Code).Any())
                {
                    CurrSmtCode = input.Code;
                    action.IsSuccessed = true;
                    action.LocaleMsg = Biz.L($"机器编码验证通过!");
                    loadingReturn.SmtCode = CurrSmtCode;
                    loadingReturn.Step = (int)Step_Types.SmtCode;
                    loadingReturn.Status = (int)Statuss.SmtCodeOK;
                }
                else
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"料站表中不存在此机器编码,请确认料站表是否正确上传!");
                }
                action.Data = loadingReturn;
            }
            catch (Exception ex)
            {
@@ -133,12 +227,34 @@
            return action;
        }
        private ApiAction ExecuteSlotNo()
        /// <summary>
        /// 02扫描槽位操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteSlotNo(SmtLoadingInput input)
        {
            var action = new ApiAction();
            var action = new ApiAction<SmtLoadingReturn>();
            SmtLoadingReturn loadingReturn = new();
            try
            {
                if (Biz.Db.Queryable<SMT_WO_TABLE>().Where(x => x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == CurrSmtCode && x.SLOT_NO == input.Code).Any())
                {
                    CurrSlotNo = input.Code;
                    action.IsSuccessed = true;
                    action.LocaleMsg = Biz.L($"槽位验证通过!");
                    loadingReturn.SmtCode = CurrSmtCode;
                    loadingReturn.SlotNo = CurrSlotNo;
                    loadingReturn.Step = (int)Step_Types.SlotNo;
                    loadingReturn.Status = (int)Statuss.SlotNoOK;
                    loadingReturn.LoadingCount = Biz.Db.Queryable<SMT_LOADING>().Where(x=> x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == CurrSmtCode && x.SLOT_NO == input.Code).Count();
                }
                else
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此槽位[{input.Code}]不存在或料站表未上传!");
                }
                action.Data = loadingReturn;
            }
            catch (Exception ex)
            {
@@ -147,12 +263,50 @@
            return action;
        }
        private ApiAction ExecuteFeeder()
        /// <summary>
        /// 03扫描飞达操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteFeeder(SmtLoadingInput input)
        {
            var action = new ApiAction();
            var action = new ApiAction<SmtLoadingReturn>();
            SmtLoadingReturn loadingReturn = new();
            try
            {
                var _feeder = Biz.Db.Queryable<SMT_FEEDER>().Where(x => x.FEEDER_CODE == input.Code).First();
                //检查飞达保养维护情况
                if (_feeder.FEEDER_TYPE.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此飞达[{input.Code}]未维护类型信息!");
                    return action;
                }
                if (_feeder.FEEDER_TYPE != input.feederType)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此Feeder[{input.Code}]类型不一致!要求的类型:[{_feeder.FEEDER_TYPE}];当前Feeder的类型:[{input.feederType}]");
                    return action;
                }
                if (_feeder.USED_COUNT >= _feeder.MAX_COUNT)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此Feeder[{input.Code}]已达最大使用次数,请保养后再使用!");
                    return action;
                }
                var _loading = Biz.Db.Queryable<SMT_LOADING>().Where(x => x.FEEDER_CODE == input.Code).First();
                if (_loading!=null)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此Feeder[{input.Code}]已被占用!线别:[{_loading.LINE_CODE}],工单:[{_loading.WORK_ORDER}],机器:[{_loading.SMT_CODE}],槽位:[{_loading.SLOT_NO}]");
                    return action;
                }
                action.LocaleMsg = Biz.L($"此Feeder验证通过!");
                loadingReturn.SmtCode = CurrSmtCode;
                loadingReturn.SlotNo = CurrSlotNo;
                loadingReturn.Step = (int)Step_Types.Feeder;
                loadingReturn.Status = (int)Statuss.FeederOK;
                loadingReturn.LoadingCount = Biz.Db.Queryable<SMT_LOADING>().Where(x => x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == CurrSmtCode && x.FEEDER_CODE == input.Code && x.SLOT_NO == CurrSlotNo).Count();
            }
            catch (Exception ex)
            {
@@ -161,9 +315,14 @@
            return action;
        }
        private ApiAction ExecuteSN()
        /// <summary>
        /// 04扫描物料条码操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteSN(SmtLoadingInput input)
        {
            var action = new ApiAction();
            var action = new ApiAction<SmtLoadingReturn>();
            try
            {