From 4208b722c7faa9d571c3c1e05612b2e9423ee80c Mon Sep 17 00:00:00 2001 From: walker Date: Wed, 13 Sep 2017 21:22:21 +0800 Subject: [PATCH] init --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 61 +++ README.md | 28 ++ app.js | 169 +++++++ index.html | 1174 ++++++++++++++++++++++++++++++++++++++++++++++++ output.json | 1 + package.json | 19 + run.sh | 1 + template.h | 35 ++ template.m | 27 ++ templatebase.m | 23 + 11 files changed, 1538 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 README.md create mode 100755 app.js create mode 100644 index.html create mode 100644 output.json create mode 100644 package.json create mode 100755 run.sh create mode 100644 template.h create mode 100644 template.m create mode 100644 templatebase.m diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d77463ddcc0d176a1c0249a623d880e4c499f93a GIT binary patch literal 6148 zcmeHKyH3ME5S)bwMS>zF<^2MGU`62z@&QmJq6rQHOzn=}X7&L};?Po{S!s8CdpmdX z6kaa?TMnB$U;$uGcf_ZMsrkP9#4al1XmQ2^p0URU19p?@^9kqPpbyp-hx{$xKGv`O zZr?xU`M6@$fOoujJlQ*cy0TJ03P=GdAO)nrsRHcTZu9FzMJXT!q`;2?{(We4$F6Wp zj86wci~z(L(_ws$S%TO+LF@|0L}qA~RAN%CMhr_j^R4Q-!Z9)Fu(+A$)Xi2CipA~B zw5>MJ5IQLV+*lCmY59 literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09274a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +output/ +package-lock.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..121d8ed --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# 基本使用 + +``` +./app.js -C aaa,bbb,ccc -K aaa,bbb,ccc -P aaa,bbb,ccc +``` + +或 + +``` +./app.js -c aaa -c bbb -k aaa -k bbb -p aaa -p ccc +``` + +视参数多少自行使用, + +或者将带参数命令写入`run.sh`文件并执行该文件 + +# 参数介绍 + ++ 类名: 本次生成所需要用到的所有自定义类名, 请按文档顺序自上而下. 目前请保证参数个数与需要的个数一致, 用`-c`一次一个, 可重复, 或`-C`, 逗号分隔, 不支持空格 ++ 基类名: 见示例. 目前只支持两个基类 `-b` ++ 不处理的键: 跳过, 不写到文件, 如果有基类的情况, 适用此属性. `-p, -P` ++ 子类对应的键: 如果该键对应的是一个对象或对象数组, 请传入键名. `-k, -K` + +请用`-h`命令查看更多帮助 + +# 模板介绍 + +模板文件用ES2015的模板字符串语法编写, 请参阅[文档](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) diff --git a/app.js b/app.js new file mode 100755 index 0000000..8d39088 --- /dev/null +++ b/app.js @@ -0,0 +1,169 @@ +#!/usr/bin/env node + +let fs = require('fs-extra'), + path = require('path'), + program = require('commander'), + cheerio = require('cheerio'), + $; + +// 命令行参数 +let collect = function(val, col) { + col.push(val); + return col; +}; +let batchCollect = function(val) { + return val.split(','); +}; +program + .version('0.0.1') + .option('-f, --file [type]', 'set input file name','index.html') + .option('-k, --datakeys [keys]', 'set data key names', collect, []) + .option('-K, --batchdatakeys ', 'batch set data keys', batchCollect) + .option('-b, --base [name]', 'set the base class names', collect, []) + .option('-c, --classes [name]', 'set the sub class names', collect, []) + .option('-C, --batchclasses ', 'batch set sub class names', batchCollect) + .option('-p, --passkeys [key]', 'set exclued keys', collect, []) + .option('-P, --batchpasskeys ', 'batch set exclued keys', batchCollect) + .parse(process.argv); + +let baseClasses = program.base.length || ['PMLResponseBaseHD', 'PMLModelBase'], + classCollect = program.classes.length?program.classes : program.batchclasses||[], + dataKeys = program.datakeys.length?program.datakeys : program.batchdatakeys||[], + passKeys = program.passkeys.length?program.passkeys : program.batchpasskeys||[], + nameFactory = classNameGenerator(); +dataKeys.push('data'); // 添加一个默认的 data 键, 要通用性的话, 这里不应该加 +(async () => { +let content = await readFile(program.file), + $ = cheerio.load(content), + contentJSON = []; +await $(".wiki-content>.table-wrap").each(async (i, table) => { + if(i%2 == 0) return; + processTable(table); +}); +await fs.writeJson('./output.json', contentJSON); // for test +await parseTemplate(contentJSON); +console.log("done!"); + +function processTable(table, classMeta) { + let modelName = "", + baseName = baseClasses[0], + isRoot = true; // 子类如果需要继承不同的基类, 则利用此标识 + if(classMeta) { + // 有classMeta, 说明是一个子类 + modelName = classMeta["model"]; + baseName = baseClasses[1]; + isRoot = false; + }else{ + modelName = nameFactory.next().value; + } + let fileName_h = modelName + ".h", + fileName_m = modelName + ".m", + rowIsTable = false, + props = [], + complexProperty; // 如果当前行表示是个对象或数据, 把元数据保存, 用来生成子表格对应的类 + $(table).children(".confluenceTable").children("tbody").children("tr") + .each(async (i,tr) => { + if(rowIsTable){ + // 进入这个方法,说明上一行标识这一行是子类 + rowIsTable = false; + return processTable($(tr).children("td").children(".table-wrap"), complexProperty); + } + let tds = $(tr).children('td'); + let nameMatch = /[a-z]+/ig.exec(tds.eq(0).text()); + if(!nameMatch) return; // 非英文则理解为不是属性名 + if(passKeys.indexOf(nameMatch[0])>=0) return; // 包含预设排除关键字, 不需要处理 + let isComplexObj = dataKeys.indexOf(nameMatch[0])>=0; // 包含预设子类关键字, 理解为复杂对象 + // 记录属性名, 类型, 注释等 + let pname = tds.eq(0).text().trim(); + let ptype = tds.eq(2).text().trim(); + let isArray = ptype.toLowerCase() == 'list'; + if(isComplexObj) ptype = nameFactory.next().value; + let assume_type = assumeVarType(ptype, isArray, ptype); + let prop = { + "name": pname, + "des": tds.eq(1).text(), + "type": assume_type[0], + "isArray": isArray + }; + if(tds.eq(3).text().trim()) { + prop["des"] = prop["des"] + " " + tds.eq(3).text(); + } + if(isComplexObj){ + prop["model"] = assume_type[1]; + rowIsTable = true; + complexProperty = prop; + } + props.push(prop); + }); // end of basetable > tr > foreach + contentJSON.push({"isRoot": isRoot, "className": modelName,"baseName": baseName, "props": props}); + console.log("生成模型:", modelName) + } +})(); + + +// 类名生成器 +function* classNameGenerator() { + yield* classCollect; +} + +async function readFile(filename) { + let fullpath = path.join(__dirname, filename); + console.log('start processing file:', fullpath); + return await fs.readFile(fullpath, 'utf8') + .catch(console.log); +} + +async function createFile(filename) { + let fullpath = path.join(__dirname, filename), + stat = await fs.stat(fullpath).catch(e=>{ + console.log('create file', fullpath); + }); + await fs.writeFile(fullpath, 'hey there') + .catch(console.log); +} + +/** + * 根据关键字推断类型 + * @prarm str: 关键字 + * @param isArray: 是否数组类型 + * @param model: 自定义类型 + * @return 返回[变量类型, 模型类型] + * 比如 [NSArray *, Doctor *] + * 一个用于建模, 一个用于写属性 + */ +function assumeVarType(str, isArray, model) { + let l_str = str.toLowerCase(), + model_type = str, // 类型 + var_type = str; // 字段 + if(l_str.indexOf('string') >= 0) model_type = "NSString *"; + else if(['int', 'integer', 'long'].findIndex(v=>(new RegExp(v,'ig')).test(l_str)) >= 0) model_type = "NSInteger"; + else { + console.log("====undefined type: =====", str); + model_type = model + " *"; + } + var_type = isArray ? "NSArray<"+model_type+"> *" : model_type;; + model_type = model_type.replace(' *',''); + return [var_type, model_type]; +} + +async function parseTemplate(data) { + console.log("开始应用模板"); + // 暂时不支持别的语言, 为本项目使用(3个模板文件) + // 以后要优化则要根据模板文件的个数有所个性化 + let copyright = "民康", + projectname = "项目名", + date = (new Date()).toLocaleDateString(), + author = "walker", + // 模板内容 + h_content = await fs.readFile(path.join(__dirname, 'template.h'), 'utf8').catch(console.log), + m_content1 = await fs.readFile(path.join(__dirname, 'template.m'), 'utf8').catch(console.log), + m_content2 = await fs.readFile(path.join(__dirname, 'templatebase.m'), 'utf8').catch(console.log); + for(let model of data) { + let m_content = model.isRoot ? m_content2 : m_content1; + // 输出路径 + let h_file = path.join(__dirname, 'output', model.className+'.h'), + m_file = path.join(__dirname, 'output', model.className+'.m'); + await fs.writeFile(h_file, eval(h_content), 'utf8').catch(console.log); + await fs.writeFile(m_file, eval(m_content), 'utf8').catch(console.log); + } +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..b33926d --- /dev/null +++ b/index.html @@ -0,0 +1,1174 @@ + + + + 7. 医生相关 - 04-01 团队:平台建设部-技术部 - 微医集团知识库 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + +
+
+ + + + + + +
+ +
+
+ + + + +
+
+ + +
    +
    +
    +
+ + +
+ + + +
+
+ + + + + +
+
+ + + + + +

+ + + 7. 医生相关 + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + Skip to end of metadata +
+ + + + +Go to start of metadata +
+ + + +
+

医生列表

1) 功能描述

查询医生列表

接口地址:${服务地址}/doctor/list.json

2) 请求参数

