/******************************************************************************
 * 文件名称: IrisInterfaceService.cs
 * 文件说明: IRIS接口服务的封装
 * 当前版本: V1.0
 * 创建日期: 2022-04-14
 *
 * 2020-04-12: 增加 getDirectoryMaxVersionNO 方法

 ******************************************************************************/
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectoryDownload.Helper;


namespace DirectoryDownload.Business
{
    class IrisInterfaceService
    {
        /// <summary>
        /// 根据HisType获取当前目录最大版本号
        /// </summary>
        /// <param name="directoryType"></param>
        /// <returns></returns>
        public JObject getDirectoryMaxVersionNO(int directoryType)
        {
            try
            {
                dynamic joParam = new JObject();
                joParam.HospitalDr = GlobalVariables.hospitalDr;
                joParam.InterfaceDr = GlobalVariables.interfaceDr_Download;
                joParam.HisType = directoryType + 1;
                JObject joInparam = JsonHelper.getIrisServiceInparamBaseJson("09010037", joParam);

                IrisServices iris = new IrisServices();
                string sRtn = iris.Invoke(joInparam.ToString());
                JObject joRtn = new JObject();
                joRtn = JObject.Parse(sRtn);

                return joRtn;
            }
            catch (Exception ex)
            {
                return JsonHelper.getIrisExceptionJson(-1,"获取版本号异常：" , ex.Message);
            }
        }

        /// <summary>
        /// 通过分页的方式查询医保目录
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="irisCode"></param>
        /// <param name="directoryType"></param>
        public JObject getDirectoryByPagination(int currentPage, int pageSize, string serviceCode, int directoryType, string directoryCode, string directoryName,int directoryDr)
        {
            try
            {
                InvokeHelper invoker = new InvokeHelper();
                dynamic joInput = new JObject();
                joInput.code = serviceCode;
                dynamic joTmp = new JObject();
                JArray jaParmas = new JArray();
                joTmp.HospitalDr = GlobalVariables.hospitalDr;
                joTmp.InterfaceDr = directoryDr;
                joTmp.Code = directoryCode;
                joTmp.Name = directoryName;
                jaParmas.Add(joTmp);
                joInput.Add("params", JArray.FromObject(jaParmas));
                JArray jaPagination = new JArray();
                joTmp = new JObject();
                joTmp.pageSize = pageSize;
                joTmp.currentPage = currentPage;
                joTmp.sortColumn = "";
                joTmp.sortOrder = "";
                joTmp.hisType = directoryType; 
                jaPagination.Add(joTmp);
                joInput.Add("pagination", JArray.FromObject(jaPagination));

                return invoker.invokeInsuService(joInput.ToString(), "getDirectoryByPagination");
            }
            catch (Exception ex)
            {
                return JsonHelper.getIrisExceptionJson(-1, "getDirectoryByPagination", ex.Message);
            }

        }


        public JObject getHospital()
        {
            dynamic joParam = new JObject();
            joParam.hospID = "";
            //joParam.logonHospID = GlobalVariables.hospitalDr;
            joParam.logonHospID = "";
            //JObject joInparam = JsonHelper.getIrisServiceInparamBaseJson("09010039", joParam);
            JObject joInparam = JsonHelper.getIrisServiceInparamBaseJson("05111001", joParam);
            InvokeHelper invoker = new InvokeHelper();
            return invoker.invokeHISService(joInparam.ToString(), "获取医院列表");
        }

        public JObject getInterface()
        {
            dynamic joParam = new JObject();
            joParam.HospitalDr = GlobalVariables.hospitalDr;
            joParam.InterfaceID = "";
            JObject joInparam = JsonHelper.getIrisServiceInparamBaseJson("09010003", joParam);
            InvokeHelper invoke = new InvokeHelper();
            return invoke.invokeInsuService(joInparam.ToString(), "获取接口信息");
        }

        public JObject getInterface(string interfaceID)
        {
            dynamic joParam = new JObject();
            joParam.HospitalDr = GlobalVariables.hospitalDr;
            joParam.InterfaceID = interfaceID;
            JObject joInparam = JsonHelper.getIrisServiceInparamBaseJson("09010003", joParam);
            InvokeHelper invoke = new InvokeHelper();
            JObject joRtn = invoke.invokeInsuService(joInparam.ToString(), "获取接口信息");
            JObject joInterfaceInfo = JObject.Parse(JsonHelper.getJsonValue(joRtn, "result.data[0]"));
            joInterfaceInfo.Add("operatorNO", "0");
            joInterfaceInfo.Add("operatorName", "管理员");


            return joInterfaceInfo;
        }

    }

    
}
