Search in sources :

Example 1 with JsonUtil

use of com.bc.pmpheep.back.util.JsonUtil in project pmph by BCSquad.

the class DecPositionServiceImpl method updateDecPositionEditorSelection.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Integer updateDecPositionEditorSelection(String jsonDecPosition, Integer selectionType, Integer editorOrSubeditorType, Integer unselectedHold, Long textbookId, String sessionId) throws CheckedServiceException, IOException {
    if (StringUtil.isEmpty(jsonDecPosition)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "遴选职位不能为空");
    }
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Integer count = 0;
    List<DecPosition> decPositions = // json字符串转List对象集合
    new JsonUtil().getArrayListObjectFromStr(DecPosition.class, jsonDecPosition);
    // 编委遴选界面 (0:未选中)
    Integer unselectedHold_0 = 0;
    if (CollectionUtil.isEmpty(decPositions) && unselectedHold_0 == unselectedHold && 2 == editorOrSubeditorType && 1 == selectionType) {
        // 编委遴选界面,没有人员被选中也可以进行暂存
        // 查询书籍下所有申报id
        List<Long> ids = decPositionService.getDecPositionIdByBookId(textbookId, editorOrSubeditorType);
        // 初始化作家职位申报表
        if (CollectionUtil.isNotEmpty(ids)) {
            decPositionService.updateDecPositionSetDefault(ids, editorOrSubeditorType);
        }
    } else {
        if (CollectionUtil.isEmpty(decPositions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "遴选职位为空");
        }
        // (1:确定,2:发布)
        Integer selectionType_1 = 1;
        Integer selectionType_2 = 2;
        // 获取书籍id
        textbookId = decPositions.get(0).getTextbookId();
        // 原来的历史遴选记录
        List<DecPosition> oldlist = decPositionService.listChosenDecPositionsByTextbookId(textbookId);
        // 1:确定
        if (selectionType_1.intValue() == selectionType.intValue()) {
            // 查询书籍下所有申报id
            List<Long> ids = decPositionService.getDecPositionIdByBookId(textbookId, editorOrSubeditorType);
            if (2 == editorOrSubeditorType) {
                // 遴选的编委ID
                List<Long> newEditorialMemberIds = new ArrayList<Long>();
                for (DecPosition decPosition : decPositions) {
                    if (1 == decPosition.getChosenPosition() || 8 == decPosition.getChosenPosition()) {
                        if (!ids.contains(decPosition.getId())) {
                            newEditorialMemberIds.add(decPosition.getId());
                        }
                    }
                }
                if (newEditorialMemberIds.isEmpty()) {
                    Textbook textbook = textbookService.getTextbookById(textbookId);
                    if (0 != textbook.getRevisionTimes()) {
                        textbookService.updatRevisionTimesByTextBookId(-1, textbookId);
                    }
                } else {
                    textbookService.updatRevisionTimesByTextBookId(1, textbookId);
                }
                // 清楚dec_position_temp表
                decPositionTempService.deleteDecPositionTempByTextbookId(textbookId);
            }
            // 初始化作家职位申报表
            if (CollectionUtil.isNotEmpty(ids)) {
                decPositionService.updateDecPositionSetDefault(ids, editorOrSubeditorType);
            }
            if (CollectionUtil.isNotEmpty(decPositions)) {
                count = decPositionDao.updateDecPositionEditorSelection(decPositions);
            }
            if (ObjectUtil.isNull(textbookId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "书籍id为空");
            }
            // 用户类型
            Integer userType = 1;
            // 获取修改者id
            Long updaterId = pmphUser.getId();
            // 添加新的遴选记录
            textbookLogService.addTextbookLog(oldlist, textbookId, updaterId, userType);
        }
        // 2:发布
        if (selectionType_2.intValue() == selectionType.intValue()) {
            // 发布的时候 先确认
            this.updateDecPositionEditorSelection(jsonDecPosition, 1, editorOrSubeditorType, unselectedHold, textbookId, sessionId);
            if (ObjectUtil.isNull(textbookId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "书籍id为空");
            }
            // 获取当前书籍书申报信息(包含没有被遴选上的)
            List<DecPosition> decPositionsList = decPositionService.listDecPositionsByTextBookIds(new ArrayList<Long>(Arrays.asList(textbookId)));
            if (CollectionUtil.isEmpty(decPositionsList)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "当前书籍还未遴选主编,副主编");
            }
            // DecPositionPublished对象集合
            List<DecPositionPublished> decPositionPublisheds = new ArrayList<DecPositionPublished>(decPositionsList.size());
            for (DecPosition decPosition : decPositionsList) {
                // 筛选出遴选上的主编副主编人员
                Integer chosenPosition = decPosition.getChosenPosition();
                if (null != chosenPosition && (chosenPosition == 4 || chosenPosition == 2 || chosenPosition == 12 || chosenPosition == 10)) {
                    chosenPosition = chosenPosition > 8 ? chosenPosition - 8 : chosenPosition;
                    decPositionPublisheds.add(new DecPositionPublished(pmphUser.getId(), decPosition.getDeclarationId(), textbookId, decPosition.getPresetPosition(), chosenPosition, decPosition.getRank(), decPosition.getSyllabusId(), decPosition.getSyllabusName()));
                }
            }
            // 已经公布的列表
            List<DecPositionPublished> lst = decPositionPublishedService.getDecPositionPublishedListByBookId(textbookId);
            List<DecPositionPublished> addNew = new ArrayList<DecPositionPublished>(16);
            for (DecPositionPublished item : lst) {
                // 编委 | 数字编委
                if (item.getChosenPosition() == 1 || item.getChosenPosition() >= 8) {
                    // item.setChosenPosition(item.getChosenPosition() > 8
                    // ?(item.getChosenPosition()-8):item.getChosenPosition() );
                    addNew.add(item);
                }
            }
            // 加入主编副主编
            for (DecPositionPublished item : decPositionPublisheds) {
                boolean no = true;
                for (DecPositionPublished itemadd : addNew) {
                    if (itemadd.getDeclarationId().intValue() == item.getDeclarationId().intValue()) {
                        no = false;
                        itemadd.setChosenPosition(item.getChosenPosition() + 8);
                        break;
                    }
                }
                if (no) {
                    addNew.add(item);
                }
            }
            // clear Id
            for (DecPositionPublished item : addNew) {
                item.setId(null);
            }
            // 对比重新发布之前于之后的不同
            List<DecPositionPublished> newMessage = new ArrayList<>();
            for (DecPositionPublished now : decPositionPublisheds) {
                DecPositionPublished published = decPositionPublishedService.getDecPositionByDeclarationId(now.getDeclarationId(), now.getTextbookId());
                if (ObjectUtil.isNull(published)) {
                    newMessage.add(now);
                }
                for (DecPositionPublished old : lst) {
                    if (now.getDeclarationId().equals(old.getDeclarationId())) {
                        if (!now.getChosenPosition().equals(old.getChosenPosition()) || !now.getRank().equals(old.getRank())) {
                            newMessage.add(now);
                        }
                    }
                }
            }
            // 先删除当前发布人已发布的
            decPositionPublishedService.deleteDecPositionPublishedByTextBookId(textbookId);
            // 再添加
            decPositionPublishedService.batchInsertDecPositionPublished(addNew);
            // 发布时更新textbook表中is_chief_published(是否已公布主编/副主编)字段
            count = textbookService.updateTextbook(new Textbook(textbookId, true));
            if (count > 0) {
                // 发送消息
                systemMessageService.sendWhenConfirmFirstEditor(textbookId, newMessage);
            }
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) JsonUtil(com.bc.pmpheep.back.util.JsonUtil) DecPosition(com.bc.pmpheep.back.po.DecPosition) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition) Textbook(com.bc.pmpheep.back.po.Textbook)

