BigDataServiceImpl.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package jnpf.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import jnpf.base.Pagination;
  6. import jnpf.base.entity.SuperBaseEntity;
  7. import jnpf.base.service.DbLinkService;
  8. import jnpf.base.service.SuperServiceImpl;
  9. import jnpf.config.ConfigValueUtil;
  10. import jnpf.constant.GlobalConst;
  11. import jnpf.constant.MsgCode;
  12. import jnpf.database.model.entity.DbLinkEntity;
  13. import jnpf.database.util.ConnUtil;
  14. import jnpf.database.util.DataSourceUtil;
  15. import jnpf.database.util.DbTypeUtil;
  16. import jnpf.database.util.TenantDataSourceUtil;
  17. import jnpf.entity.BigDataEntity;
  18. import jnpf.exception.WorkFlowException;
  19. import jnpf.mapper.BigDataMapper;
  20. import jnpf.service.BigDataService;
  21. import jnpf.util.DateUtil;
  22. import jnpf.util.RandomUtil;
  23. import jnpf.util.StringUtil;
  24. import jnpf.util.UserProvider;
  25. import lombok.Cleanup;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.stereotype.Service;
  30. import java.sql.Connection;
  31. import java.sql.PreparedStatement;
  32. import java.sql.Timestamp;
  33. import java.text.SimpleDateFormat;
  34. import java.util.Date;
  35. import java.util.List;
  36. /**
  37. * 大数据测试
  38. *
  39. * @author JNPF开发平台组
  40. * @version V3.1.0
  41. * @copyright 引迈信息技术有限公司
  42. * @date 2019年9月26日 上午9:18
  43. */
  44. @Slf4j
  45. @Service
  46. public class BigDataServiceImpl extends SuperServiceImpl<BigDataMapper, BigDataEntity> implements BigDataService {
  47. @Autowired
  48. private DataSourceUtil dataSourceUtils;
  49. @Autowired
  50. private ConfigValueUtil configValueUtil;
  51. @Autowired
  52. private DbLinkService dbLinkService;
  53. @Override
  54. public List<BigDataEntity> getList(Pagination pagination) {
  55. QueryWrapper<BigDataEntity> queryWrapper = new QueryWrapper<>();
  56. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  57. queryWrapper.lambda().and(
  58. t -> t.like(BigDataEntity::getFullName, pagination.getKeyword())
  59. .or().like(BigDataEntity::getEnCode, pagination.getKeyword())
  60. );
  61. }
  62. //排序
  63. queryWrapper.lambda().orderByDesc(SuperBaseEntity.SuperCBaseEntity::getCreatorTime, SuperBaseEntity.SuperIBaseEntity::getId);
  64. Page<BigDataEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  65. IPage<BigDataEntity> iPage = this.page(page, queryWrapper);
  66. return pagination.setData(iPage.getRecords(), page.getTotal());
  67. }
  68. @Override
  69. public void create(int insertCount) throws WorkFlowException {
  70. Integer code = this.baseMapper.maxCode();
  71. if (code == null) {
  72. code = 0;
  73. }
  74. int index = code == 0 ? 10000001 : code;
  75. if (index > 11500001) {
  76. throw new WorkFlowException(MsgCode.ETD113.get());
  77. }
  78. try {
  79. @Cleanup Connection conn = ConnUtil.getConnOrDefault(dataSourceUtils);
  80. @Cleanup PreparedStatement pstm = null;
  81. String sql = "";
  82. String tenantColumn = TenantDataSourceUtil.getTenantColumn();
  83. DbLinkEntity dbLinkEntity = dbLinkService.getResource("0");
  84. if (DbTypeUtil.checkOracle(dbLinkEntity)||DbTypeUtil.checkDM(dbLinkEntity)) {
  85. 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})";
  86. } else {
  87. sql = "INSERT INTO ext_big_data(F_ID,F_EN_CODE,F_FULL_NAME,F_CREATOR_TIME{column}) VALUES (?,?,?,?{value})";
  88. }
  89. sql = sql.replaceAll("\\{column}", "," + configValueUtil.getMultiTenantColumn());
  90. sql = sql.replaceAll("\\{value}", ",?");
  91. pstm = conn.prepareStatement(sql);
  92. conn.setAutoCommit(false);
  93. if (DbTypeUtil.checkPostgre(dbLinkEntity)) {
  94. for (int i = 0; i < insertCount; i++) {
  95. pstm.setString(1, RandomUtil.uuId());
  96. pstm.setInt(2, index);
  97. pstm.setString(3, "测试大数据" + index);
  98. pstm.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
  99. if (StringUtil.isNotEmpty(tenantColumn)) {
  100. pstm.setString(5, tenantColumn);
  101. }
  102. pstm.addBatch();
  103. index++;
  104. }
  105. } else {
  106. for (int i = 0; i < insertCount; i++) {
  107. pstm.setString(1, RandomUtil.uuId());
  108. pstm.setInt(2, index);
  109. pstm.setString(3, "测试大数据" + index);
  110. pstm.setString(4, DateUtil.getNow());
  111. // pstm.setString(4, DateUtil.daFormatHHMMSSAddEight(System.currentTimeMillis()));
  112. if (StringUtil.isNotEmpty(tenantColumn)) {
  113. pstm.setString(5, tenantColumn);
  114. }
  115. pstm.addBatch();
  116. index++;
  117. }
  118. }
  119. pstm.executeBatch();
  120. conn.commit();
  121. pstm.close();
  122. conn.close();
  123. } catch (Exception e) {
  124. log.error(e.getMessage());
  125. }
  126. }
  127. }