Search in sources :

Example 81 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class PmphUserServiceImpl method updatePassword.

@Override
public Integer updatePassword(HttpServletRequest request, String oldPassword, String newPassword) {
    // 获取当前用户
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser sessionPmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == sessionPmphUser) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    Long id = sessionPmphUser.getId();
    if (null == id) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止查询");
    }
    if (StringUtil.isEmpty(oldPassword)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "原密码为空");
    }
    if (StringUtil.isEmpty(newPassword)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "新密码为空");
    }
    oldPassword = oldPassword.trim();
    newPassword = newPassword.trim();
    if (newPassword.length() > 50) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "新密码长度不能超过50");
    }
    if (oldPassword.equals(newPassword)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "新旧密码不能一致");
    }
    // 先修改SSO
    // ---------------------------------
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", id);
    // 加密密码
    map.put("oldPassword", new DesRun("", oldPassword).enpsw);
    map.put("newPassword", new DesRun("", newPassword).enpsw);
    Integer res = pmphUserDao.updatePassword(map);
    if (null == res || res == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "原密码错误");
    }
    return 1;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) HashMap(java.util.HashMap) DesRun(com.bc.pmpheep.back.util.DesRun) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 82 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class PmphUserServiceImpl method getInfo.

/**
 * 根据主键 id 加载用户对象
 *
 * @param id
 * @return
 */
@Override
public PmphUser getInfo(HttpServletRequest request) throws CheckedServiceException {
    // 获取当前用户
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser sessionPmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == sessionPmphUser) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    Long id = sessionPmphUser.getId();
    if (ObjectUtil.isNull(id)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止查询");
    }
    PmphUser pmphUser = pmphUserDao.getInfo(id);
    if (null == pmphUser) {
        pmphUser = new PmphUser();
    }
    String avatar = pmphUser.getAvatar();
    pmphUser.setAvatar(RouteUtil.userAvatar(avatar));
    return pmphUser;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 83 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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 84 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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 85 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class SurveyTargetServiceImpl method batchSaveSurveyTargetByList.

