ming_node 2.2.2 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
 - package/beforeTest/ApiCloudBaseRpcApiTest.js +17 -0
 - package/beforeTest/FileBaseRpcApiTest.js +8 -0
 - package/beforeTest/MemorDbTest.js +16 -0
 - package/beforeTest/MemoryBaseRestApiTest.js +8 -0
 - package/beforeTest/MemoryBaseRpcApiTest.js +8 -0
 - package/beforeTest/MiApiCloudClientTest.js +16 -0
 - package/beforeTest/MongoDbBaseRestApiTest.js +22 -0
 - package/beforeTest/MongoDbBaseRpcApiTest.js +19 -0
 - package/beforeTest/MySqlBaseRestApiTest.js +13 -0
 - package/beforeTest/MysqlBaseRpcApiTest.js +18 -0
 - package/beforeTest/graphql_test.js +12 -0
 - package/beforeTest/installPluginTest.js +10 -0
 - package/beforeTest/sseserver.js +44 -0
 - package/beforeTest/static/ssetest.html +21 -0
 - package/index.js +198 -44
 - package/ming_node.md +4 -4
 - package/module/BaseMapper.js +90 -35
 - package/module/MemoryDb.js +136 -0
 - package/module/MiApiCloudClient.js +649 -0
 - package/package.json +1 -1
 - package/plugins/BaseGraphqlApi/getGraphqlSchema.js +145 -0
 - package/plugins/BaseGraphqlApi/getGraphqlSchemaDemo.js +76 -0
 - package/plugins/BaseGraphqlApi/index.js +23 -0
 - package/plugins/BaseRestApi/AbstractBaseRestApi.js +59 -0
 - package/plugins/BaseRestApi/ApiCloudBaseRestApi.js +56 -0
 - package/plugins/BaseRestApi/FileBaseRestApi.js +62 -0
 - package/plugins/BaseRestApi/MemoryBaseRestApi.js +50 -0
 - package/plugins/BaseRestApi/MongoDbBaseRestApi.js +75 -0
 - package/plugins/BaseRestApi/MysqlBaseRestApi.js +72 -0
 - package/plugins/BaseRpcApi/AbstractBaseRpcApi.js +72 -0
 - package/plugins/BaseRpcApi/ApiCloudBaseRpcApi.js +57 -0
 - package/plugins/BaseRpcApi/FileBaseRpcApi.js +62 -0
 - package/plugins/BaseRpcApi/MemoryBaseRpcApi.js +50 -0
 - package/plugins/BaseRpcApi/MongoDbBaseRpcApi.js +75 -0
 - package/plugins/BaseRpcApi/MysqlBaseRpcApi.js +72 -0
 - package/utils/common/CollectionUtils.js +28 -0
 - package/beforeTest/t1.js +0 -18
 
