BE_PlateForm_CodeList.groovy 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import com.alibaba.fastjson2.JSON
  2. import com.yinjie.heating.common.api.BusinessExecutor
  3. import com.yinjie.heating.common.datas.ERPModule
  4. import com.yinjie.heating.common.entity.base.InvokeCallParams
  5. import com.yinjie.heating.common.entity.base.InvokeCallResult
  6. import com.sweetfish.service.RetResult
  7. import groovy.json.JsonSlurper
  8. import org.apache.logging.log4j.LogManager
  9. import org.apache.logging.log4j.Logger
  10. import javax.annotation.Resource
  11. @SuppressWarnings("unused")
  12. class BE_PlateForm_CodeList implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
  13. protected final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
  14. @Resource(name = "APP_HOME")
  15. private String appHome
  16. private def platformCodeArray = []
  17. @Override
  18. String scriptName() {
  19. return "获取平台编号大全"
  20. }
  21. @Override
  22. ERPModule module() {
  23. return ERPModule.DOC
  24. }
  25. void start(long supplierCode) {
  26. def jsonSlurper = new JsonSlurper()
  27. def platformCodeJsonFile = new File(appHome + File.separator +
  28. "conf" + File.separator +
  29. "script" + File.separator +
  30. supplierCode + File.separator +
  31. "scriptFiles" + File.separator +
  32. "platformCode.json")
  33. platformCodeArray = jsonSlurper.parse(platformCodeJsonFile)
  34. }
  35. @Override
  36. RetResult<InvokeCallResult> execute(InvokeCallParams source) {
  37. //JsonOutput不知道怎么改编码。。。中文用unicode编码输出了,虽然也能用,但log不方便。。。
  38. //查了一下
  39. // https://stackoverflow.com/questions/38569874/how-to-use-groovy-jsonoutput-tojson-with-data-encoded-with-utf-8
  40. // https://docs.groovy-lang.org/latest/html/api/groovy/json/JsonGenerator.Options.html
  41. // new JsonGenerator.Options()
  42. // .disableUnicodeEscaping()
  43. // .build()
  44. // .toJson(platformCodeArray)
  45. String codeJson = JSON.toJSONString(platformCodeArray)// JsonOutput.toJson(platformCodeArray)
  46. logger.info(codeJson)
  47. return RetResult.<InvokeCallResult> successT().result(
  48. InvokeCallResult.success().data(codeJson)
  49. )
  50. }
  51. }