function.ftl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <#--获取查询数据类型-->
  2. <#function getDataType colType start>
  3. <#if (colType=="long") > <#return "L">
  4. <#elseif (colType=="int")><#return "N">
  5. <#elseif (colType=="double")><#return "BD">
  6. <#elseif (colType=="Short")><#return "SN">
  7. <#elseif (colType=="Date" && start=="1")><#return "DL">
  8. <#elseif (colType=="Date" && start=="0")><#return "DG">
  9. <#else><#return "SL"></#if>
  10. </#function>
  11. <#--将字符串 user_id 转换为 类似userId-->
  12. <#function convertUnderLine field>
  13. <#assign rtn><#list field?split("_") as x><#if (x_index==0)><#if x?length==1>${x?upper_case}<#else>${x?lower_case}</#if><#else>${x?lower_case?cap_first}</#if></#list></#assign>
  14. <#return rtn>
  15. </#function>
  16. <#function getPk model>
  17. <#assign rtn><#if (model.pkModel??) >${model.pkModel.columnName}<#else>"id"</#if></#assign>
  18. <#return rtn>
  19. </#function>
  20. <#--获取主键类型-->
  21. <#function getPkType model>
  22. <#list model.columnList as col>
  23. <#if col.isPK>
  24. <#if (col.colType=="Integer")><#assign rtn>"Long"</#assign><#return rtn>
  25. <#else><#assign pkType=col.colType ></#if>
  26. </#if>
  27. </#list>
  28. <#assign rtn>${pkType}</#assign>
  29. <#return rtn>
  30. </#function>
  31. <#--获取外键类型 没有则返回Long-->
  32. <#function getFkType model>
  33. <#assign fk=model.foreignKey>
  34. <#list model.columnList as col>
  35. <#if (col.columnName?lower_case)==(fk?lower_case)>
  36. <#if (col.colType=="Integer")><#assign rtn>Long</#assign><#return rtn><#else><#assign rtn>${col.colType}</#assign><#return rtn></#if>
  37. </#if>
  38. </#list>
  39. <#assign rtn>Long</#assign><#return rtn>
  40. </#function>
  41. <#function getPkVar model>
  42. <#assign pkModel=model.pkModel>
  43. <#assign rtn><#if (model.pkModel??) ><#noparse>${</#noparse>${model.pkModel.columnName}<#noparse>}</#noparse><#else>"id"</#if></#assign>
  44. <#return rtn>
  45. </#function>
  46. <#function getJdbcType dataType>
  47. <#assign dbtype=dataType?lower_case>
  48. <#assign rtn>
  49. <#if dbtype?ends_with("int") || (dbtype=="double") || (dbtype=="float") || (dbtype=="decimal") || dbtype?ends_with("number")||dbtype?starts_with("numeric") >
  50. NUMERIC
  51. <#elseif (dbtype?index_of("char")>-1) >
  52. VARCHAR
  53. <#elseif (dbtype=="date") || (dbtype=="datetime") >
  54. DATE
  55. <#elseif (dbtype?index_of("timestamp")>-1)>
  56. TIMESTAMP
  57. <#elseif (dbtype?ends_with("text") || dbtype?ends_with("clob")) >
  58. CLOB
  59. </#if></#assign>
  60. <#return rtn?trim>
  61. </#function>
  62. <#function isSubTableExist subtables>
  63. <#assign rtn=false>
  64. <#if subtables?exists && subtables?size!=0>
  65. <#assign rtn=true>
  66. </#if>
  67. <#return rtn>
  68. </#function>
  69. <#function supportFlow model>
  70. <#assign rtn=false>
  71. <#if model.variables.flowKey?exists>
  72. <#assign rtn=true>
  73. </#if>
  74. <#return rtn>
  75. </#function>
  76. <#function getComment table>
  77. <#assign comment=table.tabComment>
  78. <#if !comment?exists>
  79. <#assign comment=table.tableName>
  80. </#if>
  81. <#return comment>
  82. </#function>
  83. <#-- 解释字段类型 -->
  84. <#function getColType type>
  85. <#if (type=="Integer")>
  86. <#return "Long">
  87. <#elseif type=="java.util.Date"||type=="timestamp">
  88. <#return "Date">
  89. <#else> <#return type>
  90. </#if>
  91. </#function>
  92. <#function getJdbcDataType dataType>
  93. <#assign dbtype=dataType?lower_case>
  94. <#assign rtn>
  95. <#if dbtype?ends_with("int") || (dbtype=="double") || (dbtype=="float") || (dbtype=="decimal") || dbtype?ends_with("number")||dbtype?starts_with("numeric") >
  96. FieldPool.DATATYPE_NUMBER
  97. <#elseif (dbtype?index_of("char")>-1) >
  98. FieldPool.DATATYPE_VARCHAR
  99. <#elseif (dbtype=="date") || (dbtype=="datetime") >
  100. FieldPool.DATATYPE_DATE
  101. <#elseif (dbtype?index_of("timestamp")>-1)>
  102. FieldPool.DATATYPE_DATE
  103. <#elseif (dbtype?ends_with("text") || dbtype?ends_with("clob")) >
  104. FieldPool.DATATYPE_CLOB
  105. </#if></#assign>
  106. <#return rtn?trim>
  107. </#function>