| 
         @@ -0,0 +1,57 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * 数据源为内存的rpc风格接口
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
            const AbstractBaseRpcApi=require("./AbstractBaseRpcApi");
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class ApiCloudBaseRpcApi extends AbstractBaseRpcApi{
         
     | 
| 
      
 8 
     | 
    
         
            +
                constructor(props) {
         
     | 
| 
      
 9 
     | 
    
         
            +
                    super(props);
         
     | 
| 
      
 10 
     | 
    
         
            +
                    this.appid=props.appid;
         
     | 
| 
      
 11 
     | 
    
         
            +
                    this.appkey=props.appkey;
         
     | 
| 
      
 12 
     | 
    
         
            +
                    this.apiCloudClient = props.apiCloudClient;
         
     | 
| 
      
 13 
     | 
    
         
            +
                    this.tableClient= this.apiCloudClient.tableClient(props.tableName);
         
     | 
| 
      
 14 
     | 
    
         
            +
                }
         
     | 
| 
      
 15 
     | 
    
         
            +
                async add(obj){
         
     | 
| 
      
 16 
     | 
    
         
            +
                   let r= await this.tableClient.add(obj);
         
     | 
| 
      
 17 
     | 
    
         
            +
                   return r;
         
     | 
| 
      
 18 
     | 
    
         
            +
                }
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                async delete(obj){
         
     | 
| 
      
 21 
     | 
    
         
            +
                    let r= await this.tableClient.delete(obj);
         
     | 
| 
      
 22 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 23 
     | 
    
         
            +
                }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                async getById(id){
         
     | 
| 
      
 26 
     | 
    
         
            +
                    let r=await this.tableClient.list({id},null,null,"sort");
         
     | 
| 
      
 27 
     | 
    
         
            +
                    return r[0];
         
     | 
| 
      
 28 
     | 
    
         
            +
                }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                async list({page=1,num=10,queryCase}){
         
     | 
| 
      
 31 
     | 
    
         
            +
                    page=Number.parseInt(page);
         
     | 
| 
      
 32 
     | 
    
         
            +
                    num=Number.parseInt(num);
         
     | 
| 
      
 33 
     | 
    
         
            +
                    let limit=num;
         
     | 
| 
      
 34 
     | 
    
         
            +
                    let skip= (page-1)*num
         
     | 
| 
      
 35 
     | 
    
         
            +
                    let rows=await this.tableClient.list(queryCase,limit,skip,"createdAt ASC");
         
     | 
| 
      
 36 
     | 
    
         
            +
                    let countResult=await this.tableClient.count(queryCase);
         
     | 
| 
      
 37 
     | 
    
         
            +
                    return {rows, total:countResult.count}
         
     | 
| 
      
 38 
     | 
    
         
            +
                }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                async listAll(obj){
         
     | 
| 
      
 41 
     | 
    
         
            +
                    let r=await this.tableClient.list(obj,null,null,"sort");
         
     | 
| 
      
 42 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 43 
     | 
    
         
            +
                }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                async update(obj){
         
     | 
| 
      
 46 
     | 
    
         
            +
                    let r=  await this.tableClient.update(obj);
         
     | 
| 
      
 47 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 48 
     | 
    
         
            +
                }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                async getChildenList(id,caseObj){
         
     | 
| 
      
 51 
     | 
    
         
            +
                    let r= this.listAll({parent_id:id,...caseObj});
         
     | 
| 
      
 52 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 53 
     | 
    
         
            +
                }
         
     | 
| 
      
 54 
     | 
    
         
            +
            }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            module.exports = ApiCloudBaseRpcApi;
         
     | 
| 
         @@ -0,0 +1,62 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * 数据源为内存的rpc风格接口
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
            const M=require("../../index")
         
     | 
