From 1ba5e86262b1925d53ba64ab80e7a50f22959fd6 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期六, 28 五月 2022 09:32:50 +0800
Subject: [PATCH] 新增Anonymous匿名访问不鉴权注解

---
 src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java |   81 ++++++++++++++++++++++++++++++----------
 1 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java b/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java
index 0d05572..6c792ea 100644
--- a/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java
+++ b/src/main/java/com/ruoyi/project/tool/gen/util/VelocityUtils.java
@@ -3,8 +3,10 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import org.apache.velocity.VelocityContext;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.common.constant.GenConstants;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -29,7 +31,7 @@
 
     /**
      * 璁剧疆妯℃澘鍙橀噺淇℃伅
-     * 
+     *
      * @return 妯℃澘鍒楄〃
      */
     public static VelocityContext prepareContext(GenTable genTable)
@@ -58,6 +60,7 @@
         velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
         velocityContext.put("columns", genTable.getColumns());
         velocityContext.put("table", genTable);
+        velocityContext.put("dicts", getDicts(genTable));
         setMenuVelocityContext(velocityContext, genTable);
         if (GenConstants.TPL_TREE.equals(tplCategory))
         {
@@ -73,7 +76,7 @@
     public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
     {
         String options = genTable.getOptions();
-        JSONObject paramsObj = JSONObject.parseObject(options);
+        JSONObject paramsObj = JSON.parseObject(options);
         String parentMenuId = getParentMenuId(paramsObj);
         context.put("parentMenuId", parentMenuId);
     }
@@ -81,7 +84,7 @@
     public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
     {
         String options = genTable.getOptions();
-        JSONObject paramsObj = JSONObject.parseObject(options);
+        JSONObject paramsObj = JSON.parseObject(options);
         String treeCode = getTreecode(paramsObj);
         String treeParentCode = getTreeParentCode(paramsObj);
         String treeName = getTreeName(paramsObj);
@@ -117,9 +120,10 @@
         context.put("subclassName", StringUtils.uncapitalize(subClassName));
         context.put("subImportList", getImportList(genTable.getSubTable()));
     }
+
     /**
      * 鑾峰彇妯℃澘淇℃伅
-     * 
+     *
      * @return 妯℃澘鍒楄〃
      */
     public static List<String> getTemplateList(String tplCategory)
@@ -218,15 +222,14 @@
 
     /**
      * 鑾峰彇鍖呭墠缂�
-     * 
+     *
      * @param packageName 鍖呭悕绉�
      * @return 鍖呭墠缂�鍚嶇О
      */
     public static String getPackagePrefix(String packageName)
     {
         int lastIndex = packageName.lastIndexOf(".");
-        String basePackage = StringUtils.substring(packageName, 0, lastIndex);
-        return basePackage;
+        return StringUtils.substring(packageName, 0, lastIndex);
     }
 
     /**
@@ -260,8 +263,46 @@
     }
 
     /**
-     * 鑾峰彇鏉冮檺鍓嶇紑
+     * 鏍规嵁鍒楃被鍨嬭幏鍙栧瓧鍏哥粍
      * 
+     * @param genTable 涓氬姟琛ㄥ璞�
+     * @return 杩斿洖瀛楀吀缁�
+     */
+    public static String getDicts(GenTable genTable)
+    {
+        List<GenTableColumn> columns = genTable.getColumns();
+        Set<String> dicts = new HashSet<String>();
+        addDicts(dicts, columns);
+        if (StringUtils.isNotNull(genTable.getSubTable()))
+        {
+            List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
+            addDicts(dicts, subColumns);
+        }
+        return StringUtils.join(dicts, ", ");
+    }
+
+    /**
+     * 娣诲姞瀛楀吀鍒楄〃
+     * 
+     * @param dicts 瀛楀吀鍒楄〃
+     * @param columns 鍒楅泦鍚�
+     */
+    public static void addDicts(Set<String> dicts, List<GenTableColumn> columns)
+    {
+        for (GenTableColumn column : columns)
+        {
+            if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
+                    column.getHtmlType(),
+                    new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX }))
+            {
+                dicts.add("'" + column.getDictType() + "'");
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇鏉冮檺鍓嶇紑
+     *
      * @param moduleName 妯″潡鍚嶇О
      * @param businessName 涓氬姟鍚嶇О
      * @return 杩斿洖鏉冮檺鍓嶇紑
@@ -273,8 +314,8 @@
 
     /**
      * 鑾峰彇涓婄骇鑿滃崟ID瀛楁
-     * 
-     * @param options 鐢熸垚鍏朵粬閫夐」
+     *
+     * @param paramsObj 鐢熸垚鍏朵粬閫夐」
      * @return 涓婄骇鑿滃崟ID瀛楁
      */
     public static String getParentMenuId(JSONObject paramsObj)
@@ -289,8 +330,8 @@
 
     /**
      * 鑾峰彇鏍戠紪鐮�
-     * 
-     * @param options 鐢熸垚鍏朵粬閫夐」
+     *
+     * @param paramsObj 鐢熸垚鍏朵粬閫夐」
      * @return 鏍戠紪鐮�
      */
     public static String getTreecode(JSONObject paramsObj)
@@ -304,8 +345,8 @@
 
     /**
      * 鑾峰彇鏍戠埗缂栫爜
-     * 
-     * @param options 鐢熸垚鍏朵粬閫夐」
+     *
+     * @param paramsObj 鐢熸垚鍏朵粬閫夐」
      * @return 鏍戠埗缂栫爜
      */
     public static String getTreeParentCode(JSONObject paramsObj)
@@ -319,8 +360,8 @@
 
     /**
      * 鑾峰彇鏍戝悕绉�
-     * 
-     * @param options 鐢熸垚鍏朵粬閫夐」
+     *
+     * @param paramsObj 鐢熸垚鍏朵粬閫夐」
      * @return 鏍戝悕绉�
      */
     public static String getTreeName(JSONObject paramsObj)
@@ -334,14 +375,14 @@
 
     /**
      * 鑾峰彇闇�瑕佸湪鍝竴鍒椾笂闈㈡樉绀哄睍寮�鎸夐挳
-     * 
+     *
      * @param genTable 涓氬姟琛ㄥ璞�
      * @return 灞曞紑鎸夐挳鍒楀簭鍙�
      */
     public static int getExpandColumn(GenTable genTable)
     {
         String options = genTable.getOptions();
-        JSONObject paramsObj = JSONObject.parseObject(options);
+        JSONObject paramsObj = JSON.parseObject(options);
         String treeName = paramsObj.getString(GenConstants.TREE_NAME);
         int num = 0;
         for (GenTableColumn column : genTable.getColumns())
@@ -358,4 +399,4 @@
         }
         return num;
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.9.3