瀏覽代碼

feat:中文汉字转换pinyin接口、初始化默认按钮逻辑、封装按钮权限数据

韩帛霖 1 年之前
父節點
當前提交
12e8a79c38

+ 13 - 1
zkqy-admin/src/main/java/com/zkqy/web/controller/dragForm/DragTableBtnController.java

@@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import com.zkqy.system.entity.DragTableBtn;
 import com.zkqy.system.entity.DragTableBtnRelevance;
+import com.zkqy.system.entity.vo.DragTableBtnDefaultVo;
 import com.zkqy.system.service.IDragTableBtnRelevanceService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -113,6 +114,17 @@ public class DragTableBtnController extends BaseController {
      */
     @GetMapping("/checkBtn")
     public TableDataInfo checkBtn(String btnKey) {
-         return getDataTable(dragTableBtnRelevanceService.selectDragTableBtnRelevanceList(new DragTableBtnRelevance(btnKey)));
+        return getDataTable(
+            dragTableBtnRelevanceService.selectDragTableBtnRelevanceList(new DragTableBtnRelevance(btnKey)));
+    }
+
+    /**
+     * 创建动态表格时默认新增按钮组以及默认操作按钮
+     *
+     * @return
+     */
+    @PostMapping("/insertByDefaultBtn")
+    public AjaxResult insertByDefaultBtn(@RequestBody DragTableBtnDefaultVo dragTableBtnDefaultVo) {
+        return AjaxResult.success(dragTableBtnService.insertByDefaultBtn(dragTableBtnDefaultVo));
     }
 }

+ 6 - 0
zkqy-common/pom.xml

@@ -171,6 +171,12 @@
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.belerweb</groupId>
+            <artifactId>pinyin4j</artifactId>
+            <version>2.5.0</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 223 - 326
zkqy-common/src/main/java/com/zkqy/common/core/text/Convert.java

@@ -6,16 +6,19 @@ import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.text.NumberFormat;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import com.zkqy.common.utils.StringUtils;
 import org.apache.commons.lang3.ArrayUtils;
+import net.sourceforge.pinyin4j.PinyinHelper;
 
 /**
  * 类型转换器
  *
  * @author zkqy
  */
