package com.product.kt.test.service;
|
|
import java.util.List;
|
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.kt.test.config.SyncConfig;
|
import com.product.util.BaseUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.datasource.dao.Dao;
|
import com.product.datasource.entity.DataBaseEntity;
|
|
/**
|
* 读取数据工具类
|
*
|
* @author 86151
|
*/
|
@Component
|
public class ReadToolsService {
|
|
@Autowired
|
BaseDao baseDao;
|
|
/**
|
* 获取总条数
|
*
|
* @return
|
*/
|
public int getToolCount(String sourceLinkUUID, String tableName) {
|
//获取数据同步配置
|
FieldSetEntity sourceDataSourceFse = baseDao.getFieldSetEntity("product_sys_data_sync_manager", SyncConfig.DATA_SOURCE_MAP.get(sourceLinkUUID), false);
|
|
DataBaseEntity sourceDbe = null;
|
Dao sourceDao = null;
|
int countSize = 0;
|
try {
|
sourceDbe = new DataBaseEntity(sourceDataSourceFse);
|
sourceDao = sourceDbe.getDao();
|
//获取数据总条数
|
FieldSetEntity fseTableInfo = sourceDao.getOne("SELECT COUNT(*) count FROM " + tableName);
|
if (fseTableInfo != null) {
|
countSize = fseTableInfo.getInteger("count");
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
if (sourceDao != null) {
|
sourceDao.closeConnection();
|
}
|
}
|
return countSize;
|
}
|
|
|
/**
|
* 获取数据
|
*
|
* @param a cpage
|
* @param b pageSize
|
* @return
|
*/
|
public List<FieldSetEntity> getToolListByAutoId(String sourceLinkUUID, int a, int b, String tableName, String dateField) {
|
//获取数据同步配置
|
FieldSetEntity sourceDataSourceFse = baseDao.getFieldSetEntity("product_sys_data_sync_manager", SyncConfig.DATA_SOURCE_MAP.get(sourceLinkUUID), false);
|
|
DataBaseEntity sourceDbe = null;
|
Dao sourceDao = null;
|
DataTableEntity dt = null;
|
|
try {
|
sourceDbe = new DataBaseEntity(sourceDataSourceFse);
|
sourceDao = sourceDbe.getDao();
|
//获取数据
|
dt = sourceDao.getList(tableName, "", new Object[]{}, dateField, a, b);
|
} catch (Exception e) {
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
e.printStackTrace();
|
} finally {
|
if (sourceDao != null) {
|
sourceDao.closeConnection();
|
}
|
}
|
if (!BaseUtil.dataTableIsEmpty(dt)) {
|
return dt.getData();
|
} else {
|
return null;
|
}
|
}
|
}
|