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.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.TaskBookEvent
{
    public class TaskBookBehavior_63012 : BaseTaskBookBehavior
    {
        public TaskBookBehavior_63012() : base(63012)
        {
        }

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

                string host = Common.Config.ExcelConfig.Instance.GetLocationMemberCache(stepInfo.WareHouseID, "磅秤接口地址");
                string url = $@"http://{host}/AVS/ScaleOn";
                bool result = ScaleApi.Post(url, null, new { VEHICLENO = carrierInfo.AgvID.ToString() }, out ScaleState scaleState, out string msg);

                TaskBookRegister.Log(taskDetailInfo, stepInfo, $"通知秤台称重，操作结果:{result}，秤台号：{scaleState?.SCALE_NAME}，消息：{msg}");
                return result;
            }
            catch (Exception ex)
            {
                TaskBookRegister.LogException(ex);
            }
            return false;
        }
    }
}
