Skip to content

Commit

Permalink
更改去重逻辑;增加float
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerwzy committed Jan 18, 2018
1 parent 159766f commit 8a02ce1
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 20 deletions.
34 changes: 20 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function parseResponseTable(table, classMeta) {
let assume_type = assumeVarType(ptype, isArray, ptype);
let prop = {
"name": pname,
"des": tds.eq(1).text(),
"des": tds.eq(1).text().replace(/[\s\/\*]/ig,''),
"type": assume_type[0],
"isArray": isArray
};
Expand Down Expand Up @@ -153,7 +153,7 @@ function parseRequestTable(table) {
if(i<2) return;
let tds = Array.from($(tr).children('td'));
if($(tds[0]).text() == '业务参数' || $(tds[0]).text().trim().length == 0) return;
let propdes = tds.map(t=>$(t).text().replace(/\s/ig, '')).join(' ');
let propdes = tds.map(t=>$(t).text().replace(/[\s]/ig, '')).join(' ');
param_des.push(propdes);
});
methodArgs.push(param_des);
Expand Down Expand Up @@ -253,18 +253,24 @@ async function parseTemplate() {
h_task = await getFileContent(task_path, 'task.h'),
m_task = await getFileContent(task_path, 'task.m');
let out_model = "output_model",
out_task = "output_task",
exist_file = []; // 重复定义的类, 只生成一次, 生成过一次就丢到这个数组里打标
out_task = "output_task";
await fs.emptyDir(out_model); // 创建/清空输出文件夹
await fs.emptyDir(out_task); // 创建/清空输出文件夹
if(program.verbose) console.log("开始生成实体类")
entities.forEach(async (model, index) => {
// 有些子类字段是一样的, 我们写脚本的时候把类名写成一样的, 此处会 pass 掉
// 但只对单次执行脚本有效
if(classCollect.filter(m=>m==model.className).length>1) {
if(exist_file.includes(model)) return;
exist_file.push(model);
}
if(program.verbose) console.log("开始生成实体类");
// 先去重
let usedModels = [],
datasource = [];
entities.forEach((model, index) => {
if(classCollect.filter(m=>m==model.className).length==1) return datasource.push(model);
if(usedModels.includes(model.className)) return;
usedModels.push(model.className);
datasource.push(model);
});
datasource.forEach(async (model, index) => {
// if(classCollect.filter(m=>m==model.className).length>1) {
// if(exist_file.includes(model)) return;
// exist_file.push(model);
// }
let m_content = model.isRoot ? m_content2 : m_content1;
// 输出路径
let h_file = getPath(out_model, model.className+'.h'),
Expand All @@ -278,8 +284,8 @@ async function parseTemplate() {
if(program.verbose) console.log("开始生成请求类");
let h_file = getPath(out_task, `${modulename}.h`),
m_file = getPath(out_task, `${modulename}.m`);
if(endpoints.length!=methodArgs.length)
return console.log("接口数量与入参数量不一致的", endpoints, methodArgs); // 接口由解析文本来的, 入参描述由解析表格来的, 可能不一致
if(endpoints.length>methodArgs.length)
return console.log("接口数量与入参数量不一致的", endpoints, methodArgs); // 接口由解析文本来的, 入参描述由解析表格来的, 可能不一致, 但是入参可以多(有的接口不需要post->.json)
if(endpoints.length>methodTitles.length)
return console.log("接口数量与接口标题数量不一致", endpoints, methodTitles); // 分别由解析文本而来, 可能不一致
if(endpoints.length<methodTitles.length)
Expand Down
61 changes: 61 additions & 0 deletions scripts/jyd/1.公共.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
author='walker'
projectname='FamilyDoctor'
passkeys='code,flag,message'
fileuri='/Users/walker/Desktop/index.html'
offset=1
debug=true
verbose=false
modulename='taskCommon'
httpclient='PMLRESTBaseDoctor'
models=(
#地区列表
modelAreaListItem
#获取图片验证码
#医生其他端获取手机验证码
#医生APP获取手机验证码
#医院搜索
modelHospitalSearchResult,modelHospitalSearchResultItem
#医院详情
modelHospitalDetail
#科室搜索
modelHospitalDeptSearchResult,modelDeptSearchResultItem
#科室详情
modelHospitalDeptDetail
#医生搜索
modelDoctorSearchResult,modelDoctorSearchResultItem
#医生(专家)详情
modelDoctorDetail,modelDoctorDeptListItem
#疾病搜索
modelDieaseSearchResult,modelDieaseSearchResultItem
#套餐列表
modelServicePkgListPlainItem
#药品搜索
modelMedicineSearchResultItem
#kanoServer


)

for model in ${models[@]}; do
types=${types}${model},
done
types=${types}

if [ "$debug" = true ] ; then
enableDebug='--debug'
fi

if [ "$verbose" = true ] ; then
enableVerbose='--verbose'
fi

./app.js ${enableVerbose} ${enableDebug} \
-C ${types} \
-P ${passkeys} \
-f ${fileuri} \
-a ${author} \
-m ${modulename} \
-j ${projectname} \
-B ${httpclient} \
-o ${offset}
2 changes: 2 additions & 0 deletions scripts/jyd/2.用户相关.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ httpclient='PMLRESTBaseDoctor'
models=(
#用户登录
'modelUserProfile'
#医生APP用户登录
'modelUserProfile'
#修改用户密码
#找回密码
#微信免登陆
Expand Down
39 changes: 39 additions & 0 deletions scripts/jyd/22.医生团队.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
author='walker'
projectname='FamilyDoctor'
passkeys='code,flag,message'
fileuri='/Users/walker/Desktop/index.html'
offset=1
debug=true
verbose=false
modulename='taskDoctorGroup'
httpclient='PMLRESTBaseDoctor'
models=(
#团队列表
modelDoctorGroupListItem,modelExpertRoleDOListItem
#团队详情
modelDoctorGroupInfo,modelExpertRoleDOListItem
)

for model in ${models[@]}; do
types=${types}${model},
done
types=${types}

if [ "$debug" = true ] ; then
enableDebug='--debug'
fi

if [ "$verbose" = true ] ; then
enableVerbose='--verbose'
fi

./app.js ${enableVerbose} ${enableDebug} \
-C ${types} \
-P ${passkeys} \
-f ${fileuri} \
-a ${author} \
-m ${modulename} \
-j ${projectname} \
-B ${httpclient} \
-o ${offset}
37 changes: 37 additions & 0 deletions scripts/jyd/27.banner相关.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
author='walker'
projectname='FamilyDoctor'
passkeys='code,flag,message'
fileuri='/Users/walker/Desktop/index.html'
offset=1
debug=true
verbose=false
modulename='taskBanner'
httpclient='PMLRESTBaseDoctor'
models=(
#banner列表
modelBannerListItem
)

for model in ${models[@]}; do
types=${types}${model},
done
types=${types}

if [ "$debug" = true ] ; then
enableDebug='--debug'
fi

if [ "$verbose" = true ] ; then
enableVerbose='--verbose'
fi

./app.js ${enableVerbose} ${enableDebug} \
-C ${types} \
-P ${passkeys} \
-f ${fileuri} \
-a ${author} \
-m ${modulename} \
-j ${projectname} \
-B ${httpclient} \
-o ${offset}
51 changes: 51 additions & 0 deletions scripts/jyd/8.查询统计相关.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
author='walker'
projectname='FamilyDoctor'
passkeys='code,flag,message'
fileuri='/Users/walker/Desktop/index.html'
offset=0
debug=true
verbose=false
modulename='taskStatistics'
httpclient='PMLRESTBaseDoctor'
models=(
#签约统计
modelStatisticAgreementByYear
#签约统计(月)
modelStatisticAgreementByMonth,modelStatisticExpertCountMonthDO,modelStatisticFocusNumMonthDO
#服务统计
modelStatisticServiceByYear,modelStatisticServiceTopItem
#服务统计(月)
modelStatisticServiceMonthDO
#服务统计明细列表
modelStatisticServiceList,modelStatisticServiceListItem
#签约统计明细列表
modelStatisticAgreementList,modelStatisticAgreementListItem
#导出服务统计明细列表
#导出签约统计明细列表
#重点人群统计
modelStatisticKeyCrowdDetail,modelStatisticKeyCrowdListItem
)

for model in ${models[@]}; do
types=${types}${model},
done
types=${types}

if [ "$debug" = true ] ; then
enableDebug='--debug'
fi

if [ "$verbose" = true ] ; then
enableVerbose='--verbose'
fi

./app.js ${enableVerbose} ${enableDebug} \
-C ${types} \
-P ${passkeys} \
-f ${fileuri} \
-a ${author} \
-m ${modulename} \
-j ${projectname} \
-B ${httpclient} \
-o ${offset}
2 changes: 1 addition & 1 deletion templates/httpclient/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ endpoints.map(e=>`
${e.args.map(p=>
` * @param ${p}
`).join('')} */
- (NSURLSessionDataTask *)${e.method}:(NSDictionary *)params completion:(void (^)(${e.model} *response, NSError *error))completion;`).join('')}
- (NSURLSessionDataTask *)${e.method}:(NSDictionary *)params completion:(void (^)(${e.model} *response, NSError *error))completion;`).join('').trim()}

@end`
2 changes: 1 addition & 1 deletion templates/httpclient/task.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ @implementation ${modulename}

${endpoints.map(e=>
`PMTASK_EXPORT_IMP(${e.method}, ${e.model})
`).join('')}
`).join('').trim()}

@end`
10 changes: 8 additions & 2 deletions templates/model/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ if(prop.type == 'NSInteger') return `
*/
@property (nonatomic, assign) ${prop.type} ${prop.name};
`;
else if(prop.type == 'CGFloat') 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};
@property (nonatomic, copy) ${prop.type} ${prop.name};
`;
else if(prop.type == 'BOOL') return `
/**
Expand All @@ -36,6 +42,6 @@ return `
* ${prop.des}
*/
@property (nonatomic, strong) ${prop.type}${prop.name};
`;}).join('')}
`;}).join('').trim()}

@end`
10 changes: 9 additions & 1 deletion templates/model/template.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey {
return @(i);
}];
}`;
if(prop.type=='CGFloat') return `
+ (NSValueTransformer *)${prop.name}JSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(id value, BOOL *success, NSError *__autoreleasing *error) {
NSString *str = [NSString stringWithFormat:@"%@", value];
CGFloat i = [str floatValue];
return @(i);
}];
}`;
if(!prop.model) return '';
if(prop.isArray) return `
+ (NSValueTransformer *)${prop.name}JSONTransformer {
Expand All @@ -34,6 +42,6 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey {
+ (NSValueTransformer *)${prop.name}JSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[${prop.model} class]];
}`;
}).join('')}
}).join('').trim()}

@end`
10 changes: 9 additions & 1 deletion templates/model/templatebase.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey {
return @(i);
}];
}`;
if(prop.type=='CGFloat') return `
+ (NSValueTransformer *)${prop.name}JSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(id value, BOOL *success, NSError *__autoreleasing *error) {
NSString *str = [NSString stringWithFormat:@"%@", value];
CGFloat i = [str floatValue];
return @(i);
}];
}`;
if(!prop.model) return '';
if(prop.isArray) return `
+ (NSValueTransformer *)${prop.name}JSONTransformer {
Expand All @@ -33,6 +41,6 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey {
+ (NSValueTransformer *)${prop.name}JSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[${prop.model} class]];
}`;
}).join('')}
}).join('').trim()}

@end`

0 comments on commit 8a02ce1

Please sign in to comment.