Search in sources :

Example 6 with SurveyQuestionListVO

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;
}
Also used : SurveyTemplate(com.bc.pmpheep.back.po.SurveyTemplate) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) JsonUtil(com.bc.pmpheep.back.util.JsonUtil) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Survey(com.bc.pmpheep.back.po.Survey) SurveyTemplateQuestion(com.bc.pmpheep.back.po.SurveyTemplateQuestion)

Aggregations

SurveyQuestionListVO (com.bc.pmpheep.back.vo.SurveyQuestionListVO)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 ArrayList (java.util.ArrayList)5 SurveyQuestion (com.bc.pmpheep.back.po.SurveyQuestion)3 SurveyQuestionOption (com.bc.pmpheep.back.po.SurveyQuestionOption)3 JsonUtil (com.bc.pmpheep.back.util.JsonUtil)3 Survey (com.bc.pmpheep.back.po.Survey)2 SurveyTemplate (com.bc.pmpheep.back.po.SurveyTemplate)2 SurveyTemplateQuestion (com.bc.pmpheep.back.po.SurveyTemplateQuestion)2 PmphUser (com.bc.pmpheep.back.po.PmphUser)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 List (java.util.List)1