Search in sources :

Example 1 with SurveyQuestionListVO

use of com.bc.pmpheep.back.vo.SurveyQuestionListVO in project pmph by BCSquad.

the class JsonUtil method main.

@SuppressWarnings({ "deprecation", "unchecked" })
public static void main(String[] args) throws Exception {
    // String jsonDecPosition =
    // "[{'id':4,'chosenPosition':1,'rank':1,'isDigitalEditor':true},{'id':3,'chosenPosition':2,'rank':3,'isDigitalEditor':true},{'id':1,'chosenPosition':3,'rank':'','isDigitalEditor':false}]";
    String jsonString = "[{'title':'你会网上冲浪吗?','type':1,'direction':null,'sort':1,'surveyQuestionOptionList':[{'optionContent':'不会'},{'optionContent':'会'}]},{'title':'你最喜欢的运动是什么','type':2,'direction':'','sort':'2','surveyQuestionOptionList':[{'optionContent':'篮球'},{'optionContent':'足球'},{'optionContent':'乒乓球'},{'optionContent':'羽毛球'},{'optionContent':'棒球'},{'optionContent':'网球'}]}]";
    // JavaType javaType = getCollectionType(ArrayList.class, SurveyQuestionListVO.class);
    // List<SurveyQuestionListVO> lst =
    // (List<SurveyQuestionListVO>) objectMapper.readValue(jsonString, javaType);
    // System.out.println(lst.toString());
    // System.out.println(decode(jsonString, new TypeReference<SurveyQuestionListVO>() {
    // }).toString());
    JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, SurveyQuestionListVO.class);
    List<SurveyQuestionListVO> lst = (List<SurveyQuestionListVO>) objectMapper.readValue(jsonString, javaType);
    // List<SurveyQuestionListVO> beanList =
    // objectMapper.readValue(jsonString, new TypeReference<List<SurveyQuestionListVO>>() {
    // });
    System.out.println(lst.toString());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with SurveyQuestionListVO

use of com.bc.pmpheep.back.vo.SurveyQuestionListVO in project pmph by BCSquad.

the class SurveyServiceImpl method updateSurveyAndTemplate.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Integer updateSurveyAndTemplate(String questionAnswerJosn, SurveyVO surveyVO) throws CheckedServiceException {
    if (StringUtil.isEmpty(questionAnswerJosn)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问题为空");
    }
    if (ObjectUtil.isNull(surveyVO)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "对象为空");
    }
    if (ObjectUtil.isNull(surveyVO.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷ID为空");
    }
    if (ObjectUtil.isNull(surveyVO.getTemplateId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "模版ID为空");
    }
    // json字符串转List对象集合
    List<SurveyQuestionListVO> SurveyQuestionListVO = new JsonUtil().getArrayListObjectFromStr(SurveyQuestionListVO.class, questionAnswerJosn);
    if (CollectionUtil.isEmpty(SurveyQuestionListVO)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    // 问卷ID
    Long surveyId = surveyVO.getId();
    // 问卷名称
    String title = surveyVO.getTemplateName();
    // 问卷概述
    String intro = surveyVO.getIntro();
    // 问卷调查对象
    Long typeId = surveyVO.getTypeId();
    // 模版ID
    Long templateId = surveyVO.getTemplateId();
    Integer count = 0;
    // 更新问卷表
    count = this.updateSurvey(new Survey(surveyId, title, intro, typeId));
    surveyTemplateService.updateSurveyTemplate(new SurveyTemplate(templateId, title, intro, // 更新模版表
    typeId));
    // 查询模版下的所有问题
    List<SurveyTemplateQuestion> lists = surveyTemplateQuestionService.getSurveyTemplateQuestionByTemplateId(templateId);
    List<Long> questionIdList = new ArrayList<Long>(lists.size());
    for (SurveyTemplateQuestion surveyTemplateQuestion : lists) {
        questionIdList.add(surveyTemplateQuestion.getQuestionId());
    }
    // 删除模版问题中间表下模版对应的所有问题
    surveyTemplateQuestionService.deleteSurveyTemplateQuestionByTemplateId(templateId);
    // 删除问题表
    surveyQuestionService.batchDeleteSurveyQuestionByQuestionIds(questionIdList);
    // 删除问题选项表
    surveyQuestionOptionService.batchDeleteSurveyQuestionOptionByQuestionIds(questionIdList);
    // 重新添加问题
    List<Long> newIds = this.addQuestionAndOption(SurveyQuestionListVO);
    // 模版问题中间表
    List<SurveyTemplateQuestion> surveyTemplateQuestions = new ArrayList<SurveyTemplateQuestion>(newIds.size());
    for (Long questionId : newIds) {
        surveyTemplateQuestions.add(new SurveyTemplateQuestion(templateId, questionId));
    }
    // 重新添加模版问题中间表
    count = surveyTemplateQuestionService.batchInsertSurveyTemplateQuestion(surveyTemplateQuestions);
    return count;
}
Also used : SurveyTemplate(com.bc.pmpheep.back.po.SurveyTemplate) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) JsonUtil(com.bc.pmpheep.back.util.JsonUtil) Survey(com.bc.pmpheep.back.po.Survey) SurveyTemplateQuestion(com.bc.pmpheep.back.po.SurveyTemplateQuestion)

