|
|
|
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<Object> getDistinctEqmids(String tableName, String field) {
|
|
|
|
String sql = "SELECT DISTINCT(" + field + ") FROM " + tableName;
|
|
|
|
List<Object> list = jdbcTemplate.queryForList(sql, Object.class);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getData(Object eqmid, Date lasttime, SyncTablesInfo table) {
|
|
|
|
String sqlSelect = "SELECT * FROM " + table.getId().getTableName();
|
|
|
|
|
|
|
|
String sqlWhere = " WHERE " + table.getDevidFieldName();
|
|
|
|
if (eqmid instanceof String) {
|
|
|
|
sqlWhere = sqlWhere + "='" + eqmid + "'";
|
|
|
|
} else {
|
|
|
|
sqlWhere = sqlWhere + "=" + 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<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|