package com.mortals.xhx.module.access.dao.ibatis;


import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.access.dao.AccessLogDao;
import com.mortals.xhx.module.access.model.AccessLogEntity;
import java.util.Date;
import com.mortals.framework.model.TableParam;
import com.mortals.framework.model.TableStrategy;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import com.mortals.framework.dao.ibatis.SubmeterDaoImpl;
import com.mortals.xhx.module.access.model.AccessLogQuery;
import java.util.List;
/**
* 访问日志DaoImpl DAO接口
*
* @author zxfei
* @date 2022-08-17
*/
@Repository("accessLogDao")
public class AccessLogDaoImpl extends SubmeterDaoImpl<AccessLogEntity,Long> implements AccessLogDao {

    @Override
    protected TableStrategy getTableStrategy() {
        return new TableStrategy("mortals_xhx_access_log_${unionTime}", TableStrategy.STRATEGY_BY_MONTH, 3);
    }

    @Override
    public TableParam getTableParam(AccessLogEntity makeTableNameOfentity) {
        TableParam tableParam = new TableParam();
        if (!ObjectUtils.isEmpty(makeTableNameOfentity.getCreateTime())) {
            tableParam.unionTime = makeTableNameOfentity.getCreateTime();
        } else if (makeTableNameOfentity instanceof AccessLogQuery) {
            AccessLogQuery AccessLogQuery = (AccessLogQuery) makeTableNameOfentity;
            if (StringUtils.isNotEmpty(AccessLogQuery.getCreateTimeStart())) {
                tableParam.unionTime = DateUtils.StrToDate(AccessLogQuery.getCreateTimeStart());
            } else if (StringUtils.isNotEmpty(AccessLogQuery.getCreateTimeEnd())) {
                tableParam.unionTime = DateUtils.StrToDate(AccessLogQuery.getCreateTimeEnd());
            }
        }
        if (ObjectUtils.isEmpty(tableParam.unionTime)) {
            tableParam.unionTime = new Date();
        }
        return tableParam;
    }



}
