using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using PushService.Act.BLL;
using PushPlatform.Common.Model;
using PushService.Act.Model;
using PushPlatform.Common.Util;
using PushInfo.Act.Models.QueryResults;
using PushService.Act.Model.QueryResults;
using PushInfo.Act.BLL;
using PushInfo.Act.Models.Tables;
using PushPlatform.Common.Enumerate;
using DapperORM.Common.Models;
using PushService.Act.Model.Request;
using PushPlatform.Data.MvcModels;
using PushPlatform.Data.Bll;
using PushPlatform.Data.Criteria;

namespace PushPfWebServer
{
    /// <summary>
    /// PushPfService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class PushPfService : System.Web.Services.WebService
    {
        private PushLogBLL pLogBll = new PushLogBLL();
        private PushCfgBLL pCfgBll = new PushCfgBLL();

        [WebMethod]
        public string HelloWorld(ExecuteStatus eStatus, PushStyle pStyle, PushType pType)
        {
            return "Hello World";
        }

        #region 获取程序员配置的模板列表
        /// <summary>
        /// 获取程序员配置的模板列表
        /// </summary>
        /// <param name="likeName">模块描述模糊名</param>
        /// <returns>模板列表</returns>
        [WebMethod]
        public ResultEntity<ListModel<SysPushSimple>> QuerySysPushSelect(string likeName)
        {
            ResultEntity<ListModel<SysPushSimple>> response = new ResultEntity<ListModel<SysPushSimple>>();
            try
            {
                response.Result = 1;
                response.Data = pCfgBll.GetSysPushSelect(likeName);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取某个模板的详细信息
        /// <summary>
        /// 获取某个模板的详细信息
        /// </summary>
        /// <param name="Id">主键Id</param>
        /// <returns>某个模板配置详情</returns>
        [WebMethod]
        public ResultEntity<PushConfigResult> GetSysPushModel(string Id)
        {
            ResultEntity<PushConfigResult> response = new ResultEntity<PushConfigResult>();
            try
            {
                if (string.IsNullOrEmpty(Id))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                PushConfigBLL bll = new PushConfigBLL();
                PushConfigResult pushConfig = bll.GetPushTempletById(Id);
                if (pushConfig == null)
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "查询结果为空，请联系管理员。";
                    return response;
                }
                response.Result = 1;
                response.Data = pushConfig;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取下拉控件的数据
        [WebMethod]
        public ResultEntity<List<SelectItemDetail>> QuerySelectItem()
        {
            ResultEntity<List<SelectItemDetail>> response = new ResultEntity<List<SelectItemDetail>>();
            try
            {
                PushConfigBLL bll = new PushConfigBLL();
                List<PushInfo.Act.Models.QueryResults.SelectItemDetail> list = bll.GetCycleDetailList().ToList();
                list.Sort((x, y) => {
                    int intx = 0;
                    int inty = 0;
                    if (int.TryParse(x.Value, out intx) && int.TryParse(y.Value, out inty))
                        return intx - inty;
                    else
                        return 0;
                });
                response.Data = list;
                response.Result = 1;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取当前用户配置推送列表
        /// <summary>
        /// 获取当前用户配置推送列表
        /// </summary>
        /// <param name="projectId">子项目Id</param>
        /// <param name="execStatus">推送状态</param>
        /// <param name="likeName">推送描述模糊查询</param>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">每页大小</param>
        /// <returns>查询返回的推送列表</returns>
        [WebMethod]
        public ResultEntity<ListModel<ProjectCfgPush>> QueryProCfgPushList(string projectId, int? execStatus, string likeName, string likeBody, int? pageIndex, int? pageSize)
        {
            ResultEntity<ListModel<ProjectCfgPush>> response = new ResultEntity<ListModel<ProjectCfgPush>>();
            try
            {
                if (string.IsNullOrEmpty(projectId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                response.Result = 1;
                response.Data = pCfgBll.GetProCfgPushList(projectId, execStatus, likeName, likeBody, pageIndex, pageSize);
                if (response.Data.DataList != null && response.Data.DataList.Count > 0)
                {
                    response.Data.DataList = response.Data.DataList.OrderBy(o => o.Create_Time).ToList<ProjectCfgPush>();
                }
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取当前用户某个配置详细信息
        /// <summary>
        /// 获取当前用户某个配置详细信息
        /// </summary>
        /// <param name="Id">主键Id</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<PushConfigResult> GetProCfgPushMo(string Id)
        {
            ResultEntity<PushConfigResult> response = new ResultEntity<PushConfigResult>();
            try
            {
                if (string.IsNullOrEmpty(Id))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                PushConfigBLL bll = new PushConfigBLL();
                PushConfigResult pushConfig = bll.GetConfigById(Id);
                if (pushConfig == null)
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "查询结果为空，请联系管理员。";
                    return response;
                }
                response.Result = 1;
                response.Data = pushConfig;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 保存当前用户某个配置详细信息提交
        /// <summary>
        /// 保存当前用户某个配置详细信息提交
        /// </summary>
        /// <param name="pushConfig">数据体</param>
        /// <param name="isNew">是否新增</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> proCfgSaveConfig(PushConfigResult pushConfig)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            ResultModel result = new ResultModel();
            PushConfigBLL bll = new PushConfigBLL();
            bool isNew = false;
            Map_Project_Push mapProjectPush = null;
            if (!string.IsNullOrEmpty(pushConfig.Id))
            {
                mapProjectPush = bll.GetMapProjectPushById(pushConfig.Id);
            }
            if(mapProjectPush == null)
            {
                isNew = true;
                mapProjectPush = new Map_Project_Push();
            }
            try
            {
                if (pushConfig == null)
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                ObjectHelper.CopyProperties(pushConfig, mapProjectPush);
                if (isNew)
                {
                    mapProjectPush.Id = Guid.NewGuid().ToString();
                    mapProjectPush.Exec_Status = (int)ExecuteStatus.新建未安排触发器;
                    mapProjectPush.Create_Time = DateTime.Now;
                    result = bll.SaveMapProjectPush(mapProjectPush);
                }
                else
                {
                    mapProjectPush.Update_Time = DateTime.Now;
                    mapProjectPush.Exec_Status = (int)ExecuteStatus.修改后未安排触发器;
                    result = bll.UpdateMapProjectPush(mapProjectPush);
                }
                response.Result = result.Result;
                response.Msg = result.Msg;
                response.Data = mapProjectPush.Id;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 修改当前用户某个推送配置状态
        /// <summary>
        /// 修改当前用户某个推送配置状态
        /// </summary>
        /// <param name="pushCfjId">推送配置表的主Id</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> UpPushCfgState(string pushCfjId,int state)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            ResultModel result = new ResultModel();
            PushConfigBLL bll = new PushConfigBLL();
            try
            {
                if (!string.IsNullOrEmpty(pushCfjId))
                {
                    result = bll.UpdateMapProPushState(pushCfjId, state);
                }
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 删除当前用户某个推送配置
        /// <summary>
        /// 删除当前用户某个推送配置
        /// </summary>
        /// <param name="pushCfjId">推送配置表的主Id</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> deletePushCfg(string pushCfjId)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            ResultModel result = new ResultModel();
            PushConfigBLL bll = new PushConfigBLL();
            try
            {
                if (!string.IsNullOrEmpty(pushCfjId))
                {
                    result = bll.DeleteMapProjectPushById(pushCfjId);
                }
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取推送的日志没有项目参数
        [WebMethod]
        /// <summary>
        /// 获取推送的日志
        /// </summary>
        /// <param name="userId">推送对象的Id</param>
        /// <param name="pushStyle">推送类型APP = 1,短信 = 2,微信 = 3,socket = 4,站内推送 = 5</param>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns></returns>
        public ResultEntity<ListModel<PushMsg>> QueryPushMsgList(string userId, List<int> pushStyle, int? haveRead, int pageIndex = 1, int pageSize = 10)
        {
            ResultEntity<ListModel<PushMsg>> response = new ResultEntity<ListModel<PushMsg>>();
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                if (pushStyle != null && pushStyle.Count() > 10)
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "pushStyle参数传输异常！";
                    return response;
                }
                response.Result = 1;
                response.Data = pLogBll.GetPushMsgList(userId, pushStyle, pageIndex, pageSize, haveRead,"","",null);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取推送的日志有项目
        [WebMethod]
        /// <summary>
        /// 获取推送的日志
        /// </summary>
        /// <param name="userId">推送对象的Id</param>
        /// <param name="pushStyle">推送类型APP = 1,短信 = 2,微信 = 3,socket = 4,站内推送 = 5</param>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns></returns>
        public ResultEntity<ListModel<PushMsg>> QueryPushLogList(string title, string projectId,string userId, List<int> pushStyle, int? haveRead, int pageIndex = 1, int pageSize = 10)
        {
            ResultEntity<ListModel<PushMsg>> response = new ResultEntity<ListModel<PushMsg>>();
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                if (pushStyle != null && pushStyle.Count() > 10)
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "pushStyle参数传输异常！";
                    return response;
                }
                response.Result = 1;
                response.Data = pLogBll.GetPushMsgList(userId, pushStyle, pageIndex, pageSize, haveRead,title,projectId,null);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }

        [WebMethod]
        /// <summary>
        /// 获取推送的日志,加时间过滤
        /// </summary>
        /// <param name="title"></param>
        /// <param name="projectId"></param>
        /// <param name="userId"></param>
        /// <param name="pushStyle"></param>
        /// <param name="haveRead"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="createDate"></param>
        /// <returns></returns>
        public ResultEntity<ListModel<PushMsg>> QueryPushLogListDat(string title, string projectId, string userId, List<int> pushStyle, int? haveRead, int pageIndex = 1, int pageSize = 10, DateTime? createDate=null)
        {
            ResultEntity<ListModel<PushMsg>> response = new ResultEntity<ListModel<PushMsg>>();
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                if (pushStyle != null && pushStyle.Count() > 10)
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "pushStyle参数传输异常！";
                    return response;
                }
                response.Result = 1;
                response.Data = pLogBll.GetPushMsgList(userId, pushStyle, pageIndex, pageSize, haveRead, title, projectId, createDate);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 获取未读取信息数量
        [WebMethod]
        /// <summary>
        /// 获取未读取信息数量
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="projectId">项目Id</param>
        /// <param name="pushStyle">推送类型</param>
        /// <returns></returns>
        public ResultEntity<int> GetNotReadCount(string userId,string projectId, List<int> pushStyle)
        {
            ResultEntity<int> response = new ResultEntity<int>();
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    response.Data = 0;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                if (pushStyle != null && pushStyle.Count() > 10)
                {
                    response.Data = 0;
                    response.Result = 0;
                    response.Msg = "pushStyle参数传输异常！";
                    return response;
                }
                return pLogBll.GetNotReadCount(userId, projectId, pushStyle,null);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }

        [WebMethod]
        /// <summary>
        /// 获取未读取信息数量
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="projectId">项目Id</param>
        /// <param name="pushStyle">推送类型</param>
        /// <returns></returns>
        public ResultEntity<int> GetNotReadCountDate(string userId, string projectId, List<int> pushStyle, DateTime? createTime)
        {
            ResultEntity<int> response = new ResultEntity<int>();
            try
            {
                if (string.IsNullOrEmpty(userId))
                {
                    response.Data = 0;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                if (pushStyle != null && pushStyle.Count() > 10)
                {
                    response.Data = 0;
                    response.Result = 0;
                    response.Msg = "pushStyle参数传输异常！";
                    return response;
                }
                return pLogBll.GetNotReadCount(userId, projectId, pushStyle, createTime);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 根据Id获取推送日志
        [WebMethod]
        /// <summary>
        /// 根据Id获取推送日志
        /// </summary>
        /// <param name=")">消息日志Id</param>
        /// <returns></returns>
        public ResultEntity<PushMsg> GetMsgById(string id)
        {
            ResultEntity<PushMsg> response = new ResultEntity<PushMsg>();
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                return pLogBll.GetMsgById(id);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 修改推送的日志为已读
        [WebMethod]
        /// <summary>
        /// 修改推送的日志为已读
        /// </summary>
        /// <param name="pushMsgId">推送表的主键Id</param>
        /// <returns></returns>
        public ResultEntity<string> UpPushMsgRead(string pushMsgId)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                if (string.IsNullOrEmpty(pushMsgId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                response = pLogBll.UpPushMsgRead(pushMsgId);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }

        [WebMethod]
        /// <summary>
        /// 设置全部已读
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ResultEntity<string> UpPushAllMsgRead(string projectId, string userId)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                response = pLogBll.UpPushAllMsgRead(projectId, userId);
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 系统主动调用发送任务,数据来源配置表查询
        /// <summary>
        /// 系统主动调用发送任务,数据来源配置表查询
        /// </summary>
        /// <param name="proCfgId">配置推送表的Id</param>
        /// <param name="userId">推送用户Id</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> SendPushOfProCfg(string proCfgId, string userId)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                if (string.IsNullOrEmpty(proCfgId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                var result = OutProcessTaskBLL.SendPushOfProCfg(proCfgId, userId);
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 系统主动调用发送任务,数据来源配置表查询,参数外部传
        /// <summary>
        /// 系统主动调用发送任务,数据来源配置表查询
        /// </summary>
        /// <param name="proCfgId">配置推送表的Id</param>
        /// <param name="userId">推送用户Id</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> SendPushOfPCValmap(string proCfgId,string userId, string valMapStr)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                if (string.IsNullOrEmpty(proCfgId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                Dictionary<string, string> valMap = null;
                if(!string.IsNullOrEmpty(valMapStr))
                {
                    valMap = JsonUtil.ConvertToObject<Dictionary<string, string>>(valMapStr);
                }
                var result = OutProcessTaskBLL.SendPushOfProCfg(proCfgId, userId, valMap);
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 系统主动调用发送任务,根据通用配置，还有项目Id锁定推送任务配置
        /// <summary>
        /// 系统主动调用发送任务,数据来源配置表查询
        /// </summary>
        /// <param name="proCfgId">配置推送表的Id</param>
        /// <param name="userId">推送用户Id</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> SendPushOfProject(string sysPushId, string projectId, string valMapStr)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            LogHelper.Info("系统主动调用发送任务，sysPushId：" + sysPushId + "；projectId：" + projectId + "；valMapStr：" + valMapStr);
            try
            {
                if (string.IsNullOrEmpty(sysPushId) || string.IsNullOrEmpty(projectId))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                Dictionary<string, string> valMap = null;
                if (!string.IsNullOrEmpty(valMapStr))
                {
                    valMap = JsonUtil.ConvertToObject<Dictionary<string, string>>(valMapStr);
                }
                var result = OutProcessTaskBLL.SendPushOfProSyspush(sysPushId, projectId, valMap);
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 系统主动调用发送任务,数据来源外部
        /// <summary>
        /// 系统主动调用发送任务,数据来源外部
        /// </summary>
        /// <param name="valModel">ProCfg_Id必须传输</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> SendPushOfExternal(PushValueModel valModel)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                if (string.IsNullOrEmpty(valModel.Push_Style) || (string.IsNullOrEmpty(valModel.Push_Body) && string.IsNullOrEmpty(valModel.Wx_MsmTemp)) || string.IsNullOrEmpty(valModel.ProCfg_Id) || string.IsNullOrEmpty(valModel.User_Id))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                var result = OutProcessTaskBLL.SendPushOfExternal(valModel);
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 系统主动调用发送短信,数据来源外部
        /// <summary>
        ///  系统主动调用发送短信,数据来源外部
        /// </summary>
        /// <param name="proPushCfgId">发送配置Id</param>
        /// <param name="mobile">手机号</param>
        /// <param name="sendContext">短信内容</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> SendMessage(string proPushCfgId,string mobile, string sendContext)
        {
            PushValueModel valModel = new PushValueModel();
            valModel.Push_Style = ((int)PushStyle.短信).ToString();
            valModel.ProCfg_Id = proPushCfgId;
            valModel.Push_Body = sendContext;
            valModel.User_Id = mobile;
            valModel.Mobile = mobile;

            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                if (string.IsNullOrEmpty(valModel.Push_Style) || (string.IsNullOrEmpty(valModel.Push_Body) && string.IsNullOrEmpty(valModel.Wx_MsmTemp)) || string.IsNullOrEmpty(valModel.ProCfg_Id) || string.IsNullOrEmpty(valModel.User_Id))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                var result = OutProcessTaskBLL.SendPushOfExternal(valModel);
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 保存修改标签
        /// <summary>
        /// 保存修改标签
        /// </summary>
        /// <param name="tagModel">标签数据体</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<string> SaveOrUpdateTag(TagModel tagModel)
        {
            ResultEntity<string> response = new ResultEntity<string>();
            try
            {
                if (tagModel == null || string.IsNullOrEmpty(tagModel.PushSys_ProId) || string.IsNullOrEmpty(tagModel.TagName))
                {
                    response.Data = null;
                    response.Result = 0;
                    response.Msg = "缺少必要参数";
                    return response;
                }
                ResultModel result = new ResultModel();
                BllPushTag bll = new BllPushTag();
                ushort is_deleted = 0;
                ushort.TryParse(tagModel.Is_Deleted.ToString(), out is_deleted);
                if (string.IsNullOrEmpty(tagModel.Id))
                {
                    PushPlatform.Data.PushTag model = new PushPlatform.Data.PushTag
                    {
                        Id = Guid.NewGuid().ToString(),
                        PushSys_ProId = tagModel.PushSys_ProId,
                        TagName = tagModel.TagName,
                        TagDesc = tagModel.TagDesc,
                        Is_Deleted = is_deleted,
                        Create_User = "admin",
                        Create_Time = DateTime.Now
                    };
                    result.Result = bll.Save(model);
                    response.Data = model.Id;
                }
                else
                {
                    PushPlatform.Data.PushTag model = new BllPushTag().Get(tagModel.Id);

                    if (model == null || string.IsNullOrEmpty(model.Id))
                    {
                        response.Data = null;
                        response.Result = 0;
                        response.Msg = "标签数据错误，请检查";
                        return response;
                    }

                    model.PushSys_ProId = tagModel.PushSys_ProId;
                    model.TagName = tagModel.TagName;
                    model.TagDesc = tagModel.TagDesc;
                    model.Is_Deleted = is_deleted;
                    model.Update_User = "admin";
                    model.Update_Time = DateTime.Now;

                    result.Result = bll.Update(model);
                    response.Data = model.Id;
                }
                response.Result = result.Result;
                response.Msg = result.Msg;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion

        #region 查询标签
        /// <summary>
        /// 查询标签
        /// </summary>
        /// <param name="projectId">项目ID</param>
        /// <returns></returns>
        [WebMethod]
        public ResultEntity<List<PushPlatform.Data.PushTag>> TagList(string projectId)
        {
            ResultEntity<List<PushPlatform.Data.PushTag>> response = new ResultEntity<List<PushPlatform.Data.PushTag>>();
            try
            {
                CriteriaPushTag criTag = new CriteriaPushTag { EqPushsysProid = projectId, EqIsDeleted = 0 };
                criTag.UsePage = false;
                criTag.AddOrder(CriteriaPushTag.MapCreateTime, true);
                response.Data = new BllPushTag().Fetch(criTag);
                response.Result = 1;
            }
            catch (Exception ex)
            {
                response.Result = 0;
                response.Msg = "服务器异常，请联系负责人。";
                LogHelper.Error(ex);
            }
            return response;
        }
        #endregion
    }
}