Example 2 with JsonUtil

use of com.bc.pmpheep.back.util.JsonUtil 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 JsonUtil

use of com.bc.pmpheep.back.util.JsonUtil 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)

Example 4 with JsonUtil

use of com.bc.pmpheep.back.util.JsonUtil 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

JsonUtil (com.bc.pmpheep.back.util.JsonUtil)4 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)4 SurveyQuestionListVO (com.bc.pmpheep.back.vo.SurveyQuestionListVO)3 ArrayList (java.util.ArrayList)3 PmphUser (com.bc.pmpheep.back.po.PmphUser)2 Survey (com.bc.pmpheep.back.po.Survey)2 SurveyTemplate (com.bc.pmpheep.back.po.SurveyTemplate)2 SurveyTemplateQuestion (com.bc.pmpheep.back.po.SurveyTemplateQuestion)2 DecPosition (com.bc.pmpheep.back.po.DecPosition)1 DecPositionPublished (com.bc.pmpheep.back.po.DecPositionPublished)1 SurveyQuestion (com.bc.pmpheep.back.po.SurveyQuestion)1 SurveyQuestionOption (com.bc.pmpheep.back.po.SurveyQuestionOption)1 Textbook (com.bc.pmpheep.back.po.Textbook)1 NewDecPosition (com.bc.pmpheep.back.vo.NewDecPosition)1