Init_51_DesignTempalte.groovy 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import com.sdtool.business.dao.DesignDao
  2. import com.sdtool.common.api.NoSqlKeysService
  3. import com.sdtool.common.datas.RedisKeys
  4. import com.dySweetFishPlugin.redis.RedisService
  5. import com.sdtool.common.entity.design.DesignTemplate
  6. import com.sdtool.common.entity.design.DesignTemplateItem
  7. import com.sweetfish.convert.json.JsonConvert
  8. import com.sweetfish.source.PageFlipper
  9. import org.apache.commons.lang3.StringUtils
  10. import org.apache.logging.log4j.Logger
  11. import org.rex.RMap
  12. import java.nio.file.Files
  13. import java.nio.file.Paths
  14. /**
  15. * @Author: xl Created on 2024-05-11
  16. * @Content:
  17. */
  18. static def createRunnable(RedisService redisService, NoSqlKeysService keysService,
  19. DesignDao designDao, Logger logger, JsonConvert jsonConvert, String dataSourceId, long supplierCode) {
  20. RMap params = new RMap()
  21. return {
  22. redisService.del(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_EDIT, supplierCode))
  23. redisService.del(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_IMPOSITION, supplierCode))
  24. //删除系统转跳临时token
  25. redisService.del(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_SYS_USER_TOKEN, -1000))
  26. Ignore_ExecPageFlipper.execute(1000, { PageFlipper p ->
  27. List<DesignTemplate> templates = designDao.selectDesignTemplates(params, dataSourceId, supplierCode, p)
  28. if (!templates.isEmpty()) {
  29. templates.each {
  30. if (StringUtils.isNotEmpty(it.jsonContent)) {
  31. File file = new File(it.jsonContent)
  32. if (file.exists()) {
  33. String content = new String(Files.readAllBytes(Paths.get(it.jsonContent)), "UTF-8")
  34. it.setJsonContent(content)
  35. }
  36. }
  37. }
  38. Map<String, String> redisMap = templates.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
  39. redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_EDIT, supplierCode), redisMap)
  40. RMap itemParams = new RMap()
  41. templates.each {
  42. itemParams.set("idTemplate", it.id)
  43. List<DesignTemplateItem> itemList = designDao.selectDesignTemplateItems(itemParams, dataSourceId, supplierCode)
  44. it.setItemList(itemList)
  45. it.setJsonContent("")
  46. }
  47. redisMap = templates.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
  48. redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_IMPOSITION, supplierCode), redisMap)
  49. logger.info("设计模板共" + templates.size() + "条记录")
  50. }
  51. })
  52. } as Runnable
  53. }
  54. createRunnable(redisService, keysService, designDao, logger, jsonConvert, dataSourceId, supplierCode)