package ${packageName}.dao.ibatis;


import org.springframework.stereotype.Repository;
import ${packageName}.dao.${ClassName}Dao;
import ${packageName}.model.${ClassName}Entity;
import java.util.Date;
<#if table.dividedTableType==0 >
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
<#else>
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 ${packageName}.model.${ClassName}Query;
</#if>
<#if table.dividedTableType==1 >
    <#assign TableStrategy = "TableStrategy.STRATEGY_BY_DAY">
<#elseif table.dividedTableType==2>
    <#assign TableStrategy = "TableStrategy.STRATEGY_BY_WEEK">
<#elseif table.dividedTableType==3>
    <#assign TableStrategy = "TableStrategy.STRATEGY_BY_MONTH">
<#elseif table.dividedTableType==4>
    <#assign TableStrategy = "TableStrategy.STRATEGY_BY_MOD">
<#elseif table.dividedTableType==0>
</#if>
import java.util.List;
/**
* ${functionName}DaoImpl DAO接口
*
* @author ${author}
* @date ${datetime}
*/
@Repository("${ClassName?uncap_first}Dao")
<#if table.dividedTableType!=0 >
public class ${ClassName}DaoImpl extends SubmeterDaoImpl<${ClassName}Entity,${pkColumn.javaType}> implements ${ClassName}Dao {

    @Override
    protected TableStrategy getTableStrategy() {
        return new TableStrategy("${tableName}_<#noparse>$</#noparse>{unionTime}", ${TableStrategy}, 3);
    }

    @Override
    public TableParam getTableParam(${ClassName}Entity makeTableNameOfentity) {
        TableParam tableParam = new TableParam();
        if (!ObjectUtils.isEmpty(makeTableNameOfentity.getCreateTime())) {
            tableParam.unionTime = makeTableNameOfentity.getCreateTime();
        } else if (makeTableNameOfentity instanceof ${ClassName}Query) {
            ${ClassName}Query ${ClassName}Query = (${ClassName}Query) makeTableNameOfentity;
            if (StringUtils.isNotEmpty(${ClassName}Query.getCreateTimeStart())) {
                tableParam.unionTime = DateUtils.StrToDate(${ClassName}Query.getCreateTimeStart());
            } else if (StringUtils.isNotEmpty(${ClassName}Query.getCreateTimeEnd())) {
                tableParam.unionTime = DateUtils.StrToDate(${ClassName}Query.getCreateTimeEnd());
            }
        }
        if (ObjectUtils.isEmpty(tableParam.unionTime)) {
            tableParam.unionTime = new Date();
        }
        return tableParam;
    }
<#else>
public class ${ClassName}DaoImpl extends BaseCRUDDaoMybatis<${ClassName}Entity,${pkColumn.javaType}> implements ${ClassName}Dao {
<#if pkColumn.columnName!="id" >
    @Override
    protected String getPrimaryKeyLabel() {
        return "${pkColumn.columnName}";
    }
</#if>
</#if>


<#if table.tplCategory=="tree" >
    @Override
    public List<${ClassName}Entity> selectChildren${ClassName}ById(String ${ClassName?uncap_first}Id) {
        return getSqlSession().selectList(getSqlId("selectChildren${ClassName}ById"), ${ClassName?uncap_first}Id);
    }
</#if>

}
