package com.mortals.xhx.modules.supplement.dao.ibatis;

import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.modules.supplement.dao.SupplementDao;
import com.mortals.xhx.modules.supplement.model.SupplementEntity;
import com.mortals.xhx.modules.supplement.model.SupplementQuery;
import org.springframework.stereotype.Repository;
import com.mortals.framework.dao.ibatis.SubmeterDaoImpl;
import com.mortals.framework.model.TableParam;
import com.mortals.framework.model.TableStrategy;
import org.springframework.util.ObjectUtils;

import java.util.Date;

/**
* <p>Title: 办件信息临时表</p>
* <p>Description: SupplementDaoImpl DAO接口 </p>
* @author
* @version 1.0.0
*/
@Repository("supplementDao")
public class SupplementDaoImpl extends SubmeterDaoImpl<SupplementEntity,Long> implements SupplementDao {
    @Override
    protected TableStrategy getTableStrategy()
    {
        return new TableStrategy("mortals_iot_zd_supplement_${unionTime}", TableStrategy.STRATEGY_BY_MONTH,3);
    }

    @Override
    public TableParam getTableParam(SupplementEntity entity)
    {
        TableParam param = new TableParam();
        if (!ObjectUtils.isEmpty(entity.getCreateTime())){
            param.unionTime = entity.getCreateTime();
        }else if (entity instanceof SupplementQuery) {
            SupplementQuery accountDetailQuery = (SupplementQuery) entity;
            if (StringUtils.isNotEmpty(accountDetailQuery.getCreateDateStart())) {
                param.unionTime = DateUtils.StrToDate(accountDetailQuery.getCreateDateStart());
            } else if (StringUtils.isNotEmpty(accountDetailQuery.getCreateDateEnd())) {
                param.unionTime = DateUtils.StrToDate(accountDetailQuery.getCreateDateEnd());
            }
        }
        if (ObjectUtils.isEmpty(param.unionTime)) {
            param.unionTime = new Date();
        }
        return param;
    }
}
