浏览代码

优化生成代码

wanggaokun 11 月之前
父节点
当前提交
bd25f88eb6

+ 18 - 29
als-modules/generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -102,35 +102,24 @@
             AND column_type <![CDATA[ <> ]]> '-'
         </if>
         <if test="@org.eco.common.orm.helper.DataBaseHelper@isDmSql()">
-            select sc.NAME column_name,
-            (case when sc.NULLABLE$ = 'N' then '1' else null end) as is_required,
-            (case when sc.INFO2 = 1 then '1' else '0' end) is_pk,
-            sc.COLID sort,
-            scc.COMMENT$ column_comment,
-            (case when sc.INFO2 = 1 then '1' else '0' end) as is_increment,
-            LOWER(sc.TYPE$) column_type
-            from SYS.SYSCOLUMNS sc
-            left join SYS.SYSOBJECTS so on sc.ID = so.ID
-            left join SYS.SYSCOLUMNCOMMENTS SCC
-            on sc.NAME = scc.COLNAME and scc.TABLE_TYPE = 'TABLE' and
-            scc.SCHNAME = (select CURR_SCH
-            from V$SESSIONS
-            WHERE CURR_SCH = 'als'
-            LIMIT 1) and
-            scc.TVNAME = so.NAME
-            where so.TYPE$ = 'SCHOBJ'
-            and so.SUBTYPE$ = 'UTAB'
-            and so.PID = -1
-            and so.SCHID =
-            (select ID
-            from SYS.SYSOBJECTS
-            where TYPE$ = 'SCH'
-            and NAME = (select CURR_SCH
-            from V$SESSIONS
-            WHERE CURR_SCH = 'als'
-            LIMIT 1))
-            and so.NAME = #{tableName}
-            order by sc.COLID
+            select lower(temp.column_name) as column_name,
+            (case when (temp.nullable = 'N'  and  temp.constraint_type != 'P') then '1' else null end) as is_required,
+            (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk,
+            temp.column_id as sort,
+            temp.comments as column_comment,
+            (case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment,
+            lower(temp.data_type) as column_type
+            from (
+            select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type
+            , row_number() over (partition by col.column_name order by uc.constraint_type desc) as row_flg
+            from user_tab_columns col
+            left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name
+            left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name
+            left join user_constraints uc on uc.constraint_name = ucc.constraint_name
+            where col.table_name = upper(#{tableName})
+            ) temp
+            WHERE temp.row_flg = 1
+            ORDER BY temp.column_id
         </if>
 
     </select>

+ 4 - 0
als-modules/generator/src/main/resources/vm/api/api.ts.types.vm

@@ -1,4 +1,8 @@
+#if($table.crud || $table.sub)
 import { PageQuery, BaseEntity } from '@/api/interface/index'
+#elseif($table.tree)
+import { BaseEntity } from '@/api/interface/index'
+#end
 export interface ${BusinessName}VO extends BaseEntity {
 #foreach ($column in $columns)
     #if($column.list)

+ 1 - 1
als-modules/generator/src/main/resources/vm/api/api.ts.vm

@@ -66,5 +66,5 @@ export const import${BusinessName}DataApi = (data: any) => {
  * @returns returns
  */
 export const export${BusinessName}Api = (data: any) => {
-    return http.downloadPost('/${moduleName}/${businessName}/export', data)
+    return http.post('/${moduleName}/${businessName}/export', data)
 }

+ 11 - 2
als-modules/generator/src/main/resources/vm/java/controller.java.vm

@@ -1,7 +1,5 @@
 package ${packageName}.controller;
 
-import java.util.List;
-
 import lombok.RequiredArgsConstructor;
 import jakarta.servlet.http.HttpServletResponse;
 import cn.dev33.satoken.annotation.SaCheckPermission;
@@ -13,8 +11,10 @@ import org.eco.common.log.enums.BusinessType;
 import org.eco.common.security.utils.LoginHelper;
 import org.eco.common.core.core.domain.model.LoginUser;
 import org.eco.common.web.annotation.RepeatSubmit;
+import org.eco.common.excel.utils.ExcelUtil;
 import org.eco.common.web.core.BaseController;
 import jakarta.annotation.Resource;
+import ${packageName}.domain.vo.${ClassName}ImportVo;
 import ${packageName}.domain.vo.${ClassName}Vo;
 import ${packageName}.domain.bo.${ClassName}Bo;
 import ${packageName}.service.I${ClassName}Service;
@@ -24,6 +24,9 @@ import org.eco.common.core.core.page.PageResult;
 #elseif($table.tree)
 #end
 
+import java.util.List;
+import java.util.ArrayList;
+
 /**
  * ${functionName}Controller
  *
@@ -67,6 +70,12 @@ public class ${ClassName}Controller extends BaseController {
         return CommonResult.success();
     }
 
+    @SaCheckPermission("${permissionPrefix}:import")
+    @PostMapping("/importTemplate")
+    public void importTemplate(HttpServletResponse response) {
+        ExcelUtil.exportExcel(new ArrayList<>(), "${functionName}", ${ClassName}ImportVo.class, response);
+    }
+
     /**
      * 导入${functionName}列表
      */