四零语境后端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
11 KiB

1 month ago
  1. <#---->
  2. <#-- freemarker 的一些工具方法 -->
  3. <#---->
  4. <#-- 驼峰转其他字符 -->
  5. <#-- @param str 待转换的文本 -->
  6. <#-- @param character 要转换成的字符 -->
  7. <#-- @param case 转换大小写(normal 不转换,lower 小写,upper 大写) -->
  8. <#function camelToChar(str, character, case='normal')>
  9. <#assign text=str?replace("([a-z])([A-Z]+)","$1${character}$2","r")/>
  10. <#if case=="upper">
  11. <#return text?upper_case>
  12. <#elseif case=="lower">
  13. <#return text?lower_case>
  14. <#else>
  15. <#return text>
  16. </#if>
  17. </#function>
  18. <#--下划线转驼峰-->
  19. <#function dashedToCamel(str)>
  20. <#assign text=""/>
  21. <#assign strlist = str?split("_")/>
  22. <#list strlist as v>
  23. <#assign text=text+v?cap_first/>
  24. </#list>
  25. <#return text?uncap_first>
  26. </#function>
  27. <#-- 驼峰转下划线 -->
  28. <#function camelToDashed(str, case='lower')>
  29. <#return camelToChar(str, "_", case)>
  30. </#function>
  31. <#---->
  32. <#-- 驼峰转横线 -->
  33. <#function camelToHorizontal(str, case='normal')>
  34. <#return camelToChar(str, "-", case)>
  35. </#function>
  36. <#---->
  37. <#-- 获取 v-model 属性 -->
  38. <#function getVModel po,suffix="">
  39. <#return "v-model=\"queryParam.${po.fieldName}${suffix}\"">
  40. </#function>
  41. <#-- 获取 placeholder 属性 -->
  42. <#function getPlaceholder po,prefix,fillComment=true>
  43. <#if fillComment>
  44. <#return "placeholder=\"${prefix}${po.filedComment}\"">
  45. <#else>
  46. <#return "placeholder=\"${prefix}\"">
  47. </#if>
  48. </#function>
  49. <#-- ** 判断某字段是否配置了校验 * -->
  50. <#function poHasCheck po>
  51. <#if (po.fieldValidType!'')?trim?length gt 0 || po.nullable == 'N'>
  52. <#if po.fieldName != 'id'>
  53. <#if po.nullable == 'N'
  54. || po.fieldValidType == '*'
  55. || po.fieldValidType == 'only'
  56. || po.fieldValidType == 'n6-16'
  57. || po.fieldValidType == '*6-16'
  58. || po.fieldValidType == 's6-18'
  59. || po.fieldValidType == 'url'
  60. || po.fieldValidType == 'e'
  61. || po.fieldValidType == 'm'
  62. || po.fieldValidType == 'p'
  63. || po.fieldValidType == 's'
  64. || po.fieldValidType == 'n'
  65. || po.fieldValidType == 'z'
  66. || po.fieldValidType == 'money'
  67. || po.fieldValidType != ''
  68. >
  69. <#return true>
  70. </#if>
  71. </#if>
  72. </#if>
  73. <#return false>
  74. </#function>
  75. <#-- ** 如果配置了校验就显示 validatorRules * -->
  76. <#function autoWriteRules po>
  77. <#if poHasCheck(po)>
  78. <#return ", validatorRules.${po.fieldName}">
  79. <#else>
  80. <#return "">
  81. </#if>
  82. </#function>
  83. <#-- ** 如果Blob就显示 String * -->
  84. <#function autoStringSuffix po>
  85. <#if po.fieldDbType=='Blob'>
  86. <#return "'${po.fieldName}String'">
  87. <#else>
  88. <#return "'${po.fieldName}'">
  89. </#if>
  90. </#function>
  91. <#-- ** 如果Blob就显示model方式 String * -->
  92. <#function autoStringSuffixForModel po>
  93. <#if po.fieldDbType=='Blob'>
  94. <#return "${po.fieldName}String">
  95. <#else>
  96. <#return "${po.fieldName}">
  97. </#if>
  98. </#function>
  99. <#-- ** 高级查询生成 * -->
  100. <#function superQueryFieldList po>
  101. <#assign superQuery_dictTable="">
  102. <#assign superQuery_dictText="">
  103. <#if po.dictTable?default("")?trim?length gt 1>
  104. <#assign superQuery_dictTable="${po.dictTable}">
  105. </#if>
  106. <#if po.dictText?default("")?trim?length gt 1>
  107. <#assign superQuery_dictText="${po.dictText}">
  108. </#if>
  109. <#if po.classType=="popup">
  110. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}', popup:{code:'${po.dictTable}',field:'${po.dictField?split(',')[0]}',orgFields:'${po.dictField?split(',')[0]}',destFields:'${po.dictText?split(',')[0]}'}}">
  111. <#elseif po.classType=="sel_user" || po.classType=="sel_depart" || po.classType=="datetime" || po.classType=="date" || po.classType=="pca" || po.classType=="switch">
  112. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}'}">
  113. <#else>
  114. <#if po.classType=="sel_search" || po.classType=="list_multi">
  115. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}',dictTable:\"${superQuery_dictTable}\", dictText:'${superQuery_dictText}', dictCode:'${po.dictField}'}">
  116. <#elseif po.dictTable?? && po.dictTable!="" && po.classType!="sel_tree" && po.classType!="cat_tree" && po.classType!="link_down">
  117. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}',dictCode:\"${po.dictTable},${po.dictText},${po.dictField}\"}">
  118. <#elseif po.dictField?? && po.classType!="sel_tree" && po.classType!="cat_tree" && po.classType!="link_down">
  119. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}',dictCode:'${po.dictField}'}">
  120. <#elseif po.fieldDbType=="Text">
  121. <#return "{type:'string',value:'${po.fieldName}',text:'${po.filedComment}'}">
  122. <#elseif po.fieldDbType=="Blob">
  123. <#return "{type:'byte',value:'${po.fieldName}',text:'${po.filedComment}'}">
  124. <#elseif po.fieldDbType=="BigDecimal" || po.fieldDbType=="double">
  125. <#return "{type:'number',value:'${po.fieldName}',text:'${po.filedComment}'}">
  126. <#else>
  127. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}'}">
  128. </#if>
  129. </#if>
  130. </#function>
  131. <#-- update-begin---author:chenrui ---date:20231228 for:[QQYUN-7527]vue3代码生成默认带上高级查询---------- -->
  132. <#-- ** 高级查询生成(Vue3 * -->
  133. <#function superQueryFieldListForVue3(po,order)>
  134. <#-- 字段展示/DB类型 -->
  135. <#assign baseAttrs="view: '${po.classType}', type: 'string',">
  136. <#if po.fieldDbType=='int' || po.fieldDbType=='double' || po.fieldDbType=='BigDecimal'>
  137. <#assign baseAttrs="view: 'number', type: 'number',">
  138. </#if>
  139. <#-- 特殊类型控件扩展字段 -->
  140. <#assign extAttrs="">
  141. <#assign dictCode="">
  142. <#if po.dictTable?default('')?trim?length gt 1 && po.dictText?default('')?trim?length gt 1 && po.dictField?default("")?trim?length gt 1>
  143. <#-- update-begin---author:chenrui ---date:20231228 for:fix 带条件字典存在单引号导致js编译错误---------- -->
  144. <#assign dictCode="dictTable: \"${po.dictTable}\", dictCode: '${po.dictField}', dictText: '${po.dictText}'">
  145. <#-- update-begin---author:chenrui ---date:20231228 for:fix 带条件字典存在单引号导致js编译错误---------- -->
  146. <#elseif po.dictField?default("")?trim?length gt 1>
  147. <#assign dictCode="dictCode: '${po.dictField}'">
  148. <#else>
  149. <#assign dictCode="dictCode: ''">
  150. </#if>
  151. <#if po.classType=='list' || po.classType=='list_multi' || po.classType=='sel_search' || po.classType=='checkbox' || po.classType=='radio'>
  152. <#assign extAttrs="${dictCode},">
  153. <#elseif po.classType=='cat_tree'>
  154. <#-- 分类字典树 -->
  155. <#-- update-begin---author:chenrui ---date:20240109 for:[issue/5787]增加非空判断防止代码生成时空指针异常---------- -->
  156. <#assign extAttrs="pcode: '${po.dictField?default('')}',">
  157. <#-- update-end---author:chenrui ---date:20240109 for:[issue/5787]增加非空判断防止代码生成时空指针异常---------- -->
  158. <#elseif po.classType=='sel_tree'>
  159. <#-- 自定义树 -->
  160. <#if po.dictText??>
  161. <#-- dictText示例:id,pid,name,has_child -->
  162. <#if po.dictText?split(',')[2]?? && po.dictText?split(',')[0]??>
  163. <#assign extAttrs="dict: '${po.dictTable},${po.dictText?split(',')[2]},${po.dictText?split(',')[0]}'">
  164. <#elseif po.dictText?split(',')[1]??>
  165. <#assign extAttrs="pidField: '${po.dictText?split(',')[1]}'">
  166. <#elseif po.dictText?split(',')[3]??>
  167. <#assign extAttrs="hasChildField: '${po.dictText?split(',')[3]}'">
  168. </#if>
  169. </#if>
  170. <#-- update-begin---author:chenrui ---date:20240109 for:[issue/5787]增加非空判断防止代码生成时空指针异常---------- -->
  171. <#assign extAttrs="${extAttrs}, pidValue: '${po.dictField?default('')}',">
  172. <#-- update-end---author:chenrui ---date:20240109 for:[issue/5787]增加非空判断防止代码生成时空指针异常---------- -->
  173. <#elseif po.classType=='popup'>
  174. <#-- popup -->
  175. <#-- update-begin---author:chenrui ---date:20240109 for:[issue/5787]增加非空判断防止代码生成时空指针异常---------- -->
  176. <#if po.dictText?default("")?trim?length gt 1 && po.dictText?index_of(',') gt 0 && po.dictField?default("")?trim?length gt 1>
  177. <#-- update-begin---author:chenrui ---date:20240109 for:[issue/5787]增加非空判断防止代码生成时空指针异常---------- -->
  178. <#-- 如果有多个回填字段,找到popup字段对应的来源字段 -->
  179. <#assign orgFieldIx=po.dictText?split(',')?seq_index_of(po.fieldDbName)>
  180. <#assign orgField=po.dictField?split(',')[orgFieldIx]>
  181. <#else>
  182. <#assign orgField=po.dictField?default("")>
  183. </#if>
  184. <#assign extAttrs="code: '${po.dictTable?default('')}', orgFields: '${orgField}', destFields: '${po.fieldName}', popupMulti: false,">
  185. </#if>
  186. <#return "${po.fieldName}: {title: '${po.filedComment}',order: ${order},${baseAttrs}${extAttrs}}" >
  187. </#function>
  188. <#-- update-end---author:chenrui ---date:20231228 for:[QQYUN-7527]vue3代码生成默认带上高级查询---------- -->
  189. <#-- vue3 获取表单modal的宽度-->
  190. <#function getModalWidth fieldRowNum>
  191. <#assign modal_width = 800>
  192. <#if fieldRowNum==2>
  193. <#assign modal_width = 896>
  194. <#elseif fieldRowNum==3>
  195. <#assign modal_width = 1024>
  196. <#elseif fieldRowNum==4>
  197. <#assign modal_width = 1280>
  198. </#if>
  199. <#return modal_width>
  200. </#function>
  201. <#-- vue3 获取表单 colspan -->
  202. <#function getFormSpan fieldRowNum>
  203. <#assign form_span = 24>
  204. <#if fieldRowNum==2>
  205. <#assign form_span = 12>
  206. <#elseif fieldRowNum==3>
  207. <#assign form_span = 8>
  208. <#elseif fieldRowNum==4>
  209. <#assign form_span = 6>
  210. </#if>
  211. <#return form_span>
  212. </#function>
  213. <#-- vue3 native 判断字段名不是 pidField -->
  214. <#function isNotPidField(tableVo, fieldDbName) >
  215. <#assign flag = true>
  216. <#if tableVo??>
  217. <#if tableVo.extendParams??>
  218. <#if tableVo.extendParams.pidField?default("")?trim == fieldDbName>
  219. <#assign flag = false>
  220. </#if>
  221. </#if>
  222. </#if>
  223. <#return flag>
  224. </#function>
  225. <#-- vue3 native 获取范围字段 -->
  226. <#function getRangeField(columns) >
  227. <#assign rangeField = "">
  228. <#list columns as po>
  229. <#if po.isQuery=='Y'>
  230. <#if po.queryMode=='group'>
  231. <#if po.fieldDbType=='int' || po.fieldDbType=='double' || po.fieldDbType=='BigDecimal' || po.classType=='time' || po.classType=='date' || po.classType=='datetime'>
  232. <#assign rangeField = rangeField + "${po.fieldName},">
  233. </#if>
  234. </#if>
  235. </#if>
  236. </#list>
  237. <#return rangeField>
  238. </#function>