字段名

变量名

类型(长度)

说明

可空

样例

统一参数

authentication可以为空

业务参数

pageIndex

页码

Integer

 

可空,默认为 1

 

pageSize每页大小Integer 可空,默认为 20 
hospitalId医院IDString 可空(不可与channelId同时为空 
channelId渠道idstring 可空(不可与hospitalId同时为空 


3) 响应参数

字段名

变量名

类型(长度)

说明

可空

样例

统一响应参数(公共)

code状态码String   
flag业务标识String

0:查询医生列表成功

1:当前不在签约时间内

2:未查到签约时间配置信息

3:查询医生列表失败

  
message业务标识信息String   
pageIndex页码Integer   
pageSize每页大小Integer   
total记录总数Integer   
totalPage总页数Integer   

data

 

List

   
doctorId
医生IDString   
doctorUserId医生姓名Long   
doctorName医生姓名String   
techTitle医生职称String
   
doctorImg医生头像String   
deptId科室IDString   
deptName科室名称String   
signCount医生签约量Integer   
isFull签约人数是否已满int0-未满,1—已满不可空 
hasPkg是否有服务包int0-没有,1-有服务包不可空 

 

附近家医列表

1) 功能描述

查询医生列表

接口地址:${服务地址}/doctor/nearlist.json

