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 OutMapUserImgroupRepository : BaseRepositoryToASHermed_SinoInterface<Out_Map_User_Imgroup>, IOutMapUserImgroupRepository
    {

        public int InsertOutIMGroup(Out_IM_Group outImGroup)
        {
            StringBuilder str = new StringBuilder();
            str.Append("insert into out_im_group ");
            str.Append(@"(GROUP_ID,GROUP_CONTENT,IM_ID,`STATUS`,CREATE_TIME) ");
            str.Append(" values ");
            str.Append(@"(@GROUP_ID,@GROUP_CONTENT,@IM_ID,@STATUS,@CREATE_TIME); ");
            str.Append("select @@identity; ");
            var parms = new Dictionary<string, object>();
            parms.Add("@GROUP_ID", outImGroup.Group_Id);
            parms.Add("@GROUP_CONTENT", outImGroup.Group_Content);
            parms.Add("@IM_ID", outImGroup.IM_Id);
            parms.Add("@STATUS", outImGroup.Status);
            parms.Add("@CREATE_TIME", outImGroup.Create_Time);
            var result = Execute(str.ToString(), parms);
            return result;
        }

        public Out_Map_User_Imgroup SelectByGroup(string groupId, string account)
        {
            var parms = new Dictionary<string, object>();
            StringBuilder str = new StringBuilder();
            str.Append(@" select * from out_map_user_imgroup
                            where GROUP_ID = @GROUP_ID
                              and IM_ID = @IM_ID
                              and STATUS = 1");
            parms.Add("@GROUP_ID", groupId);
            parms.Add("@IM_ID", account);

            var result = Query<Out_Map_User_Imgroup>(str.ToString(), parms);
            return result?.FirstOrDefault();
        }




    }


}
