package cn.estsh.i3plus.pojo.mdm.jpa.dao;

import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.MdmEnumUtil;
import cn.estsh.i3plus.pojo.mdm.bean.base.BaseMdmBean;
import cn.estsh.i3plus.pojo.mdm.bean.base.BaseMdmBusiExtdBean;
import cn.estsh.i3plus.pojo.mdm.bean.base.BaseMdmBusiModelBean;
import cn.estsh.i3plus.pojo.mdm.bean.base.DdlPackMdmModelBean;

import java.util.List;

/**
 * @Description : 自定义Repository的方法接口
 * @Reference : 对jpaRepository进行扩展
 * @Author : alwaysfrin
 * @CreateDate : 2018-09-13 10:34
 * @Modify:
 **/
public interface MdmBusiModelRepository<T extends BaseMdmBusiModelBean<M, B>, M extends BaseMdmBean, B extends BaseMdmBusiExtdBean> {
    T getById(long id);

    List<T> list();

    List<T> list(final String hql);

    List<T> listPager(Pager pager);

    List<T> findByPage(final DdlPackMdmModelBean packBean, final int offset, final int pageSize);

    /**
     * @param hql      hql入参需要用问号代替
     * @param values   按照入参问号的顺序进行赋值
     * @param offset
     * @param pageSize
     * @return
     */
    List<T> findByPage(final String hql, final Object[] values, final int offset, final int pageSize);

    List<T> findByProperty(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String propertyName, Object value);

    List<T> findByProperty(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values);

    List<T> findByProperty(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String propertyName, Object value, String orderByStuff);

    List<T> findByProperty(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values, String orderByStuff);

    T getByProperty(DdlPackMdmModelBean packBean);

    T getByProperty(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String propertyName, Object value);

    T getByProperty(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values);

    int listCount();

    int findByPropertyCount(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String propertyName, Object value);

    int findByPropertyCount(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values);

    List<T> findByPropertyPage(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String propertyName, Object value, String orderByStuff, Pager pager);

    List<T> findByPropertyPage(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values, String orderByStuff, Pager pager);

    List<T> findByHqlWhere(DdlPackMdmModelBean packBean);

    List<T> findByHqlWhere(String hqlWhere, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values, String orderByStuff);

    int findByHqlWhereCount(String hqlWhere, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values);

    List<T> findByHqlWherePage(String hqlWhere, Pager pager, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values, String orderByStuff);

    List<T> findByHqlWherePage(DdlPackMdmModelBean packBean, Pager pager);

    int findByHqlWhereCount(DdlPackMdmModelBean packBean);

    int findByHqlCount(String hql);

    int findByHqlCount(String hql, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] paramName, Object[] paramValue);

    List<T> findByHqlPage(DdlPackMdmModelBean packBean, Pager pager);

    List<T> findByHqlPage(String hql, Pager pager, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] paramName, Object[] paramValue);

    double findByHqlDouble(DdlPackMdmModelBean packBean);

    long findByHqlLong(DdlPackMdmModelBean packBean);

    List<T> findByHqlTopWhere(DdlPackMdmModelBean packBean, int topNum);

    /**********************  多表联查，返回Object[]数组根据hql查询翻页信息  开始 ****************************/
    List<Object[]> findByHqlObjects(String hql);

    List<Object[]> findByHqlObjects(String hql, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] paramName, Object[] paramValue);

    List<Object[]> findByHqlPageObjects(String hql, Pager pager);

    List<Object[]> findByHqlPageObjects(String hql, Pager pager, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] paramName, Object[] paramValue);

    List<Object[]> findBySqlObjList(String sql);

    List<Object[]> findBySqlObjListByPager(String sql, Pager pager);

    /****************** 部分业务处理 *******************/

    boolean isExitByProperty(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String propertyName, Object value);

    boolean isExitByProperty(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values);

    boolean isExitByHqlWhere(String hqlWhere, MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, String[] propertyNames, Object[] values);

    boolean isExitByHql(DdlPackMdmModelBean packBean);

}
