From adc0a1df2d5bc0842b5d4b950380a5b7ce469711 Mon Sep 17 00:00:00 2001
From: master <master@163.com>
Date: 星期五, 25 三月 2022 10:22:59 +0800
Subject: [PATCH] 2022-03-25 10:22:00

---
 src/app/modules/base/utils/createEntity.ts |  340 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 170 insertions(+), 170 deletions(-)

diff --git a/src/app/modules/base/utils/createEntity.ts b/src/app/modules/base/utils/createEntity.ts
index fd9f42d..ed271dc 100644
--- a/src/app/modules/base/utils/createEntity.ts
+++ b/src/app/modules/base/utils/createEntity.ts
@@ -2,191 +2,191 @@
 import * as fs from 'fs';
 
 /**
-聽* 涓嶉渶瑕佺櫥褰曠殑鍚庡彴鎺ュ彛
-聽*/
+ * 涓嶉渶瑕佺櫥褰曠殑鍚庡彴鎺ュ彛
+ */
 @Provide()
 export class CreateEntityUtil {
 
-聽 聽 createEntity(table) {
-聽 聽 聽 聽 console.log('鐢熸垚缁煎悎瀹炰綋绫讳换鍔″紑濮嬫墽琛�');
-聽 聽 聽 聽 let EntityName = this.firstToUpper3(table.entityName)
-聽 聽 聽 聽 let columnstr = [];
-聽 聽 聽 聽 columnstr.push(`import { EntityModel } from '@midwayjs/orm';\n`)
-聽 聽 聽 聽 columnstr.push(`import { BaseEntity } from '@cool-midway/core';\n`)
-聽 聽 聽 聽 columnstr.push(`import { Column, Double } from 'typeorm';\n`)
-聽 聽 聽 聽 columnstr.push(`/**
+  createEntity(table) {
+    console.log('鐢熸垚缁煎悎瀹炰綋绫讳换鍔″紑濮嬫墽琛�');
+    let EntityName = this.firstToUpper3(table.entityName)
+    let columnstr = [];
+    columnstr.push(`import { EntityModel } from '@midwayjs/orm';\n`)
+    columnstr.push(`import { BaseEntity } from '@cool-midway/core';\n`)
+    columnstr.push(`import { Column, Double } from 'typeorm';\n`)
+    columnstr.push(`/**
 聽 聽 聽 聽 * ${table.comment}
 聽 聽 聽 聽 */\n`)
-聽 聽 聽 聽 columnstr.push(`@EntityModel('${table.name}') \n`)
-聽 聽 聽 聽 columnstr.push(`export class ${EntityName} extends BaseEntity { \n`)
-聽 聽 聽 聽 table.tbcolumn.forEach(item => {
-聽 聽 聽 聽 聽 聽 if (item?.table_name == table.name) {
-聽 聽 聽 聽 聽 聽 聽 聽 let fieldType = 'string'; 聽//nullable length 聽primary 聽enum 聽 enumName 聽width
-聽 聽 聽 聽 聽 聽 聽 聽 let matResult = item.column_type.match(/\(([^)]*)\)/);
-聽 聽 聽 聽 聽 聽 聽 聽 let length = 0;
-聽 聽 聽 聽 聽 聽 聽 聽 if (matResult) {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 length = matResult[1]; 
-聽 聽 聽 聽 聽 聽 聽 聽 }
-聽 聽 聽 聽 聽 聽 聽 聽 switch (item.data_type) {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'varchar':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'string'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(item.column_default) ? item.column_default : '';
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:'${item.column_default}', length:${length}})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'text':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'string'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(item.column_default) ? item.column_default : '';
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:'${item.column_default}'})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'int':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'number'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}, width:${length}})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'bigint':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'number'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}}, width:${length})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'tinyint':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'number'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}, width:${length}})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'datetime':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'Date'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = item.column_default != 'null' ? item.column_default : `${new Date()}`;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}'})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'double':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'Double'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 case 'decimal':
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 fieldType = 'Double'
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}})\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 default:
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 break;
-聽 聽 聽 聽 聽 聽 聽 聽 }
+    columnstr.push(`@EntityModel('${table.name}') \n`)
+    columnstr.push(`export class ${EntityName} extends BaseEntity { \n`)
+    table.tbcolumn.forEach(item => {
+      if (item?.table_name == table.name) {
+        let fieldType = 'string'; 聽//nullable length 聽primary 聽enum 聽 enumName 聽width
+        let matResult = item.column_type.match(/\(([^)]*)\)/);
+        let length = 0;
+        if (matResult) {
+          length = matResult[1];
+        }
+        switch (item.data_type) {
+          case 'varchar':
+            fieldType = 'string'
+            item.column_default = !isNaN(item.column_default) ? item.column_default : '';
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:'${item.column_default}', length:${length}})\n`)
+            break;
+          case 'text':
+            fieldType = 'string'
+            item.column_default = !isNaN(item.column_default) ? item.column_default : '';
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:'${item.column_default}'})\n`)
+            break;
+          case 'int':
+            fieldType = 'number'
+            item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}, width:${length}})\n`)
+            break;
+          case 'bigint':
+            fieldType = 'number'
+            item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}}, width:${length})\n`)
+            break;
+          case 'tinyint':
+            fieldType = 'number'
+            item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}, width:${length}})\n`)
+            break;
+          case 'datetime':
+            fieldType = 'Date'
+            item.column_default = item.column_default != 'null' ? item.column_default : `${new Date()}`;
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}'})\n`)
+            break;
+          case 'double':
+            item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
+            fieldType = 'Double'
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}})\n`)
+            break;
+          case 'decimal':
+            item.column_default = !isNaN(Number(item.column_default)) ? item.column_default : 0;
+            fieldType = 'Double'
+            columnstr.push(`@Column({ comment:'${item.column_comment}', type:'${item.data_type}', default:${item.column_default}})\n`)
+            break;
+          default:
+            break;
+        }
 
-聽 聽 聽 聽 聽 聽 聽 聽 // let fieldType = item.data_type=='varchar' ? 'string' : item.data_type=='int' ? 'number' : item.data_type=='bigint' ? 'number' : item.data_type=='tinyint' ? 'number' 
-聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`${item.column_name}: ${fieldType};\n`)
-聽 聽 聽 聽 聽 聽 聽 聽 columnstr.push(`\n`)
-聽 聽 聽 聽 聽 聽 }
+        // let fieldType = item.data_type=='varchar' ? 'string' : item.data_type=='int' ? 'number' : item.data_type=='bigint' ? 'number' : item.data_type=='tinyint' ? 'number' 
+        columnstr.push(`${item.column_name}: ${fieldType};\n`)
+        columnstr.push(`\n`)
+      }
 
-聽 聽 聽 聽 });
-聽 聽 聽 聽 columnstr.push(`}`)
-聽 聽 聽 聽 if (fs.existsSync(`../../business/entity/${table.entityName}.ts`)) {
-聽 聽 聽 聽 聽 聽 console.log(' file is exists')
-聽 聽 聽 聽 } else {
-聽 聽 聽 聽 聽 聽 console.log(' file is not exists')
-聽 聽 聽 聽 聽 聽 // API
-聽 聽 聽 聽 聽 聽 fs.writeFile(`./src/app/modules/business/entity/${table.entityName}.ts`,
-聽 聽 聽 聽 聽 聽 聽 聽 columnstr.join(''), (error) => {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // 鍒涘缓澶辫触
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (error) {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 console.log(`鍒涘缓澶辫触锛�${error}`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 }
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // 鍒涘缓鎴愬姛
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 console.log(`鍒涘缓鎴愬姛锛乣)
-聽 聽 聽 聽 聽 聽 聽 聽 })
-聽 聽 聽 聽 }
-聽 聽 聽 聽 console.log(`--------------------鐢熸垚瀹炰綋绫荤粨鏉�${table.entityName}Service--------------------`);
-聽 聽 }
+    });
+    columnstr.push(`}`)
+    if (fs.existsSync(`../../business/entity/${table.entityName}.ts`)) {
+      console.log(' file is exists')
+    } else {
+      console.log(' file is not exists')
+      // API
+      fs.writeFile(`./src/app/modules/business/entity/${table.entityName}.ts`,
+        columnstr.join(''), (error) => {
+          // 鍒涘缓澶辫触
+          if (error) {
+            console.log(`鍒涘缓澶辫触锛�${error}`)
+          }
+          // 鍒涘缓鎴愬姛
+          console.log(`鍒涘缓鎴愬姛锛乣)
+        })
+    }
+    console.log(`--------------------鐢熸垚瀹炰綋绫荤粨鏉�${table.entityName}Service--------------------`);
+  }
 
 
-聽 聽 createService(table) {
-聽 聽 聽 聽 console.log('鐢熸垚鏈嶅姟绫诲紑濮嬫墽琛�');
-聽 聽 聽 聽 let EntityName = this.firstToUpper3(table.entityName)
-聽 聽 聽 聽 let columnstr = [];
-聽 聽 聽 聽 columnstr.push(`import { Provide } from '@midwayjs/decorator';\n`)
-聽 聽 聽 聽 columnstr.push(`import { BaseService } from '@cool-midway/core';\n`)
-聽 聽 聽 聽 columnstr.push(`import { InjectEntityModel } from '@midwayjs/orm';\n`)
-聽 聽 聽 聽 columnstr.push(`import { Repository } from 'typeorm';\n`)
-聽 聽 聽 聽 columnstr.push(`import { DataService } from '../../base/service/dataapi/dataapi';\n`)
-聽 聽 聽 聽 columnstr.push(`import { ${EntityName} } from '../entity/${table.entityName}';\n`)
-聽 聽 聽 聽 columnstr.push(`/**
+  createService(table) {
+    console.log('鐢熸垚鏈嶅姟绫诲紑濮嬫墽琛�');
+    let EntityName = this.firstToUpper3(table.entityName)
+    let columnstr = [];
+    columnstr.push(`import { Provide } from '@midwayjs/decorator';\n`)
+    columnstr.push(`import { BaseService } from '@cool-midway/core';\n`)
+    columnstr.push(`import { InjectEntityModel } from '@midwayjs/orm';\n`)
+    columnstr.push(`import { Repository } from 'typeorm';\n`)
+    columnstr.push(`import { DataService } from '../../base/service/dataapi/dataapi';\n`)
+    columnstr.push(`import { ${EntityName} } from '../entity/${table.entityName}';\n`)
+    columnstr.push(`/**
 聽 聽 聽 聽 * ${table.comment}
 聽 聽 聽 聽 */\n`)
-聽 聽 聽 聽 columnstr.push(`@Provide()\n`)
-聽 聽 聽 聽 columnstr.push(`export class ${EntityName}Service extends DataService { \n`)
-聽 聽 聽 聽 columnstr.push(` 聽 聽@InjectEntityModel(${EntityName}) \n`)
-聽 聽 聽 聽 columnstr.push(` 聽 聽${table.entityName}: Repository<${EntityName}> \n`);
-聽 聽 聽 聽 columnstr.push(`}`)
-聽 聽 聽 聽 if (fs.existsSync(`../../business/service/${table.entityName}.ts`)) {
-聽 聽 聽 聽 聽 聽 console.log(' file is exists')
-聽 聽 聽 聽 } else {
-聽 聽 聽 聽 聽 聽 console.log(' file is not exists')
-聽 聽 聽 聽 聽 聽 // API
-聽 聽 聽 聽 聽 聽 fs.writeFile(`./src/app/modules/business/service/${table.entityName}.ts`,
-聽 聽 聽 聽 聽 聽 聽 聽 columnstr.join(''), (error) => {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // 鍒涘缓澶辫触
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (error) {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 console.log(`鍒涘缓澶辫触锛�${error}`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 }
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // 鍒涘缓鎴愬姛
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 console.log(`鍒涘缓鎴愬姛锛乣)
-聽 聽 聽 聽 聽 聽 聽 聽 })
-聽 聽 聽 聽 }
-聽 聽 聽 聽 console.log(`--------------------鐢熸垚鏈嶅姟绫荤粨鏉�${EntityName}Service--------------------`);
-聽 聽 }
+    columnstr.push(`@Provide()\n`)
+    columnstr.push(`export class ${EntityName}Service extends DataService { \n`)
+    columnstr.push(` 聽 聽@InjectEntityModel(${EntityName}) \n`)
+    columnstr.push(` 聽 聽${table.entityName}: Repository<${EntityName}> \n`);
+    columnstr.push(`}`)
+    if (fs.existsSync(`../../business/service/${table.entityName}.ts`)) {
+      console.log(' file is exists')
+    } else {
+      console.log(' file is not exists')
+      // API
+      fs.writeFile(`./src/app/modules/business/service/${table.entityName}.ts`,
+        columnstr.join(''), (error) => {
+          // 鍒涘缓澶辫触
+          if (error) {
+            console.log(`鍒涘缓澶辫触锛�${error}`)
+          }
+          // 鍒涘缓鎴愬姛
+          console.log(`鍒涘缓鎴愬姛锛乣)
+        })
+    }
+    console.log(`--------------------鐢熸垚鏈嶅姟绫荤粨鏉�${EntityName}Service--------------------`);
+  }
 
-聽 聽 createController(table) {
-聽 聽 聽 聽 console.log('鐢熸垚鎺у埗绫诲紑濮嬫墽琛�');
-聽 聽 聽 聽 let EntityName = this.firstToUpper3(table.entityName)
-聽 聽 聽 聽 let columnstr = [];
-聽 聽 聽 聽 columnstr.push(`import { ALL, Body, Get, Inject, Post, Provide, Query } from '@midwayjs/decorator';\n`)
-聽 聽 聽 聽 columnstr.push(`import { CoolController, BaseController } from '@cool-midway/core';\n`)
-聽 聽 聽 聽 columnstr.push(`import { ${EntityName} } from '../../entity/${table.entityName}';\n`)
-聽 聽 聽 聽 columnstr.push(`import { ${EntityName}Service } from '../../service/${table.entityName}';\n`)
-聽 聽 聽 聽 columnstr.push(`import { DataController } from '../../../base/controller/dataController';\n`)
-聽 聽 聽 聽 columnstr.push(`/**
+  createController(table) {
+    console.log('鐢熸垚鎺у埗绫诲紑濮嬫墽琛�');
+    let EntityName = this.firstToUpper3(table.entityName)
+    let columnstr = [];
+    columnstr.push(`import { ALL, Body, Get, Inject, Post, Provide, Query } from '@midwayjs/decorator';\n`)
+    columnstr.push(`import { CoolController, BaseController } from '@cool-midway/core';\n`)
+    columnstr.push(`import { ${EntityName} } from '../../entity/${table.entityName}';\n`)
+    columnstr.push(`import { ${EntityName}Service } from '../../service/${table.entityName}';\n`)
+    columnstr.push(`import { DataController } from '../../../base/controller/dataController';\n`)
+    columnstr.push(`/**
 聽 聽 聽 聽 * ${table.comment}
 聽 聽 聽 聽 */\n`)
-聽 聽 聽 聽 columnstr.push(`@Provide()\n`)
-聽 聽 聽 聽 columnstr.push(`@CoolController({ \n`)
-聽 聽 聽 聽 columnstr.push(` 聽api: ['add', 'delete', 'update', 'list'],\n`)
-聽 聽 聽 聽 columnstr.push(` 聽entity: ${EntityName},\n`)
-聽 聽 聽 聽 columnstr.push(` 聽service: ${EntityName}Service,\n`)
-聽 聽 聽 聽 columnstr.push(`})\n`)
-聽 聽 聽 聽 columnstr.push(`export class ${EntityName}Controller extends DataController {\n`)
-聽 聽 聽 聽 columnstr.push(` 聽@Inject()\n`)
-聽 聽 聽 聽 columnstr.push(` 聽${table.entityName}Service: ${EntityName}Service;\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽\n`) 
-聽 聽 聽 聽 columnstr.push(`  /**\n  * 鑾峰緱鏁版嵁\n  */\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽 @Get('/getdata', { summary: '鏁版嵁鎺ュ彛' })\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽 async getData(@Query(ALL) params: any) {\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽  聽 return this.ok(await this.dataService.getData(params));\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽 }\n`) 
-聽 聽 聽 聽 columnstr.push(`  /**\n  * 鑾峰緱鏁版嵁\n  */\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽 @Get('/postdata', { summary: '鏁版嵁鎺ュ彛' })\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽 async postData(@Query(ALL) params: any) {\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽  聽 return this.ok(await this.dataService.getData(params));\n`) 
-聽 聽 聽 聽 columnstr.push(` 聽 }\n`)
-聽 聽 聽 聽 columnstr.push(`}`)
-聽 聽 聽 聽 if (fs.existsSync(`../../business/controller/admin/${table.entityName}.ts`)) {
-聽 聽 聽 聽 聽 聽 console.log(' file is exists')
-聽 聽 聽 聽 } else {
-聽 聽 聽 聽 聽 聽 console.log(' file is not exists')
-聽 聽 聽 聽 聽 聽 // API
-聽 聽 聽 聽 聽 聽 fs.writeFile(`./src/app/modules/business/controller/admin/${table.entityName}.ts`,
-聽 聽 聽 聽 聽 聽 聽 聽 columnstr.join(''), (error) => {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // 鍒涘缓澶辫触
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (error) {
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 console.log(`鍒涘缓澶辫触锛�${error}`)
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 }
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // 鍒涘缓鎴愬姛
-聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 console.log(`鍒涘缓鎴愬姛锛乣)
-聽 聽 聽 聽 聽 聽 聽 聽 })
-聽 聽 聽 聽 }
-聽 聽 }
+    columnstr.push(`@Provide()\n`)
+    columnstr.push(`@CoolController({ \n`)
+    columnstr.push(` 聽api: ['add', 'delete', 'update', 'list','page','info'],\n`)
+    columnstr.push(` 聽entity: ${EntityName},\n`)
+    columnstr.push(` 聽service: ${EntityName}Service,\n`)
+    columnstr.push(`})\n`)
+    columnstr.push(`export class ${EntityName}Controller extends DataController {\n`)
+    columnstr.push(` 聽@Inject()\n`)
+    columnstr.push(` 聽${table.entityName}Service: ${EntityName}Service;\n`)
+    columnstr.push(` 聽\n`)
+    columnstr.push(`  /**\n  * 鑾峰緱鏁版嵁\n  */\n`)
+    columnstr.push(` 聽 @Get('/getdata', { summary: '鏁版嵁鎺ュ彛' })\n`)
+    columnstr.push(` 聽 async getData(@Query(ALL) params: any) {\n`)
+    columnstr.push(` 聽  聽 return this.ok(await this.dataService.getData(params));\n`)
+    columnstr.push(` 聽 }\n`)
+    columnstr.push(`  /**\n  * 鑾峰緱鏁版嵁\n  */\n`)
+    columnstr.push(` 聽 @Get('/postdata', { summary: '鏁版嵁鎺ュ彛' })\n`)
+    columnstr.push(` 聽 async postData(@Query(ALL) params: any) {\n`)
+    columnstr.push(` 聽  聽 return this.ok(await this.dataService.getData(params));\n`)
+    columnstr.push(` 聽 }\n`)
+    columnstr.push(`}`)
+    if (fs.existsSync(`../../business/controller/admin/${table.entityName}.ts`)) {
+      console.log(' file is exists')
+    } else {
+      console.log(' file is not exists')
+      // API
+      fs.writeFile(`./src/app/modules/business/controller/admin/${table.entityName}.ts`,
+        columnstr.join(''), (error) => {
+          // 鍒涘缓澶辫触
+          if (error) {
+            console.log(`鍒涘缓澶辫触锛�${error}`)
+          }
+          // 鍒涘缓鎴愬姛
+          console.log(`鍒涘缓鎴愬姛锛乣)
+        })
+    }
+  }
 
 
-聽 聽 firstToUpper3(str){
-聽 聽 聽 聽 return str.toLowerCase().replace(/( |^)[a-z]/g,(L)=>L.toUpperCase());
-聽 聽 }
+  firstToUpper3(str) {
+    return str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase());
+  }
 
 }

--
Gitblit v1.9.1