package com.xydl.service; import com.xydl.entity.SyncTablesInfo; import com.xydl.util.DateUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.Map; @Service @Slf4j @Transactional(rollbackFor = Exception.class) public class DbsqlService { @Resource private JdbcTemplate jdbcTemplate; public List getDistinctEqmids(String tableName, String field) { String sql = "SELECT DISTINCT(" + field + ") FROM " + tableName; List list = jdbcTemplate.queryForList(sql, Integer.class); return list; } public List> getData(Integer eqmid, Date lasttime, SyncTablesInfo table) { String sqlSelect = "SELECT * FROM " + table.getId().getTableName(); String sqlWhere = " WHERE " + table.getDevidFieldName() + "=" + eqmid; if (lasttime != null) { sqlWhere = sqlWhere + " AND " + table.getFieldName() + ">'" + DateUtil.format(lasttime) + "'"; } String sqlOrder = " ORDER BY " + table.getFieldName() + " ASC LIMIT 1000"; String sql = sqlSelect + sqlWhere + sqlOrder; // log.debug(sql); List> list = jdbcTemplate.queryForList(sql); return list; } }