Search in sources :

Example 31 with PmphUser

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

the class WechatArticleService method synchroCmsContent.

public CmsContent synchroCmsContent(String guid, HttpServletRequest request) throws IOException {
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser sessionPmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == sessionPmphUser) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    CmsContent cmsContent = new CmsContent();
    if (StringUtil.isEmpty(guid)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.NULL_PARAM, "文章唯一标识不能为空");
    }
    // 删除文件夹及以下文件
    // 获取路径
    String dir = new File("").getAbsolutePath() + "/" + guid;
    FileUtil.deleteDirectory(dir);
    if (Const.WACT_MAP.containsKey(guid)) {
        WechatArticle wechatArticle = Const.WACT_MAP.get(guid);
        String html = wechatArticle.getResult();
        String titleStart = "<h2 class=\"rich_media_title\" id=\"activity-name\">";
        String titleEnd = "</h2>";
        int titleS = html.indexOf(titleStart) + titleStart.length();
        String title = "";
        try {
            int titleE = html.indexOf(titleEnd);
            // 获取标题
            title = html.substring(titleS, titleE);
        } catch (Exception e) {
            throw new CheckedServiceException(CheckedExceptionBusiness.WECHAT_ARTICLE, CheckedExceptionResult.ILLEGAL_PARAM, "同步失败,请检查链接地址是否正确,或者其他原因");
        }
        String contentStart = "<div class=\"rich_media_content \" id=\"js_content\">";
        String contentEnd = "</div>";
        int contentS = html.indexOf(contentStart) + contentStart.length();
        int contentE = html.lastIndexOf(contentEnd);
        // 获取内容
        String content = html.substring(contentS, contentE);
        // 替换内容
        String contents = content.replace("data-src", "src");
        // 获取图片标签
        List<String> imgUrl = download.getImageUrl(contents);
        // 获取图片src地址
        List<String> imgSrc = download.getImageSrc(imgUrl);
        // 下载图片
        List<String> mongoImgs = download.download(imgSrc);
        for (int i = 0; i < imgSrc.size(); i++) {
            if (StringUtil.notEmpty(mongoImgs.get(i))) {
                // 下载路径
                String imgsId = RouteUtil.MONGODB_FILE + mongoImgs.get(i);
                contents = contents.replace(imgSrc.get(i), imgsId);
            }
        }
        if (StringUtil.isEmpty(contents)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容参数为空");
        }
        // MongoDB内容插入
        Content contentObj = contentService.add(new Content(contents));
        if (StringUtil.isEmpty(contentObj.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "Content对象内容保存失败");
        }
        // 上级id(0为内容)
        cmsContent.setParentId(0L);
        // 根节点路径
        cmsContent.setPath("0");
        // 内容id
        cmsContent.setMid(contentObj.getId());
        // 内容类型(1=随笔文章)
        cmsContent.setCategoryId(Const.CMS_CATEGORY_ID_1);
        cmsContent.setTitle(title.trim());
        // 作者类型
        cmsContent.setAuthorType((short) 0);
        // 作者id
        cmsContent.setAuthorId(sessionPmphUser.getId());
        cmsContent = cmsContentService.addCmsContent(cmsContent);
    }
    // 防止map内存溢出,操作过后就移除
    Const.WACT_MAP.remove("guid");
    return cmsContent;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) PmphUser(com.bc.pmpheep.back.po.PmphUser) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WechatArticle(com.bc.pmpheep.general.runnable.WechatArticle) File(java.io.File) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) IOException(java.io.IOException)

Example 32 with PmphUser

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

the class PmphUserRealm method doGetAuthorizationInfo.

