BE_DocClearScriptCache.groovy 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import com.sweetfish.service.RetResult
  2. import com.yinjie.heating.common.api.BusinessExecutor
  3. import com.yinjie.heating.common.api.DocInfoService
  4. import com.yinjie.heating.common.api.SystemService
  5. import com.yinjie.heating.common.api.heating.CallThirdAppService
  6. import com.yinjie.heating.common.datas.ERPModule
  7. import com.yinjie.heating.common.datas.ERPModuleEntity
  8. import com.yinjie.heating.common.entity.base.BusinessOperation
  9. import com.yinjie.heating.common.entity.base.ProcessEntityItem
  10. import org.apache.logging.log4j.LogManager
  11. import org.apache.logging.log4j.Logger
  12. import javax.annotation.Resource
  13. /**
  14. * Created by jlutt on 2020-08-25
  15. *
  16. * @author jlutt
  17. */
  18. @SuppressWarnings("unused")
  19. class BE_DocClearScriptCache implements BusinessExecutor<ProcessEntityItem<ERPModuleEntity>, ERPModuleEntity> {
  20. protected final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
  21. @Resource
  22. SystemService systemService
  23. @Resource
  24. DocInfoService docInfoService
  25. @Resource
  26. CallThirdAppService callThirdAppService
  27. @Override
  28. String scriptName() {
  29. return "保存业务脚本清除对象"
  30. }
  31. @Override
  32. ERPModule module() {
  33. return ERPModule.NONE
  34. }
  35. @Override
  36. RetResult<ERPModuleEntity> execute(ProcessEntityItem<ERPModuleEntity> source) {
  37. ERPModule erpModule = source.getInputItem().getErpModule()
  38. logger.info("修改模块" + erpModule.getModuleDisplayName())
  39. if ("Init_ExpandoGroovy".equalsIgnoreCase(source.getInputItem().getCode())) {
  40. //Init_ExpandoGroovy每个使用脚本的service都载入了,由于是默认载入的,而且是启动自动载入的,所以不提供清除的方法,而是每个都重载一次
  41. //2024-01-26未测试这个重载能不能不重启给groovy增加扩展方法,需要测试,不过理论上没啥用,因为Init_ExpandoGroovy的脚本是用的其它groovy代码实现的,先这样吧,留着以后处理,暂时不经常修改GroovyExtensions代码算了
  42. systemService.reloadScriptCache(source.inputItem.code, ERPModule.SYSTEM, source.dataSourceId, source.supplierCode)
  43. docInfoService.reloadScriptCache(source.inputItem.code, ERPModule.SYSTEM, source.dataSourceId, source.supplierCode)
  44. callThirdAppService.reloadScriptCache(source.inputItem.code, ERPModule.CALL_THIRD, source.dataSourceId, source.supplierCode)
  45. }
  46. else {
  47. switch (erpModule) {
  48. case ERPModule.NONE:
  49. break
  50. case ERPModule.SYSTEM:
  51. if (source.getOperation() == BusinessOperation.SAVE) {
  52. systemService.invalidateScriptCache(source.getSupplierCode() + "-" + source.getInputItem().getCode())
  53. } else {
  54. systemService.reloadScriptCache(source.getInputItem().getCode(), erpModule, source.getDataSourceId(), source.getSupplierCode())
  55. }
  56. break
  57. case [ERPModule.DOC, ERPModule.INQUIREINFO]:
  58. if (source.getOperation() == BusinessOperation.SAVE) {
  59. docInfoService.invalidateScriptCache(source.getSupplierCode() + "-" + source.getInputItem().getCode())
  60. } else {
  61. docInfoService.reloadScriptCache(source.getInputItem().getCode(), erpModule, source.getDataSourceId(), source.getSupplierCode())
  62. }
  63. break
  64. case [ERPModule.EXPORT, ERPModule.CHARTS]:
  65. if (source.getOperation() == BusinessOperation.SAVE) {
  66. systemService.invalidateScriptCache(source.getSupplierCode() + "-" + source.getInputItem().getCode())
  67. } else {
  68. systemService.reloadScriptCache(source.getInputItem().getCode(), erpModule, source.getDataSourceId(), source.getSupplierCode())
  69. }
  70. break
  71. case ERPModule.CALL_THIRD:
  72. if (source.getOperation() == BusinessOperation.SAVE) {
  73. callThirdAppService.invalidateScriptCache(source.getSupplierCode() + "-" + source.getInputItem().getCode())
  74. } else {
  75. callThirdAppService.reloadScriptCache(source.getInputItem().getCode(), erpModule, source.getDataSourceId(), source.getSupplierCode())
  76. }
  77. break
  78. case ERPModule.ADDRESSPARSER:
  79. break
  80. case ERPModule.APP:
  81. break
  82. default:
  83. break
  84. }
  85. }
  86. return RetResult.success().result(source.getInputItem())
  87. }
  88. }