2) 请求参数

字段名

变量名

类型(长度)

说明

可空

样例

统一参数

authentication可以为空

业务参数

pageIndex

页码

Integer

 

可空,默认为 1

 

pageSize每页大小Integer 可空,默认为 正无穷大 
provinceId省份IDInteger 非空 
 cityId 城市IDInteger  可空(直辖市全城的情况) 
 districtId 地区ID Integer  可空(直辖市附近的情况、非直辖市全城的情况) 


3) 响应参数

字段名

变量名

类型(长度)

说明

可空

样例

统一响应参数(公共)

code状态码String   
flag业务标识String

0:查询医生列表成功

1:当前不在签约时间内

2:未查到签约时间配置信息

3:查询医生列表失败

  
message业务标识信息String   
pageIndex页码Integer   
pageSize每页大小Integer   
total记录总数Integer   
totalPage总页数Integer   

data

 

List

   
doctorId
医生IDString   
doctorUserId医生姓名Long   
doctorName医生姓名String   
hospitalId
医院idstring   
hospitalName
医院名称
string   
techTitle医生职称String
   
doctorImg医生头像String   
deptId科室IDString   
deptName科室名称String   
signCount医生签约量Integer   
groupUuid团队uudistring   
groupName团队名称string   
isFull签约人数是否已满int0-未满,1—已满不可空 
hasPkg是否有服务包int0-没有,1-有服务包不可空 

