package com.nantian.cloud.dbcapp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.dbcapp.entity.ConfigureDataCollectEnable;
import com.nantian.cloud.dbcapp.entity.ConfigureDataCollectEnableApply;
import com.nantian.cloud.dbcapp.mapper.record.ConfigureDataCollectEnableMapper;
import com.nantian.cloud.dbcapp.service.ConfigureDataCollectEnableService;
import com.nantian.cloud.dbcapp.unit.DateUtil;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("ConfigureDataCollectEnableService")
public class ConfigureDataCollectEnableImpl extends ServiceImpl<ConfigureDataCollectEnableMapper, ConfigureDataCollectEnable> implements ConfigureDataCollectEnableService {
    @Override
    public IPage<ConfigureDataCollectEnable> getEnableList(Page page, String enterpriseCode, String dataCode) {
        return baseMapper.getEnableList(page,enterpriseCode,dataCode);
    }

    @Override
    public boolean removeconfigureDataCollectEnableById(ConfigureDataCollectEnable configureDataCollectEnable) {
        return baseMapper.removeconfigureDataCollectEnableById(configureDataCollectEnable);
    }

    @Override
    public List<String> getEnableDataCodeList(String enterpriseCode,String month) {
        List<String> result = new ArrayList<>();
        List<ConfigureDataCollectEnable> list = baseMapper.getEnableTimeListByEnterpriseCode(enterpriseCode);
        Date nowMonth = DateUtil.parseDateByStr(month + "-01");
        for (ConfigureDataCollectEnable info : list) {
            Date startDate = DateUtil.parseDateByStr(info.getStartTime());
            Date endDate = info.getEndTime() != null && StringUtils.isNotBlank(info.getEndTime()) ? DateUtil.parseDateByStr(info.getEndTime()) : new Date();
            if (DateUtil.belongCalendar(nowMonth,startDate, endDate)){
                result.add(info.getDataCode());
            }
        }
        return result;
    }
}
