Search in sources :

Example 51 with PmphUser

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

the class TopicServiceImpl method update.

@Override
public String update(TopicLog topicLog, String sessionId, Topic topic) throws CheckedServiceException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.NULL_PARAM, "用户为空!");
    }
    topicLog.setUserId(pmphUser.getId());
    if (ObjectUtil.isNull(topic) || ObjectUtil.isNull(topic.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.NULL_PARAM, "该选题不存在");
    }
    if (!StringUtil.isEmpty(topic.getAuthFeedback())) {
        if (topic.getAuthFeedback().length() > 200) {
            throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.ILLEGAL_PARAM, "审核意见过长,请不要超过200个字符");
        }
    }
    if (!StringUtil.isEmpty(topic.getReasonDirector())) {
        if (topic.getReasonDirector().length() > 200) {
            throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.ILLEGAL_PARAM, "退回原因过长,请不要超过200个字符");
        }
    }
    if (!StringUtil.isEmpty(topic.getReasonEditor())) {
        if (topic.getReasonEditor().length() > 200) {
            throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.ILLEGAL_PARAM, "退回原因过长,请不要超过200个字符");
        }
    }
    String result = "FIAL";
    if (topicDao.update(topic) > 0) {
        topicLogService.add(topicLog);
        result = "SUCCESS";
    }
    WriterUserTrendst writerUserTrendst = new WriterUserTrendst();
    writerUserTrendst.setUserId(topicDao.getTopicTextVO(topic.getId()).getUserId());
    writerUserTrendst.setBookId(topic.getId());
    writerUserTrendst.setType(9);
    writerUserTrendst.setIsPublic(false);
    if (ObjectUtil.notNull(topic.getAuthProgress())) {
        if (StringUtil.isEmpty(topic.getAuthFeedback())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.NULL_PARAM, "审核意见不能为空");
        }
        if (3 == topic.getAuthProgress()) {
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("title", CheckedExceptionBusiness.TOPIC);
            detail.put("content", "您的选题《" + topicDao.get(topic.getId()).getBookname() + "》已经通过。");
            detail.put("img", 1);
            writerUserTrendst.setDetail(new Gson().toJson(detail));
        // 创建本版号并将本版号放入数据中
        // String editionnum = "10" + new SimpleDateFormat("yyyy").format(new Date());
        // String vn = topicDao.get(topic.getId()).getVn();
        // if (StringUtil.isEmpty(vn)) {
        // vn = topicDao.getMaxTopicVn();
        // if (StringUtil.isEmpty(vn)) {
        // vn = editionnum + "000001";
        // } else {
        // vn = editionnum + Integer.parseInt(vn.substring(7)) + 1000000 + 1 + "";
        // }
        // }
        // topic.setNote("选题通过");
        // topic.setVn(vn);
        // topicDao.update(topic);
        // String remark = topic.getAuthFeedback();
        // TopicTextVO topicTextVO = topicTextVO(topicLog, sessionId, topic.getId());
        // String sql = "insert into i_declarestates
        // (editionnum,rwusercode,rwusername,topicname,readerpeople,sources,fontcount,piccount,timetohand,subject,booktype,levels,depositbank,bankaccount,selectreason,publishingvalue,content,authorbuybooks,authorsponsor,originalname,originalauthor,originalnationality,originalpress,publishagerevision,topicnumber,auditstates,remark,creattime,states)";
        // sql += "values('" + vn + "','" + topicTextVO.getUsername() + "','" +
        // topicTextVO.getRealname()
        // + "','','" + topicTextVO.getReadType() + "','" + topicTextVO.getSourceType()
        // + "','"
        // + topicTextVO.getWordNumber() + "','" + topicTextVO.getPictureNumber() +
        // "','"
        // + DateUtil.formatTimeStamp("yyyy-MM-dd", topicTextVO.getDeadline()) + "','"
        // + topicTextVO.getSubject() + "','" + topicTextVO.getTypeName() + "','" +
        // topicTextVO.getRank()
        // + "','" + topicTextVO.getBank() + "','" + topicTextVO.getAccountNumber() +
        // "','"
        // + topicTextVO.getTopicExtra().getReason() + "','" +
        // topicTextVO.getTopicExtra().getPrice()
        // + "','" + topicTextVO.getTopicExtra().getScore() + "','" +
        // topicTextVO.getPurchase() + "','"
        // + topicTextVO.getSponsorship() + "','" + topicTextVO.getOriginalBookname() +
        // "','"
        // + topicTextVO.getOriginalAuthor() + "','" + topicTextVO.getNation() +
        // "','','"
        // + topicTextVO.getEdition() + "','','11','" + remark + "',GETDATE(),1)";
        // SqlHelper.executeUpdate(sql, null);
        } else {
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("title", CheckedExceptionBusiness.TOPIC);
            detail.put("content", "您的选题《" + topicDao.get(topic.getId()).getBookname() + "》未通过。");
            detail.put("img", 2);
            writerUserTrendst.setDetail(new Gson().toJson(detail));
        }
        writerUserTrendstService.addWriterUserTrendst(writerUserTrendst);
    }
    return result;
}
Also used : WriterUserTrendst(com.bc.pmpheep.back.po.WriterUserTrendst) PmphUser(com.bc.pmpheep.back.po.PmphUser) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) JSONObject(net.sf.json.JSONObject)

