use of com.myblog.model.Relation 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.Relation 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();
}