package com.docus.server.collect.report.noview;

import com.docus.core.util.Func;
import com.docus.core.util.MapObjUtil;
import com.docus.core.util.json.JSON;
import com.docus.server.collect.AbstractJobCollector;
import com.docus.server.collect.web.common.dto.NoViewCollectionDto;
import com.docus.server.entity.TaskConfig;
import com.docus.server.collect.web.enums.QueryWayEnum;
import com.docus.server.util.PeriodTime;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component("defJobNoViewCollectorImpl")
public class DefJobNoViewCollectorImpl
    extends AbstractJobCollector<Map<String, Object>> {

    @Override
    public List<Map<String, Object>> page(PeriodTime periodTime, TaskConfig taskConfig) {

        NoViewCollectionDto noViewCollectionDto = JSON.fromJSON(taskConfig.getParam(), NoViewCollectionDto.class);
        noViewCollectionDto.setStartTime(Func.format(periodTime.getPeriodStartDate(), "yyyy-MM-dd HH:mm:ss"));
        noViewCollectionDto.setEndTime(Func.format(periodTime.getPeriodEndDate(), "yyyy-MM-dd HH:mm:ss"));
        noViewCollectionDto.setOffset(taskConfig.getOffset());
        noViewCollectionDto.setPageSize(taskConfig.getPageSize());

        int queryway = noViewCollectionDto.getQueryway();

        List<Map<String, Object>> results = new ArrayList<>();
        Map<String, Object> param = MapObjUtil.object2Map(noViewCollectionDto);
        if (queryway == QueryWayEnum.outtime.value()) {
            results = basicService.getBasicOutData(param);
        }
        if (queryway == QueryWayEnum.createtime.value()) {
            results = basicService.getBasicData(param);
        }
        return results;
    }
}
