public FirstCheckSnOrder getOrderBySN(CV_QM_FIRSTCHECK_SN_QueryParam param)
        {
            FirstCheckSnOrder resp = api_QM_BO.getInspectionOrderStep(param);

            if (string.IsNullOrEmpty(resp.message))
            {
                resp.minSampleSize = getMinSampleSize(resp.snOrder.Quantity.Value);
                if (resp.minSampleSize == -1)
                {
                    resp.message = "序列号[" + param.LotID + "]对应的工单[" + resp.snOrder.OrderID + "]数量为" + resp.snOrder.Quantity.Value + ",未配置首检样本数";
                }
                else if (resp.minSampleSize == 0)
                {
                    resp.message = "序列号[" + param.LotID + "]对应的工单[" + resp.snOrder.OrderID + "]数量为" + resp.snOrder.Quantity.Value + ",首检样本数为0,不需要首检";
                }
            }
            return(resp);
        }
        //增加中表/底表数据
        public QM_PROCESS_Util_Response addInspectionMBDatas(QM_PROCESS_Util_Param param)
        {
            QM_PROCESS_Util_Response       response = new QM_PROCESS_Util_Response();
            CV_QM_FIRSTCHECK_SN_QueryParam sn_param = new CV_QM_FIRSTCHECK_SN_QueryParam()
            {
                CurrentOrderID = param.WorkOrderID,
                IsNamePlate    = param.IsNamePlate,
                LotID          = param.sn,
                CurrentStep    = param.Step //当前Step
            };
            FirstCheckSnOrder snOrderInfo = api_QM_BO.getInspectionOrderStep(sn_param);

            if (string.IsNullOrEmpty(snOrderInfo.message))
            {
                CV_QM_FIRSTCHECK_SN info = snOrderInfo.snOrder;
                info.Step = param.inspectSource == "4" ? null : info.Step;//成品抽检只是在包装工段
                IList <CV_QM_PROCESSITEM> processItemList = cv_qm_processitem.GetEntitiesByOrderID(info.OrderID, param.inspectSource, info.Step);
                if (processItemList.Count() == 0)
                {
                    response.message = "NG,无检验项信息";
                }
                else
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        if (param.isFirst)
                        {
                            log.Info("第一个SN,需要更新主表的MES工单和SAP订单");
                            //操作主表,更新MES工单和SAP订单,物料,产线
                            QM_PROCESS_TOP topUpdate = new QM_PROCESS_TOP()
                            {
                                KID              = param.KID,         //主键
                                WorkOrderID      = info.OrderID,      //MES工单
                                SapOrderID       = info.SalesOrderID, //SAP订单
                                MaterielID       = info.DefID,        //物料
                                MaterielVer      = info.DefVer,       //物料版本
                                MaterielDescript = info.DefDescript,  //物料描述
                                Step             = info.Step,
                                PlantID          = info.PlanPlant,    //工厂ID
                                Plant            = info.PlantName,    //工厂
                                Workshop         = info.DepartID,     //车间
                                LineID           = info.LineID,       //产线ID
                                ProdLine         = info.LineName      //产线
                            };
                            process_topbo.UpdateSome(topUpdate);
                            //查询当前主表
                            response.top = process_topbo.GetEntity(param.KID.Value);
                        }
                        insertInspectionMiddle(param);//新增SN
                        //获得中表主键  (主表KID,SN码)
                        IList <QM_PROCESS_MIDDLE> middleQList = process_middlebo.GetByKIDSN(param.KID.Value, param.sn);
                        //插入底表数据
                        foreach (CV_QM_PROCESSITEM cv_temp_inspection in processItemList)
                        {
                            //填充子表数据
                            QM_PROCESS_BOTTOM bottom = new QM_PROCESS_BOTTOM()
                            {
                                KLID       = middleQList[0].KLID,//中表主键
                                Sequence   = param.Sequence,
                                SN         = param.sn,
                                MaterielID = param.isFirst ? info.DefID : param.MaterielID,
                                ItemIndex  = cv_temp_inspection.InforDetailID,
                                Item       = cv_temp_inspection.InspectItemDes,
                                ItemStatus = "待检"
                            };
                            if (!String.IsNullOrEmpty(cv_temp_inspection.InspectItemProperty) && cv_temp_inspection.InspectItemProperty == "1")
                            {
                                bottom.ItemProperty = "定性";
                            }
                            else
                            {
                                bottom.ItemProperty = "定量";
                            }
                            if (!String.IsNullOrEmpty(cv_temp_inspection.UpperLimit))
                            {
                                bottom.Target     = Convert.ToInt32(cv_temp_inspection.TargetValue);
                                bottom.UpperBound = Convert.ToInt32(cv_temp_inspection.UpperLimit);
                                bottom.LowerBound = Convert.ToInt32(cv_temp_inspection.LowerLimit);
                            }
                            process_bottombo.Insert(bottom);
                        }
                        //重新获得中表的数据
                        response.middleList = process_middlebo.GetByKid(param.KID.Value);
                        ts.Complete();
                    }
                }
            }
            else
            {
                response.message = snOrderInfo.message;
            }

            return(response);
        }