Example 3 with SurveyQuestionListVO

use of com.bc.pmpheep.back.vo.SurveyQuestionListVO in project pmph by BCSquad.

the class SurveyServiceImpl method addQuestionAndOption.

/**
 * <pre>
 * 功能描述:添加问题及问题选项
 * 使用示范:
 *
 * @param surveyQuestionListVO
 * @return
 * </pre>
 */
private List<Long> addQuestionAndOption(List<SurveyQuestionListVO> surveyQuestionListVO) {
    List<Long> questionIds = new ArrayList<Long>(surveyQuestionListVO.size());
    for (SurveyQuestionListVO surveyQuestionLists : surveyQuestionListVO) {
        // 遍历获取问题的集合
        SurveyQuestion surveyQuestion = new SurveyQuestion(surveyQuestionLists.getTitle(), surveyQuestionLists.getType(), surveyQuestionLists.getSort(), // 问题实体
        surveyQuestionLists.getDirection());
        SurveyQuestion surveyQuestions = // 先保存问题
        surveyQuestionService.addSurveyQuestion(surveyQuestion);
        if (ObjectUtil.isNull(surveyQuestions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "新增数据为空");
        }
        // 获取数据库新生成的问题id
        Long newId = surveyQuestions.getId();
        questionIds.add(newId);
        if (Const.SURVEY_QUESTION_TYPE_1 == surveyQuestionLists.getType() || Const.SURVEY_QUESTION_TYPE_2 == surveyQuestionLists.getType()) {
            List<SurveyQuestionOption> surveyQuestionOptionList = // 获取问题选项list
            surveyQuestionLists.getSurveyQuestionOptionList();
            for (SurveyQuestionOption surveyQuestionOptions : surveyQuestionOptionList) {
                // 遍历问题选项
                SurveyQuestionOption surveyQuestionOption = new SurveyQuestionOption(newId, surveyQuestionOptions.getOptionContent(), surveyQuestionOptions.getIsOther(), // 问题选项实体
                surveyQuestionOptions.getRemark());
                // 再保存问题选项
                surveyQuestionOptionService.addSurveyQuestionOption(surveyQuestionOption);
            }
        }
    }
    return questionIds;
}
Also used : SurveyQuestionOption(com.bc.pmpheep.back.po.SurveyQuestionOption) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) SurveyQuestion(com.bc.pmpheep.back.po.SurveyQuestion)

Example 4 with SurveyQuestionListVO

use of com.bc.pmpheep.back.vo.SurveyQuestionListVO in project pmph by BCSquad.

the class SurveyTemplateServiceImpl method addQuestionAndOption.

/**
 * <pre>
 * 功能描述:添加问题及问题选项
 * 使用示范:
 *
 * @param surveyQuestionListVO
 * @return
 * </pre>
 */
