From e2fa7db310e11721eaa0c026f80b97b187baf948 Mon Sep 17 00:00:00 2001 From: luch <32321690+luch1994@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:07:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=B7=B2=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=9A=84=E9=97=AE=E5=8D=B7=E5=86=8D=E6=AC=A1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=8A=B6=E6=80=81=E4=BC=9A=E5=8F=98=E6=88=90=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=AD=20(#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../surveyManage/service/surveyService.ts | 71 +++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/server/src/apps/surveyManage/service/surveyService.ts b/server/src/apps/surveyManage/service/surveyService.ts index f0674cba..81537049 100644 --- a/server/src/apps/surveyManage/service/surveyService.ts +++ b/server/src/apps/surveyManage/service/surveyService.ts @@ -82,13 +82,25 @@ class SurveyService { const surveyMetaUpdateRes = await surveyMeta.updateOne({ _id, owner: surveyParams.userData.username, - }, { + }, [{ $set: { remark: surveyParams.remark, title: surveyParams.title, updateDate: Date.now(), } - }) + }, { + $set: { + "curStatus": { + $cond: { + if: { + $eq: ["$curStatus.status", "new"] + }, + then: "$curStatus", + else: getStatusObject({ status: SURVEY_STATUS.editing }) + } + } + } + }]) if (surveyMetaUpdateRes.matchedCount < 1) { throw new CommonError("更新问卷信息失败,问卷不存在或您不是该问卷所有者") } @@ -129,20 +141,20 @@ class SurveyService { getListHeadByDataList(dataList) { const listHead = dataList.map(surveyItem => { let othersCode; - if(surveyItem.type === 'radio-star') { + if (surveyItem.type === 'radio-star') { const rangeConfigKeys = Object.keys(surveyItem.rangeConfig) - if(rangeConfigKeys.length>0) { - othersCode = [{code: `${surveyItem.field}_custom`, option: "填写理由"}] + if (rangeConfigKeys.length > 0) { + othersCode = [{ code: `${surveyItem.field}_custom`, option: "填写理由" }] } } else { othersCode = (surveyItem.options || []) - .filter(optionItem => optionItem.othersKey) - .map((optionItem) => { - return { - code: optionItem.othersKey, - option: optionItem.text - } - }) + .filter(optionItem => optionItem.othersKey) + .map((optionItem) => { + return { + code: optionItem.othersKey, + option: optionItem.text + } + }) } return { field: surveyItem.field, @@ -164,7 +176,7 @@ class SurveyService { return listHead } - async data(condition: { userData:UserType,surveyId: string, pageNum: number, pageSize: number, isShowSecret: boolean }) { + async data(condition: { userData: UserType, surveyId: string, pageNum: number, pageSize: number, isShowSecret: boolean }) { const surveyObjectId = mongo.getObjectIdByStr(condition.surveyId) const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' }); const surveyMetaData = await surveyMeta.findOne({ _id: surveyObjectId }) @@ -185,15 +197,15 @@ class SurveyService { const listBody = surveySubmitData.map((surveySubmitResList) => { const data = surveySubmitResList.data const dataKeys = Object.keys(data) - for(const itemKey of dataKeys) { - if(typeof itemKey !== 'string') {continue} - if(itemKey.indexOf("data")!==0) {continue} + for (const itemKey of dataKeys) { + if (typeof itemKey !== 'string') { continue } + if (itemKey.indexOf("data") !== 0) { continue } const itemConfigKey = itemKey.split("_")[0]; const itemConfig = dataListMap[itemConfigKey]; // 题目删除会出现,数据列表报错 - if(!itemConfig) {continue} - const doSecretData = (data)=>{ - if(itemConfig.isSecret && condition.isShowSecret) { + if (!itemConfig) { continue } + const doSecretData = (data) => { + if (itemConfig.isSecret && condition.isShowSecret) { return hanleSensitiveDate(data) } else { return data; @@ -201,7 +213,7 @@ class SurveyService { } data[itemKey] = doSecretData(data[itemKey]) // 处理选项 - if(itemConfig.type === 'radio-star' && !data[`${itemConfigKey}_custom`]) { + if (itemConfig.type === 'radio-star' && !data[`${itemConfigKey}_custom`]) { data[`${itemConfigKey}_custom`] = data[`${itemConfigKey}_${data[itemConfigKey]}`] } if (!itemConfig?.options?.length) { continue } @@ -255,13 +267,30 @@ class SurveyService { async saveConf(surveyData: { surveyId: string, configData: any }) { const surveyConf = await mongo.getCollection({ collectionName: 'surveyConf' }); + const surveyMeta = await mongo.getCollection({ collectionName: 'surveyMeta' }); const saveRes = await surveyConf.updateOne({ pageId: surveyData.surveyId }, { $set: { - code: surveyData.configData + code: surveyData.configData, } }) + const _id = mongo.getObjectIdByStr(surveyData.surveyId) + surveyMeta.updateOne({ + _id, + }, [{ + $set: { + "curStatus": { + $cond: { + if: { + $eq: ["$curStatus.status", "new"] + }, + then: "$curStatus", + else: getStatusObject({ status: SURVEY_STATUS.editing }) + } + } + } + }]) return saveRes }