@Override
public Integer batchSaveSurveyTargetByList(Message message, SurveyTargetVO surveyTargetVO, String sessionId) throws Exception {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(surveyTargetVO.getSurveyId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷表Id为空");
    }
    if (CollectionUtil.isEmpty(surveyTargetVO.getOrgIds())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "学校Id为空");
    }
    if (StringUtil.isEmpty(surveyTargetVO.getStartTime())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷开始时间为空");
    }
    if (StringUtil.isEmpty(surveyTargetVO.getEndTime())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷结束时间为空");
    }
    Timestamp statTime = DateUtil.str2Timestam(surveyTargetVO.getStartTime());
    Timestamp endTime = DateUtil.str2Timestam(surveyTargetVO.getEndTime());
    if (statTime.getTime() > DateUtil.getCurrentTimeByYMD().getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷开始时间不能大于今天");
    }
    if (endTime.getTime() < DateUtil.getCurrentTimeByYMD().getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷结束时间不能小于今天");
    }
    if (statTime.getTime() > endTime.getTime()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.ILLEGAL_PARAM, "开始日期不能大于结束日期");
    }
    List<Long> orgIds = this.listOrgIdBySurveyId(surveyTargetVO.getSurveyId());
    Integer count = 0;
    // 当前用户
    Long userId = pmphUser.getId();
    List<Long> listOrgId = new ArrayList<Long>();
    if (CollectionUtil.isEmpty(orgIds)) {
        // 第一次发布
        listOrgId.addAll(surveyTargetVO.getOrgIds());
        surveyService.updateSurvey(new Survey(surveyTargetVO.getSurveyId(), Const.SURVEY_STATUS_1, DateUtil.str2Timestam(surveyTargetVO.getStartTime()), DateUtil.str2Timestam(surveyTargetVO.getEndTime())));
    } else {
        // 第二次发布
        for (Long id : surveyTargetVO.getOrgIds()) {
            if (!orgIds.contains(id)) {
                listOrgId.add(id);
            }
        }
    }
    List<SurveyTarget> list = new ArrayList<SurveyTarget>(listOrgId.size());
    for (Long orgId : listOrgId) {
        list.add(new SurveyTarget(userId, surveyTargetVO.getSurveyId(), orgId));
    }
    if (CollectionUtil.isNotEmpty(list)) {
        // 保存发起问卷中间表
        count = surveyTargetDao.batchSaveSurveyTargetByList(list);
    }
    if (count > 0) {
        // MongoDB 消息插入
        message = messageService.add(message);
        if (StringUtil.isEmpty(message.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
        }
        // 发送消息
        List<WriterUser> writerUserList = // 作家用户
        writerUserService.getWriterUserListByOrgIds(listOrgId);
        // 系统消息
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
        for (WriterUser writerUser : writerUserList) {
            userMessageList.add(new UserMessage(message.getId(), surveyTargetVO.getTitle(), Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
        }
        // 获取学校管理员集合
        List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(listOrgId);
        // 收件人邮箱
        List<String> orgUserEmail = new ArrayList<String>(orgUserList.size());
        for (OrgUser orgUser : orgUserList) {
            userMessageList.add(new UserMessage(message.getId(), surveyTargetVO.getTitle(), Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, orgUser.getId(), Const.RECEIVER_TYPE_3, 0L));
            if (!"-".equals(orgUser.getEmail()) && !"null".equals(orgUser.getEmail())) {
            // orgUserEmail.add(orgUser.getEmail());// 获取学校管理员邮箱地址
            }
        }
        // Integer size = orgUserEmail.size();
        String[] emails = new String[] { "515944204@qq.com", "2310870657@qq.com", "501331000@qq.com" };
        // String[] toEmail = (String[]) orgUserEmail.toArray(new String[size]);
        if (ArrayUtil.isEmpty(emails)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "收件人邮箱为空");
        }
        // 发送邮件
        JavaMailSenderUtil javaMailSenderUtil = new JavaMailSenderUtil();
        String serverUrl = getLogin2frontUrl().substring(0, getLogin2frontUrl().lastIndexOf("/"));
        // 给学校管理员发送邮件
        javaMailSenderUtil.sendMail(surveyTargetVO.getTitle(), // message.getContent(),
        "<p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>您好:</span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>&nbsp; &nbsp; 现有一份《" + surveyTargetVO.getTitle() + "》需要您登陆下面地址,填写您宝贵意见。</span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>&nbsp;&nbsp;&nbsp;&nbsp;登陆地址:<a href='" + serverUrl + "/survey/writeSurvey.action?surveyId=" + surveyTargetVO.getSurveyId() + "'>人卫E教平台</a><br/></span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;'><br/></p>", emails);
        // 发送消息
        if (CollectionUtil.isNotEmpty(userMessageList)) {
            // 插入消息发送对象数据
            userMessageService.addUserMessageBatch(userMessageList);
            // websocket发送的id集合
            List<String> websocketUserIds = new ArrayList<String>();
            for (UserMessage userMessage : userMessageList) {
                websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
            }
            // webscokt发送消息
            if (CollectionUtil.isNotEmpty(websocketUserIds)) {
                WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, userId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, surveyTargetVO.getTitle(), message.getContent(), DateUtil.getCurrentTime());
                myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
            }
        }
    }
    return count;
}
Also used : SurveyTarget(com.bc.pmpheep.back.po.SurveyTarget) PmphUser(com.bc.pmpheep.back.po.PmphUser) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Timestamp(java.sql.Timestamp) Survey(com.bc.pmpheep.back.po.Survey) JavaMailSenderUtil(com.bc.pmpheep.back.util.mail.JavaMailSenderUtil) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Aggregations

CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)208 PmphUser (com.bc.pmpheep.back.po.PmphUser)81 ArrayList (java.util.ArrayList)73 PageResult (com.bc.pmpheep.back.plugin.PageResult)33 Material (com.bc.pmpheep.back.po.Material)30 IOException (java.io.IOException)30 HashMap (java.util.HashMap)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)24 Workbook (org.apache.poi.ss.usermodel.Workbook)23 UserMessage (com.bc.pmpheep.back.po.UserMessage)22 LogDetail (com.bc.pmpheep.annotation.LogDetail)20 Message (com.bc.pmpheep.general.po.Message)20 Textbook (com.bc.pmpheep.back.po.Textbook)18 WriterUser (com.bc.pmpheep.back.po.WriterUser)17 OutputStream (java.io.OutputStream)17 CmsContent (com.bc.pmpheep.back.po.CmsContent)16 BufferedOutputStream (java.io.BufferedOutputStream)16 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14