Browse Source

诗词done

master
nili 3 years ago
parent
commit
4df91f6d22
  1. 6
      luigi-api/src/main/java/com/bzgame/server/luigi/api/rest/AuthorController.java
  2. 7
      luigi-api/src/main/java/com/bzgame/server/luigi/api/rest/PoemController.java
  3. 12
      luigi-dao/src/main/java/com/bzgame/server/luigi/dao/mapper/manual/ManualMapper.java
  4. 32
      luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java

6
luigi-api/src/main/java/com/bzgame/server/luigi/api/rest/AuthorController.java

@ -36,4 +36,10 @@ public class AuthorController {
}
return new Response<>(authorService.seek(name), "ok", Response.CODE_SUCCESS);
}
@GetMapping("/get")
@ApiFlag
public Response<Author> getAuthorById(@RequestParam Integer id) {
return new Response<>(authorService.getById(id), "ok", Response.CODE_SUCCESS);
}
}

7
luigi-api/src/main/java/com/bzgame/server/luigi/api/rest/PoemController.java

@ -29,7 +29,14 @@ public class PoemController {
}
@GetMapping("/detail")
@ApiFlag
public Response<PoemBo> poemDetail(@RequestParam Integer id) {
return new Response<>(poemService.detail(id), "ok", Response.CODE_SUCCESS);
}
@PostMapping("/save")
@ApiFlag
public Response<Integer> savePoem(@RequestBody PoemBo poemBo) {
return new Response<>(poemService.save(poemBo), "ok", 1);
}
}

12
luigi-dao/src/main/java/com/bzgame/server/luigi/dao/mapper/manual/ManualMapper.java

@ -0,0 +1,12 @@
package com.bzgame.server.luigi.dao.mapper.manual;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
public interface ManualMapper {
@Update("update author set poem_cnt = poem_cnt - 1 where id = #{id}")
void decrAuthorPoemCnt(@Param("id") Integer authorId);
@Update("update author set poem_cnt = poem_cnt + 1 where id = #{id}")
void incrAuthorPoemCnt(@Param("id") Integer authorId);
}

32
luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java

@ -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;
}

Loading…
Cancel
Save