| 
      
 5 
     | 
    
         
            +
            const AbstractBaseRpcApi=require("./AbstractBaseRpcApi");
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class FileBaseRpcApi extends AbstractBaseRpcApi{
         
     | 
| 
      
 8 
     | 
    
         
            +
                constructor(props) {
         
     | 
| 
      
 9 
     | 
    
         
            +
                    super(props);
         
     | 
| 
      
 10 
     | 
    
         
            +
                }
         
     | 
| 
      
 11 
     | 
    
         
            +
                async add(obj){
         
     | 
| 
      
 12 
     | 
    
         
            +
                    obj.id = M.randomStr();
         
     | 
| 
      
 13 
     | 
    
         
            +
                    M.addObjToFile(this.tableName, obj);
         
     | 
| 
      
 14 
     | 
    
         
            +
                    return obj;
         
     | 
| 
      
 15 
     | 
    
         
            +
                }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                async delete(obj){
         
     | 
| 
      
 18 
     | 
    
         
            +
                    let r=0;
         
     | 
| 
      
 19 
     | 
    
         
            +
                    if (obj) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                        r= M.deleteObjByPropFile(this.tableName, obj);
         
     | 
| 
      
 21 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 22 
     | 
    
         
            +
                        r=M.writeObjToFile(this.tableName,[]);
         
     | 
| 
      
 23 
     | 
    
         
            +
                    }
         
     | 
| 
      
 24 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 25 
     | 
    
         
            +
                }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                async getById(id){
         
     | 
| 
      
 28 
     | 
    
         
            +
                    let r=M.getById(this.tableName,id);
         
     | 
| 
      
 29 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 30 
     | 
    
         
            +
                }
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                async list({page=1,num=10,queryCase}){
         
     | 
| 
      
 33 
     | 
    
         
            +
                    page=Number.parseInt(page);
         
     | 
| 
      
 34 
     | 
    
         
            +
                    num=Number.parseInt(num);
         
     | 
| 
      
 35 
     | 
    
         
            +
                    if (page <= 0) page = 1;
         
     | 
| 
      
 36 
     | 
    
         
            +
                    let rows =await this.listAll(queryCase);
         
     | 
| 
      
 37 
     | 
    
         
            +
                    let total = rows.length;
         
     | 
| 
      
 38 
     | 
    
         
            +
                    rows = rows.splice((page - 1) * num, num)
         
     | 
| 
      
 39 
     | 
    
         
            +
                    return {rows, total}
         
     | 
| 
      
 40 
     | 
    
         
            +
                }
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                async listAll(obj){
         
     | 
| 
      
 43 
     | 
    
         
            +
                    if (obj) {
         
     | 
| 
      
 44 
     | 
    
         
            +
                        return M.listAllObjByPropFile(this.tableName, obj);
         
     | 
| 
      
 45 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 46 
     | 
    
         
            +
                        return M.getObjByFile(this.tableName);
         
     | 
| 
      
 47 
     | 
    
         
            +
                    }
         
     | 
| 
      
 48 
     | 
    
         
            +
                }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                async update(obj){
         
     | 
| 
      
 51 
     | 
    
         
            +
                    let r=  M.updateObjByIdFile(this.tableName,obj);
         
     | 
| 
      
 52 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 53 
     | 
    
         
            +
                }
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                async getChildenList(id,caseObj){
         
     | 
| 
      
 56 
     | 
    
         
            +
                    let r= this.listAll({parent_id:id,...caseObj});
         
     | 
| 
      
 57 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 58 
     | 
    
         
            +
                }
         
     | 
| 
      
 59 
     | 
    
         
            +
            }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            module.exports = FileBaseRpcApi;
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * 数据源为内存的rpc风格接口
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
            const MemoryDb=require("../../module/MemoryDb");
         
     | 
