using MadRunFabric.Common.Repositories;
using MadRunFabric.Model.TestUserTypeApi;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Common;
using System.Text;
using System.Threading.Tasks;
using TestUserTypeApi.IRepositories;

namespace TestUserTypeApi.Repositories
{
    public class v_csm_zhuyuanRepository : BaseOracleRepository<V_CSM_ZHUYUAN>, Iv_csm_zhuyuanRepository
    {

        public async Task<PageData<V_CSM_ZHUYUAN>> GetListViewByPage(List<IConditionalModel> conModels, MyPageModel pagemodel, string nowdatetime, string orderby)
        {
            var userlist = await Db.SqlQueryable<V_CSM_ZHUYUAN>("select distinct zy_no,NAME,SEX,ZY_AGE,BIRTH_DAY,ID_NO,PAT_PHONE,CON_NAME,CON_PHONE,PA_ADDRESS,REL_BETWEEN,DIA_CODE, JB_NAME, CY_ZD, DIA_NAME, NURSE_IN_CHARGE, CY_DEPT_NAME, BIZ_CODE, P_ID, ZY_TIMES, ZY_DEPT_NO, CY_DEPT_NO, RY_DATE, CY_DATE, CY_TIME, IS_SZ, SZ_QX, LY_TYPE, DIRECTOR, ZZ_DOC, JZ_DOC, ZY_DAYS, ZY_DEPT_NAME, JOB, OUT_OR_IN from sf.v_csm_zhuyuan where cy_date = '" + nowdatetime + "' order by zy_no desc").Where(conModels).OrderBy(orderby).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);

            var list = new List<V_CSM_ZHUYUAN>();
            foreach (var item in userlist)
            {
                list.Add(item);
            }
            PageData<V_CSM_ZHUYUAN> pd = new PageData<V_CSM_ZHUYUAN>();
            pd.Rows = list;
            pd.Totals = pagemodel.PageCount;
            return pd;// CurrentDb.GetPageList(conModels, pagemodel);
        }
        public int GetListcount(string stime, string etime, string deptname)
        {
            var countlist =  Db.SqlQueryable<V_CSM_ZHUYUAN>("select * from (select distinct zy_no,NAME,SEX,ZY_AGE,BIRTH_DAY,ID_NO,PAT_PHONE,CON_NAME,CON_PHONE,PA_ADDRESS,REL_BETWEEN,DIA_CODE, JB_NAME, CY_ZD, DIA_NAME, NURSE_IN_CHARGE, CY_DEPT_NAME, BIZ_CODE, P_ID, ZY_TIMES, ZY_DEPT_NO, CY_DEPT_NO, RY_DATE, CY_DATE, CY_TIME, IS_SZ, SZ_QX, LY_TYPE, DIRECTOR, ZZ_DOC, JZ_DOC, ZY_DAYS, ZY_DEPT_NAME, JOB, OUT_OR_IN from sf.v_csm_zhuyuan  where to_date(CY_DATE,'yyyy-MM-dd')>=to_date('" + stime + "','yyyy-MM-dd') and to_date(CY_DATE,'yyyy-MM-dd')<=to_date('"+etime+ "','yyyy-MM-dd') and CY_DEPT_NAME='"+deptname+"')");

           int count = countlist.Count();


            return count;// CurrentDb.GetPageList(conModels, pagemodel);
        }
    }
}
