Commit 31cc04c3 by 钟占达

zzd_prac copyFormInfo && deleteFormInfo

parent d2cdb5a3
......@@ -58,8 +58,11 @@ class Templateconfig extends APIBase {
case "getTemplateAndLinkInfo": // 根据链接参数获取模板链接信息
opResult = await this.templatelinkSve.getTemplateAndLinkInfo2(pobj);
break;
case "copyForm": // 复制表单
opResult = await this.forminfoSve.copyForm(pobj.actionBody);
case "copyFormInfo": // 复制表单
opResult = await this.forminfoSve.copyFormInfo(pobj.actionBody);
break;
case "deleteFormInfo": // 删除表单
opResult = await this.forminfoSve.deleteFormInfo(pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
......
......@@ -221,6 +221,72 @@ class ForminfoService extends ServiceBase {
let res = await this.dao.findAndCountAll(pobj);
return system.getResult(res);
}
async copyFormInfo (pobj) {
let form = await this.findById(pobj.id);
if (!form) {
return system.getResultFail(-1, "表单不存在");
}
// console.log(form.dataValues);
let formCode = await this.getBusUid("fm");
let formCopyObj = {
code: formCode,
name: form.name + "_副本",
form_items: form.form_items,
form_describe: form.form_describe,
notes: form.notes,
version: form.version,
// created_at: form.created_at,
// updated_at: form.updated_at,
uder_id: form.user_id,
user_name: form.user_name,
company_id: form.company_id,
record_num: form.record_num,
form_table: form.form_table
};
// console.log(formCopyObj);
// 创建新的表单信息
let formCopy = await this.create(formCopyObj);
let formCopyId = formCopy.id;
// 获取表单相关的表单项,复制并与新的表单关联
let formItems = await this.formitemDao.findAll({form_id: pobj.id});
if (formItems.length > 0) {
formItems.forEach(async (item) => {
let itemCode = await this.getBusUid("it");
let itemNew = {
form_id: formCopyId,
code: itemCode,
name: item.name,
item_type: item.item_type,
item_type_name: item.item_type_name,
config_params: item.config_params,
id_enabled: item.is_enabled,
is_required: item.is_required,
sequence: item.sequence,
notes: item.notes,
version: item.version,
// created_at: item.created_at,
// updated_at: item.updated_at
};
await this.formitemDao.create(itemNew);
});
}
return system.getResultSuccess(formCopy);
}
async deleteFormInfo (pobj) {
let template = await this.templateDao.findOne({"form_id": pobj.id});
if (template && template.is_enabled === 1) {
return system.getResultFail(-1, "表单使用中,无法删除");
}
let form = await this.delete({"id": pobj.id});
// let formItems = await this.formitemDao.findAll({"form_id": pobj.id});
// formItems.forEach(async (item) => await item.destory());
await this.formitemDao.bulkDeleteByWhere({where: {"form_id": pobj.id}});
return system.getResultSuccess(form);
}
}
module.exports = ForminfoService;
\ No newline at end of file
......@@ -459,6 +459,7 @@ class TemplatelinkService extends ServiceBase {
};
// 将数据保存到redis中
await this.redisClient.set(shaStr, JSON.stringify(rtnObj));
// await this.redisClient.setWithEx(shaStr, JSON.stringify(rtnObj), 60); // 保存的同时设置过期时间
}
addObj = { // 需要保存到浏览记录的内容
......
......@@ -52,6 +52,7 @@
"sequelize-cli": "^4.1.1",
"serve-favicon": "^2.4.5",
"sha1": "^1.1.1",
"sha256": "^0.2.0",
"socket.io": "^2.1.1",
"uuid": "^3.2.1",
"xml2js": "^0.4.19"
......
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