/**
 * 授权
 *
 * @param principalCollection
 * @return
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    logger.info("--- MyRealm doGetAuthorizationInfo ---");
    // 获得经过认证的主体信息
    PmphUser user = (PmphUser) principalCollection.getPrimaryPrincipal();
    Long userId = user.getId();
    // UserService userService = (UserService)InitServlet.getBean("userService");
    List<PmphPermission> resourceList = null;
    List<String> roleSnList = null;
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    try {
        resourceList = userService.getListAllResource(userId);
        roleSnList = userService.getListRoleSnByUser(userId);
        List<String> resStrList = new ArrayList<>();
        for (PmphPermission resource : resourceList) {
            resStrList.add(resource.getUrl());
        }
        info.setRoles(new HashSet<>(roleSnList));
        info.setStringPermissions(new HashSet<>(resStrList));
        // 以上完成了动态地对用户授权
        logger.info("role => " + roleSnList);
        logger.info("permission => " + resStrList);
    } catch (Exception e) {
        logger.info("message => " + e);
    }
    return info;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphPermission(com.bc.pmpheep.back.po.PmphPermission) ArrayList(java.util.ArrayList) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Example 33 with PmphUser

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

the class PmphUserRealm method clearCachedAuthenticationInfo.

/**
 * <pre>
 * 功能描述:更新身份验证信息缓存
 * 使用示范:
 *
 * @param principals
 * </pre>
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void clearCachedAuthenticationInfo(PrincipalCollection principals) {
    Cache c = getAuthenticationCache();
    logger.info("清除【认证】缓存之前");
    for (Object o : c.keys()) {
        logger.info(o + " , " + c.get(o));
    }
    super.clearCachedAuthenticationInfo(principals);
    logger.info("调用父类清除【认证】缓存之后");
    for (Object o : c.keys()) {
        logger.info(o + " , " + c.get(o));
    }
    // 添加下面的代码清空【认证】的缓存
    PmphUser user = (PmphUser) principals.getPrimaryPrincipal();
    SimplePrincipalCollection spc = new SimplePrincipalCollection(user.getUsername(), getName());
    super.clearCachedAuthenticationInfo(spc);
    logger.info("添加了代码清除【认证】缓存之后");
    int cacheSize = c.keys().size();
    logger.info("【认证】缓存的大小:" + c.keys().size());
    if (cacheSize == 0) {
        logger.info("说明【认证】缓存被清空了。");
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Cache(org.apache.shiro.cache.Cache)

Example 34 with PmphUser

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

the class SessionUtil method getPmphUser.

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

Example 35 with PmphUser

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

the class PmphGroupFileServiceImpl method addPmphGroupFile.

/**
 * @param pmphGroupFile
 *            实体对象
 * @return 带主键的 PmphGroupFile
 * @throws CheckedServiceException
 * @update Mryang 2017.10.13 15:30
 */
@Override
public String addPmphGroupFile(Long[] ids, MultipartFile file, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(ids) || ids.length == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "参数不能为空");
    }
    if (ObjectUtil.isNull(file)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "文件不能为空");
    }
    Long userId = pmphUser.getId();
    List<PmphGroupFile> list = new ArrayList<>();
    for (Long id : ids) {
        if (ObjectUtil.isNull(id)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组id不能为空");
        }
        PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(id, userId, false);
        PmphGroupFile pmphGroupFile = new PmphGroupFile(id, pmphGroupMemberVO.getId(), "0" + pmphGroupMemberVO.getId(), file.getOriginalFilename(), 0, null);
        Long fileLenth = file.getSize();
        pmphGroupFile.setFileSize(Double.valueOf(fileLenth / 1024));
        pmphGroupFileDao.addPmphGroupFile(pmphGroupFile);
        list.add(pmphGroupFile);
    }
    // list.get(0).getId()获取上传的第一条数据的id
    String fileId = fileService.save(file, FileType.GROUP_FILE, list.get(0).getId());
    for (PmphGroupFile pmphGroupFile : list) {
        pmphGroupFile.setFileId(fileId);
        pmphGroupFileDao.updatePmphGroupFile(pmphGroupFile);
        PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(pmphGroupFile.getGroupId(), userId, false);
        pmphGroupMessageService.addGroupMessage(pmphGroupMemberVO.getDisplayName() + "上传了文件" + file.getOriginalFilename(), pmphGroupFile.getGroupId(), sessionId, Const.SENDER_TYPE_0);
    }
    return "success";
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupFile(com.bc.pmpheep.back.po.PmphGroupFile) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

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