using System;
using System.Linq;
using System.Collections.Generic;
using PushPlatform.Data;
using PushPlatform.Data.MvcModels.QueryResults;
using System.Data;
using MySql.Data.MySqlClient;
using System.Text;
using Dapper;

namespace PushPlatform.Data.DaoAchieve
{
    public partial class WechatMsgmodelDaoAchieve
    {

        #region Dao

        #region 获取用户的项目列表
        public List<WechatTemModel> GetWechatTem(string proId)
        {
            if(string.IsNullOrEmpty(proId))
            {
                return new List<WechatTemModel>();
            }
            using (IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select t1.Id,t1.Config_Info,GROUP_CONCAT('{','\"Id\":\"',t2.Id,'\",','\"Title\":\"',t2.Title,'\",','\"Create_Time\":\"',t2.Create_Time,'\"','}' order by t2.Create_Time ASC) as temModelStr");
                sb.Append(@" from sys_send_cfg t1
                                           left JOIN wechat_msgmodel t2
                                             on t1.Id = t2.Send_Cfg_Id  and t2.ProjectId = @ProjectId  
                                     where t1.ProjectId = @ProjectId and t1.Type = 4 GROUP BY t1.Id");
                var query = connection.Query<WechatTemModel>(sb.ToString(), new { ProjectId = proId });
                return query.ToList();
            }
        }
        #endregion


        #endregion
    }
}