PDAService.cs 2.59 KB
using ApkInfo;
using Hh.Mes.Common;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Redis;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.Service.Repository;
using Hh.Mes.Service.SystemAuth;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Hh.Mes.Service
{
    public class PDAService : RepositorySqlSugar<sys_user>
    {
        AuthContextFactory authContextFactory;
        public PDAService(AuthContextFactory authContextFactory)
        {
            this.authContextFactory = authContextFactory;
        }

        /// <summary>
        /// PDA物料追溯查询
        /// (扫码查询物料追溯码,查看物料的批次,物料名称,壁厚等物料信息)
        /// </summary>
        /// <param name="barCode"></param>
        /// <returns></returns>
        public dynamic GetMaterialInfoByBarCode(string barCode)
        {
            return ExceptionsHelp.Instance.ExecuteT<dynamic>(() =>
            {
                var response = new Response();
                //1:扫码 BarCode 查询bus_workOrder_detail 表确认BarCode是否存在。
                var bwdInfo = Context.Queryable<bus_workOrder_detail>().First(x => x.BarCode == barCode);
                if (bwdInfo == null || string.IsNullOrEmpty(bwdInfo.BarCode))
                {
                    response.Code = 500;
                    response.Message = $"BarCode:【{barCode}】不存在工序任务明细表中,请核对!";
                    return response;
                }
                if (string.IsNullOrEmpty(bwdInfo.materialCode))
                {
                    response.Code = 500;
                    response.Message = $"根据BarCode:【{barCode}】未查询到工序任务明细表中的物料编码信息,请核对!";
                    return response;
                }
                //2:根据BarCode 查询到当前行的 materialCode,在去物料表查询 返回物料表的基础信息。
                var materialInfo = Context.Queryable<base_material>().First(x => x.materialCode == bwdInfo.materialCode);
                if (materialInfo == null)
                {
                    response.Code = 500;
                    response.Message = $"未查询到{bwdInfo.materialCode}的物料基础信息,请检查!";
                    return response;
                }
                response.Code = 200;
                response.Result = materialInfo;
                return response;
            });
        }
    }
}