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.IMasterService;
import org.jeecg.modules.dataVue.service.IZjyService;
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.List;
import java.util.Map;

@Service
@DS("master")
public class MasterServiceImpl extends ServiceImpl<MockMapper, Mock> implements IMasterService {

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

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

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

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

    /**
     * 根据井号名称获得表代码
     *
     * @param AJH
     * @return
     */
    @Override
    public String getTableCode(String AJH) {
        //井号预处理
        String s = AJH.replace('-', '_').toUpperCase();
        List<Map<String, Object>> list = this.mockMapper.querySqlA("select jh,tab_code from A_JH_TABLE where JH='" + AJH + "'");
        if(list.size()>0){
            s = list.get(0).get("TAB_CODE").toString();
            return "\"LTD_" + s + "\"@ljss";
        }
        return "\"LTD_" + s + "\"@ljss";
    }


    @Override
    public String getTableCodeNew(String AJH) {
        //井号预处理
        String s = AJH.replace('-', '_').toUpperCase();
        List<Map<String, Object>> list = this.mockMapper.querySqlA("select jh,tab_code from A_JH_TABLE where JH='" + AJH + "'");
        if(list.size()>0){
            s = list.get(0).get("TAB_CODE").toString();
            return "LTD_" + s ;
        }
        return "LTD_" + s ;
    }

}
