|
|
@ -6,10 +6,13 @@ import com.bzgame.server.luigi.dao.domain.Author; |
|
|
|
import com.bzgame.server.luigi.dao.domain.Poem; |
|
|
|
import com.bzgame.server.luigi.dao.domain.PoemExample; |
|
|
|
import com.bzgame.server.luigi.dao.mapper.PoemMapper; |
|
|
|
import com.bzgame.server.luigi.dao.mapper.manual.ManualMapper; |
|
|
|
import com.bzgame.server.luigi.service.bo.request.PoemQuery; |
|
|
|
import com.bzgame.server.luigi.service.bo.response.CommonList; |
|
|
|
import com.bzgame.server.luigi.service.bo.response.PoemBo; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
@ -28,6 +31,9 @@ public class PoemService { |
|
|
|
@Resource |
|
|
|
private AuthorService authorService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ManualMapper manualMapper; |
|
|
|
|
|
|
|
public CommonList<PoemBo> query(PoemQuery query) { |
|
|
|
PoemExample example = new PoemExample(); |
|
|
|
PoemExample.Criteria criteria = example.createCriteria(); |
|
|
@ -50,6 +56,30 @@ public class PoemService { |
|
|
|
return bo; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
public Integer save(PoemBo poemBo) { |
|
|
|
Poem p = new Poem(); |
|
|
|
if (poemBo.getId() == null) { |
|
|
|
manualMapper.incrAuthorPoemCnt(poemBo.getAuthorId()); |
|
|
|
BeanUtils.copyProperties(poemBo, p); |
|
|
|
poemMapper.insertSelective(p); |
|
|
|
} else { |
|
|
|
if (poemBo.getAuthorId() != null) { |
|
|
|
Integer prevAuthorId = poemMapper.selectByPrimaryKey(poemBo.getId()).getAuthorId(); |
|
|
|
if (poemBo.getStatus() < 0) { |
|
|
|
manualMapper.decrAuthorPoemCnt(prevAuthorId); |
|
|
|
} else if (!poemBo.getAuthorId().equals(prevAuthorId)) { |
|
|
|
manualMapper.decrAuthorPoemCnt(prevAuthorId); |
|
|
|
manualMapper.incrAuthorPoemCnt(poemBo.getAuthorId()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
BeanUtils.copyProperties(poemBo, p); |
|
|
|
poemMapper.updateByPrimaryKeySelective(p); |
|
|
|
} |
|
|
|
return p.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
private List<PoemBo> convert(List<Poem> poems) { |
|
|
|
List<Integer> authorIds = poems.stream().map(Poem::getAuthorId).collect(Collectors.toList()); |
|
|
|
if (CollectionUtils.isEmpty(authorIds)) { |
|
|
@ -64,6 +94,8 @@ public class PoemService { |
|
|
|
} |
|
|
|
|
|
|
|
private void setQuery(PoemQuery query, PoemExample.Criteria criteria) { |
|
|
|
criteria.andStatusGreaterThanOrEqualTo(0); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(query.getQuery())) { |
|
|
|
return; |
|
|
|
} |
|
|
|