use of com.myblog.model.Tag in project newblogback by Zephery.
the class TagServiceImpl method updatetag.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Integer updatetag(Integer tId) {
// 标签
List<Tag> tags = tagMapper.getAllTags();
JsonArray jsonArray = new JsonArray();
for (Tag tag : tags) {
List<Blog> blogs = tagMapper.getblogbytagid(tag.gettId());
String str = tag.gettName() + " " + "(" + String.valueOf(blogs.size()) + ")";
KeyAndValue keyAndValue = new KeyAndValue();
keyAndValue.setKey(tag.gettName());
keyAndValue.setValue(str);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key", tag.gettId());
jsonObject.addProperty("value", str);
jsonArray.add(jsonObject);
}
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
connection.set(serializer.serialize("biaoqian"), serializer.serialize(jsonArray.toString()));
return true;
}
});
return tId;
}
use of com.myblog.model.Tag in project newblogback by Zephery.
the class BlogServiceImpl method updateByPrimaryKeySelective.
@Override
public Integer updateByPrimaryKeySelective(Blog blog) {
blog.setSummary(blog.getContent().length() > 120 ? blog.getContent().substring(0, 120) : blog.getContent());
Matcher matcher = Pattern.compile(IMGSRC_REG).matcher(blog.getContent());
String image_url = null;
while (matcher.find()) {
image_url = matcher.group();
}
blog.setImageurl(getImageURl(image_url));
String[] array = blog.getTagforsplit().split(",");
List<Tag> tags = new ArrayList<>();
for (String string : array) {
if (tagMapper.selectByName(string) == null) {
Tag tag = new Tag();
tag.settName(string);
// TODO 为了下面的relation增加标签id
tagMapper.insert(tag);
Tag newtag = tagMapper.selectByName(string);
tags.add(newtag);
} else {
tags.add(tagMapper.selectByName(string));
}
}
blog.setTags(tags.size() == 0 ? null : tags);
blog.setContent(StringEscapeUtils.escapeSql(blog.getContent()));
blogMapper.updateByPrimaryKeySelective(blog);
relationMapper.deletebyblogid(blog.getBlogid());
if (tags.size() > 0) {
for (Tag tag : tags) {
Relation relation = new Relation();
relation.setBlogid(blog.getBlogid());
relation.settId(tag.gettId());
relationMapper.insert(relation);
}
}
return blog.getBlogid();
}
use of com.myblog.model.Tag in project newblogback by Zephery.
the class CategoryController method index.
@GetMapping(value = "")
public ModelAndView index() {
List<Category> categories = categoryService.getAllCategory();
List<Tag> tags = tagService.getAllTags();
ModelAndView mv = new ModelAndView();
mv.addObject("categories", categories);
mv.addObject("tags", tags);
mv.setViewName("/admin/category");
return mv;
}
use of com.myblog.model.Tag in project newblogback by Zephery.
the class BlogServiceImpl method getBlogDetail.
@Override
public Blog getBlogDetail(Integer blogid) {
Blog blog = blogMapper.selectByPrimaryKey(blogid);
if (blog == null) {
return null;
}
Category category = categoryMapper.selectByPrimaryKey(blog.getCategoryid());
blog.setCategory(category);
List<Tag> tags = tagMapper.getTagByBlogId(blog.getBlogid());
List<String> list = new ArrayList<>();
for (Tag tag : tags) {
list.add(tag.gettName());
}
blog.setTagforsplit(StringUtils.join(list, ","));
blog.setTags(tags.size() > 0 ? tags : null);
if (blogMapper.updatehits(blogid)) {
logger.info("read count success");
} else {
logger.info("read count failure");
}
return blog;
}
use of com.myblog.model.Tag in project newblogback by Zephery.
the class BlogServiceImpl method insertblog.
@Override
public synchronized Integer insertblog(Blog blog) {
blog.setSummary(blog.getContent().length() > 120 ? blog.getContent().substring(0, 120) : blog.getContent());
blog.setCreateAt(DateTime.now().toString("yyyy-MM-dd"));
Matcher matcher = Pattern.compile(IMGSRC_REG).matcher(blog.getContent());
String image_url = null;
while (matcher.find()) {
image_url = matcher.group();
}
// http://image.wenzhihuai.com/images/20171018051437.png?imageInfo
// {"size":14736,"format":"png","width":667,"height":387,"colorModel":"rgba"}
blog.setImageurl(getImageURl(image_url));
String[] array = blog.getTagforsplit().split(",");
List<Tag> tags = new ArrayList<>();
for (String string : array) {
if (tagMapper.selectByName(string) == null) {
Tag tag = new Tag();
tag.settName(string);
tagMapper.insertSelective(tag);
Tag newtag = tagMapper.selectByName(string);
tags.add(newtag);
// tag.settId(tId);//TODO 返回主键长不起作用
// tags.add(tag);
} else {
tags.add(tagMapper.selectByName(string));
}
}
blog.setTags(tags.size() == 0 ? null : tags);
blog.setHits(0);
blog.setContent(StringEscapeUtils.escapeSql(blog.getContent()));
blogMapper.insert(blog);
Blog newblog = blogMapper.selectByTitle(blog.getTitle());
if (tags.size() > 0) {
for (Tag tag : tags) {
Relation relation = new Relation();
relation.setBlogid(newblog.getBlogid());
relation.settId(tag.gettId());
relationMapper.insert(relation);
}
}
return blogMapper.selectMaxId();
}
Aggregations