Эх сурвалжийг харах

自动生成代码模板修改

Wang Zi Wen 2 жил өмнө
parent
commit
5678c42b08

+ 1 - 0
ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm

@@ -50,6 +50,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
      * @return ${functionName}
      */
     @Override
+    @DataScope(deptAlias = "d", userAlias = "u")
     public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
     {
         return ${className}Mapper.select${ClassName}List(${className});

+ 7 - 9
ruoyi-generator/src/main/resources/vm/sql/sql.vm

@@ -1,29 +1,27 @@
 -- 菜单 SQL
 insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
-values(${table.menuId}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');
+values(${table.menuId}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate, '', null, '${functionName}菜单');
 
 -- 按钮 SQL
 insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
-values(seq_sys_menu.nextval, '${functionName}查询', ${table.menuId}, '1',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query',        '#', 'admin', sysdate(), '', null, '');
+values(seq_sys_menu.nextval, '${functionName}查询', ${table.menuId}, '1',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query',        '#', 'admin', sysdate, '', null, '');
 
 insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
-values(seq_sys_menu.nextval, '${functionName}新增', ${table.menuId}, '2',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add',          '#', 'admin', sysdate(), '', null, '');
+values(seq_sys_menu.nextval, '${functionName}新增', ${table.menuId}, '2',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add',          '#', 'admin', sysdate, '', null, '');
 
 insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
-values(seq_sys_menu.nextval, '${functionName}修改', ${table.menuId}, '3',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit',         '#', 'admin', sysdate(), '', null, '');
+values(seq_sys_menu.nextval, '${functionName}修改', ${table.menuId}, '3',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit',         '#', 'admin', sysdate, '', null, '');
 
 insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
-values(seq_sys_menu.nextval, '${functionName}删除', ${table.menuId}, '4',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove',       '#', 'admin', sysdate(), '', null, '');
+values(seq_sys_menu.nextval, '${functionName}删除', ${table.menuId}, '4',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove',       '#', 'admin', sysdate, '', null, '');
 
 insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
-values(seq_sys_menu.nextval, '${functionName}导出', ${table.menuId}, '5',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export',       '#', 'admin', sysdate(), '', null, '');
+values(seq_sys_menu.nextval, '${functionName}导出', ${table.menuId}, '5',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export',       '#', 'admin', sysdate, '', null, '');
 
-#if($pkColumn.increment)
 -- ${tableName}主键序列
 create sequence seq_${tableName}
 increment by 1
 start with 1000
 nomaxvalue
 nominvalue
-cache 20;
-#end
+cache 20;

+ 53 - 50
ruoyi-generator/src/main/resources/vm/vue/index.vue.vm

@@ -348,10 +348,10 @@ export default {
 #else
 #set($comment=$column.columnComment)
 #end
-#if(${column.dictType} != '')
-      // $comment字典
-      ${column.javaField}Options: [],
-#end
+###if(${column.dictType} != '')
+##      // $comment字典
+##      ${column.javaField}Options: [],
+###end
 #end
         // 用户导入参数
         upload: {
@@ -413,13 +413,13 @@ export default {
       })
     this.getList();
     this.getTreeselect();
-#foreach ($column in $columns)
-#if(${column.dictType} != '')
-    this.getDicts("${column.dictType}").then(response => {
-      this.${column.javaField}Options = response.data;
-    });
-#end
-#end
+###foreach ($column in $columns)
+###if(${column.dictType} != '')
+##    this.getDicts("${column.dictType}").then(response => {
+##      this.${column.javaField}Options = response.data;
+##    });
+###end
+###end
   },
   methods: {
     /** 查询${functionName}列表 */
@@ -437,20 +437,20 @@ export default {
               this.deptOptions = response.data;
           });
      },
-#foreach ($column in $columns)
-#if(${column.dictType} != '')
-#set($parentheseIndex=$column.columnComment.indexOf("("))
-#if($parentheseIndex != -1)
-#set($comment=$column.columnComment.substring(0, $parentheseIndex))
-#else
-#set($comment=$column.columnComment)
-#end
-    // $comment字典翻译
-    ${column.javaField}Format(row, column) {
-      return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
-    },
-#end
-#end
+###foreach ($column in $columns)
+###if(${column.dictType} != '')
+###set($parentheseIndex=$column.columnComment.indexOf("("))
+###if($parentheseIndex != -1)
+###set($comment=$column.columnComment.substring(0, $parentheseIndex))
+###else
+###set($comment=$column.columnComment)
+###end
+##    // $comment字典翻译
+##    ${column.javaField}Format(row, column) {
+##      return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
+##    },
+###end
+###end
     // 取消按钮
     cancel() {
       this.open = false;
@@ -511,31 +511,34 @@ export default {
         this.title = "修改${functionName}";
       });
     },
-    /** 提交按钮 */
-    submitForm() {
-      this.#[[$]]#refs["form"].validate(valid => {
-        if (valid) {
-#foreach ($column in $columns)
-#if($column.htmlType == "checkbox")
-          this.form.$column.javaField = this.form.${column.javaField}.join(",");
-#end
-#end
-          if (this.form.${pkColumn.javaField} != null) {
-            update${BusinessName}(this.form).then(response => {
-              this.msgSuccess("修改成功");
-              this.open = false;
-              this.getList();
-            });
-          } else {
-            add${BusinessName}(this.form).then(response => {
-              this.msgSuccess("新增成功");
-              this.open = false;
-              this.getList();
-            });
-          }
-        }
-      });
-    },
+      /** 提交按钮 */
+      submitForm() {
+          this.#[[$]]#refs["form"].validate(valid => {
+              if (valid) {
+                  #foreach ($column in $columns)
+                  #if($column.htmlType == "checkbox")
+                  this.form.$column.javaField = this.form.${column.javaField}.join(",");
+                  #end
+                  #end
+                  #if($table.sub)
+                  this.form.${subclassName}List = this.${subclassName}List;
+                  #end
+                  if (this.form.${pkColumn.javaField} != null) {
+                      update${BusinessName}(this.form).then(response => {
+                          this.#[[$modal]]#.msgSuccess("修改成功");
+                          this.open = false;
+                          this.getList();
+                      });
+                  } else {
+                      add${BusinessName}(this.form).then(response => {
+                          this.#[[$modal]]#.msgSuccess("新增成功");
+                          this.open = false;
+                          this.getList();
+                      });
+                  }
+              }
+          });
+      },
     /** 删除按钮操作 */
     handleDelete(row) {
       const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;

+ 15 - 13
ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm

@@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 #end
 
     <sql id="select${ClassName}Vo">
-        select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
+        select#foreach($column in $columns) u.$column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName} u left join sys_dept d on u.dept_id = d.dept_id
     </sql>
 
     <select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
@@ -37,33 +37,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
 #if($column.query)
 #if($column.queryType == "EQ")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName = #{$javaField}</if>
 #elseif($queryType == "NE")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName != #{$javaField}</if>
 #elseif($queryType == "GT")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName &gt; #{$javaField}</if>
 #elseif($queryType == "GTE")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName &gt;= #{$javaField}</if>
 #elseif($queryType == "LT")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName &lt; #{$javaField}</if>
 #elseif($queryType == "LTE")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName &lt;= #{$javaField}</if>
 #elseif($queryType == "LIKE")
-            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
+            <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and u.$columnName like concat('%', #{$javaField}, '%')</if>
 #elseif($queryType == "BETWEEN")
-            <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
+            <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and u.$columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
 #end
 #end
 #end
-            and del_flag = 0
+            and u.del_flag = 0
         </where>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
     </select>
     
     <select id="select${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
 #if($table.crud || $table.tree)
         <include refid="select${ClassName}Vo"/>
-        where ${pkColumn.columnName} = #{${pkColumn.javaField}}
-        and del_flag = 0
+        where u.${pkColumn.columnName} = #{${pkColumn.javaField}}
+        and u.del_flag = 0
 #elseif($table.sub)
         select#foreach($column in $columns) a.$column.columnName#if($foreach.count != $columns.size()),#end#end,
            #foreach($column in $subTable.columns) b.$column.columnName as sub_$column.columnName#if($foreach.count != $subTable.columns.size()),#end#end
@@ -71,7 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from ${tableName} a
         left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName}
         where a.${pkColumn.columnName} = #{${pkColumn.javaField}}
-        and del_flag = 0
+        and u.del_flag = 0
 #end
     </select>