Example 52 with PmphUser

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

the class TopicServiceImpl method listTopicEditorVOs.

@Override
public PageResult<TopicEditorVO> listTopicEditorVOs(String sessionId, PageParameter<TopicEditorVO> pageParameter) throws CheckedServiceException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    PageResult<TopicEditorVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    Integer total = 0;
    String submitTime = DateUtil.date2Str(pageParameter.getParameter().getSubmitTime(), "yyyy-MM-dd");
    if (pmphUser.getIsAdmin()) {
        total = topicDao.totalEditorView(pageParameter.getParameter().getBookname(), submitTime);
        if (total > 0) {
            List<TopicEditorVO> list = topicDao.listEditorView(pageParameter.getParameter().getBookname(), submitTime, pageParameter.getStart(), pageParameter.getPageSize());
            list = addTypeNameEditor(list);
            pageResult.setRows(list);
        }
    } else {
        total = topicDao.totalTopicEditorVOs(pmphUser.getId(), pageParameter.getParameter().getBookname(), submitTime);
        if (total > 0) {
            List<TopicEditorVO> list = topicDao.listTopicEditorVOs(pmphUser.getId(), pageParameter.getParameter().getBookname(), submitTime, pageParameter.getStart(), pageParameter.getPageSize());
            list = addTypeNameEditor(list);
            pageResult.setRows(list);
        }
    }
    pageResult.setTotal(total);
    return pageResult;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) TopicEditorVO(com.bc.pmpheep.back.vo.TopicEditorVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageResult(com.bc.pmpheep.back.plugin.PageResult)

Example 53 with PmphUser

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

the class UserMessageServiceImpl method updateMyMessageDetail.

@Override
public MyMessageVO updateMyMessageDetail(Long id) throws CheckedServiceException {
    if (ObjectUtil.isNull(id)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息id为空!");
    }
    MyMessageVO myMessageVO = userMessageDao.getMyMessageDetail(id);
    switch(myMessageVO.getSenderType()) {
        case 0:
            myMessageVO.setSenderName("系统");
            break;
        case 1:
            PmphUser pmphUser = pmphUserService.get(myMessageVO.getSenderId());
            myMessageVO.setSenderAvatar(pmphUser.getAvatar());
            myMessageVO.setSenderName(pmphUser.getRealname());
            break;
        case 2:
            WriterUser writerUser = writerUserService.get(myMessageVO.getSenderId());
            myMessageVO.setSenderAvatar(writerUser.getAvatar());
            myMessageVO.setSenderName(writerUser.getRealname());
            break;
        case 3:
            // 现在没有机构用户
            break;
        default:
            throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "发送者类型不正确!");
    }
    Message message = messageService.get(myMessageVO.getMsgId());
    if (ObjectUtil.isNull(message)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "没有获取到消息详情");
    }
    myMessageVO.setContent(message.getContent());
    List<MessageAttachment> messageAttachments = messageAttachmentService.getMessageAttachmentByMsgId(myMessageVO.getMsgId());
    for (MessageAttachment messageAttachment : messageAttachments) {
        messageAttachment.setAttachment(RouteUtil.MONGODB_FILE + messageAttachment.getAttachment());
    }
    myMessageVO.setMessageAttachments(messageAttachments);
    UserMessage userMessage = new UserMessage();
    userMessage.setId(id);
    userMessage.setIsRead(true);
    userMessageDao.updateUserMessage(userMessage);
    return myMessageVO;
}
Also used : MessageAttachment(com.bc.pmpheep.back.po.MessageAttachment) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) PmphUser(com.bc.pmpheep.back.po.PmphUser) MyMessageVO(com.bc.pmpheep.back.vo.MyMessageVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 54 with PmphUser

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

the class PmphLoginController method login.

/**
 * <pre>
 * 功能描述:登陆
 * 使用示范:
 *
 * @param user
 * @param model
 * @return
 * </pre>
 *
 * //* @throws SingleSignOnException
 */
@ResponseBody
@OAuthRequired
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "wechatUserId", required = false) String wechatUserId, @RequestParam(value = "token", required = false) String token, HttpServletRequest request) throws CheckedServiceException {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    logger.info("username => " + username);
    logger.info("password => " + password);
    // HttpSingleSignOnService service = new HttpSingleSignOnService();
    // String url = service.getSingleSignOnURL();
    // try {
    // 判断是否从企业微信App登陆
    String userAgent = request.getHeader("user-agent").toLowerCase();
    Boolean isTrue = userAgent == null || userAgent.indexOf("micromessenger") == -1 ? false : true;
    if (isTrue) {
        if (StringUtil.notEmpty(token)) {
            String newToken = username + password + wechatUserId + "<pmpheep>";
            if (!newToken.equals(new DesRun(token).depsw)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名密码错误!");
            }
        }
        username = new DesRun(username).depsw;
        password = new DesRun(password).depsw;
    }
    if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "请输入用户名和密码!");
    }
    PmphUser pmphUser = pmphUserService.login(username, new DesRun("", password).enpsw);
    // PmphUser pmphUser = pmphUserService.login(userName, null);
    pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
    if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
        pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
    }
    // 根据用户Id查询对应角色(是否为管理员)
    List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
    if (pmphRoles.isEmpty()) {
        // 添加默认权限
        pmphRoleService.addUserRole(pmphUser.getId(), 2L);
        pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
    }
    List<Long> roleIds = new ArrayList<Long>();
    for (PmphRole pmphRole : pmphRoles) {
        roleIds.add(pmphRole.getId());
        if (ObjectUtil.notNull(pmphRole)) {
            if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
                pmphUser.setIsAdmin(true);
            } else {
                pmphUser.setIsAdmin(false);
            }
        }
        if (Const.TRUE == pmphUser.getIsAdmin()) {
            break;
        }
    }
    // 根据用户Id查询对应权限Id
    List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
    // 判断是否从企业微信App登陆
    if (isTrue) {
        PmphUserWechat pmphUserWechat = pmphUserWechatService.getPmphUserWechatByWechatId(wechatUserId);
        if (ObjectUtil.isNull(pmphUserWechat)) {
            pmphUserWechatService.add(new PmphUserWechat(username, wechatUserId));
        }
    }
    // String materialPermission =
    // pmphUserService.getMaterialPermissionByUserId(pmphUser.getId()); 根据用户返回书籍
    // 验证成功在Session中保存用户信息
    request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
    // 验证成功在Session中保存用户Token信息
    request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
    // pmphUserSessionId
    resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
    resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
    resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
    resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
    // resultMap.put("materialPermission", materialPermission);
    return new ResponseBean(resultMap);
