Search in sources :

Example 16 with WriterUser

use of com.bc.pmpheep.back.po.WriterUser in project pmph by BCSquad.

the class SessionUtil method getWriterUserBySessionId.

/**
 * <pre>
 * 功能描述:根据SessionId获取用户对象(现阶段使用)
 * 使用示范:
 *
 * @return
 * </pre>
 */
public static WriterUser getWriterUserBySessionId(String sessionId) throws CheckedServiceException {
    HttpSession session = SessionContext.getSession(sessionId);
    if (ObjectUtil.isNull(session)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.SESSION, CheckedExceptionResult.USER_SESSION, "当前Session会话已过期,请重新登录!");
    }
    WriterUser writerUser = (WriterUser) session.getAttribute(Const.SESSION_WRITER_USER);
    return writerUser;
}
Also used : HttpSession(javax.servlet.http.HttpSession) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 17 with WriterUser

use of com.bc.pmpheep.back.po.WriterUser in project pmph by BCSquad.

the class SessionUtil method getWriterUser.

/**
 * <pre>
 * 功能描述:根据Request获取用户(现阶段不使用)
 * 使用示范:
 *
 * @return
 * </pre>
 */
public static WriterUser getWriterUser() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    WriterUser writerUser = (WriterUser) session.getAttribute(Const.SESSION_WRITER_USER);
    return writerUser;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 18 with WriterUser

use of com.bc.pmpheep.back.po.WriterUser in project pmph by BCSquad.

the class PmphGroupMemberServiceImpl method addPmphGroupMemberOnGroup.

@Override
public String addPmphGroupMemberOnGroup(Long groupId, List<PmphGroupMember> pmphGroupMembers, String sessionId) throws CheckedServiceException {
    String result = "FAIL";
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    /**
     *        Textbook textbook=new Textbook();
     *        if(null!=pmphGroupMembers.get(0).getTextbookId()){
     *        	//查询书籍信息
     *        	textbook=textbookService.getTextbookById(pmphGroupMembers.get(0).getTextbookId());
     *        }
     *        Material material=new Material();
     *        if(null!=pmphGroupMembers.get(0).getMaterialId()){
     *        	 //查询教材信息
     *            material=materialService.getMaterialById(pmphGroupMembers.get(0).getMaterialId());
     *        }
     *        //查询该教材是否存在项目编辑
     *        MaterialProjectEditor materialProjectEditor=materialProjectEditorService.getMaterialProjectEditorByMaterialIdAndUserId(material.getId(), pmphUser.getId());
     *        ////判断当前教材是否有创建小组的权限
     *        if (!material.getDirector().equals(pmphUser.getId()) && !textbook.getPlanningEditor().equals(pmphUser.getId())
     *                && null == materialProjectEditor && !pmphUser.getIsAdmin()) {
     *            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
     *                    CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
     *
     *        }
     *        if (null != material.getPlanPermission()) {
     *            if (!BinaryUtil.getBit(material.getPlanPermission(), 7)) {
     *                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
     *                        CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
     *            }
     *        }
     *        if (null != material.getProjectPermission()) {
     *            if (!BinaryUtil.getBit(material.getProjectPermission(), 7)) {
     *                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
     *                        CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
     *            }
     *        }
     */
    // 小组权限的判断
    Long materialId = pmphGroupMembers.get(0).getMaterialId();
    Long textBookId = pmphGroupMembers.get(0).getTextbookId();
    String myPower = textbookService.listBookPosition(1, 9999, null, "[" + textBookId + "]", null, materialId, sessionId).getRows().get(0).getMyPower();
    String groupPower = myPower.substring(6, 7);
    /**
     *        if (pmphUser.getIsAdmin() || isFounderOrisAdmin(groupId, sessionId)
     *        		||material.getDirector()==pmphUser.getId()||textbook.getPlanningEditor()==pmphUser.getId()
     *        		||pmphUser.getId()==materialProjectEditor.getEditorId()) {// 是超级管理员或者该小组的创建人和管理员才可以添加成员
     */
    if ("1".equals(groupPower)) {
        // 小组权限的判断  end
        if (pmphGroupMembers.size() > 0) {
            List<Long> writers = new ArrayList<>();
            List<Long> pmphs = new ArrayList<>();
            for (PmphGroupMember pmphGroupMember : pmphGroupMembers) {
                PmphGroupMemberVO groupMember = pmphGroupMemberDao.getPmphGroupMemberByMemberId(groupId, pmphGroupMember.getUserId(), // 查看当前添加人员是否以前在小组中
                pmphGroupMember.getIsWriter());
                if (ObjectUtil.isNull(groupMember)) {
                    // 当前人员以前不在小组中
                    if (null == pmphGroupMember.getUserId()) {
                        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "成员id为空");
                    }
                    if (pmphGroupMember.getIsWriter()) {
                        WriterUser writerUser = writerUserService.get(pmphGroupMember.getUserId());
                        pmphGroupMember.setDisplayName(writerUser.getRealname());
                        writers.add(pmphGroupMember.getUserId());
                    } else {
                        PmphUser user = pmphUserService.get(pmphGroupMember.getUserId());
                        pmphGroupMember.setDisplayName(user.getRealname());
                        pmphs.add(pmphGroupMember.getUserId());
                    }
                    pmphGroupMember.setGroupId(groupId);
                    pmphGroupMemberDao.addPmphGroupMember(pmphGroupMember);
                } else {
                    if (groupMember.getIsDeleted()) {
                        pmphGroupMember.setGroupId(groupId);
                        pmphGroupMember.setIsDeleted(false);
                        pmphGroupMemberDao.update(pmphGroupMember);
                        if (groupMember.getIsWriter()) {
                            writers.add(pmphGroupMember.getUserId());
                        } else {
                            pmphs.add(pmphGroupMember.getUserId());
                        }
                    } else {
                        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户已在小组中,请勿重复添加");
                    }
                }
            }
            // 向添加的小组成员发送消息
            try {
                if (!writers.isEmpty()) {
                    // 向作家用户发送消息
                    systemMessageService.sendWhenInviteJoinGroup(pmphUser.getRealname(), groupId, writers, (short) 2);
                }
                if (!pmphs.isEmpty()) {
                    // 向社内用户发送消息
                    systemMessageService.sendWhenInviteJoinGroup(pmphUser.getRealname(), groupId, pmphs, (short) 1);
                }
            } catch (IOException e) {
                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "发送消息失败" + e.getMessage());
            }
            result = "SUCCESS";
        } else {
            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "参数为空");
        }
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
    }
    return result;
}
Also used : PmphGroupMember(com.bc.pmpheep.back.po.PmphGroupMember) PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser) IOException(java.io.IOException)

