package org.jeecg.modules.dataVue.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.dataVue.entity.Mock;
import org.jeecg.modules.dataVue.mapper.MockMapper;
import org.jeecg.modules.dataVue.service.ILjrbService;
import org.jeecg.modules.dataVue.service.IZjfzService;
import org.jeecg.modules.system.mapper.SysAnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

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

@Service
@DS("ljrbDataSource2021")
public class LjrbServiceImpl extends ServiceImpl<MockMapper, Mock> implements ILjrbService {

    @Resource
    private MockMapper mockMapper;
    @Autowired
    public JdbcTemplate jdbcTemplate;

    private List<Map<String, Object>> ejdwList = new ArrayList<>();

    @Override
    public JdbcTemplate getJdbc() {
        return jdbcTemplate;
    }

    @Override
    public List<Map<String, Object>> querySql(String sqlStr, String reserve) {
        return mockMapper.querySqlA(sqlStr);
    }

    @Override
    public List<Map<String, Object>> getEjdwList() {

        if (ejdwList.size() == 0) {
            String sql = "SELECT groupid, g_cname FROM V_SYS_gROUP \n" +
                    "WHERE G_PARENTID='101'\n" +
                    "ORDER BY G_SHOWORDER";

            try {
                ejdwList = mockMapper.querySqlA(sql);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println(e);
                return ejdwList;
            }

        }
        return ejdwList;
    }

    @Override
    public void clearEjdwList() {

        String sql = "SELECT groupid, g_cname FROM V_SYS_gROUP \n" +
                "WHERE G_PARENTID='101'\n" +
                "ORDER BY G_SHOWORDER";
        try {
            ejdwList = mockMapper.querySqlA(sql);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e);
        }
    }


    @Override
    public int querySqlCount(String sqlStr, String reserve) {
        return mockMapper.queryCountA(sqlStr);
    }

}
