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);
}
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);
}
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);
}
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<>("");
}
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;
}
Aggregations