许鹏程
2023-06-30 3bbfaa3d7d416afbd154576453c8ee9e7e2f8899
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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;
        }
    }
}