| 
      
 5 
     | 
    
         
            +
            const AbstractBaseRpcApi=require("./AbstractBaseRpcApi");
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class MemoryBaseRpcApi extends AbstractBaseRpcApi{
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                constructor(props) {
         
     | 
| 
      
 10 
     | 
    
         
            +
                   super(props);
         
     | 
| 
      
 11 
     | 
    
         
            +
                   this.memoryDb=new MemoryDb(props.tableName);
         
     | 
| 
      
 12 
     | 
    
         
            +
                }
         
     | 
| 
      
 13 
     | 
    
         
            +
                async add(obj){
         
     | 
| 
      
 14 
     | 
    
         
            +
                    let r= this.memoryDb.add(obj);
         
     | 
| 
      
 15 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 16 
     | 
    
         
            +
                }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                async delete(obj){
         
     | 
| 
      
 19 
     | 
    
         
            +
                    let r= this.memoryDb.deleteAll(obj);
         
     | 
| 
      
 20 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 21 
     | 
    
         
            +
                }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                async getById(id){
         
     | 
| 
      
 24 
     | 
    
         
            +
                    let r=this.memoryDb.getById(id);
         
     | 
| 
      
 25 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                async list({page,num,queryCase}){
         
     | 
| 
      
 29 
     | 
    
         
            +
                    let r= this.memoryDb.listByPage(page,num,queryCase);
         
     | 
| 
      
 30 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                async listAll(obj){
         
     | 
| 
      
 34 
     | 
    
         
            +
                    let r= this.memoryDb.listAll(obj);
         
     | 
| 
      
 35 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 36 
     | 
    
         
            +
                }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                async update(obj){
         
     | 
| 
      
 39 
     | 
    
         
            +
                    let r= this.memoryDb.update(obj);
         
     | 
| 
      
 40 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 41 
     | 
    
         
            +
                }
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                async getChildenList(id,caseObj){
         
     | 
| 
      
 44 
     | 
    
         
            +
                    let r= this.memoryDb.listAll({parent_id:id,...caseObj});
         
     | 
| 
      
 45 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 46 
     | 
    
         
            +
                }
         
     | 
| 
      
 47 
     | 
    
         
            +
            }
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            module.exports = MemoryBaseRpcApi;
         
     | 
| 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @type {MemoryDb|{}}
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
            const M=require("../../index");
         
     | 
| 
      
 5 
     | 
    
         
            +
            const AbstractBaseRpcApi=require("./AbstractBaseRpcApi");
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class MongoDbBaseRpcApi extends AbstractBaseRpcApi{
         
     | 
| 
      
 9 
     | 
    
         
            +
                constructor(props) {
         
     | 
| 
      
 10 
     | 
    
         
            +
                    super(props);
         
     | 
| 
      
 11 
     | 
    
         
            +
                    this.mongoDb=M.mongoDb;
         
     | 
| 
      
 12 
     | 
    
         
            +
                }
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                async add(obj){
         
     | 
| 
      
 15 
     | 
    
         
            +
                    let r= this.mongoDb.insert(this.tableName,obj);
         
     | 
| 
      
 16 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 17 
     | 
    
         
            +
                }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                async delete(obj){
         
     | 
| 
      
 20 
     | 
    
         
            +
                    let r= this.mongoDb.remove(this.tableName,{
         
     | 
| 
      
 21 
     | 
    
         
            +
                        _id:  M.mongoDb.ObjectID(obj.id)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    });
         
     | 
| 
      
 23 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 24 
     | 
    
         
            +
                }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                async getById(id){
         
     | 
| 
      
 27 
     | 
    
         
            +
                    let r=await this.mongoDb.getById(this.tableName,id);
         
     | 
| 
      
 28 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 29 
     | 
    
         
            +
                }
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                async list({page=1,num=10,queryCase}){
         
     | 
| 
      
 32 
     | 
    
         
            +
                    page=Number.parseInt(page);
         
     | 
| 
      
 33 
     | 
    
         
            +
                    num=Number.parseInt(num);
         
     | 
| 
      
 34 
     | 
    
         
            +
                    let tableName=this.tableName;
         
     | 
| 
      
 35 
     | 
    
         
            +
                    return new Promise(async (resolve,reject)=>{
         
     | 
| 
      
 36 
     | 
    
         
            +
                        this.mongoDb.connect().then((db)=>{
         
     | 
| 
      
 37 
     | 
    
         
            +
                            var result=db.collection(this.tableName).find(queryCase,{
         
     | 
| 
      
 38 
     | 
    
         
            +
                                skip:(page-1)*num,
         
     | 
| 
      
 39 
     | 
    
         
            +
                                limit:num
         
     | 
| 
      
 40 
     | 
    
         
            +
                            });
         
     | 
| 
      
 41 
     | 
    
         
            +
                            result.toArray(async function(err,docs){
         
     | 
| 
      
 42 
     | 
    
         
            +
                                if(err){
         
     | 
| 
      
 43 
     | 
    
         
            +
                                    reject(err);
         
     | 
| 
      
 44 
     | 
    
         
            +
                                    return;
         
     | 
| 
      
 45 
     | 
    
         
            +
                                }
         
     | 
| 
      
 46 
     | 
    
         
            +
                                let total=await db.collection(tableName).count(queryCase);
         
     | 
| 
      
 47 
     | 
    
         
            +
                                resolve({rows:docs,total:total});
         
     | 
| 
      
 48 
     | 
    
         
            +
                            })
         
     | 
| 
      
 49 
     | 
    
         
            +
                        })
         
     | 
| 
      
 50 
     | 
    
         
            +
                    })
         
     | 
| 
      
 51 
     | 
    
         
            +
                }
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                async listAll(obj){
         
     | 
| 
      
 55 
     | 
    
         
            +
                    let r= this.mongoDb.find(this.tableName,obj);
         
     | 
| 
      
 56 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 57 
     | 
    
         
            +
                }
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                async update(obj){
         
     | 
| 
      
 60 
     | 
    
         
            +
                    let {id,...newObj}=obj;
         
     | 
| 
      
 61 
     | 
    
         
            +
                    let r= this.mongoDb.update(this.tableName,{
         
     | 
| 
      
 62 
     | 
    
         
            +
                        _id:  M.mongoDb.ObjectID(id)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    },newObj);
         
     | 
| 
      
 64 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 65 
     | 
    
         
            +
                }
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                async getChildenList(id,caseObj){
         
     | 
| 
      
 68 
     | 
    
         
            +
                    let r= this.listAll({parent_id:id,...caseObj});
         
     | 
| 
      
 69 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 70 
     | 
    
         
            +
                }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            }
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            module.exports = MongoDbBaseRpcApi;
         
     | 
| 
         @@ -0,0 +1,72 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @type {MemoryDb|{}}
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            const BaseMapper=require("../../module/BaseMapper");
         
     | 
| 
      
 6 
     | 
    
         
            +
            const AbstractBaseRpcApi=require("./AbstractBaseRpcApi");
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            class MysqlBaseRpcApi extends AbstractBaseRpcApi{
         
     | 
| 
      
 10 
     | 
    
         
            +
                constructor(props) {
         
     | 
| 
      
 11 
     | 
    
         
            +
                    super(props);
         
     | 
| 
      
 12 
     | 
    
         
            +
                    this.dbBaseMapper= new BaseMapper(this.tableName);
         
     | 
| 
      
 13 
     | 
    
         
            +
                }
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                async add(obj){
         
     | 
| 
      
 16 
     | 
    
         
            +
                    if(obj.gmt_create){
         
     | 
| 
      
 17 
     | 
    
         
            +
                        obj.gmt_create=obj.gmt_create.format("yyyy-MM-dd hh:mm:ss");
         
     | 
| 
      
 18 
     | 
    
         
            +
                    }
         
     | 
| 
      
 19 
     | 
    
         
            +
                    let r= this.dbBaseMapper.insert(obj);
         
     | 
| 
      
 20 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 21 
     | 
    
         
            +
                }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                async delete(obj){
         
     | 
| 
      
 24 
     | 
    
         
            +
                    let r= this.dbBaseMapper.delete(obj);
         
     | 
| 
      
 25 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                async getById(id){
         
     | 
| 
      
 29 
     | 
    
         
            +
                    let r=await this.dbBaseMapper.selectById({id});
         
     | 
| 
      
 30 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                async list({page,num,queryCase}){
         
     | 
| 
      
 34 
     | 
    
         
            +
                    let queryCaseStr= MysqlBaseRpcApi.obj2QueryCase(queryCase);
         
     | 
| 
      
 35 
     | 
    
         
            +
                    let r= this.dbBaseMapper.selectPage({page,num,queryCase:queryCaseStr});
         
     | 
| 
      
 36 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 37 
     | 
    
         
            +
                }
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                async listAll(obj){
         
     | 
| 
      
 40 
     | 
    
         
            +
                    let queryCase= MysqlBaseRpcApi.obj2QueryCase(obj);
         
     | 
| 
      
 41 
     | 
    
         
            +
                    let r= this.dbBaseMapper.selectList({queryCase:queryCase});
         
     | 
| 
      
 42 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 43 
     | 
    
         
            +
                }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                async update(obj){
         
     | 
| 
      
 46 
     | 
    
         
            +
                    if(obj.gmt_modified){
         
     | 
| 
      
 47 
     | 
    
         
            +
                        obj.gmt_modified=obj.gmt_modified.format("yyyy-MM-dd hh:mm:ss");
         
     | 
| 
      
 48 
     | 
    
         
            +
                    }
         
     | 
| 
      
 49 
     | 
    
         
            +
                    let {id,...newObj}=obj;
         
     | 
| 
      
 50 
     | 
    
         
            +
                    let r= this.dbBaseMapper.update(newObj,`id=${id}`);
         
     | 
| 
      
 51 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 52 
     | 
    
         
            +
                }
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                async getChildenList(id,caseObj){
         
     | 
| 
      
 55 
     | 
    
         
            +
                    let r= this.listAll({parent_id:id,...caseObj});
         
     | 
| 
      
 56 
     | 
    
         
            +
                    return r;
         
     | 
| 
      
 57 
     | 
    
         
            +
                }
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                static obj2QueryCase(obj){
         
     | 
| 
      
 60 
     | 
    
         
            +
                    let queryCase="1=1";
         
     | 
| 
      
 61 
     | 
    
         
            +
                    if(obj && Object.keys(obj).length>0){
         
     | 
| 
      
 62 
     | 
    
         
            +
                        for(var p in obj) {
         
     | 
| 
      
 63 
     | 
    
         
            +
                            queryCase=queryCase+` and ${p}='${obj[p]}' `
         
     | 
| 
      
 64 
     | 
    
         
            +
                        }
         
     | 
| 
      
 65 
     | 
    
         
            +
                    }
         
     | 
| 
      
 66 
     | 
    
         
            +
                    return queryCase;
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                }
         
     | 
| 
      
 69 
     | 
    
         
            +
            }
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            module.exports = MysqlBaseRpcApi;
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class CollectionUtils{
         
     | 
| 
      
 4 
     | 
    
         
            +
                static async selectTree(getChildenList,parent_id=-1,queryCase={}){
         
     | 
| 
      
 5 
     | 
    
         
            +
                    async function addChilden(record){
         
     | 
| 
      
 6 
     | 
    
         
            +
                        let cList= await getChildenList(record.id,queryCase);
         
     | 
| 
      
 7 
     | 
    
         
            +
                        record.childen=cList;
         
     | 
| 
      
 8 
     | 
    
         
            +
                        if(cList.length==0){
         
     | 
| 
      
 9 
     | 
    
         
            +
                            return
         
     | 
| 
      
 10 
     | 
    
         
            +
                        }
         
     | 
| 
      
 11 
     | 
    
         
            +
                        for (let i=0;i<cList.length;i++){
         
     | 
| 
      
 12 
     | 
    
         
            +
                            let cObj= cList[i];
         
     | 
| 
      
 13 
     | 
    
         
            +
                            addChilden(cObj);
         
     | 
| 
      
 14 
     | 
    
         
            +
                        }
         
     | 
| 
      
 15 
     | 
    
         
            +
                    }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                    let rootList=await getChildenList(parent_id,queryCase);
         
     | 
| 
      
 18 
     | 
    
         
            +
                    for (let i=0;i<rootList.length;i++){
         
     | 
| 
      
 19 
     | 
    
         
            +
                        let obj=rootList[i];
         
     | 
| 
      
 20 
     | 
    
         
            +
                        await addChilden(obj);
         
     | 
| 
      
 21 
     | 
    
         
            +
                    }
         
     | 
| 
      
 22 
     | 
    
         
            +
                    return rootList;
         
     | 
| 
      
 23 
     | 
    
         
            +
                }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            }
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            module.exports = CollectionUtils;
         
     | 
    
        package/beforeTest/t1.js
    DELETED
    
    | 
         @@ -1,18 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            var M=require("../index");
         
     | 
| 
       2 
     | 
    
         
            -
            var app=M.server();
         
     | 
| 
       3 
     | 
    
         
            -
            app.listen(8888);
         
     | 
| 
       4 
     | 
    
         
            -
            app.put("/getById/:id",(req,res)=>{
         
     | 
| 
       5 
     | 
    
         
            -
                console.log("put",req.params);
         
     | 
| 
       6 
     | 
    
         
            -
                res.send("ok");
         
     | 
| 
       7 
     | 
    
         
            -
            })
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            app.post("/getById/:id",(req,res)=>{
         
     | 
| 
       10 
     | 
    
         
            -
                console.log("post",req.params);
         
     | 
| 
       11 
     | 
    
         
            -
                res.send("ok");
         
     | 
| 
       12 
     | 
    
         
            -
            })
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            app.delete("/getById/:id",(req,res)=>{
         
     | 
| 
       16 
     | 
    
         
            -
                console.log("delete",req.params);
         
     | 
| 
       17 
     | 
    
         
            -
                res.send("ok");
         
     | 
| 
       18 
     | 
    
         
            -
            })
         
     |