Search in sources :

Example 16 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerCategoryServiceImpl method listBlogCategory.

@Override
public ResultBean<List<BloggerCategoryDTO>> listBlogCategory(int bloggerId, int offset, int rows) {
    List<BlogCategory> categories = categoryDao.listCategoryByBloggerId(bloggerId, offset, rows);
    if (CollectionUtils.isEmpty(categories))
        return null;
    List<BloggerCategoryDTO> result = new ArrayList<>();
    for (BlogCategory category : categories) {
        result.add(getBloggerCategoryDTO(bloggerId, category));
    }
    return new ResultBean<>(result);
}
Also used : BlogCategory(com.duan.blogos.entity.blog.BlogCategory) BloggerCategoryDTO(com.duan.blogos.dto.blogger.BloggerCategoryDTO) ArrayList(java.util.ArrayList) ResultBean(com.duan.blogos.restful.ResultBean)

Example 17 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerCollectBlogServiceImpl method listCollectBlog.

@Override
public ResultBean<List<FavouriteBlogListItemDTO>> listCollectBlog(int bloggerId, int categoryId, int offset, int rows, BlogSortRule sortRule) {
    List<BlogCollect> collects = collectDao.listCollectBlog(bloggerId, categoryId, offset, rows);
    if (CollectionUtils.isEmpty(collects))
        return null;
    // 排序
    List<BlogStatistics> temp = new ArrayList<>();
    // 方便排序后的重组
    Map<Integer, BlogCollect> blogCollectMap = new HashMap<>();
    for (BlogCollect collect : collects) {
        int blogId = collect.getBlogId();
        BlogStatistics statistics = statisticsDao.getStatistics(blogId);
        temp.add(statistics);
        blogCollectMap.put(blogId, collect);
    }
    BlogListItemComparatorFactory factory = new BlogListItemComparatorFactory();
    temp.sort(factory.get(sortRule.getRule(), sortRule.getOrder()));
    // 构造结果
    List<FavouriteBlogListItemDTO> result = new ArrayList<>();
    for (BlogStatistics statistics : temp) {
        int blogId = statistics.getBlogId();
        // BlogListItemDTO
        Blog blog = blogDao.getBlogById(blogId);
        String ch = dbProperties.getStringFiledSplitCharacterForNumber();
        // category
        int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), ch);
        List<BlogCategory> categories = null;
        if (!CollectionUtils.isEmpty(cids)) {
            categories = categoryDao.listCategoryById(cids);
        }
        // label
        int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
        List<BlogLabel> labels = null;
        if (!CollectionUtils.isEmpty(lids)) {
            labels = labelDao.listLabelById(lids);
        }
        BlogListItemDTO listItemDTO = fillingManager.blogListItemToDTO(statistics, CollectionUtils.isEmpty(categories) ? null : categories.toArray(new BlogCategory[categories.size()]), CollectionUtils.isEmpty(labels) ? null : labels.toArray(new BlogLabel[labels.size()]), blog, null);
        // BloggerDTO
        int authorId = blog.getBloggerId();
        BloggerAccount account = accountDao.getAccountById(authorId);
        BloggerProfile profile = profileDao.getProfileByBloggerId(authorId);
        BloggerPicture avatar = profile.getAvatarId() == null ? null : pictureDao.getPictureById(profile.getAvatarId());
        // 使使用默认的博主头像
        if (avatar == null) {
            avatar = new BloggerPicture();
            avatar.setCategory(BloggerPictureCategoryEnum.PUBLIC.getCode());
            avatar.setBloggerId(authorId);
            avatar.setId(-1);
        }
        String url = constructorManager.constructPictureUrl(avatar, BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR);
        avatar.setPath(url);
        BloggerDTO bloggerDTO = fillingManager.bloggerAccountToDTO(account, profile, avatar);
        // 结果
        BlogCollect collect = blogCollectMap.get(blogId);
        FavouriteBlogListItemDTO dto = fillingManager.collectBlogListItemToDTO(bloggerId, collect, listItemDTO, bloggerDTO);
        result.add(dto);
    }
    return new ResultBean<>(result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlogListItemComparatorFactory(com.duan.blogos.manager.comparator.BlogListItemComparatorFactory) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 18 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerProfileController method get.

/**
 * 获取资料
 */
@RequestMapping(method = RequestMethod.GET)
public ResultBean<BloggerProfile> get(HttpServletRequest request, @PathVariable Integer bloggerId) {
    handleAccountCheck(request, bloggerId);
    BloggerProfile profile = bloggerProfileService.getBloggerProfile(bloggerId);
    if (profile == null)
        handlerEmptyResult(request);
    return new ResultBean<>(profile);
}
Also used : ResultBean(com.duan.blogos.restful.ResultBean) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile)

