using com.hnshituo.core.webapp.vo;
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MeterConditionLibrary
{
    /// <summary>
    /// 厂内危化品限载
    /// </summary>
    public class validInnerExceedWgt
    {
        Log lg = Log.GetInstance();
        /// <summary>
        /// 验证物料是否是危化品
        /// </summary>
        /// <param name="scale">预报信息</param>
        public void validMatMethod(InnerMeterInfo scale, RESTfulResult<List<MeterBaseHisTareData>> rm)
        {
            //未锁定的情况下
            //if (!PbCache.isLockFrm)
            {
                PbCache.monitorResult.valid_exceed_wgt = true;
                //验证危化品
                if (PbCache.monitor.validExceedWgt == "1" && !PbCache.isNotValid)
                {
                    if (PbCache.limit != null && PbCache.limit.Count > 0)
                    {
                        List<MeterBaseLimitChemical> mblc = PbCache.limit.Where(s => s.matterNo == scale.matterNo).ToList();
                        //该物料是危化品
                        if (mblc.Count > 0)
                        {
                            //PbCache.monitorResult.valid_exceed_mat = true;

                            //获取车辆历史皮重
                            //查询车辆的历史皮重
                            if (rm.Succeed && rm.Data != null && rm.Data.Count > 0)
                            {
                                if (mblc[0].limitTypeNo == "001015001") //净重
                                {
                                    if (PbCache.lockWgt - (PbCache.tareCount.contrastTypeNo == "001012001" ? rm.Data[0].upWeight.Value : rm.Data[0].meterWeight.Value) - PbCache.addWgt > mblc[0].limitWeight) //当前重量-历史皮重-附加重量
                                    {
                                        PbCache.monitorResult.valid_exceed_mat = false;
                                        PbCache.monitorResult.valid_exceed_train = false;
                                        PbCache.monitorResult.valid_exceed_wgt = false;
                                        PbCache.ResultMessage = "车辆托运的货物重量超过危化品限载重量[" + mblc[0].limitWeight / 1000 + "T]";
                                    }
                                }
                                else if (mblc[0].limitTypeNo == "001015002") //毛重
                                {
                                    if (PbCache.lockWgt > mblc[0].limitWeight)
                                    {
                                        PbCache.monitorResult.valid_exceed_mat = false;
                                        PbCache.monitorResult.valid_exceed_train = false;
                                        PbCache.monitorResult.valid_exceed_wgt = false;
                                        PbCache.ResultMessage = "车辆重量超过危化品限载重量[" + mblc[0].limitWeight /1000 + "T]";
                                    }
                                }
                            }
                        }
                        else
                        {
                            PbCache.monitorResult.valid_exceed_mat = false;
                            PbCache.monitorResult.valid_exceed_train = false;
                            PbCache.monitorResult.valid_exceed_wgt = true;
                        }
                    }
                    else
                    {
                        PbCache.monitorResult.valid_exceed_mat = false;
                        PbCache.monitorResult.valid_exceed_train = false;
                        PbCache.monitorResult.valid_exceed_wgt = true;
                    }
                }
                else
                {
                    PbCache.monitorResult.valid_exceed_mat = false;
                    PbCache.monitorResult.valid_exceed_train = false;
                    PbCache.monitorResult.valid_exceed_wgt = true;
                }
            }
        }
    }
}
