using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZXDT.CallCenter.Model;
using ZXDT.CallCenter.MVCWeb.Models;

/// <summary>
///来电辅助类
/// </summary>
namespace ZXDT.CallCenter.MVCWeb.Controllers
{
    public class CallHelperController : BaseController
    {
        BLL.T_Call_CallRecords busCallRecords = new BLL.T_Call_CallRecords();
        //工单信息
        BLL.T_Wo_WorkOrderBase orderBLL = new BLL.T_Wo_WorkOrderBase();

        BLL.T_Cus_CustomerBase cusBLL = new BLL.T_Cus_CustomerBase();

        [ActionName("setline")]
        public string SetLine(int lineNum,string CallId)
        {          

            if (busCallRecords.SetLine(lineNum, CallId))
            {
                AddAction("T_Call_CallRecords", CallId, "修改IVR选择线路", "将线路修改为"+ lineNum);
                AddAction("T_Call_CallRecords", CallId, "修改IVR选择线路", "将线路修改为" + lineNum,"关键信息");
                return Success("成功");
            }
            else
                return Error("失败");
        }


        /// <summary>
        /// 来电弹屏页面
        /// </summary>
        /// <param name="workOrderNum">工单编号</param>
        /// <returns></returns>
        public string CallScreen(string workOrderNum)
        {

            //workOrderNum = "12";
            //实例化基础信息表
            CallScreenModel callScreenModel = new CallScreenModel();

            //获取业务工单信息
            if (!string.IsNullOrEmpty(workOrderNum))
            {
                callScreenModel.WorkOrderBaseModel = orderBLL.GetModel(int.Parse(workOrderNum.ToString()));
                if (callScreenModel.WorkOrderBaseModel == null)
                {
                    callScreenModel.WorkOrderBaseModel = new Model.T_Wo_WorkOrderBase()
                    {
                        CustomerBaseModel = new T_Cus_CustomerBase { F_CustomerId = 0 },
                        F_WORKORDERID = 0
                    };
                }
                //如果电话号码不为空
                if (callScreenModel.WorkOrderBaseModel != null && !string.IsNullOrEmpty(callScreenModel.WorkOrderBaseModel.F_CUSTOMERTELEPHONE))
                {
                    //获取客户基本信息
                    callScreenModel.WorkOrderBaseModel.CustomerBaseModel = cusBLL.GetCusInfoModel(callScreenModel.WorkOrderBaseModel.F_CUSTOMERTELEPHONE);
                }

                if (callScreenModel.WorkOrderBaseModel != null && !string.IsNullOrEmpty(callScreenModel.WorkOrderBaseModel.F_KSHADDRESSCODE))
                {
                    Model.T_Call_CallRecords callRecordModel = busCallRecords.GetModelByCallId(callScreenModel.WorkOrderBaseModel.F_KSHADDRESSCODE);

                    if (callRecordModel != null)
                    {
                        if (callRecordModel.BusinessType != null)
                        {
                            //业务选择按键
                            callScreenModel.SelectBussType = int.Parse(callRecordModel.BusinessType.ToString());
                        }
                        else
                        {
                            callScreenModel.SelectBussType = 1;
                        }

                    }
                }

            }
            callScreenModel.WorkOrderTypeModelList = GetWorkTypeModelList();//业务类型字典表
            //获取处理年龄段字典表                                                             
            callScreenModel.AgeModelList = GetCodeType("NLD");


            return Success("成功",callScreenModel);
        }



    }
}
