using ASHermed.SinoInterface.Api.ContractModel;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository;
using ASHermed.SinoInterface.Repository.MySql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASHermed.SinoInterface.Api.MySqlRepository
{
    public class OutMapPatTagRepository : BaseRepositoryToASHermed_SinoInterface<Out_Map_Pat_Tag>, IOutMapPatTagRepository
    {
        public Out_Map_Pat_Tag SelectMapByTagPat(int tagId, int doctorId, int patId)
        {
            var selectSql = new StringBuilder();
            var parms = new Dictionary<string, object>();
            selectSql.Append(@" select * from out_map_pat_tag
                              where DOCTOR_ID=@DOCTOR_ID
                              and PAT_ID=@PAT_ID
                              and TAG_ID=@TAG_ID
                              and `STATUS`=1");
            parms.Add("@DOCTOR_ID", doctorId);
            parms.Add("@PAT_ID", patId);
            parms.Add("@TAG_ID", tagId);
            var result = Query<Out_Map_Pat_Tag>(selectSql.ToString(), parms);
            return result?.FirstOrDefault();
        }

        public int InsertPatTag(Out_Map_Pat_Tag ent)
        {
            StringBuilder selectSql = new StringBuilder();
            selectSql.Append(@"INSERT INTO `out_map_pat_tag` (
								`ID`,
								`DOCTOR_ID`,
								`PAT_ID`,
								`TAG_ID`,
								`STATUS`,
								`CREATE_TIME`,
								`UPDATE_TIME`,
								`REMARK`)
								VALUES
									(@ID,@DOCTOR_ID,@PAT_ID,@TAG_ID,@STATUS,@CREATE_TIME,@UPDATE_TIME,@REMARK);");
            return Execute(selectSql.ToString(), ent);
        }


    }
}
