using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.Entity.QT;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.Entity.Basic;
using QMAPP.MD.DAL;
using QMAPP.MD.Entity;
namespace QMAPP.FJC.TRACING.DataValidator
{
///
/// 校验PBOM组合
///
public class PbomValidater
{
public OperationServiceParam Validate(OperationServiceParam _para)
{
List daiList = _para.tranferDaiList;
PbomDAL bomItemDal = new PbomDAL();
//获取条码的采集点信息
daiList = daiList.Where(o => o.DATA_TYPE == "SN" && string.IsNullOrEmpty(o.PBOMITEM) == false).ToList();
StringBuilder sqlBomItem = new StringBuilder();
//当扫描第一个件时
if (daiList.Count == 1)
{
DAI dai = _para.tranferDaiList.First(o => o.DATA_TYPE == "SN");
dai.isOk = true;
return _para;
}
#region 通过零件号获取是否存在这样的BOM组合
StringBuilder sql = new StringBuilder();
//通过是否存在交集来判断
for (int i = 0; i < daiList.Count; i++)
{
sql.AppendFormat(" select pbom_code from T_MD_PBOM_ITEM where MATERIAL_CODE='{0}' ", daiList[i].MATERIAL_CODE);
if (i != daiList.Count - 1)
{
sql.AppendFormat(" intersect ");
}
}
List pblist = new List(); //bomItemDal.GetList(sql.ToString());
if (pblist.Count == 0)
{
DAI dai = _para.tranferDaiList.First(o => o.DATA_TYPE == "SN" && o.isOk == false);
dai.isOk = false;
return _para;
}
if (pblist.Count > 0)
{
foreach (var o in daiList)
{
//设置通过
o.isOk = true;
//如果只有一个BOM组合设置BOM
o.PBOM = (pblist.Count == 1) ? pblist[0].PBOM_CODE : "";
}
}
#endregion
return _para;
}
}
}