Example 19 with WriterUser

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

Example 20 with WriterUser

use of com.bc.pmpheep.back.po.WriterUser in project pmph by BCSquad.

the class SurveyTargetServiceImpl method reissueSurveyMessage.

@Override
public Integer reissueSurveyMessage(Message message, String title, Long surveyId, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(surveyId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷表Id为空");
    }
    if (StringUtil.isEmpty(title)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷名称为空");
    }
    // MongoDB 消息插入
    message = messageService.add(message);
    if (StringUtil.isEmpty(message.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
    }
    List<Long> listUserId = surveyQuestionAnswerService.getUserIdBySurveyId(surveyId);
    Integer count = 0;
    List<Long> orgIds = this.listOrgIdBySurveyId(surveyId);
    if (CollectionUtil.isNotEmpty(orgIds)) {
        count = orgIds.size();
        Long userId = pmphUser.getId();
        String surveyTitle = title + "-(问卷催办)";
        // 发送消息
        // 作家用户
        List<WriterUser> writerUserList = writerUserService.getWriterUserListByOrgIds(orgIds);
        // 系统消息
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
        for (WriterUser writerUser : writerUserList) {
            if (!listUserId.contains(writerUser.getId())) {
                userMessageList.add(new UserMessage(message.getId(), surveyTitle, Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
            }
        }
        // 发送消息
        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, surveyTitle, message.getContent(), DateUtil.getCurrentTime());
                myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
            }
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Aggregations

WriterUser (com.bc.pmpheep.back.po.WriterUser)49 BaseTest (com.bc.pmpheep.test.BaseTest)26 Test (org.junit.Test)26 Rollback (org.springframework.test.annotation.Rollback)24 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)17 ArrayList (java.util.ArrayList)14 PmphUser (com.bc.pmpheep.back.po.PmphUser)11 UserMessage (com.bc.pmpheep.back.po.UserMessage)7 OrgUser (com.bc.pmpheep.back.po.OrgUser)6 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)6 DesRun (com.bc.pmpheep.back.util.DesRun)4 Message (com.bc.pmpheep.general.po.Message)4 HashMap (java.util.HashMap)4 PageResult (com.bc.pmpheep.back.plugin.PageResult)3 MyMessageVO (com.bc.pmpheep.back.vo.MyMessageVO)3 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)2 Material (com.bc.pmpheep.back.po.Material)2 MessageAttachment (com.bc.pmpheep.back.po.MessageAttachment)2 Org (com.bc.pmpheep.back.po.Org)2 PmphRole (com.bc.pmpheep.back.po.PmphRole)2