医生详情

1) 功能描述

查询医生详情

接口地址:${服务地址}/doctor/detail.json

2) 请求参数

字段名

变量名

类型(长度)

说明

可空

样例

统一参数

authentication可以为空

业务参数

doctorUserId医生IDLong 非空 

3) 响应参数

 

字段名

变量名

类型(长度)

说明

可空

样例

统一响应参数(公共)

code状态码String   
flag业务标识String

0:成功

1:失败

  
message业务标识信息String   

data

 

   
doctorId
医生IDString样例  
doctorUserId医生用户IDLong   
doctorName医生姓名String   
sex医生性别string  
techTitle医生职称String
   
doctorImg医生头像String   
deptId科室IDString   
deptName科室名称String   
feature擅长String   
introduction简介String   
signCount医生签约量Integer   
commonly一般String10%  
satisfied满意String10%  
verySatisfied非常满意String10%  
serviceArea服务区域string   
servicePkgDOList
服务包列表list   
 
id
服务包idInteger   
provinceId
省Id
Integer
   
provinceName
省名称
String
   
cityId
市id
Integer
   
cityName
String
   
districtId
区id
Integer
   
districtName
区名称
String
   
serviceName
服务或套餐名称
String
   
serviceType
套餐类型 '0:签约套餐,1:特色服务包',
Integer
   
serviceRecommend
0:推荐,1:否',
Integer
   
fee
价格
Integer
   
serviceImg
套餐服务图标
String
   
serviceContent
服务内容
String
   
link
链接页面
String
   
businessType
'业务类型1-家庭医生 2-责任医生',
Integer
   
isDeleted
是否删除
* '0:未删除 ,1:删除',
Integer
   
serviceStatus
服务包状态
* '0:暂停 ,1:启用',
Integer
   
agreementApplyUUID
签约申请ID
String
   
hospitalId
医院id
String
   
hospitalName
医院名称
Integer
   
serviceCycle
服务周期(单位:月)
Integer
   
purchaseStart
购买开始时间
String
   
purchaseEnd
购买结束时间
String
   
serviceStart
服务开始时间
String
   
serviceEnd
服务结束时间
 String   
isResetCalc
按照实际生效时间重新计算服务期限,1是 0否
 Integer   
serviceAbstract
服务摘要
String
   
servicePkgStatus
服务包状态 1-已生效,2-已退订,3-退款中,4-已退款
Integer
   
refundMoney
退款金额
Integer
   
 crowdList 人群类别列表 String   
 dieaseList 疾病标签列表 String   
servicePkgItemDOList 服务项目列表 list   
pkgId
服务包id
Integer
   
projectTitle
项目名称
String
   
projectType
类别 关联字典表取值
String
   
tag
标签 多个以逗号分割
String
   
serviceCount
服务次数
Integer
   
serviceUseCount
已用次数
Integer
   
 
+ +
+ + + + + + + + +
+
+ Labels +
+
+ + + +
+
+
+ + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
Write a comment…
+ +
+ +
+

+ Add Comment +

