Init_14_Platform.groovy 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import com.dderp.business.dao.PlatformDao
  2. import com.dderp.common.api.NoSqlKeysService
  3. import com.dderp.common.datas.ESKeys
  4. import com.dderp.common.datas.RedisKeys
  5. import com.dderp.common.entity.platform.PlatformInfo
  6. import com.dderp.common.entity.platform.PlatformRequire
  7. import com.dySweetFishPlugin.elasticsearch.ESClient
  8. import com.dySweetFishPlugin.redis.RedisService
  9. import com.sweetfish.convert.json.JsonConvert
  10. import com.sweetfish.source.PageFlipper
  11. import com.sweetfish.util.Utility
  12. import org.apache.logging.log4j.Logger
  13. import org.elasticsearch.action.bulk.BulkRequestBuilder
  14. import org.elasticsearch.action.bulk.BulkResponse
  15. import org.elasticsearch.action.index.IndexRequestBuilder
  16. import org.elasticsearch.common.xcontent.XContentType
  17. import org.rex.RMap
  18. static def createRunnable(ESClient esClient, RedisService redisService, NoSqlKeysService keysService,
  19. PlatformDao platformDao, Logger logger, JsonConvert jsonConvert, String dataSourceId, long supplierCode) {
  20. return {
  21. esClient.createIndex(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
  22. ESKeys.INDEX_CONFIG,
  23. Utility.ofMap(ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE, "platforminfo.json"))
  24. redisService.del(keysService.getRedisKey(RedisKeys.KEY_DELIVER_PLATFORM_INFO, supplierCode))
  25. esClient.createIndex(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_REQUIRE_INDEX, supplierCode),
  26. ESKeys.INDEX_CONFIG,
  27. Utility.ofMap(ESKeys.ES_DELIVER_PLATFORM_REQUIRE_TYPE, "platformrequire.json"))
  28. redisService.del(keysService.getRedisKey(RedisKeys.KEY_DELIVER_PLATFORM_REQUIRE, supplierCode))
  29. RMap params = new RMap()
  30. params.put("voidFlag", -1)
  31. Ignore_ExecPageFlipper.execute(1000, { PageFlipper p ->
  32. List<PlatformInfo> platformInfoList = platformDao.queryPlatformInfoList(params, p, dataSourceId, supplierCode)
  33. if (!platformInfoList.isEmpty()) {
  34. Map<String, String> redisMap = platformInfoList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
  35. if (!redisMap.isEmpty()) {
  36. redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_DELIVER_PLATFORM_INFO, supplierCode), redisMap)
  37. }
  38. BulkRequestBuilder bulkRequest = esClient.getClient().prepareBulk()
  39. platformInfoList.each { x ->
  40. IndexRequestBuilder indexRequest = esClient.getClient()
  41. .prepareIndex(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode), ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE)
  42. .setId(String.valueOf(x.getId()))
  43. .setSource(jsonConvert.convertTo(x), XContentType.JSON)
  44. bulkRequest.add(indexRequest)
  45. }
  46. BulkResponse bulkResponse = bulkRequest.execute().actionGet()
  47. if (bulkResponse.hasFailures()) {
  48. logger.error("索引平台档案出错:" + bulkResponse.buildFailureMessage())
  49. } else {
  50. logger.info("索引平台档案,共" + platformInfoList.size() + "条记录")
  51. }
  52. }
  53. })
  54. Ignore_ExecPageFlipper.execute(1000, { PageFlipper p ->
  55. List<PlatformRequire> platformRequireList = platformDao.queryPlatformRequireList(params, p, dataSourceId, supplierCode)
  56. if (!platformRequireList.isEmpty()) {
  57. Map<String, String> redisMap = platformRequireList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
  58. if (!redisMap.isEmpty()) {
  59. redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_DELIVER_PLATFORM_REQUIRE, supplierCode), redisMap)
  60. }
  61. BulkRequestBuilder bulkRequest = esClient.getClient().prepareBulk()
  62. platformRequireList.each { x ->
  63. IndexRequestBuilder indexRequest = esClient.getClient()
  64. .prepareIndex(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_REQUIRE_INDEX, supplierCode), ESKeys.ES_DELIVER_PLATFORM_REQUIRE_TYPE)
  65. .setId(String.valueOf(x.getId()))
  66. .setSource(jsonConvert.convertTo(x), XContentType.JSON)
  67. bulkRequest.add(indexRequest)
  68. }
  69. BulkResponse bulkResponse = bulkRequest.execute().actionGet()
  70. if (bulkResponse.hasFailures()) {
  71. logger.error("索引平台需求条件档案出错:" + bulkResponse.buildFailureMessage())
  72. } else {
  73. logger.info("索引平台需求条件档案,共" + platformRequireList.size() + "条记录")
  74. }
  75. }
  76. })
  77. } as Runnable
  78. }
  79. createRunnable(esClient, redisService, keysService, platformDao, logger, jsonConvert, dataSourceId, supplierCode)