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

namespace MeterSceneLibrary
{
    public class compare
    {

        private rtInfo rt = new rtInfo();

        MeterWorkCompareSpotScaleService meterWorkCompareSpotScaleService = new MeterWorkCompareSpotScaleService();

        MeterWorkCompareSpotService meterWorkCompareSpotService = new MeterWorkCompareSpotService();

        private JISCO.SaveMethod saveMethod = new JISCO.SaveMethod();

        public rtInfo MeterMethod(PreTrackScale scale)
        {
            RESTfulResult<List<MeterWorkCompareSpotSacle>> reSacle = meterWorkCompareSpotScaleService.doQuery(new MeterWorkCompareSpotSacle { carNo = PbCache.lockCarNo,valueFlag = "1" });

            if (reSacle.Succeed)
            {
                if (reSacle.Data == null || reSacle.Data.Count == 0)
                {
                    rt = saveMethod.doError("未查询到较称预约");
                    rt.resultInfo = "未查询到较称预约";
                    PbCache.LEDResultMessage = "未查询到较称预约";
                    PbCache.voiceType = 25;
                    PbCache.monitorResultMessage = "车号"+PbCache.lockCarNo+ "未查询到较称预约";
                }
                else
                {
                    Hashtable hashtable = new Hashtable();
                    hashtable.Add("carNo", PbCache.lockCarNo);
                    hashtable.Add("weight", int.Parse(PbCache.lockWgt.ToString()));
                    hashtable.Add("spotName", PbCache.sportInfo.baseSpotName);
                    hashtable.Add("spotNo", PbCache.sportInfo.baseSpotNo);
                    hashtable.Add("scaleNo", reSacle.Data[0].CompareSpotScaleId);
                    hashtable.Add("name", "admin");
                    hashtable.Add("compareType", "2");
                    rt = saveMethod.doCompare(hashtable);
                    PbCache.voiceType = 16;
                    PbCache.LEDResultMessage = string.Format("车号{0}，较秤完成，重量{1}吨", PbCache.lockWgt, Math.Round((PbCache.lockWgt / 1000), 2));
                }
            }
            // 后台失败处理
            if (!rt.result)
            {
                rt.resultInfo = "称重数据保存失败";
                PbCache.voiceType = 25;
                PbCache.LEDResultMessage = "计量失败，请联系计量大厅";
                PbCache.monitorResultMessage = "";
            }
             return rt;
        }
    }
}