+
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+
+ +
+
+ + + + +
+ + + diff --git a/output.json b/output.json new file mode 100644 index 0000000..9be3d33 --- /dev/null +++ b/output.json @@ -0,0 +1 @@ +[{"isRoot":false,"className":"DoctorListInfoModel","baseName":"PMLModelBase","props":[{"name":"doctorId","des":"医生ID","type":"NSString *","isArray":false},{"name":"doctorUserId","des":"医生姓名","type":"NSInteger","isArray":false},{"name":"doctorName","des":"医生姓名","type":"NSString *","isArray":false},{"name":"techTitle","des":"医生职称","type":"NSString *","isArray":false},{"name":"doctorImg","des":"医生头像","type":"NSString *","isArray":false},{"name":"deptId","des":"科室ID","type":"NSString *","isArray":false},{"name":"deptName","des":"科室名称","type":"NSString *","isArray":false},{"name":"signCount","des":"医生签约量","type":"NSInteger","isArray":false},{"name":"isFull","des":"签约人数是否已满 0-未满,1—已满","type":"NSInteger","isArray":false},{"name":"hasPkg","des":"是否有服务包 0-没有,1-有服务包","type":"NSInteger","isArray":false}]},{"isRoot":true,"className":"DoctorListResponseModel","baseName":"PMLResponseBaseHD","props":[{"name":"pageIndex","des":"页码","type":"NSInteger","isArray":false},{"name":"pageSize","des":"每页大小","type":"NSInteger","isArray":false},{"name":"total","des":"记录总数","type":"NSInteger","isArray":false},{"name":"totalPage","des":"总页数","type":"NSInteger","isArray":false},{"name":"data","des":" ","type":"NSArray *","isArray":true,"model":"DoctorListInfoModel"}]},{"isRoot":false,"className":"NearDoctorInfoModel","baseName":"PMLModelBase","props":[{"name":"doctorId","des":"医生ID","type":"NSString *","isArray":false},{"name":"doctorUserId","des":"医生姓名","type":"NSInteger","isArray":false},{"name":"doctorName","des":"医生姓名","type":"NSString *","isArray":false},{"name":"hospitalId","des":"医院id","type":"NSString *","isArray":false},{"name":"hospitalName","des":"医院名称","type":"NSString *","isArray":false},{"name":"techTitle","des":"医生职称","type":"NSString *","isArray":false},{"name":"doctorImg","des":"医生头像","type":"NSString *","isArray":false},{"name":"deptId","des":"科室ID","type":"NSString *","isArray":false},{"name":"deptName","des":"科室名称","type":"NSString *","isArray":false},{"name":"signCount","des":"医生签约量","type":"NSInteger","isArray":false},{"name":"groupUuid","des":"团队uudi","type":"NSString *","isArray":false},{"name":"groupName","des":"团队名称","type":"NSString *","isArray":false},{"name":"isFull","des":"签约人数是否已满 0-未满,1—已满","type":"NSInteger","isArray":false},{"name":"hasPkg","des":"是否有服务包 0-没有,1-有服务包","type":"NSInteger","isArray":false}]},{"isRoot":true,"className":"NearDoctorsResponseModel","baseName":"PMLResponseBaseHD","props":[{"name":"pageIndex","des":"页码","type":"NSInteger","isArray":false},{"name":"pageSize","des":"每页大小","type":"NSInteger","isArray":false},{"name":"total","des":"记录总数","type":"NSInteger","isArray":false},{"name":"totalPage","des":"总页数","type":"NSInteger","isArray":false},{"name":"data","des":" ","type":"NSArray *","isArray":true,"model":"NearDoctorInfoModel"}]},{"isRoot":false,"className":"ServicePackageItemModel","baseName":"PMLModelBase","props":[{"name":"pkgId","des":"服务包id","type":"NSInteger","isArray":false},{"name":"projectTitle","des":"项目名称","type":"NSString *","isArray":false},{"name":"projectType","des":"类别 关联字典表取值","type":"NSString *","isArray":false},{"name":"tag","des":"标签 多个以逗号分割","type":"NSString *","isArray":false},{"name":"serviceCount","des":"服务次数","type":"NSInteger","isArray":false},{"name":"serviceUseCount","des":"已用次数","type":"NSInteger","isArray":false}]},{"isRoot":false,"className":"ServicePackageInfoModel","baseName":"PMLModelBase","props":[{"name":"id","des":"服务包id","type":"NSInteger","isArray":false},{"name":"provinceId","des":"省Id","type":"NSInteger","isArray":false},{"name":"provinceName","des":"省名称","type":"NSString *","isArray":false},{"name":"cityId","des":"市id","type":"NSInteger","isArray":false},{"name":"cityName","des":"市","type":"NSString *","isArray":false},{"name":"districtId","des":"区id","type":"NSInteger","isArray":false},{"name":"districtName","des":"区名称","type":"NSString *","isArray":false},{"name":"serviceName","des":"服务或套餐名称","type":"NSString *","isArray":false},{"name":"serviceType","des":"套餐类型 '0:签约套餐,1:特色服务包',","type":"NSInteger","isArray":false},{"name":"serviceRecommend","des":"0:推荐,1:否',","type":"NSInteger","isArray":false},{"name":"fee","des":"价格","type":"NSInteger","isArray":false},{"name":"serviceImg","des":"套餐服务图标","type":"NSString *","isArray":false},{"name":"serviceContent","des":"服务内容","type":"NSString *","isArray":false},{"name":"link","des":"链接页面","type":"NSString *","isArray":false},{"name":"businessType","des":"'业务类型1-家庭医生 2-责任医生',","type":"NSInteger","isArray":false},{"name":"isDeleted","des":"是否删除* '0:未删除 ,1:删除',","type":"NSInteger","isArray":false},{"name":"serviceStatus","des":"服务包状态* '0:暂停 ,1:启用',","type":"NSInteger","isArray":false},{"name":"agreementApplyUUID","des":"签约申请ID","type":"NSString *","isArray":false},{"name":"hospitalId","des":"医院id","type":"NSString *","isArray":false},{"name":"hospitalName","des":"医院名称","type":"NSInteger","isArray":false},{"name":"serviceCycle","des":"服务周期(单位:月)","type":"NSInteger","isArray":false},{"name":"purchaseStart","des":"购买开始时间","type":"NSString *","isArray":false},{"name":"purchaseEnd","des":"购买结束时间","type":"NSString *","isArray":false},{"name":"serviceStart","des":"服务开始时间","type":"NSString *","isArray":false},{"name":"serviceEnd","des":"服务结束时间","type":"NSString *","isArray":false},{"name":"isResetCalc","des":"按照实际生效时间重新计算服务期限,1是 0否","type":"NSInteger","isArray":false},{"name":"serviceAbstract","des":"服务摘要","type":"NSString *","isArray":false},{"name":"servicePkgStatus","des":"服务包状态 1-已生效,2-已退订,3-退款中,4-已退款","type":"NSInteger","isArray":false},{"name":"refundMoney","des":"退款金额","type":"NSInteger","isArray":false},{"name":"crowdList","des":" 人群类别列表","type":"NSString *","isArray":false},{"name":"dieaseList","des":" 疾病标签列表","type":"NSString *","isArray":false},{"name":"servicePkgItemDOList","des":" 服务项目列表","type":"NSArray *","isArray":true,"model":"ServicePackageItemModel"}]},{"isRoot":false,"className":"DoctorInfoDetailModel","baseName":"PMLModelBase","props":[{"name":"doctorId","des":"医生ID 样例","type":"NSString *","isArray":false},{"name":"doctorUserId","des":"医生用户ID","type":"NSInteger","isArray":false},{"name":"doctorName","des":"医生姓名","type":"NSString *","isArray":false},{"name":"sex","des":"医生性别 男","type":"NSString *","isArray":false},{"name":"techTitle","des":"医生职称","type":"NSString *","isArray":false},{"name":"doctorImg","des":"医生头像","type":"NSString *","isArray":false},{"name":"deptId","des":"科室ID","type":"NSString *","isArray":false},{"name":"deptName","des":"科室名称","type":"NSString *","isArray":false},{"name":"feature","des":"擅长","type":"NSString *","isArray":false},{"name":"introduction","des":"简介","type":"NSString *","isArray":false},{"name":"signCount","des":"医生签约量","type":"NSInteger","isArray":false},{"name":"commonly","des":"一般 10%","type":"NSString *","isArray":false},{"name":"satisfied","des":"满意 10%","type":"NSString *","isArray":false},{"name":"verySatisfied","des":"非常满意 10%","type":"NSString *","isArray":false},{"name":"serviceArea","des":"服务区域","type":"NSString *","isArray":false},{"name":"servicePkgDOList","des":"服务包列表","type":"NSArray *","isArray":true,"model":"ServicePackageInfoModel"}]},{"isRoot":true,"className":"DoctorInfoResponseModel","baseName":"PMLResponseBaseHD","props":[{"name":"data","des":" ","type":"DoctorInfoDetailModel *","isArray":false,"model":"DoctorInfoDetailModel"}]}] diff --git a/package.json b/package.json new file mode 100644 index 0000000..5510a28 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "talbetomodel", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node app.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "walker", + "license": "MIT", + "dependencies": { + "cheerio": "^1.0.0-rc.2", + "commander": "^2.11.0", + "fs-extra": "^4.0.1" + }, + "devDependencies": { + } +} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..ee1f1c7 --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +./app.js -C DoctorListResponseModel,DoctorListInfoModel,NearDoctorsResponseModel,NearDoctorInfoModel,DoctorInfoResponseModel,DoctorInfoDetailModel,ServicePackageInfoModel,ServicePackageItemModel -K servicePkgItemDOList,servicePkgDOList -P code,flag,message diff --git a/template.h b/template.h new file mode 100644 index 0000000..a38a3dc --- /dev/null +++ b/template.h @@ -0,0 +1,35 @@ +`// +// ${model.className}.h +// ${projectname} +// +// Created by ${author} on ${date}. +// Copyright © 2017 ${copyright} All rights reserved. +// + +#import +${model.props.filter(m=>m.model).map(prop => +`#import ${prop.model}.h` +).join('')} + +@interface ${model.className} : ${model.baseName} +${model.props.map(prop => { +if(prop.type == 'NSInteger') return ` +/** + * ${prop.des} + */ +property (nonatomic, assign) ${prop.type} ${prop.name}; +`; +else if(prop.type == 'NSString *') return ` +/** + * ${prop.des} + */ +property (nonatomic, copy) ${prop.type} ${prop.name}; +`; +return ` +/** + * ${prop.des} + */ +property (nonatomic, strong) ${prop.type} ${prop.name}; +`}).join('')} + +@end` \ No newline at end of file diff --git a/template.m b/template.m new file mode 100644 index 0000000..5768023 --- /dev/null +++ b/template.m @@ -0,0 +1,27 @@ +`// +// ${model.className}.m +// ${projectname} +// +// Created by ${author} on ${date}. +// Copyright © 2017 ${copyright} All rights reserved. +// + +#import ${model.className}.h + +@implementation ${model.className} + ++ (NSDictionary *)JSONKeyPathsByPropertyKey { + return [NSDictionary mtl_identityPropertyMapWithModel:[self class]]; +} + +${model.props.filter(m=>m.model&&m.isArray).map(prop => +`+ (NSValueTransformer *)${prop.name}JSONTransformer { + return [MTLJSONAdapter arrayTransformerWithModelClass:[${prop.model} class]]; +}`).join()} + +${model.props.filter(m=>m.model&&!m.isArray).map(prop => +`+ (NSValueTransformer *)${prop.name}JSONTransformer { + return [MTLJSONAdapter dictionaryTransformerWithModelClass:[${prop.model} class]]; +}`).join()} + +@end` \ No newline at end of file diff --git a/templatebase.m b/templatebase.m new file mode 100644 index 0000000..94a8ac0 --- /dev/null +++ b/templatebase.m @@ -0,0 +1,23 @@ +`// +// ${model.className}.m +// ${projectname} +// +// Created by ${author} on ${date}. +// Copyright © 2017 ${copyright} All rights reserved. +// + +#import ${model.className}.h + +@implementation ${model.className} + ++ (NSDictionary *)JSONKeyPathsByPropertyKey { + NSDictionary *dict = [NSDictionary mtl_identityPropertyMapWithModel:[self class]]; + return [super mergeDict:dict withDict:[super JSONKeyPathsByPropertyKey]]; +} + +${model.props.filter(m=>m.model).map(prop => +`+ (NSValueTransformer *)${prop.name}JSONTransformer { + return [MTLJSONAdapter dictionaryTransformerWithModelClass:[${prop.model} class]]; +}`).join()} + +@end` \ No newline at end of file