Commit cdeb880c by chenjinjing

no message

parent 0ef9f5e3
......@@ -3,19 +3,29 @@
*/
import { TABLENAME } from "../config/dbEnum";
import { QUESTIONTITLE, TESTTYPE } from "../config/enum";
import { selectDataToTableAssociation } from "../data/findData";
import { eccEnumValue } from "../tools/eccEnum";
/**
* 获取题目
* @param test_type 题目类型:1. 霍兰德
* @param chapter 章节
* 1.霍兰德(一、我感兴趣的活动)2.霍兰德(二、我能完成的活动)3.霍兰德(三、我喜欢的职业)4.霍兰德(四、我的能力类型简评A)5.霍兰德(四、我的能力类型简评B)
* @returns
*/
export async function getQuestion(chapter) {
export async function getQuestion(test_type, chapter) {
eccEnumValue("获取题目", "test_type", TESTTYPE, test_type);
eccEnumValue("获取题目", "chapter", QUESTIONTITLE, chapter);
let selectParam:any = {is_del:0, test_type:1, chapter:1};
if (test_type) selectParam.test_type = test_type;
if (chapter) selectParam.chapter = chapter;
/** includeConf:关联表配置*/
let includeConf = {};
includeConf[TABLENAME.题目选项表] = []; // 关联表需要查询的字段,可不填
includeConf[TABLENAME.题目选项表] = {colum:["option_name", "points"], where:{is_del:0} }; // colum:关联表需要查询的字段,where:关联表查询条件
/** questionInfo:多表联查*/
let questionInfo = await selectDataToTableAssociation(TABLENAME.题目表, includeConf, {chapter:1}, []);
let questionInfo = await selectDataToTableAssociation(TABLENAME.题目表, includeConf, selectParam, ["chapter", "title"]);
return {};
......
......@@ -8,6 +8,16 @@ export enum OPERATIONTYPEENUM {
}
/**上传文件类型 */
export enum FILETYPE {
word = 1,
pdf,
图片,
视频,
多类型
}
/**
* 题目大标题
*/
......
import { ERRORENUM } from "../config/errorEnum";
import { BizError } from "../util/bizError";
/**
* 校验value是否符合传入的枚举
* @param name 被掉用名称 用于输出异常日志
* @param key 目标字段 用于输出异常日志
* @param enumConf 目标枚举
* @param value 目标值
* 无返回 有异常直接报错
*/
export function eccEnumValue(name:string, key:string, enumConf, value:any) {
let eccSuccess = true;
if ( typeof value == 'number' ) {
if (!enumConf[value] ) eccSuccess = false;
} else if (Array.isArray(value)) {
value.forEach(item => {
if ( !enumConf[item] ) eccSuccess = false;
});
}
if (!eccSuccess) throw new BizError(ERRORENUM.请完善信息, `${name} 下的 ${key} 字段值为 ${value} 不满足枚举范围`);
}
/**
* 将枚举值转换成对应的枚举名(key)
* @param enumConf 目标枚举
* @param value 目标值
* @returns string 返回字符串 如果传入多个枚举值,就拼接字符串
*/
export function changeEnumValue(enumConf, value:any) {
if (!value) return '';
if ( typeof value == 'number' ) {
let str = enumConf[value];
/**特化处理 */
if(/_dou/.test(str)) str = str.replace(/_dou/gm, ",");
if(/_zyh/.test(str)) str = str.replace(/_zyh/gm, "“");
if(/_yyh/.test(str)) str = str.replace(/_yyh/gm, "”");
if(/_dun/.test(str)) str = str.replace(/_dun/gm, "、");
if(/_ju/.test(str)) str = str.replace(/_ju/gm, "。");
return str
} else if (typeof value == 'string') {
try {//兼容数据库 '[1,2,3]'
value = JSON.parse(value);
}catch(err) {
return enumConf[parseInt(value)];
}
}
let str = "";
value.forEach((item, index) => {
let subStr = enumConf[item];
/**特化处理 */
if(/_dou/.test(subStr)) subStr = subStr.replace(/_dou/gm, ",");
if(/_zyh/.test(subStr)) subStr = subStr.replace(/_zyh/gm, "“");
if(/_yyh/.test(subStr)) subStr = subStr.replace(/_yyh/gm, "”");
if(/_dun/.test(subStr)) subStr = subStr.replace(/_dun/gm, "、");
if(/_ju/.test(subStr)) subStr = subStr.replace(/_ju/gm, "。");
str += subStr;
if (index == value.length-1) str+="";
else str += ","
});
return str;
}
\ No newline at end of file
import moment = require("moment");
import { ERRORENUM } from "../config/errorEnum";
import { BizError } from "../util/bizError";
import { FILETYPE } from "../config/enum";
const md5 = require("md5");
export function getUserToken(loginId:string) {
return md5(`${loginId}_${Math.ceil(Math.random()*1000)}${new Date().valueOf()}`);
}
export function getMySqlMs(time?) {
time = time || new Date().valueOf();
// time += (8*3600*1000);
return moment(time).format("YYYY-MM-DD HH:mm:ss");
}
export function getClientMs(time) {
if (!time) return new Date().valueOf();
return new Date(time).valueOf();
}
export function getPartyMemberId(param) {
return md5(`${param}-${new Date().valueOf()}-${Math.ceil(Math.random() * 10000)}`);
}
export function getDefPwd(phone:string) {
return md5(`${phone.slice(5, 11)}`);
}
export function getFileType(fileName) {
let fileType = 0;
fileName.forEach(info => {
let repList = info.split(".");
let type = repList[repList.length-1];
if (!type) throw new BizError(ERRORENUM.文件不存在, `文件名 ${info}`);
let typeNum = 0;
switch(type) {
case 'pdf': typeNum = FILETYPE.pdf; break;
case 'doc':
case 'docx': typeNum = FILETYPE.word; break;
case 'jpg':
case 'png': typeNum = FILETYPE.图片; break;
};
if (typeNum) {
if (!fileType) fileType = typeNum;
else if (fileType != typeNum) fileType = FILETYPE.多类型;
}
});
return fileType;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment