/******************************************************************************
 * 文件名称: CenterBusiness.cs
 * 文件说明: 中心业务的封装
 * 当前版本: V1.0
 * 创建日期: 2022-04-14
 * 2020-04-14: 增加 DownDirecotry 方法


******************************************************************************/
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 CenterBusiness
    {
        /// <summary>
        /// 下载业务（1301-1309），返回会的JSON串中包含解压后的TXT地址
        /// </summary>
        /// <param name="funNO"></param>
        /// <param name="ver"></param>
        /// <param name="outPath"></param>
        /// <returns></returns>
        public JObject DownDirecotry(string funNO, string ver)
        {
            try
            {             
                dynamic joTmp = new JObject();
                joTmp.ver = ver;
                dynamic joParam = new JObject();
                joParam.hospitalDr = GlobalVariables.hospitalDr;
                joParam.hospitalName = GlobalVariables.hospitalName;
                joParam.InterfaceDr = GlobalVariables.interfaceDr_Download;
                joParam.InterfaceID = GlobalVariables.InterfaceID;
                joParam.businessType = "DirectoryDownload";
                joParam.funNO = funNO;
                joParam.operatorNO = GlobalVariables.operatorNO;
                joParam.operatorName = GlobalVariables.operatorName;
                joParam.data = joTmp;
                IrisInterfaceService iris = new IrisInterfaceService();
                JObject joInterface = iris.getInterface(GlobalVariables.interfaceDr.ToString());
                JArray jaParams = new JArray();
                jaParams.Add(joParam);
                dynamic joInParam = new JObject();
                joInParam.businessType = "DirectoryDownload";
                joInParam.hospitalDr = GlobalVariables.hospitalDr;
                joInParam.InterfaceDr = GlobalVariables.interfaceDr;
                joInParam.interfaceinfo = joInterface;
                joInParam.code = "";
                joInParam.Add("params", JArray.FromObject(jaParams));
                joInParam.Add("session", JArray.Parse(@"[{""userID"":""555"",""userCode"":""200006"",""userName"":""巢丽丽"",""locID"":""292"",""locDesc"":""住院收费处"",""groupID"":""315"",""groupDesc"":""住院收费"",""hospID"":""63"",""hospCode"":""H20"",""hospDesc"":""合肥瑶海普瑞眼科医院"",""langID"":""1"",""langDesc"":""简体中文"",""changeFlag"":""N"",""changeDesc"":"""",""lastLoginDate"":""2022-04-25"",""lastLoginTime"":""16:37:46"",""directorAuth"":""N"",""defaultMenuType"":""1"",""titleDesc"":"""",""path"":"""",""sessionID"":""vXxOkIXkUh"",""language"":""CN"",""messageTime"":1}]"));
                string outParam = string.Empty;
                string errorMessage = string.Empty;
                InvokeHelper invokeHelper = new InvokeHelper();
                return invokeHelper.businessDLLInvoke("Download", joInParam.ToString());
                //return invokeHelper.invokeShellDll("Download", joInParam.ToString());
            }
            catch (Exception ex)
            {
                return JsonHelper.getIrisExceptionJson(-1, "DownDirecotry:" , ex.Message);
            }
        }


        /// <summary>
        /// 下载业务（1301-1309），返回会的JSON串中包含解压后的TXT地址
        /// </summary>
        /// <param name="funNO"></param>
        /// <param name="ver"></param>
        /// <param name="outPath"></param>
        /// <returns></returns>
        public JObject DownDictionay(JObject joData)
        {
            string outparam = "";
            try
            {
                dynamic joParam = new JObject();
                joParam.hospitalDr = GlobalVariables.hospitalDr;
                joParam.hospitalName = GlobalVariables.hospitalName;
                joParam.InterfaceDr = GlobalVariables.interfaceDr_Download;
                GlobalVariables.writeLog("GlobalVariables.interfaceDr_Download:" + GlobalVariables.interfaceDr_Download.ToString());
                joParam.InterfaceID = GlobalVariables.InterfaceID;
                joParam.businessType = "DictionayDownload";

                joParam.operatorNO = GlobalVariables.operatorNO;
                joParam.operatorName = GlobalVariables.operatorName;
                joParam.data = joData;
                JArray jaParams = new JArray();
                jaParams.Add(joParam);
                dynamic joInParam = new JObject();
                joParam.funNO = "1901";
                joInParam.code = "";
                //获取接口信息
                IrisInterfaceService iris = new IrisInterfaceService();
                JObject joInterface = iris.getInterface(GlobalVariables.interfaceDr.ToString());
                GlobalVariables.writeLog("joInterface:" + joInterface);
                //设置SESSION
                JArray jaSession = JArray.Parse(@"[{""userID"":""555"",""userCode"":""200006"",""userName"":""巢丽丽"",""locID"":""291"",""locDesc"":""门诊收费处"",""groupID"":""308"",""groupDesc"":""门诊收费"",""hospID"":""63"",""hospCode"":""H20"",""hospDesc"":""合肥瑶海普瑞眼科医院"",""langID"":""1"",""langDesc"":""简体中文"",""changeFlag"":""N"",""changeDesc"":"""",""lastLoginDate"":""2022-05-12"",""lastLoginTime"":""08:52:48"",""directorAuth"":""N"",""defaultMenuType"":""1"",""titleDesc"":"""",""path"":""/05100010"",""sessionID"":""rnXwMYrnoi"",""language"":""CN"",""messageTime"":1}]");
                joInParam.Add("params", JArray.FromObject(jaParams));
                joInParam.Add("interfaceinfo", joInterface);
                joInParam.Add("session", jaSession);
                joInParam.Add("businessType", "DictionayDownload");
                joInParam.Add("hospID", GlobalVariables.hospitalDr);
                GlobalVariables.writeLog("jaSession:" + jaSession);
                InvokeHelper invokeHelper = new InvokeHelper();
                JObject joRtn = invokeHelper.businessDLLInvoke("Download", joInParam.ToString());
                outparam = joRtn.ToString();
                return joRtn;
            }
            catch (Exception ex)
            {
                JObject joRtn = JsonHelper.getIrisExceptionJson(-1, "DownDictionay:", ex.Message);
                outparam = joRtn.ToString();
                return joRtn;
            }
            finally
            {
                GlobalVariables.writeLog("DownDictionay1" , joData.ToString(), outparam);
            }
        }
    }
}
