package com.citygis.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.citygis.common.annotation.DataSource;
import com.citygis.common.enums.DataSourceType;
import com.citygis.web.domain.*;
import com.citygis.web.mapper.TabSystemMsgMapper;
import com.citygis.web.service.ITabSystemMsgService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author citygis
 * @since 2025-01-09
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class TabSystemMsgServiceImpl extends ServiceImpl<TabSystemMsgMapper, TabSystemMsg> implements ITabSystemMsgService {

    @Resource
    TabSystemMsgMapper tabSystemMsgMapper;

    @Override
    public List<TabSystemMsg> getTabSystemMsgList(TabSystemMsg tabSystemMsg) {
        List<TabAccessTableMsg> tabAccessTableMsg = tabSystemMsgMapper.getTabAccessTableMsgList();
        List<TabSystemMsg> list = this.list();
        list.forEach(tabSystemMsg1 -> {
            tabAccessTableMsg.forEach(tabAccessTableMsg1 -> {
                if (tabAccessTableMsg1.getTableName().equals(tabSystemMsg1.getTableName())) {
                    tabSystemMsg1.setCount(tabAccessTableMsg1.getCount());
                }
            });
        });

        return list;
    }

    @Override
    public List<Exchange> getExchangeCount(String dateTime) {
        return tabSystemMsgMapper.getExchangeCount(dateTime);
    }

    @Override
    public List<JkCloudCount> getJkcloudCount() {
        return tabSystemMsgMapper.getJkcloudCount();
    }

    @Override
    public List<UrlDayCount> getUrlDayCount() {
        return tabSystemMsgMapper.getUrlDayCount();
    }

    @Override
    public List<TopicCount> getTopicCountYesterday() {
        return tabSystemMsgMapper.getTopicCountYesterday();
    }

    @Override
    public List<NewCount> getNew() {
        return tabSystemMsgMapper.getNew();
    }


    @DataSource(DataSourceType.SLAVE)
    public Boolean insertTabSystemMsg(TabSystemMsg tabSystemMsg) {
        return this.save(tabSystemMsg);
    }
}