Example 19 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerProfileController method update.

/**
 * 更新资料
 */
@RequestMapping(method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request, @PathVariable Integer bloggerId, @RequestParam(value = "avatarId", required = false) Integer avatarId, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "email", required = false) String email, @RequestParam(value = "aboutMe", required = false) String aboutMe, @RequestParam(value = "intro", required = false) String intro) {
    if (phone == null && email == null && aboutMe == null && intro == null) {
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));
    }
    handleBloggerSignInCheck(request, bloggerId);
    handlePictureExistCheck(request, bloggerId, avatarId);
    handleParamsCheck(phone, email, request);
    int av = avatarId == null || avatarId <= 0 ? -1 : avatarId;
    boolean result = bloggerProfileService.updateBloggerProfile(bloggerId, av, phone, email, aboutMe, intro);
    if (!result)
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 20 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class SMSController method send.

/**
 * 向指定号码发送短信
 */
@RequestMapping(method = RequestMethod.POST)
public ResultBean send(HttpServletRequest request, @RequestParam("phone") String phone, @RequestParam("content") String content) {
    String url;
    try {
        url = JiSuApiUtils.getSmsUrl(phone, content);
    } catch (UnsupportedEncodingException e) {
        return new ResultBean(exceptionManager.getUnknownException(new RequestContext(request), e));
    }
    OkHttpClient client = new OkHttpClient();
    Request okRequest = new Request.Builder().post(new FormBody.Builder().build()).url(url).build();
    Response response = null;
    try {
        response = client.newCall(okRequest).execute();
    } catch (IOException e) {
        return new ResultBean(exceptionManager.getUnknownException(new RequestContext(request), e));
    }
    if (response != null) {
        try {
            JSONObject obj = JSONObject.parseObject(response.body().string());
            String status = obj.getString("status");
            if (Integer.valueOf(status) == 0) {
                return new ResultBean<>("");
            } else {
                // FIXME 极速短信API“签名不存在”错误
                return new ResultBean<>(obj.getString("msg"), ResultBean.FAIL);
            }
        } catch (IOException e) {
            return new ResultBean(exceptionManager.getUnknownException(new RequestContext(request), e));
        }
    }
    handlerOperateFail(request);
    return null;
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) JSONObject(com.alibaba.fastjson.JSONObject) Request(okhttp3.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestContext(org.springframework.web.servlet.support.RequestContext) IOException(java.io.IOException) ResultBean(com.duan.blogos.restful.ResultBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResultBean (com.duan.blogos.restful.ResultBean)28 RequestContext (org.springframework.web.servlet.support.RequestContext)12 Blog (com.duan.blogos.entity.blog.Blog)5 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)5 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)5 HttpSession (javax.servlet.http.HttpSession)5 BlogCategory (com.duan.blogos.entity.blog.BlogCategory)4 ArrayList (java.util.ArrayList)4 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)3 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)3 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 BloggerCategoryDTO (com.duan.blogos.dto.blogger.BloggerCategoryDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)2 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 HashMap (java.util.HashMap)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BlogMainContentDTO (com.duan.blogos.dto.blog.BlogMainContentDTO)1