using DbCommon.BusinessCore.BaseCore;
using DbCommon.Enties.DbModels;
using DbCommon.Extenions;
using PmsSecondaryPackaging.Interface.Model.Carrier;
using PmsSecondaryPackaging.Interface.Model.StepBook;
using PmsSecondaryPackaging.Interface.Model.TaskBook;
using PmsSecondaryPackaging.TaskManager.TaskBookBehavior;
using ProjectManagementSystem.Common.Log;
using ProjectManagementSystem.Common.WebApi;
using ProjectManagementSystem.Model.DataCache;
using ProjectManagementSystem.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.TaskBookEvent
{
    public class TaskBookBehavior_63013 : BaseTaskBookBehavior
    {

        public TaskBookBehavior_63013() : base(63013)
        {
        }

        public override bool TaskBookOperator(TaskDetailInfoModel taskDetailInfo, List<StepDetailInfoModel> taskStepInfoList, CarrierInfoModel carrierInfo)
        {
            try
            {
                var stepInfo = TaskBookRegister.GetCurrentStepDetailInfo(taskDetailInfo, taskStepInfoList);

                string scaleName = Common.Config.ExcelConfig.Instance.GetLocationMemberCache(stepInfo.WareHouseID, "磅秤号");
                if(!CacheScaleWeightData.CacheInstance.ContainsKey(scaleName))
                {
                    return false;
                }

                var scaleWeightData = CacheScaleWeightData.CacheInstance[scaleName];
                if(!scaleWeightData.DataValid)
                {
                    return false;
                }

                bool result = true;
                scaleWeightData.Status = 1;

                TaskBookRegister.Log(taskDetailInfo, stepInfo, $"等待秤台称重完成，操作结果:{result}，秤台号：{scaleWeightData.scaleName}，净重：{scaleWeightData.netWeight}");
                return result;
            }
            catch (Exception ex)
            {
                TaskBookRegister.LogException(ex);
            }
            return false;
        }
    }
}
