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());
|
}
|
}
|
}
|