Commit bc3ba262 by 庄冰

formitem

parent 00d0fbdd
...@@ -9,6 +9,7 @@ class Template extends APIBase { ...@@ -9,6 +9,7 @@ class Template extends APIBase {
super(); super();
this.templateinfoSve = system.getObject("service.template.templateinfoSve"); this.templateinfoSve = system.getObject("service.template.templateinfoSve");
this.templatelinkSve = system.getObject("service.template.templatelinkSve"); this.templatelinkSve = system.getObject("service.template.templatelinkSve");
this.formsubmitrecordSve= system.getObject("service.configmag.formsubmitrecordSve");
} }
/** /**
* 接口跳转-POST请求 * 接口跳转-POST请求
...@@ -54,6 +55,9 @@ class Template extends APIBase { ...@@ -54,6 +55,9 @@ class Template extends APIBase {
case "getTemplateAndLinkInfo"://根据链接参数获取模板链接信息 case "getTemplateAndLinkInfo"://根据链接参数获取模板链接信息
opResult = await this.templatelinkSve.getTemplateAndLinkInfo(pobj); opResult = await this.templatelinkSve.getTemplateAndLinkInfo(pobj);
break; break;
case "submitFormRecord"://提交表单记录
opResult = await this.formsubmitrecordSve.submitFormRecord(pobj);
break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
break; break;
......
...@@ -11,7 +11,20 @@ module.exports = { ...@@ -11,7 +11,20 @@ module.exports = {
"sex": {"male": "男", "female": "女"}, "sex": {"male": "男", "female": "女"},
"logLevel": {"debug": 0, "info": 1, "warn": 2, "error": 3, "fatal": 4}, "logLevel": {"debug": 0, "info": 1, "warn": 2, "error": 3, "fatal": 4},
"msgType": { "sys": "系统", "single": "单点", "multi": "群发"}, "msgType": { "sys": "系统", "single": "单点", "multi": "群发"},
"node_type":{"org":"组织","arc":"文档"} "node_type":{"org":"组织","arc":"文档"},
"item_type":{
"phone": "手机号",
"singleBtn": "单选按钮",
"multipleBtn": "多选按钮",
"downOptions": "下拉选项",
"singleText": "单行文本",
"multipleText": "多行文本",
"dateTime": "日期",
"area": "省市"
},
"record_status":{
"1":"未读", "2":"已读", "3":"无效"
}
} }
} }
} }
...@@ -4,11 +4,24 @@ ...@@ -4,11 +4,24 @@
* @param DataTypes * @param DataTypes
* @returns {Model|void|*} * @returns {Model|void|*}
*/ */
const record_status={"1":"未读", "2":"已读", "3":"无效"};
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("formsubmitrecord", { return db.define("formsubmitrecord", {
form_id:DataTypes.INTEGER(11),//表单id form_id:DataTypes.INTEGER(11),//表单id
record_status:DataTypes.STRING(60),//记录状态 1未读 2已读 3无效 template_id:DataTypes.INTEGER(11),//表单id
templatelink_id:DataTypes.INTEGER(11),//表单id
record_status :{//记录状态 1未读 2已读 3无效
type: DataTypes.STRING,
set: function (val) {
this.setDataValue("record_status", val);
this.setDataValue("record_status_name", record_status[val]);
}
},//
record_status_name:DataTypes.STRING(60),//记录状态名称 record_status_name:DataTypes.STRING(60),//记录状态名称
templatelink_snapshot:DataTypes.JSON,
form_snapshot:DataTypes.JSON,
record_content:DataTypes.JSON,
}, { }, {
paranoid: true,//假的删除 paranoid: true,//假的删除
underscored: true, underscored: true,
......
...@@ -5,6 +5,10 @@ const settings = require("../../../../config/settings"); ...@@ -5,6 +5,10 @@ const settings = require("../../../../config/settings");
class ForminfoService extends ServiceBase { class ForminfoService extends ServiceBase {
constructor() { constructor() {
super("configmag", ServiceBase.getDaoName(ForminfoService)); super("configmag", ServiceBase.getDaoName(ForminfoService));
this.templateinfoDao = system.getObject("db.template.templateinfoDao");
this.templatelinkDao = system.getObject("db.template.templatelinkDao");
this.forminfoDao = system.getObject("db.form.forminfoDao");
this.formitemDao = system.getObject("db.form.formitemDao");
} }
/** /**
...@@ -37,6 +41,92 @@ class ForminfoService extends ServiceBase { ...@@ -37,6 +41,92 @@ class ForminfoService extends ServiceBase {
} }
return system.getResult(resData); return system.getResult(resData);
} }
/**
* 提交表单记录
* @param {*} pobj
*/
async submitFormRecord(pobj){
var ab = pobj.actionBody;
var xctx = pobj.xctx;
if(!ab){
return system.getResultFail(-100,"参数错误");
}
if(!ab.link_code){
return system.getResultFail(-101,"模板链接编码不能为空");
}
if(!ab.form_id){
return system.getResultFail(-102,"表单id不能为空");
}
//获取模板链接信息
var linkInfo = await this.templatelinkDao.model.findOne({
where:{code:ab.link_code},raw:true
});
if(!linkInfo || !linkInfo.id){
return system.getResultFail(-300,"未知模板链接")
}
//获取表单信息
var forminfo = await this.forminfoDao.model.findOne({
where:{id:ab.form_id},raw:true
});
if(!forminfo || !forminfo.id){
return system.getResultFail(-400,"未知表单")
}
//获取表单项
var formitems = await this.formitemDao.model.findAll({
where:{form_id:ab.form_id},raw:true
});
//校验封装参数
var res = await this.checkAndPackageFormItems(formitems,ab);
if(res && res.status && res.status<0){
return res;
}
var params = res;
var addObj={
template_id:linkInfo.template_id,templatelink_id:linkInfo.id,
form_id:forminfo.id,record_status:1,templatelink_snapshot:linkInfo,
form_snapshot:{forminfo:forminfo,formitems:formitems},
record_content:params
}
await this.dao.create(addObj);//创建记录
return system.getResultSuccess();
}
/**
* 参数校验
* @param {*} formitems 表单项
* @param {*} ab 表单提交数据
*/
async checkAndPackageFormItems(formitems,ab){
var params = {};
for(var i=0;i<formitems.length;i++){
var item = formitems[i];
var itemConfig = item.config_params;
if(item && item.code && item.is_enabled){//显示状态的表单项
var value = ab[item.code];
if(item.is_required===1){//必填
if(!ab[item.code]){
return system.getResultFail(-100,item.name+"参数不能为空");
}
}
if(itemConfig.mobile_input_length===1){//手机号 1:限定11位 2:限定7-11位
if(value && value.length!=11){
return system.getResultFail(-101,item.name+"参数限定11位");
}
}
if(itemConfig.mobile_input_length===2){//手机号 1:限定11位 2:限定7-11位
if(value && (value.length<7 || value.length>11)){
return system.getResultFail(-102,item.name+"参数限定7-11位");
}
}
if(itemConfig.input_length && itemConfig.input_length.length==2){//输入长度区间
if(value && (value.length<itemConfig.input_length[0] || value.length>itemConfig.input_length[1])){
return system.getResultFail(-103,item.name+"参数输入长度为"+itemConfig.input_length[0]+"-"+itemConfig.input_length[1]+"位");
}
}
params[item.code] = value;
}
}
return params;
}
} }
module.exports = ForminfoService; module.exports = ForminfoService;
\ No newline at end of file
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