use of com.bc.pmpheep.back.vo.SurveyQuestionListVO in project pmph by BCSquad.
the class SurveyTemplateServiceImpl method addSurveyTemplateVO.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public SurveyTemplate addSurveyTemplateVO(String questionAnswerJosn, SurveyTemplateVO surveyTemplateVO, String sessionId) throws CheckedServiceException {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (ObjectUtil.isNull(surveyTemplateVO)) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (StringUtil.isEmpty(questionAnswerJosn)) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问题及问题选项为空");
}
// json字符串转List对象集合
List<SurveyQuestionListVO> surveyQuestionListVO;
try {
surveyQuestionListVO = new JsonUtil().getArrayListObjectFromStr(SurveyQuestionListVO.class, questionAnswerJosn);
} catch (Exception e) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.VO_CONVERSION_FAILED, "json字符串转List对象失败");
}
if (CollectionUtil.isEmpty(surveyQuestionListVO)) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
// 问卷名称
String templateName = surveyTemplateVO.getTemplateName();
if (templateName.length() > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷标题不能超过50个字符");
}
// 问卷概述
String intro = surveyTemplateVO.getIntro();
if (templateName.length() > 200) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷概述不能超过200个字符");
}
if (templateName.length() > 200) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷概述不能超过200个字符");
}
// 问卷调查类型
Long typeId = surveyTemplateVO.getTypeId();
// 问卷创建人
Long userId = pmphUser.getId();
SurveyTemplate surveyTemplate = // 添加模版表
addSurveyTemplate(new SurveyTemplate(templateName, intro, typeId, userId));
// 获取模版id
Long templateId = surveyTemplate.getId();
if (ObjectUtil.isNull(templateId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "新增模版失败");
}
Survey survey = // 添加问卷表
surveyService.addSurvey(new Survey(templateName, intro, templateId, typeId, userId));
if (ObjectUtil.isNull(survey.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "新增问卷失败");
}
// 添加问题及问题选项
List<Long> newIds = addQuestionAndOption(surveyQuestionListVO);
// 模版问题中间表
List<SurveyTemplateQuestion> surveyTemplateQuestions = new ArrayList<SurveyTemplateQuestion>(newIds.size());
for (Long questionId : newIds) {
surveyTemplateQuestions.add(new SurveyTemplateQuestion(templateId, questionId));
}
// 添加模版问题中间表
surveyTemplateQuestionDao.batchInsertSurveyTemplateQuestion(surveyTemplateQuestions);
System.out.println(surveyTemplate.toString());
return surveyTemplate;
}
Aggregations