4
0

function.ftl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. <#if field?index_of("_")==-1>
  14. <#assign rtn>${field?lower_case?trim}</#assign>
  15. <#return rtn>
  16. </#if>
  17. <#if field?index_of("F_")==0>
  18. <#assign rtn><#list (field?substring(2))?split("_") as x><#if (x_index==0)><#if x?length==1>${x?upper_case?trim}<#else>${x?lower_case?trim}</#if><#else>${x?lower_case?cap_first?trim}</#if></#list></#assign>
  19. <#return rtn>
  20. </#if>
  21. <#assign rtn><#list field?split("_") as x><#if (x_index==0)><#if x?length==1>${x?upper_case?trim}<#else>${x?lower_case?trim}</#if><#else>${x?lower_case?cap_first?trim}</#if></#list></#assign>
  22. <#return rtn>
  23. </#function>
  24. <#--判断是否有子表-->
  25. <#function hasSubTable model>
  26. <#assign subtables=model.subTableList>
  27. <#assign rtn><#if (subtables?exists && subtables?size!=0)>1<#else>0</#if></#assign>
  28. <#return rtn>
  29. </#function>
  30. <#function getPk model>
  31. <#assign rtn><#if (model.pkModel??) >${model.pkModel.columnName}<#else>id</#if></#assign>
  32. <#return rtn>
  33. </#function>
  34. <#--获取主键类型-->
  35. <#function getPkType model>
  36. <#list model.columnList as col>
  37. <#if col.isPK>
  38. <#if (col.colType=="Integer")><#assign rtn>"Long"</#assign><#return rtn>
  39. <#else><#assign pkType=col.colType ></#if>
  40. </#if>
  41. </#list>
  42. <#assign rtn>${pkType}</#assign>
  43. <#return rtn>
  44. </#function>
  45. <#--获取外键类型 没有则返回Long-->
  46. <#function getFkType model>
  47. <#assign fk=model.foreignKey>
  48. <#list model.columnList as col>
  49. <#if (col.columnName?lower_case)==(fk?lower_case)>
  50. <#if (col.colType=="Integer")><#assign rtn>Long</#assign><#return rtn><#else><#assign rtn>${col.colType}</#assign><#return rtn></#if>
  51. </#if>
  52. </#list>
  53. <#assign rtn>Long</#assign><#return rtn>
  54. </#function>
  55. <#function getPkVar model>
  56. <#assign rtn><#if (model.pkModel??) ><#noparse>${</#noparse>${convertUnderLine(model.pkModel.columnName)}<#noparse>}</#noparse><#else>id</#if></#assign>
  57. <#return rtn>
  58. </#function>
  59. <#function getJdbcType dataType>
  60. <#assign dbtype=dataType?lower_case>
  61. <#assign rtn>
  62. <#if dbtype?ends_with("int") || (dbtype=="double") || (dbtype=="float") || (dbtype=="decimal") || dbtype?ends_with("number")||dbtype?starts_with("numeric") >
  63. NUMERIC
  64. <#elseif (dbtype?index_of("char")>-1) >
  65. VARCHAR
  66. <#elseif (dbtype=="date")>
  67. DATE
  68. <#elseif (dbtype?index_of("timestamp")>-1) || (dbtype=="datetime") >
  69. TIMESTAMP
  70. <#elseif (dbtype?ends_with("text") || dbtype?ends_with("clob")) >
  71. CLOB
  72. </#if></#assign>
  73. <#return rtn?trim>
  74. </#function>
  75. <#--是否为需要排除的列-->
  76. <#function isExcludeField colName>
  77. <#if colName!="createBy" && colName!="createTime" && colName!="updateBy" && colName!="updateTime" && colName!="tenantId" && colName!="createDepId" >
  78. <#return true>
  79. <#else>
  80. <#return false>
  81. </#if>
  82. </#function>
  83. <#function getField col>
  84. <#assign rtn>
  85. <#if (col.colType=="String")><#noparse > <#if </#noparse> ${col.columnName}<#noparse >??>'${</#noparse> ${col.columnName}}'<#noparse ><#else>null</#if></#noparse><#elseif (col.colType=="Integer")><#noparse > <#if </#noparse> ${col.columnName}<#noparse >??>${</#noparse> ${col.columnName}}<#noparse ><#else>null</#if></#noparse><#else><#noparse > <#if </#noparse> ${col.columnName}<#noparse >??>'${</#noparse> ${col.columnName}}'<#noparse ><#else>null</#if></#noparse></#if></#assign>
  86. <#return rtn>
  87. </#function>
  88. <#function replaceContent text>
  89. <#assign rtn>text?replace("\n","\\n")?replace("\"","\\\"")</#assign>
  90. <#return rtn>
  91. </#function>