BE_System_SqlErrorGet.groovy 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import com.sdtool.common.api.BusinessExecutor
  2. import com.sdtool.common.datas.ERPModule
  3. import com.sdtool.common.entity.base.InvokeCallParams
  4. import com.sdtool.common.entity.base.InvokeCallResult
  5. import com.alibaba.fastjson2.JSON
  6. import com.dySweetFishPlugin.sql.dao.OperatorWait
  7. import com.dySweetFishPlugin.sql.dao.TunaDaoService
  8. import com.sweetfish.service.RetResult
  9. import groovy.json.JsonSlurper
  10. import org.apache.commons.lang3.StringUtils
  11. import org.apache.logging.log4j.LogManager
  12. import org.apache.logging.log4j.Logger
  13. import javax.annotation.Resource
  14. @SuppressWarnings("unused")
  15. class BE_System_SqlErrorGet implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
  16. protected final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
  17. @Resource
  18. private TunaDaoService daoService
  19. @Override
  20. String scriptName() {
  21. return "获取错误的SQL数据"
  22. }
  23. @Override
  24. ERPModule module() {
  25. return ERPModule.SYSTEM
  26. }
  27. @Override
  28. OperatorWait getAWait(InvokeCallParams s) {
  29. return OperatorWait.SYNC
  30. }
  31. @Override
  32. boolean needLogin(InvokeCallParams source) {
  33. return true
  34. }
  35. RetResult<InvokeCallResult> execute(InvokeCallParams source) {
  36. def jsonSlurper = new JsonSlurper()
  37. def invokeData = jsonSlurper.parseText(source.params)
  38. String sqlKey = invokeData["errorKey"]
  39. if (StringUtils.isNotBlank(sqlKey)) {
  40. try {
  41. //尝试处理下参数化的sql
  42. String sqlJsonStr = daoService.getErrorSql(sqlKey)
  43. def sqlJson = jsonSlurper.parseText(sqlJsonStr)
  44. sqlJson.successList.each { item ->
  45. item.sql = item.sql.replaceAll('\n', ' ')
  46. item.beans.each { bean ->
  47. bean.each { key, value ->
  48. def replacement = value instanceof String ? "'${value}'" : value.toString()
  49. item.sql = item.sql.replaceAll("(?i)#\\{${key}\\}", replacement)
  50. }
  51. }
  52. }
  53. return RetResult.<InvokeCallResult> successT().result(InvokeCallResult.success().data(JSON.toJSONString(sqlJson)))
  54. } catch (Exception e) {
  55. return RetResult.<InvokeCallResult> successT().result(InvokeCallResult.success().data(daoService.getErrorSql(sqlKey)))
  56. }
  57. } else {
  58. return RetResult.<InvokeCallResult> errorT().retinfo("无效的数据")
  59. }
  60. }
  61. }