private List<Long> addQuestionAndOption(List<SurveyQuestionListVO> surveyQuestionListVO) {
    List<Long> questionIds = new ArrayList<Long>(surveyQuestionListVO.size());
    for (SurveyQuestionListVO surveyQuestionLists : surveyQuestionListVO) {
        // 遍历获取问题的集合
        SurveyQuestion surveyQuestion = new SurveyQuestion(surveyQuestionLists.getTitle(), surveyQuestionLists.getType(), surveyQuestionLists.getSort(), // 问题实体
        surveyQuestionLists.getDirection());
        SurveyQuestion surveyQuestions = // 先保存问题
        surveyQuestionService.addSurveyQuestion(surveyQuestion);
        if (ObjectUtil.isNull(surveyQuestions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "新增数据为空");
        }
        // 获取数据库新生成的问题id
        Long newId = surveyQuestions.getId();
        questionIds.add(newId);
        if (Const.SURVEY_QUESTION_TYPE_1 == surveyQuestionLists.getType() || Const.SURVEY_QUESTION_TYPE_2 == surveyQuestionLists.getType()) {
            List<SurveyQuestionOption> surveyQuestionOptionList = // 获取问题选项list
            surveyQuestionLists.getSurveyQuestionOptionList();
            for (SurveyQuestionOption surveyQuestionOptions : surveyQuestionOptionList) {
                // 遍历问题选项
                SurveyQuestionOption surveyQuestionOption = new SurveyQuestionOption(newId, surveyQuestionOptions.getOptionContent(), surveyQuestionOptions.getIsOther(), // 问题选项实体
                surveyQuestionOptions.getRemark());
                // 再保存问题选项
                surveyQuestionOptionService.addSurveyQuestionOption(surveyQuestionOption);
            }
        }
    }
    return questionIds;
}
Also used : SurveyQuestionOption(com.bc.pmpheep.back.po.SurveyQuestionOption) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) SurveyQuestion(com.bc.pmpheep.back.po.SurveyQuestion)

Example 5 with SurveyQuestionListVO

use of com.bc.pmpheep.back.vo.SurveyQuestionListVO in project pmph by BCSquad.

the class SurveyQuestionServiceImpl method addSurveyQuestionListVOList.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Integer addSurveyQuestionListVOList(String jsonSurveyQuestion) throws CheckedServiceException {
    if (ObjectUtil.isNull(jsonSurveyQuestion)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    // json字符串转List对象集合
    List<SurveyQuestionListVO> SurveyQuestionListVO = new JsonUtil().getArrayListObjectFromStr(SurveyQuestionListVO.class, jsonSurveyQuestion);
    if (CollectionUtil.isEmpty(SurveyQuestionListVO)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    int count = 0;
    for (SurveyQuestionListVO SurveyQuestionLists : SurveyQuestionListVO) {
        // 遍历获取问题的集合
        // 获取问题id
        Long id = SurveyQuestionLists.getId();
        if (ObjectUtil.notNull(id)) {
            // 如果id不为空,则先删除
            deleteSurveyQuestionById(id);
            surveyQuestionOptionService.deleteSurveyQuestionOptionByQuestionId(id);
        }
        SurveyQuestion surveyQuestion = new SurveyQuestion(null, SurveyQuestionLists.getCategoryId(), SurveyQuestionLists.getTitle(), SurveyQuestionLists.getType(), SurveyQuestionLists.getSort(), SurveyQuestionLists.getDirection(), // 问题实体
        SurveyQuestionLists.getIsAnswer());
        // 先保存问题
        SurveyQuestion surveyQuestions = addSurveyQuestion(surveyQuestion);
        if (ObjectUtil.isNull(surveyQuestions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "新增数据为空");
        }
        // 获取数据库新生成的问题id
        Long newId = surveyQuestions.getId();
        List<SurveyQuestionOption> surveyQuestionOptionList = // 获取问题选项list
        SurveyQuestionLists.getSurveyQuestionOptionList();
        for (SurveyQuestionOption surveyQuestionOptions : surveyQuestionOptionList) {
            // 遍历问题选项
            SurveyQuestionOption surveyQuestionOption = new SurveyQuestionOption(newId, surveyQuestionOptions.getOptionContent(), surveyQuestionOptions.getIsOther(), // 问题选项实体
            surveyQuestionOptions.getRemark());
            // 再保存问题选项
            surveyQuestionOptionService.addSurveyQuestionOption(surveyQuestionOption);
        }
        count++;
    }
    return count;
}
Also used : SurveyQuestionOption(com.bc.pmpheep.back.po.SurveyQuestionOption) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) JsonUtil(com.bc.pmpheep.back.util.JsonUtil) SurveyQuestion(com.bc.pmpheep.back.po.SurveyQuestion)

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