using PoJun.Dapper;
using ASHermed.SinoInterface.Api.IRepository.Test;
using ASHermed.SinoInterface.Entity.Test;
using ASHermed.SinoInterface.Repository.MySql;
using ASHermed.SinoInterface.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository;

namespace ASHermed.SinoInterface.Api.MySqlRepository
{

    public class OutArticleCollectRepository : BaseRepositoryToASHermed_SinoInterface<Out_Article_Collect>, IOutArticleCollectRepository
    {
        
        public List<ArticleCollect> GetUserCollerct(int userId, string keyWords)
        {
            StringBuilder str = new StringBuilder();
            var parms = new Dictionary<string, object>();
            
            str.Append(@"select a.ID,a.TITLE,a.COVER_IMG,a.CREATE_TIME 
                            from out_article_collect c INNER JOIN out_article a ON c.ARTICLE_ID = a.id
                            where c.CREATE_USER = @userId and a.`STATUS` = 1 and c.`STATUS` =1 and c.IS_COLLECTED = TRUE");
            if (!string.IsNullOrEmpty(keyWords))
            {
                str.Append(@" and a.TITLE LIKE '%@Title%'");
                parms.Add("@Title", keyWords);
            }
            parms.Add("@userId", userId);
            var result = Query<ArticleCollect>(str.ToString(), parms);
            return result.ToList();
        }

        public int CancelUserCollerct(int userId, int artId)
        {
            var parms = new Dictionary<string, object>();
            StringBuilder str = new StringBuilder();
            str.Append(@"update out_article_collect set
                            IS_COLLECTED=@IS_COLLECTED,
                            UPDATE_USER=@UPDATE_USER,
                            UPDATE_TIME=@UPDATE_TIME
                         where ARTICLE_ID=@ARTICLE_ID and CREATE_USER=@CREATE_USER
                            ");

            parms.Add("@IS_COLLECTED", false);
            parms.Add("@UPDATE_USER", userId);
            parms.Add("@UPDATE_TIME", DateTime.Now);
            parms.Add("@ARTICLE_ID", artId);
            parms.Add("@CREATE_USER", userId);
            var result = Execute(str.ToString(), parms);
            return result;
        }




    }


}