// } catch (CheckedServiceException cException) {
// return new ResponseBean(cException);
// }
}
Also used : HashMap(java.util.HashMap) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphUserWechat(com.bc.pmpheep.back.po.PmphUserWechat) PmphRole(com.bc.pmpheep.back.po.PmphRole) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) OAuthRequired(com.bc.pmpheep.wechat.interceptor.OAuthRequired) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with PmphUser

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

the class PmphLoginController method ssoLogin.

/**
 * <pre>
 * 功能描述:SSO登陆
 * 使用示范:
 *
 * @param request
 * @return
 * </pre>
 */
@ResponseBody
@RequestMapping(value = "/sso", method = RequestMethod.GET)
public ResponseBean ssoLogin(HttpServletRequest request, HttpServletResponse response) {
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser pmUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Map<String, Object> resultMap = new HashMap<String, Object>();
    HttpSingleSignOnService service = new HttpSingleSignOnService();
    // String url = service.getSingleSignOnURL();
    try {
        Principal principal = service.singleSignOn(request);
        String userName = principal.getName();
        PmphUser pmphUser = pmphUserService.login(userName, null);
        if (ObjectUtil.isNull(pmphUser)) {
            // 为空就新建一个用户
            pmphUser = pmphUserService.add(new PmphUser(userName, "888888", userName, "DEFAULT"));
            // 添加默认权限
            pmphRoleService.addUserRole(pmphUser.getId(), 2L);
        }
        pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
        if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
            pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
        }
        // 根据用户Id查询对应角色(是否为管理员)
        List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
        List<Long> roleIds = new ArrayList<Long>(pmphRoles.size());
        for (PmphRole pmphRole : pmphRoles) {
            roleIds.add(pmphRole.getId());
            if (ObjectUtil.notNull(pmphRole)) {
                if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
                    pmphUser.setIsAdmin(true);
                } else {
                    pmphUser.setIsAdmin(false);
                }
            }
            if (Const.TRUE == pmphUser.getIsAdmin()) {
                break;
            }
        }
        // 根据用户Id查询对应权限Id
        List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
        // 验证成功在Session中保存用户信息
        request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
        // 验证成功在Session中保存用户Token信息
        request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(userName, userName).enpsw);
        // pmphUserSessionId
        resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
        resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
        resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(userName, userName).enpsw);
        resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
        return new ResponseBean(resultMap);
    } catch (SingleSignOnException e) {
        return new ResponseBean(e);
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) HashMap(java.util.HashMap) HttpSingleSignOnService(small.danfer.sso.http.HttpSingleSignOnService) ArrayList(java.util.ArrayList) SingleSignOnException(small.danfer.sso.SingleSignOnException) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphRole(com.bc.pmpheep.back.po.PmphRole) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) Principal(java.security.Principal) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PmphUser (com.bc.pmpheep.back.po.PmphUser)102 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)81 ArrayList (java.util.ArrayList)33 PageResult (com.bc.pmpheep.back.plugin.PageResult)17 HashMap (java.util.HashMap)13 Material (com.bc.pmpheep.back.po.Material)11 WriterUser (com.bc.pmpheep.back.po.WriterUser)11 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)10 PmphRole (com.bc.pmpheep.back.po.PmphRole)9 UserMessage (com.bc.pmpheep.back.po.UserMessage)9 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)9 BaseTest (com.bc.pmpheep.test.BaseTest)9 Test (org.junit.Test)9 CmsContent (com.bc.pmpheep.back.po.CmsContent)8 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)8 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)7 Textbook (com.bc.pmpheep.back.po.Textbook)7 WriterUserTrendst (com.bc.pmpheep.back.po.WriterUserTrendst)6 Gson (com.google.gson.Gson)6 OrgUser (com.bc.pmpheep.back.po.OrgUser)5