package com.xintong.visualinspection.service.impl;

import com.xintong.visualinspection.bean.*;
import com.xintong.visualinspection.dao.master.CheckTaskPeriodDao;
import com.xintong.visualinspection.service.CommonService;
import com.xintong.visualinspection.util.CacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 文件名：CommonServiceImpl
 * 版本信息：日期：2018/4/25 Copyright 江苏省交通规划设计院 Corporation 2018 版权所有.
 */
@Service
@com.alibaba.dubbo.config.annotation.Service(
        version = "1.0.0",
        application = "${dubbo.application.id}",
        protocol = "${dubbo.protocol.id}",
        registry = "${dubbo.registry.id}"
)
public class CommonServiceImpl implements CommonService {
    @Autowired
    private CheckTaskPeriodDao checkTaskPeriodDao;

    @Override
    public Map<String, String> getCommonDataMap() {
        return CacheUtil.commonDataMap;
    }

    @Override
    public Map<Long, User> getUserMap() {
        return CacheUtil.userMap;
    }

    @Override
    public Map<Long, Organ> getDeptMap() {
        return CacheUtil.deptMap;
    }

    @Override
    public Map<String, Constant> getCodeMap() {
        return CacheUtil.codeMap;
    }

    @Override
    public Map<String, List<Constant>> getCodeFlagMap() {
        return CacheUtil.codeFlagMap;
    }

    @Override
    public Map<Long, Job> getJobMap() {
        return CacheUtil.jobMap;
    }

    @Override
    public Map<Long, Item> getItemMap() {
        return CacheUtil.itemMap;
    }

    @Override
    public List<String> getCheckItemName(Long aLong) {
        return CacheUtil.itemNameMap.get(aLong);
    }

    @Override
    public List<FeeStation> getAllDeptByLayer(String s) {
        return CacheUtil.allDeptMap.get(s);
    }

    @Override
    public CheckTaskPeriod getCheckTaskPeriod(Long starttime, Long endtime) {
        List<CheckTaskPeriod> checkTaskPeriods = checkTaskPeriodDao.select(new CheckTaskPeriod());

        CheckTaskPeriod period = null;
        // 计算上个周期时间 周期时间：00:00:00 ----- 00:00:00 参数：23:00:00
        for (CheckTaskPeriod p : checkTaskPeriods) {
            if (starttime >= p.getStarttime().getTime() && endtime <= p.getEndtime().getTime()) {
                period = p;
                break;
            }
        }
       return period;
    }

    @Override
    public List<CheckTaskPeriod> getAllCheckTaskPeriod() {
        return checkTaskPeriodDao.select(new CheckTaskPeriod());
    }


}
