ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package jnpf.service.impl;
 
import jnpf.base.DataSourceApi;
import jnpf.base.Pagination;
import jnpf.base.service.SuperServiceImpl;
import jnpf.config.ConfigValueUtil;
import jnpf.constant.MsgCode;
import jnpf.database.model.entity.DbLinkEntity;
import jnpf.database.util.ConnUtil;
import jnpf.database.util.DataSourceUtil;
import jnpf.database.util.DbTypeUtil;
import jnpf.database.util.TenantDataSourceUtil;
import jnpf.entity.BigDataEntity;
import jnpf.exception.WorkFlowException;
import jnpf.mapper.BigDataMapper;
import jnpf.service.BigDataService;
import jnpf.util.DateUtil;
import jnpf.util.RandomUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.util.List;
 
/**
 * 大数据测试
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月26日 上午9:18
 */
@Slf4j
@Service
public class BigDataServiceImpl extends SuperServiceImpl<BigDataMapper, BigDataEntity> implements BigDataService {
 
    @Autowired
    private DataSourceUtil dataSourceUtils;
    @Autowired
    private ConfigValueUtil configValueUtil;
    @Autowired
    private DataSourceApi dbLinkService;
 
 
    @Override
    public List<BigDataEntity> getList(Pagination pagination) {
        return this.baseMapper.getList(pagination);
    }
 
    @Override
    public void create(int insertCount) throws WorkFlowException {
        Integer code = this.baseMapper.maxCode();
        if (code == null) {
            code = 0;
        }
        int index = code == 0 ? 10000001 : code;
        if (index > 11500001) {
            throw new WorkFlowException(MsgCode.ETD113.get());
        }
        try {
            @Cleanup Connection conn = ConnUtil.getConnOrDefault(dataSourceUtils);
            @Cleanup PreparedStatement pstm = null;
            String sql = "";
            String tenantColumn = TenantDataSourceUtil.getTenantColumn();
            DbLinkEntity dbLinkEntity = dbLinkService.getResource("0", UserProvider.getUser().getTenantId());
            if (DbTypeUtil.checkOracle(dbLinkEntity)||DbTypeUtil.checkDM(dbLinkEntity)) {
                sql = "INSERT INTO ext_big_data(F_ID,F_EN_CODE,F_FULL_NAME,F_CREATOR_TIME{column})  VALUES (?,?,?,to_date(?,'yyyy-mm-dd hh24:mi:ss'){value})";
            } else {
                sql = "INSERT INTO ext_big_data(F_ID,F_EN_CODE,F_FULL_NAME,F_CREATOR_TIME{column})  VALUES (?,?,?,?{value})";
            }
            sql = sql.replaceAll("\\{column}", "," + configValueUtil.getMultiTenantColumn());
            sql = sql.replaceAll("\\{value}", ",?");
            pstm = conn.prepareStatement(sql);
            conn.setAutoCommit(false);
            if (DbTypeUtil.checkPostgre(dbLinkEntity)) {
                for (int i = 0; i < insertCount; i++) {
                    pstm.setString(1, RandomUtil.uuId());
                    pstm.setInt(2, index);
                    pstm.setString(3, "测试大数据" + index);
                    pstm.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
                    if (StringUtil.isNotEmpty(tenantColumn)) {
                        pstm.setString(5, tenantColumn);
                    }
                    pstm.addBatch();
                    index++;
                }
            } else {
                for (int i = 0; i < insertCount; i++) {
                    pstm.setString(1, RandomUtil.uuId());
                    pstm.setInt(2, index);
                    pstm.setString(3, "测试大数据" + index);
                    pstm.setString(4, DateUtil.getNow());
//                    pstm.setString(4, DateUtil.daFormatHHMMSSAddEight(System.currentTimeMillis()));
                    if (StringUtil.isNotEmpty(tenantColumn)) {
                        pstm.setString(5, tenantColumn);
                    }
                    pstm.addBatch();
                    index++;
                }
            }
            pstm.executeBatch();
            conn.commit();
            pstm.close();
            conn.close();
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}