-public class Convert
-{
+public class Convert {
     /**
      * 转换为字符串<br>
      * 如果给定的值为null,或者转换失败,返回默认值<br>
@@ -25,15 +28,12 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static String toStr(Object value, String defaultValue)
-    {
-        if (null == value)
-        {
+    public static String toStr(Object value, String defaultValue) {
+        if (null == value) {
             return defaultValue;
         }
-        if (value instanceof String)
-        {
-            return (String) value;
+        if (value instanceof String) {
+            return (String)value;
         }
         return value.toString();
     }
@@ -46,8 +46,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static String toStr(Object value)
-    {
+    public static String toStr(Object value) {
         return toStr(value, null);
     }
 
@@ -60,15 +59,12 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Character toChar(Object value, Character defaultValue)
-    {
-        if (null == value)
-        {
+    public static Character toChar(Object value, Character defaultValue) {
+        if (null == value) {
             return defaultValue;
         }
-        if (value instanceof Character)
-        {
-            return (Character) value;
+        if (value instanceof Character) {
+            return (Character)value;
         }
 
         final String valueStr = toStr(value, null);
@@ -83,8 +79,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Character toChar(Object value)
-    {
+    public static Character toChar(Object value) {
         return toChar(value, null);
     }
 
@@ -97,31 +92,23 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Byte toByte(Object value, Byte defaultValue)
-    {
-        if (value == null)
-        {
+    public static Byte toByte(Object value, Byte defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Byte)
-        {
-            return (Byte) value;
+        if (value instanceof Byte) {
+            return (Byte)value;
         }
-        if (value instanceof Number)
-        {
-            return ((Number) value).byteValue();
+        if (value instanceof Number) {
+            return ((Number)value).byteValue();
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return Byte.parseByte(valueStr);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -134,8 +121,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Byte toByte(Object value)
-    {
+    public static Byte toByte(Object value) {
         return toByte(value, null);
     }
 
@@ -148,31 +134,23 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Short toShort(Object value, Short defaultValue)
-    {
-        if (value == null)
-        {
+    public static Short toShort(Object value, Short defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Short)
-        {
-            return (Short) value;
+        if (value instanceof Short) {
+            return (Short)value;
         }
-        if (value instanceof Number)
-        {
-            return ((Number) value).shortValue();
+        if (value instanceof Number) {
+            return ((Number)value).shortValue();
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return Short.parseShort(valueStr.trim());
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -185,8 +163,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Short toShort(Object value)
-    {
+    public static Short toShort(Object value) {
         return toShort(value, null);
     }
 
@@ -199,27 +176,20 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Number toNumber(Object value, Number defaultValue)
-    {
-        if (value == null)
-        {
+    public static Number toNumber(Object value, Number defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Number)
-        {
-            return (Number) value;
+        if (value instanceof Number) {
+            return (Number)value;
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return NumberFormat.getInstance().parse(valueStr);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -232,8 +202,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Number toNumber(Object value)
-    {
+    public static Number toNumber(Object value) {
         return toNumber(value, null);
     }
 
@@ -246,31 +215,23 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Integer toInt(Object value, Integer defaultValue)
-    {
-        if (value == null)
-        {
+    public static Integer toInt(Object value, Integer defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Integer)
-        {
-            return (Integer) value;
+        if (value instanceof Integer) {
+            return (Integer)value;
         }
-        if (value instanceof Number)
-        {
-            return ((Number) value).intValue();
+        if (value instanceof Number) {
+            return ((Number)value).intValue();
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return Integer.parseInt(valueStr.trim());
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -283,8 +244,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Integer toInt(Object value)
-    {
+    public static Integer toInt(Object value) {
         return toInt(value, null);
     }
 
@@ -294,8 +254,7 @@ public class Convert
      * @param str 被转换的值
      * @return 结果
      */
-    public static Integer[] toIntArray(String str)
-    {
+    public static Integer[] toIntArray(String str) {
         return toIntArray(",", str);
     }
 
@@ -305,8 +264,7 @@ public class Convert
      * @param str 被转换的值
      * @return 结果
      */
-    public static Long[] toLongArray(String str)
-    {
+    public static Long[] toLongArray(String str) {
         return toLongArray(",", str);
     }
 
@@ -317,16 +275,13 @@ public class Convert
      * @param split 被转换的值
      * @return 结果
      */
-    public static Integer[] toIntArray(String split, String str)
-    {
-        if (StringUtils.isEmpty(str))
-        {
+    public static Integer[] toIntArray(String split, String str) {
+        if (StringUtils.isEmpty(str)) {
             return new Integer[] {};
         }
         String[] arr = str.split(split);
         final Integer[] ints = new Integer[arr.length];
-        for (int i = 0; i < arr.length; i++)
-        {
+        for (int i = 0; i < arr.length; i++) {
             final Integer v = toInt(arr[i], 0);
             ints[i] = v;
         }
@@ -340,16 +295,13 @@ public class Convert
      * @param str 被转换的值
      * @return 结果
      */
-    public static Long[] toLongArray(String split, String str)
-    {
-        if (StringUtils.isEmpty(str))
-        {
+    public static Long[] toLongArray(String split, String str) {
+        if (StringUtils.isEmpty(str)) {
             return new Long[] {};
         }
         String[] arr = str.split(split);
         final Long[] longs = new Long[arr.length];
-        for (int i = 0; i < arr.length; i++)
-        {
+        for (int i = 0; i < arr.length; i++) {
             final Long v = toLong(arr[i], null);
             longs[i] = v;
         }
@@ -362,8 +314,7 @@ public class Convert
      * @param str 被转换的值
      * @return 结果
      */
-    public static String[] toStrArray(String str)
-    {
+    public static String[] toStrArray(String str) {
         return toStrArray(",", str);
     }
 
@@ -374,8 +325,7 @@ public class Convert
      * @param split 被转换的值
      * @return 结果
      */
-    public static String[] toStrArray(String split, String str)
-    {
+    public static String[] toStrArray(String split, String str) {
         return str.split(split);
     }
 
@@ -388,32 +338,24 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Long toLong(Object value, Long defaultValue)
-    {
-        if (value == null)
-        {
+    public static Long toLong(Object value, Long defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Long)
-        {
-            return (Long) value;
+        if (value instanceof Long) {
+            return (Long)value;
         }
-        if (value instanceof Number)
-        {
-            return ((Number) value).longValue();
+        if (value instanceof Number) {
+            return ((Number)value).longValue();
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             // 支持科学计数法
             return new BigDecimal(valueStr.trim()).longValue();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -426,8 +368,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Long toLong(Object value)
-    {
+    public static Long toLong(Object value) {
         return toLong(value, null);
     }
 
@@ -440,32 +381,24 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Double toDouble(Object value, Double defaultValue)
-    {
-        if (value == null)
-        {
+    public static Double toDouble(Object value, Double defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Double)
-        {
-            return (Double) value;
+        if (value instanceof Double) {
+            return (Double)value;
         }
-        if (value instanceof Number)
-        {
-            return ((Number) value).doubleValue();
+        if (value instanceof Number) {
+            return ((Number)value).doubleValue();
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             // 支持科学计数法
             return new BigDecimal(valueStr.trim()).doubleValue();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -478,8 +411,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Double toDouble(Object value)
-    {
+    public static Double toDouble(Object value) {
         return toDouble(value, null);
     }
 
@@ -492,31 +424,23 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Float toFloat(Object value, Float defaultValue)
-    {
-        if (value == null)
-        {
+    public static Float toFloat(Object value, Float defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Float)
-        {
-            return (Float) value;
+        if (value instanceof Float) {
+            return (Float)value;
         }
-        if (value instanceof Number)
-        {
-            return ((Number) value).floatValue();
+        if (value instanceof Number) {
+            return ((Number)value).floatValue();
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return Float.parseFloat(valueStr.trim());
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -529,8 +453,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Float toFloat(Object value)
-    {
+    public static Float toFloat(Object value) {
         return toFloat(value, null);
     }
 
@@ -543,24 +466,19 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static Boolean toBool(Object value, Boolean defaultValue)
-    {
-        if (value == null)
-        {
+    public static Boolean toBool(Object value, Boolean defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof Boolean)
-        {
-            return (Boolean) value;
+        if (value instanceof Boolean) {
+            return (Boolean)value;
         }
         String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
         valueStr = valueStr.trim().toLowerCase();
-        switch (valueStr)
-        {
+        switch (valueStr) {
             case "true":
             case "yes":
             case "ok":
@@ -583,8 +501,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static Boolean toBool(Object value)
-    {
+    public static Boolean toBool(Object value) {
         return toBool(value, null);
     }
 
@@ -597,29 +514,22 @@ public class Convert
      * @param defaultValue 默认值
      * @return Enum
      */
-    public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue)
-    {
-        if (value == null)
-        {
+    public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (clazz.isAssignableFrom(value.getClass()))
-        {
+        if (clazz.isAssignableFrom(value.getClass())) {
             @SuppressWarnings("unchecked")
-            E myE = (E) value;
+            E myE = (E)value;
             return myE;
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return Enum.valueOf(clazz, valueStr);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -632,8 +542,7 @@ public class Convert
      * @param value 值
      * @return Enum
      */
-    public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value)
-    {
+    public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) {
         return toEnum(clazz, value, null);
     }
 
@@ -646,31 +555,23 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static BigInteger toBigInteger(Object value, BigInteger defaultValue)
-    {
-        if (value == null)
-        {
+    public static BigInteger toBigInteger(Object value, BigInteger defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof BigInteger)
-        {
-            return (BigInteger) value;
+        if (value instanceof BigInteger) {
+            return (BigInteger)value;
         }
-        if (value instanceof Long)
-        {
-            return BigInteger.valueOf((Long) value);
+        if (value instanceof Long) {
+            return BigInteger.valueOf((Long)value);
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return new BigInteger(valueStr);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -683,8 +584,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static BigInteger toBigInteger(Object value)
-    {
+    public static BigInteger toBigInteger(Object value) {
         return toBigInteger(value, null);
     }
 
@@ -697,39 +597,29 @@ public class Convert
      * @param defaultValue 转换错误时的默认值
      * @return 结果
      */
-    public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue)
-    {
-        if (value == null)
-        {
+    public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) {
+        if (value == null) {
             return defaultValue;
         }
-        if (value instanceof BigDecimal)
-        {
-            return (BigDecimal) value;
+        if (value instanceof BigDecimal) {
+            return (BigDecimal)value;
         }
-        if (value instanceof Long)
-        {
-            return new BigDecimal((Long) value);
+        if (value instanceof Long) {
+            return new BigDecimal((Long)value);
         }
-        if (value instanceof Double)
-        {
-            return BigDecimal.valueOf((Double) value);
+        if (value instanceof Double) {
+            return BigDecimal.valueOf((Double)value);
         }
-        if (value instanceof Integer)
-        {
-            return new BigDecimal((Integer) value);
+        if (value instanceof Integer) {
+            return new BigDecimal((Integer)value);
         }
         final String valueStr = toStr(value, null);
-        if (StringUtils.isEmpty(valueStr))
-        {
+        if (StringUtils.isEmpty(valueStr)) {
             return defaultValue;
         }
-        try
-        {
+        try {
             return new BigDecimal(valueStr);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             return defaultValue;
         }
     }
@@ -742,8 +632,7 @@ public class Convert
      * @param value 被转换的值
      * @return 结果
      */
-    public static BigDecimal toBigDecimal(Object value)
-    {
+    public static BigDecimal toBigDecimal(Object value) {
         return toBigDecimal(value, null);
     }
 
@@ -754,8 +643,7 @@ public class Convert
      * @param obj 对象
      * @return 字符串
      */
-    public static String utf8Str(Object obj)
-    {
+    public static String utf8Str(Object obj) {
         return str(obj, CharsetKit.CHARSET_UTF_8);
     }
 
@@ -767,8 +655,7 @@ public class Convert
      * @param charsetName 字符集
      * @return 字符串
      */
-    public static String str(Object obj, String charsetName)
-    {
+    public static String str(Object obj, String charsetName) {
         return str(obj, Charset.forName(charsetName));
     }
 
@@ -780,29 +667,20 @@ public class Convert
      * @param charset 字符集
      * @return 字符串
      */
-    public static String str(Object obj, Charset charset)
-    {
-        if (null == obj)
-        {
+    public static String str(Object obj, Charset charset) {
+        if (null == obj) {
             return null;
         }
 
-        if (obj instanceof String)
-        {
-            return (String) obj;
-        }
-        else if (obj instanceof byte[])
-        {
-            return str((byte[]) obj, charset);
-        }
-        else if (obj instanceof Byte[])
-        {
-            byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj);
+        if (obj instanceof String) {
+            return (String)obj;
+        } else if (obj instanceof byte[]) {
+            return str((byte[])obj, charset);
+        } else if (obj instanceof Byte[]) {
+            byte[] bytes = ArrayUtils.toPrimitive((Byte[])obj);
             return str(bytes, charset);
-        }
-        else if (obj instanceof ByteBuffer)
-        {
-            return str((ByteBuffer) obj, charset);
+        } else if (obj instanceof ByteBuffer) {
+            return str((ByteBuffer)obj, charset);
         }
         return obj.toString();
     }
@@ -814,8 +692,7 @@ public class Convert
      * @param charset 字符集
      * @return 字符串
      */
-    public static String str(byte[] bytes, String charset)
-    {
+    public static String str(byte[] bytes, String charset) {
         return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset));
     }
 
@@ -826,15 +703,12 @@ public class Convert
      * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
      * @return 解码后的字符串
      */
-    public static String str(byte[] data, Charset charset)
-    {
-        if (data == null)
-        {
+    public static String str(byte[] data, Charset charset) {
+        if (data == null) {
             return null;
         }
 
-        if (null == charset)
-        {
+        if (null == charset) {
             return new String(data);
         }
         return new String(data, charset);
@@ -847,10 +721,8 @@ public class Convert
      * @param charset 字符集,如果为空使用当前系统字符集
      * @return 字符串
      */
-    public static String str(ByteBuffer data, String charset)
-    {
-        if (data == null)
-        {
+    public static String str(ByteBuffer data, String charset) {
+        if (data == null) {
             return null;
         }
 
@@ -864,10 +736,8 @@ public class Convert
      * @param charset 字符集,如果为空使用当前系统字符集
      * @return 字符串
      */
-    public static String str(ByteBuffer data, Charset charset)
-    {
-        if (null == charset)
-        {
+    public static String str(ByteBuffer data, Charset charset) {
+        if (null == charset) {
             charset = Charset.defaultCharset();
         }
         return charset.decode(data).toString();
@@ -880,8 +750,7 @@ public class Convert
      * @param input String.
      * @return 全角字符串.
      */
-    public static String toSBC(String input)
-    {
+    public static String toSBC(String input) {
         return toSBC(input, null);
     }
 
@@ -892,24 +761,18 @@ public class Convert
      * @param notConvertSet 不替换的字符集合
      * @return 全角字符串.
      */
-    public static String toSBC(String input, Set<Character> notConvertSet)
-    {
+    public static String toSBC(String input, Set<Character> notConvertSet) {
         char[] c = input.toCharArray();
-        for (int i = 0; i < c.length; i++)
-        {
-            if (null != notConvertSet && notConvertSet.contains(c[i]))
-            {
+        for (int i = 0; i < c.length; i++) {
+            if (null != notConvertSet && notConvertSet.contains(c[i])) {
                 // 跳过不替换的字符
                 continue;
             }
 
-            if (c[i] == ' ')
-            {
+            if (c[i] == ' ') {
                 c[i] = '\u3000';
-            }
-            else if (c[i] < '\177')
-            {
-                c[i] = (char) (c[i] + 65248);
+            } else if (c[i] < '\177') {
+                c[i] = (char)(c[i] + 65248);
 
             }
         }
@@ -922,8 +785,7 @@ public class Convert
      * @param input String.
      * @return 半角字符串
      */
-    public static String toDBC(String input)
-    {
+    public static String toDBC(String input) {
         return toDBC(input, null);
     }
 
@@ -934,24 +796,18 @@ public class Convert
      * @param notConvertSet 不替换的字符集合
      * @return 替换后的字符
      */
-    public static String toDBC(String text, Set<Character> notConvertSet)
-    {
+    public static String toDBC(String text, Set<Character> notConvertSet) {
         char[] c = text.toCharArray();
-        for (int i = 0; i < c.length; i++)
-        {
-            if (null != notConvertSet && notConvertSet.contains(c[i]))
-            {
+        for (int i = 0; i < c.length; i++) {
+            if (null != notConvertSet && notConvertSet.contains(c[i])) {
                 // 跳过不替换的字符
                 continue;
             }
 
-            if (c[i] == '\u3000')
-            {
+            if (c[i] == '\u3000') {
                 c[i] = ' ';
-            }
-            else if (c[i] > '\uFF00' && c[i] < '\uFF5F')
-            {
-                c[i] = (char) (c[i] - 65248);
+            } else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
+                c[i] = (char)(c[i] - 65248);
             }
         }
         String returnString = new String(c);
@@ -965,36 +821,77 @@ public class Convert
      * @param n 数字
      * @return 中文大写数字
      */
-    public static String digitUppercase(double n)
-    {
-        String[] fraction = { "角", "分" };
-        String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
-        String[][] unit = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } };
+    public static String digitUppercase(double n) {
+        String[] fraction = {"角", "分"};
+        String[] digit = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
+        String[][] unit = {{"元", "万", "亿"}, {"", "拾", "佰", "仟"}};
 
         String head = n < 0 ? "负" : "";
         n = Math.abs(n);
 
         String s = "";
-        for (int i = 0; i < fraction.length; i++)
-        {
-            s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
+        for (int i = 0; i < fraction.length; i++) {
+            s += (digit[(int)(Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
         }
-        if (s.length() < 1)
-        {
+        if (s.length() < 1) {
             s = "整";
         }
-        int integerPart = (int) Math.floor(n);
+        int integerPart = (int)Math.floor(n);
 
-        for (int i = 0; i < unit[0].length && integerPart > 0; i++)
-        {
+        for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
             String p = "";
-            for (int j = 0; j < unit[1].length && n > 0; j++)
-            {
+            for (int j = 0; j < unit[1].length && n > 0; j++) {
                 p = digit[integerPart % 10] + unit[1][j] + p;
                 integerPart = integerPart / 10;
             }
             s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
         }
-        return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
+        return head
+            + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
+    }
+
+    /**
+     * 中文汉字转换pinyin
+     * 
+     * @param chineseWithLabels 需要转换的参数
+     * @return
+     */
+    public static String toInitials(String chineseWithLabels) {
+        StringBuilder sb = new StringBuilder();
+        // 使用正则表达式匹配汉字
+        Pattern pattern = Pattern.compile("[\\u4E00-\\u9FA5]+");
+        Matcher matcher = pattern.matcher(chineseWithLabels);
+
+        int lastMatchEnd = 0; // 上一个匹配结束的位置
+        while (matcher.find()) {
+            // 添加上一个匹配结束位置到当前匹配开始位置之间的非汉字字符到结果字符串
+            String nonChinesePart = chineseWithLabels.substring(lastMatchEnd, matcher.start());
+            sb.append(nonChinesePart);
+
+            // 将当前匹配到的汉字转换为拼音缩写并添加到结果字符串
+            String chinese = matcher.group();
+            String pinyinAbbreviation = getPinyinAbbreviation(chinese);
+            sb.append(pinyinAbbreviation);
+
+            // 更新上一个匹配结束的位置
+            lastMatchEnd = matcher.end();
+        }
+
+        // 添加最后一个匹配结束位置到字符串末尾之间的非汉字字符到结果字符串
+        String remainingNonChinesePart = chineseWithLabels.substring(lastMatchEnd);
+        sb.append(remainingNonChinesePart);
+
+        return sb.toString();
+    }
+
+    private static String getPinyinAbbreviation(String chinese) {
+        StringBuilder sb = new StringBuilder();
+        for (char c : chinese.toCharArray()) {
+            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
+            if (pinyinArray != null) {
+                sb.append(pinyinArray[0].charAt(0));
+            }
+        }
+        return sb.toString();
     }
 }

+ 5 - 0
zkqy-system/pom.xml

@@ -22,6 +22,11 @@
             <groupId>com.zkqy</groupId>
             <artifactId>zkqy-common</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.belerweb</groupId>
+            <artifactId>pinyin4j</artifactId>
+            <version>2.5.0</version>
+        </dependency>
 
     </dependencies>
 

+ 14 - 0
zkqy-system/src/main/java/com/zkqy/system/entity/DragTableBtn.java

@@ -41,6 +41,12 @@ public class DragTableBtn extends BaseEntity {
      */
     private String btnGroupName;
 
+    /**
+     * 按钮组类型
+     */
+
+    private String btnGroupType;
+
     /**
      * 按钮名称
      */
@@ -317,6 +323,14 @@ public class DragTableBtn extends BaseEntity {
         this.btnFormType = btnFormType;
     }
 
+    public String getbtnGroupType() {
+        return btnGroupType;
+    }
+
+    public void setbtnGroupType(String btnGroupType) {
+        this.btnGroupType = btnGroupType;
+    }
+
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder("DragTableBtn{");

+ 55 - 0
zkqy-system/src/main/java/com/zkqy/system/entity/vo/DragTableBtnDefaultVo.java

@@ -0,0 +1,55 @@
+package com.zkqy.system.entity.vo;
+
+import com.zkqy.system.entity.DragTableBtn;
+
+/**
+ * @author hanzihang
+ * @date 2024/3/29 4:59 PM
+ */
+public class DragTableBtnDefaultVo {
+    private String tableKey;
+    private String hasPermiName;
+    private String menuID;
+    private DragTableBtn dragTableBtnTop;
+    private DragTableBtn dragTableBtnRight;
+
+    public String getTableKey() {
+        return tableKey;
+    }
+
+    public void setTableKey(String tableKey) {
+        this.tableKey = tableKey;
+    }
+
+    public String getHasPermiName() {
+        return hasPermiName;
+    }
+
+    public void setHasPermiName(String hasPermiName) {
+        this.hasPermiName = hasPermiName;
+    }
+
+    public String getMenuID() {
+        return menuID;
+    }
+
+    public void setMenuID(String menuID) {
+        this.menuID = menuID;
+    }
+
+    public DragTableBtn getDragTableBtnTop() {
+        return dragTableBtnTop;
+    }
+
+    public void setDragTableBtnTop(DragTableBtn dragTableBtnTop) {
+        this.dragTableBtnTop = dragTableBtnTop;
+    }
+
+    public DragTableBtn getDragTableBtnRight() {
+        return dragTableBtnRight;
+    }
+
+    public void setDragTableBtnRight(DragTableBtn dragTableBtnRight) {
+        this.dragTableBtnRight = dragTableBtnRight;
+    }
+}

+ 9 - 2
zkqy-system/src/main/java/com/zkqy/system/mapper/DragTableBtnMapper.java

@@ -10,8 +10,7 @@ import java.util.List;
  * @author zkqy
  * @date 2023-11-07
  */
-public interface DragTableBtnMapper 
-{
+public interface DragTableBtnMapper {
     /**
      * 查询格绑定的自定义按钮
      * 
@@ -85,4 +84,12 @@ public interface DragTableBtnMapper
      * @return 格绑定的自定义按钮
      */
     DragTableBtn selectDragTableBtnByBtnKey(String btnKey);
+
+    /**
+     * 批量新增默认按钮(特定列数据)
+     * 
+     * @param dragTableBtnList
+     * @return
+     */
+    int insertDragTableBtnList(List<DragTableBtn> dragTableBtnList);
 }

+ 11 - 2
zkqy-system/src/main/java/com/zkqy/system/service/IDragTableBtnService.java

@@ -1,8 +1,10 @@
 package com.zkqy.system.service;
 
 import com.zkqy.system.entity.DragTableBtn;
+import com.zkqy.system.entity.vo.DragTableBtnDefaultVo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 格绑定的自定义按钮Service接口
@@ -10,8 +12,7 @@ import java.util.List;
  * @author zkqy
  * @date 2023-11-07
  */
-public interface IDragTableBtnService 
-{
+public interface IDragTableBtnService {
     /**
      * 查询格绑定的自定义按钮
      * 
@@ -75,4 +76,12 @@ public interface IDragTableBtnService
      * @return 格绑定的自定义按钮
      */
     DragTableBtn selectDragTableBtnByBtnKey(String btnKey);
+
+    /**
+     * 新增动态表格时初始化按钮
+     * 
+     * @param dragTableBtnDefaultVo
+     * @return 返回初始化菜单权限所需数据
+     */
+    List<Map<String, Object>> insertByDefaultBtn(DragTableBtnDefaultVo dragTableBtnDefaultVo);
 }

+ 123 - 58
zkqy-system/src/main/java/com/zkqy/system/service/impl/DragTableBtnServiceImpl.java

@@ -1,13 +1,15 @@
 package com.zkqy.system.service.impl;
 
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
+import com.zkqy.common.core.text.Convert;
 import com.zkqy.common.utils.DateUtils;
 import com.zkqy.common.utils.SecurityUtils;
+import com.zkqy.common.utils.uuid.IdUtils;
 import com.zkqy.system.entity.DragTableBtn;
 import com.zkqy.system.entity.DragTableBtnRelevance;
+import com.zkqy.system.entity.vo.DragTableBtnDefaultVo;
 import com.zkqy.system.mapper.DragTableBtnRelevanceMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -22,8 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
  * @date 2023-11-07
  */
 @Service
-public class DragTableBtnServiceImpl implements IDragTableBtnService 
-{
+public class DragTableBtnServiceImpl implements IDragTableBtnService {
     @Autowired
     private DragTableBtnMapper dragTableBtnMapper;
 
@@ -37,8 +38,7 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
      * @return 格绑定的自定义按钮
      */
     @Override
-    public DragTableBtn selectDragTableBtnById(Long id)
-    {
+    public DragTableBtn selectDragTableBtnById(Long id) {
         return dragTableBtnMapper.selectDragTableBtnById(id);
     }
 
@@ -49,25 +49,26 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
      * @return 格绑定的自定义按钮
      */
     @Override
-    public List<DragTableBtn> selectDragTableBtnList(DragTableBtn dragTableBtn)
-    {
+    public List<DragTableBtn> selectDragTableBtnList(DragTableBtn dragTableBtn) {
         // 根据分页得到根节点数据
         List<DragTableBtn> rootNodes = dragTableBtnMapper.selectDragTableBtnList(dragTableBtn);
-        //给已经绑定的按钮添加标识
-        List<DragTableBtnRelevance> dragTableBtnRelevanceList = dragTableBtnRelevanceMapper.selectDragTableBtnRelevanceList(new DragTableBtnRelevance());
-        List<String> btnKeys = dragTableBtnRelevanceList.stream().map(DragTableBtnRelevance::getBtnKey).collect(Collectors.toList());
-        for (DragTableBtn r: rootNodes){
-            if(btnKeys.contains(r.getBtnKey())){
+        // 给已经绑定的按钮添加标识
+        List<DragTableBtnRelevance> dragTableBtnRelevanceList =
+            dragTableBtnRelevanceMapper.selectDragTableBtnRelevanceList(new DragTableBtnRelevance());
+        List<String> btnKeys =
+            dragTableBtnRelevanceList.stream().map(DragTableBtnRelevance::getBtnKey).collect(Collectors.toList());
+        for (DragTableBtn r : rootNodes) {
+            if (btnKeys.contains(r.getBtnKey())) {
                 r.setWhetherBind(true);
             }
         }
-        //查询子节点
+        // 查询子节点
         List<Long> ids = rootNodes.stream().map(m -> m.getId()).collect(Collectors.toList());
-        if (ids.isEmpty()){
+        if (ids.isEmpty()) {
             return rootNodes;
         }
         List<DragTableBtn> childNodes = dragTableBtnMapper.selectChildNodeById(ids);
-        //递归处理树结构
+        // 递归处理树结构
         for (DragTableBtn root : rootNodes) {
             List<DragTableBtn> children = getChildrenList(root, childNodes);
             root.setChildren(children);
@@ -77,9 +78,9 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
 
     private List<DragTableBtn> getChildrenList(DragTableBtn root, List<DragTableBtn> childNodes) {
         List<DragTableBtn> list = childNodes.stream().filter(dragTableBtn ->
-                //筛选出下一节点元素
-                Objects.equals(dragTableBtn.getBtnParentId(), root.getId())).map(dragTableBtn -> {
-            //递归set子节点
+        // 筛选出下一节点元素
+        Objects.equals(dragTableBtn.getBtnParentId(), root.getId())).map(dragTableBtn -> {
+            // 递归set子节点
             dragTableBtn.setChildren(this.getChildrenList(dragTableBtn, childNodes));
             return dragTableBtn;
         }).collect(Collectors.toList());
@@ -88,44 +89,47 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
 
     @Override
     @Transactional
-    public int insertDragTableBtn(DragTableBtn dragTableBtn){
+    public int insertDragTableBtn(DragTableBtn dragTableBtn) {
         dragTableBtn.setCreateById(SecurityUtils.getUserId());
         dragTableBtn.setCreateBy(SecurityUtils.getUsername());
         dragTableBtn.setCreateTime(DateUtils.getNowDate());
-        if(dragTableBtn.getBtnParentId() == 0L){
+        if (dragTableBtn.getBtnParentId() == 0L) {
             dragTableBtn.setAncestorsId("0");
-        }else {
-            dragTableBtn.setAncestorsId(dragTableBtnMapper.selectDragTableBtnById(dragTableBtn.getBtnParentId()).getAncestorsId()+","+dragTableBtn.getBtnParentId());
+        } else {
+            dragTableBtn.setAncestorsId(
+                dragTableBtnMapper.selectDragTableBtnById(dragTableBtn.getBtnParentId()).getAncestorsId() + ","
+                    + dragTableBtn.getBtnParentId());
         }
         return dragTableBtnMapper.insertDragTableBtn(dragTableBtn);
     }
 
-//    @Override
-//    @Transactional
-//    public void insertDragTableBtn(List<DragTableBtn> dragTableBtnList)
-//    {
-//        List<DragTableBtn> list = new ArrayList<>();
-//        list = dragTableBtnList.stream().filter(dragTableBtn -> 0L == dragTableBtn.getBtnParentId()).collect(Collectors.toList());
-//        //循环遍历数据新增
-//        for (int i = 0; i < list.size(); i++){
-//            printTree(list.get(i),0L);
-//        }
-//    }
-//    //新增动态表格自定义按钮
-//    public void printTree(DragTableBtn dragTableBtn, Long parentId) {
-//        if (dragTableBtn == null) {
-//            return;
-//        }
-//        //add按钮
-//        dragTableBtn.setCreateBy(SecurityUtils.getUsername());
-//        dragTableBtn.setCreateById(SecurityUtils.getUserId());
-//        dragTableBtn.setCreateTime(DateUtils.getNowDate());
-//        dragTableBtn.setBtnParentId(parentId);
-//        dragTableBtnMapper.insertDragTableBtn(dragTableBtn);
-//        for (DragTableBtn child : dragTableBtn.getChildren()) {  // 遍历子节点
-//            printTree(child,dragTableBtn.getId());  // 递归调用
-//        }
-//    }
+    // @Override
+    // @Transactional
+    // public void insertDragTableBtn(List<DragTableBtn> dragTableBtnList)
+    // {
+    // List<DragTableBtn> list = new ArrayList<>();
+    // list = dragTableBtnList.stream().filter(dragTableBtn -> 0L ==
+    // dragTableBtn.getBtnParentId()).collect(Collectors.toList());
+    // //循环遍历数据新增
+    // for (int i = 0; i < list.size(); i++){
+    // printTree(list.get(i),0L);
+    // }
+    // }
+    // //新增动态表格自定义按钮
+    // public void printTree(DragTableBtn dragTableBtn, Long parentId) {
+    // if (dragTableBtn == null) {
+    // return;
+    // }
+    // //add按钮
+    // dragTableBtn.setCreateBy(SecurityUtils.getUsername());
+    // dragTableBtn.setCreateById(SecurityUtils.getUserId());
+    // dragTableBtn.setCreateTime(DateUtils.getNowDate());
+    // dragTableBtn.setBtnParentId(parentId);
+    // dragTableBtnMapper.insertDragTableBtn(dragTableBtn);
+    // for (DragTableBtn child : dragTableBtn.getChildren()) { // 遍历子节点
+    // printTree(child,dragTableBtn.getId()); // 递归调用
+    // }
+    // }
 
     /**
      * 修改格绑定的自定义按钮
@@ -134,15 +138,16 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
      * @return 结果
      */
     @Override
-    public int updateDragTableBtn(DragTableBtn dragTableBtn)
-    {
+    public int updateDragTableBtn(DragTableBtn dragTableBtn) {
         dragTableBtn.setUpdateById(SecurityUtils.getUserId());
         dragTableBtn.setUpdateBy(SecurityUtils.getUsername());
         dragTableBtn.setUpdateTime(DateUtils.getNowDate());
-        if(dragTableBtn.getBtnParentId() == 0L){
+        if (dragTableBtn.getBtnParentId() == 0L) {
             dragTableBtn.setAncestorsId("0");
-        }else {
-            dragTableBtn.setAncestorsId(dragTableBtnMapper.selectDragTableBtnById(dragTableBtn.getBtnParentId()).getAncestorsId()+","+dragTableBtn.getBtnParentId());
+        } else {
+            dragTableBtn.setAncestorsId(
+                dragTableBtnMapper.selectDragTableBtnById(dragTableBtn.getBtnParentId()).getAncestorsId() + ","
+                    + dragTableBtn.getBtnParentId());
         }
         return dragTableBtnMapper.updateDragTableBtn(dragTableBtn);
     }
@@ -154,8 +159,7 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
      * @return 结果
      */
     @Override
-    public int batchDeleteDragTableBtnByBtnKeys(List<String> btnKeys)
-    {
+    public int batchDeleteDragTableBtnByBtnKeys(List<String> btnKeys) {
         return dragTableBtnMapper.batchDeleteDragTableBtnByBtnKeys(btnKeys);
     }
 
@@ -166,8 +170,7 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
      * @return 结果
      */
     @Override
-    public int deleteDragTableBtnById(Long id)
-    {
+    public int deleteDragTableBtnById(Long id) {
         return dragTableBtnMapper.deleteDragTableBtnById(id);
     }
 
@@ -180,4 +183,66 @@ public class DragTableBtnServiceImpl implements IDragTableBtnService
     public DragTableBtn selectDragTableBtnByBtnKey(String btnKey) {
         return dragTableBtnMapper.selectDragTableBtnByBtnKey(btnKey);
     }
+
+    @Override
+    public List<Map<String, Object>> insertByDefaultBtn(DragTableBtnDefaultVo dragTableBtnDefaultVo) {
+        // 主要权限字符
+        String hasPermi = Convert.toInitials(dragTableBtnDefaultVo.getHasPermiName()) + ":";
+        // 初始化按钮组名称
+        String btnGroupName = dragTableBtnDefaultVo.getHasPermiName()
+            .substring(dragTableBtnDefaultVo.getHasPermiName().indexOf(";") + 1).replace(":", "-");
+
+        dragTableBtnDefaultVo.getDragTableBtnTop().setBtnGroupName(btnGroupName);
+        dragTableBtnDefaultVo.getDragTableBtnTop().setBtnTableKey(dragTableBtnDefaultVo.getTableKey());
+        dragTableBtnDefaultVo.getDragTableBtnTop().setBtnKey(IdUtils.fastUUID());
+
+        // 初始化默认按钮
+        dragTableBtnMapper.insertDragTableBtn(dragTableBtnDefaultVo.getDragTableBtnTop());
+        Long topId = dragTableBtnDefaultVo.getDragTableBtnTop().getId();
+        dragTableBtnDefaultVo.getDragTableBtnTop().getChildren().forEach(item -> {
+            item.setBtnParentId(topId);
+            item.setBtnHasPermi(hasPermi + item.getBtnType());
+            item.setAncestorsId("0" + "," + topId);
+            item.setBtnKey(IdUtils.fastUUID());
+        });
+        dragTableBtnMapper.insertDragTableBtnList(dragTableBtnDefaultVo.getDragTableBtnTop().getChildren());
+
+        dragTableBtnDefaultVo.getDragTableBtnRight().setBtnGroupName(btnGroupName);
+        dragTableBtnDefaultVo.getDragTableBtnRight().setBtnTableKey(dragTableBtnDefaultVo.getTableKey());
+        dragTableBtnDefaultVo.getDragTableBtnRight().setBtnKey(IdUtils.fastUUID());
+        dragTableBtnMapper.insertDragTableBtn(dragTableBtnDefaultVo.getDragTableBtnRight());
+        Long rightId = dragTableBtnDefaultVo.getDragTableBtnRight().getId();
+        dragTableBtnDefaultVo.getDragTableBtnRight().getChildren().forEach(item -> {
+            item.setBtnParentId(rightId);
+            item.setBtnHasPermi(hasPermi + item.getBtnType());
+            item.setAncestorsId("0" + "," + rightId);
+            item.setBtnKey(IdUtils.fastUUID());
+        });
+        dragTableBtnMapper.insertDragTableBtnList(dragTableBtnDefaultVo.getDragTableBtnRight().getChildren());
+
+        // 新增绑定关系
+        List<DragTableBtnRelevance> dragTableBtnRelevanceList = new ArrayList<>();
+        dragTableBtnRelevanceList.add(new DragTableBtnRelevance(dragTableBtnDefaultVo.getTableKey(),
+            dragTableBtnDefaultVo.getDragTableBtnTop().getBtnKey()));
+        dragTableBtnRelevanceList.add(new DragTableBtnRelevance(dragTableBtnDefaultVo.getTableKey(),
+            dragTableBtnDefaultVo.getDragTableBtnRight().getBtnKey()));
+        dragTableBtnRelevanceMapper.batchInsertDragTableBtnRelevance(dragTableBtnRelevanceList);
+
+        // 初始化菜单权限 初始化菜单 返回前端初始化菜单所需数据结构
+        List<Map<String, Object>> menuPermsList = new ArrayList<>();
+        dragTableBtnDefaultVo.getDragTableBtnTop().getChildren().forEach(item -> {
+            Map<String, Object> menuPers = new HashMap<>();
+            menuPers.put("perms", item.getBtnHasPermi()); // 权限字符
+            menuPers.put("menuName", item.getBtnName()); // 名称
+            menuPers.put("parentId", dragTableBtnDefaultVo.getMenuID()); // 父级ID
+            menuPers.put("orderNum", item.getBtnSort()); // 顺序
+            menuPers.put("menuType", "F"); // 类型(M目录 C菜单 F按钮)
+            menuPers.put("isFrame", "1"); // 类型(M目录 C菜单 F按钮)
+            menuPers.put("isCache", "0"); // 是否缓存(0缓存 1不缓存)
+            menuPers.put("visible", "0"); // 显示状态(0显示 1隐藏)
+            menuPers.put("status", "0"); // 菜单状态(0正常 1停用)
+            menuPermsList.add(menuPers);
+        });
+        return menuPermsList;
+    }
 }

+ 129 - 33
zkqy-system/src/main/resources/mapper/dragmapper/DragTableBtnMapper.xml

@@ -1,42 +1,71 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zkqy.system.mapper.DragTableBtnMapper">
 
     <resultMap type="com.zkqy.system.entity.DragTableBtn" id="DragTableBtnResult">
-        <result property="id"    column="id"    />
-        <result property="btnParentId"    column="btn_parent_id"    />
-        <result property="btnKey"    column="btn_key"    />
+        <result property="id" column="id"/>
+        <result property="btnParentId" column="btn_parent_id"/>
+        <result property="btnKey" column="btn_key"/>
         <result property="ancestorsId" column="ancestors_id"/>
         <result property="btnGroupName" column="btn_group_name"/>
-        <result property="btnName"    column="btn_name"    />
-        <result property="btnType"    column="btn_type"    />
+        <result property="btnGroupType" column="btn_group_type"/>
+        <result property="btnName" column="btn_name"/>
+        <result property="btnType" column="btn_type"/>
         <result property="btnIcon" column="btn_icon"/>
-        <result property="btnFormKey"    column="btn_form_key"    />
-        <result property="btnFormType"    column="btn_form_type"    />
-        <result property="btnProcessKey"    column="btn_process_key"    />
-        <result property="btnTableKey"    column="btn_table_key"    />
-        <result property="btnScriptKey"    column="btn_script_key"    />
-        <result property="btnShowCondition"    column="btn_show_condition"    />
-        <result property="btnParams"    column="btn_params"    />
-        <result property="btnHasPermi"    column="btn_has_permi"    />
-        <result property="btnSort"    column="btn_sort"    />
-        <result property="delFlag"    column="del_flag"    />
-        <result property="createBy"    column="create_by"    />
-        <result property="createById"    column="create_by_id"    />
-        <result property="createTime"    column="create_time"    />
-        <result property="updateBy"    column="update_by"    />
-        <result property="updateById"    column="update_by_id"    />
-        <result property="updateTime"    column="update_time"    />
-        <result property="remark"    column="remark"    />
+        <result property="btnFormKey" column="btn_form_key"/>
+        <result property="btnFormType" column="btn_form_type"/>
+        <result property="btnProcessKey" column="btn_process_key"/>
+        <result property="btnTableKey" column="btn_table_key"/>
+        <result property="btnScriptKey" column="btn_script_key"/>
+        <result property="btnShowCondition" column="btn_show_condition"/>
+        <result property="btnParams" column="btn_params"/>
+        <result property="btnHasPermi" column="btn_has_permi"/>
+        <result property="btnSort" column="btn_sort"/>
+        <result property="delFlag" column="del_flag"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createById" column="create_by_id"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateById" column="update_by_id"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="remark" column="remark"/>
     </resultMap>
 
     <sql id="selectDragTableBtnVo">
-        select id, btn_parent_id,ancestors_id, btn_key,btn_group_name, btn_name, btn_type,btn_icon, btn_form_key, btn_form_type,btn_process_key, btn_table_key, btn_script_key,btn_table_form_group_key,btn_show_condition, btn_params, btn_has_permi, btn_sort, del_flag, create_by, create_by_id, create_time, update_by, update_by_id, update_time, remark from drag_table_btn
+        select id,
+               btn_parent_id,
+               ancestors_id,
+               btn_key,
+               btn_group_name,
+               btn_group_type,
+               btn_name,
+               btn_type,
+               btn_icon,
+               btn_form_key,
+               btn_form_type,
+               btn_process_key,
+               btn_table_key,
+               btn_script_key,
+               btn_table_form_group_key,
+               btn_show_condition,
+               btn_params,
+               btn_has_permi,
+               btn_sort,
+               del_flag,
+               create_by,
+               create_by_id,
+               create_time,
+               update_by,
+               update_by_id,
+               update_time,
+               remark
+        from drag_table_btn
     </sql>
 
-    <select id="selectDragTableBtnList" parameterType="com.zkqy.system.entity.DragTableBtn" resultMap="DragTableBtnResult">
+    <select id="selectDragTableBtnList" parameterType="com.zkqy.system.entity.DragTableBtn"
+            resultMap="DragTableBtnResult">
         <include refid="selectDragTableBtnVo"/>
         where del_flag = '0'
         <if test="btnParentId != null ">and btn_parent_id = #{btnParentId}</if>
@@ -46,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
         <if test="btnName != null  and btnName != ''">and btn_name like concat('%', #{btnName}, '%')</if>
         <if test="btnType != null  and btnType != ''">and btn_type = #{btnType}</if>
+        <if test="btnGroupType != null  and btnGroupType != ''">and btn_group_type = #{btnGroupType}</if>
         <if test="btnFormKey != null  and btnFormKey != ''">and btn_form_key = #{btnFormKey}</if>
         <if test="btnFormType != null  and btnFormType != ''">and btn_form_type = #{btnFormType}</if>
         <if test="btnProcessKey != null  and btnProcessKey != ''">and btn_process_key = #{btnProcessKey}</if>
@@ -69,13 +99,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </select>
 
-    <insert id="insertDragTableBtn" parameterType="com.zkqy.system.entity.DragTableBtn">
-        insert into drag_table_btn
+    <insert id="insertDragTableBtn" parameterType="com.zkqy.system.entity.DragTableBtn"
+            useGeneratedKeys="true"
+            keyProperty="id">
+        insert into {DBNAME}.drag_table_btn
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="btnParentId != null">btn_parent_id,</if>
             <if test="btnKey != null">btn_key,</if>
             <if test="ancestorsId != null">ancestors_id,</if>
             <if test="btnGroupName != null">btn_group_name,</if>
+            <if test="btnGroupType != null">btn_group_type ,</if>
             <if test="btnName != null">btn_name,</if>
             <if test="btnType != null">btn_type,</if>
             <if test="btnIcon != null">btn_icon,</if>
@@ -93,12 +126,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">create_time,</if>
             <if test="remark != null">remark,</if>
             del_flag
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="btnParentId != null">#{btnParentId},</if>
             <if test="btnKey != null">#{btnKey},</if>
             <if test="ancestorsId != null">#{ancestorsId},</if>
             <if test="btnGroupName != null">#{btnGroupName},</if>
+            <if test="btnGroupType != null">#{btnGroupType},</if>
             <if test="btnName != null">#{btnName},</if>
             <if test="btnType != null">#{btnType},</if>
             <if test="btnIcon != null">#{btnIcon},</if>
@@ -116,16 +150,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">#{createTime},</if>
             <if test="remark != null">#{remark},</if>
             '0'
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateDragTableBtn" parameterType="com.zkqy.system.entity.DragTableBtn">
-        update drag_table_btn
+        update {DBNAME}.drag_table_btn
         <trim prefix="SET" suffixOverrides=",">
             <if test="btnParentId != null">btn_parent_id = #{btnParentId},</if>
             <if test="btnKey != null">btn_key = #{btnKey},</if>
             <if test="ancestorsId != null">ancestors_id = #{ancestorsId},</if>
             <if test="btnGroupName != null">btn_group_name = #{btnGroupName},</if>
+            <if test="btnGroupType != null">btn_group_type = #{btnGroupType},</if>
             <if test="btnName != null">btn_name = #{btnName},</if>
             <if test="btnType != null">btn_type = #{btnType},</if>
             <if test="btnIcon != null">btn_icon = #{btnIcon},</if>
@@ -147,7 +182,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <update id="deleteDragTableBtnById" parameterType="Long">
-        update drag_table_btn set del_flag = '2' where id = #{id}
+        update drag_table_btn
+        set del_flag = '2'
+        where id = #{id}
     </update>
 
     <update id="batchDeleteDragTableBtnByBtnKeys" parameterType="String">
@@ -175,7 +212,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="hasChildByBtnId" resultType="Integer">
-        select count(1) from drag_table_btn where btn_parent_id = #{btnId} and del_flag = '0'
+        select count(1)
+        from drag_table_btn
+        where btn_parent_id = #{btnId}
+          and del_flag = '0'
     </select>
 
     <select id="selectDragTableBtnByBtnKey" parameterType="String" resultMap="DragTableBtnResult">
@@ -183,4 +223,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where btn_key = #{btnKey}
     </select>
 
+    <insert id="insertDragTableBtnList" parameterType="java.util.List">
+        INSERT INTO {DBNAME}.drag_table_btn
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            btn_parent_id,
+            btn_key,
+            ancestors_id,
+            btn_group_name,
+            btn_group_type,
+            btn_name,
+            btn_type,
+            btn_icon,
+            btn_form_key,
+            btn_form_type,
+            btn_process_key,
+            btn_table_key,
+            btn_script_key,
+            btn_show_condition,
+            btn_params,
+            btn_has_permi,
+            btn_sort,
+            create_by,
+            create_by_id,
+            create_time,
+            remark,
+            del_flag
+        </trim>
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            <trim prefix="(" suffix=")" suffixOverrides=",">
+                #{item.btnParentId},
+                #{item.btnKey},
+                #{item.ancestorsId},
+                #{item.btnGroupName},
+                #{item.btnGroupType},
+                #{item.btnName},
+                #{item.btnType},
+                #{item.btnIcon},
+                #{item.btnFormKey},
+                #{item.btnFormType},
+                #{item.btnProcessKey},
+                #{item.btnTableKey},
+                #{item.btnScriptKey},
+                #{item.btnShowCondition},
+                #{item.btnParams},
+                #{item.btnHasPermi},
+                #{item.btnSort},
+                #{item.createBy},
+                #{item.createById},
+                #{item.createTime},
+                #{item.remark},
+                '0'
+            </trim>
+        </foreach>
+    </insert>
+
+
 </mapper>