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

import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.modules.information.dao.InformationDao;
import com.mortals.xhx.modules.information.model.InformationEntity;
import com.mortals.xhx.modules.information.model.InformationQuery;
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: InformationDaoImpl DAO接口 </p>
 *
 * @author
 * @version 1.0.0
 */
@Repository("informationDao")
public class InformationDaoImpl extends SubmeterDaoImpl<InformationEntity, Long> implements InformationDao {
    @Override
    protected TableStrategy getTableStrategy() {
        return new TableStrategy("mortals_iot_zd_information_${unionTime}", TableStrategy.STRATEGY_BY_MONTH,3);
    }

    @Override
    public TableParam getTableParam(InformationEntity entity) {
        TableParam param = new TableParam();
        if (!ObjectUtils.isEmpty(entity.getCreateTime())){
            param.unionTime = entity.getCreateTime();
        }else if (entity instanceof InformationQuery) {
            InformationQuery accountDetailQuery = (InformationQuery) entity;
            if (StringUtils.isNotEmpty(accountDetailQuery.getCreateTimeStart())) {
                param.unionTime = DateUtils.StrToDate(accountDetailQuery.getCreateTimeStart());
            } else if (StringUtils.isNotEmpty(accountDetailQuery.getCreateTimeEnd())) {
                param.unionTime = DateUtils.StrToDate(accountDetailQuery.getCreateTimeEnd());
            }
        }
        if (ObjectUtils.isEmpty(param.unionTime)) {
            param.unionTime = new Date();
        }
        return param;
    }

}
