|
@ -1,10 +1,18 @@ |
|
|
package com.bzgame.server.luigi.service.bo; |
|
|
package com.bzgame.server.luigi.service.bo; |
|
|
|
|
|
|
|
|
|
|
|
import com.bczgame.server.common.exception.BizException; |
|
|
|
|
|
import com.bczgame.server.common.exception.ExceptionCode; |
|
|
import com.bzgame.server.luigi.dao.domain.Author; |
|
|
import com.bzgame.server.luigi.dao.domain.Author; |
|
|
import com.bzgame.server.luigi.dao.domain.AuthorExample; |
|
|
import com.bzgame.server.luigi.dao.domain.AuthorExample; |
|
|
|
|
|
import com.bzgame.server.luigi.dao.domain.Poem; |
|
|
|
|
|
import com.bzgame.server.luigi.dao.domain.PoemExample; |
|
|
import com.bzgame.server.luigi.dao.mapper.AuthorMapper; |
|
|
import com.bzgame.server.luigi.dao.mapper.AuthorMapper; |
|
|
|
|
|
import com.bzgame.server.luigi.dao.mapper.manual.ManualMapper; |
|
|
|
|
|
import com.bzgame.server.luigi.service.bo.request.PaginationQuery; |
|
|
import com.bzgame.server.luigi.service.bo.response.CommonList; |
|
|
import com.bzgame.server.luigi.service.bo.response.CommonList; |
|
|
|
|
|
import com.bzgame.server.luigi.service.bo.response.PoemBo; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
@ -19,6 +27,34 @@ public class AuthorService { |
|
|
@Resource |
|
|
@Resource |
|
|
private AuthorMapper authorMapper; |
|
|
private AuthorMapper authorMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private ManualMapper manualMapper; |
|
|
|
|
|
|
|
|
|
|
|
public CommonList<Author> query(PaginationQuery query) { |
|
|
|
|
|
AuthorExample example = new AuthorExample(); |
|
|
|
|
|
AuthorExample.Criteria criteria = example.createCriteria(); |
|
|
|
|
|
setQuery(query, criteria); |
|
|
|
|
|
example.setOffset((query.getCurrent() - 1) * query.getPageSize()); |
|
|
|
|
|
example.setLimit(query.getPageSize()); |
|
|
|
|
|
List<Author> authors = authorMapper.selectByExampleWithBLOBs(example); |
|
|
|
|
|
long total = authorMapper.countByExample(example); |
|
|
|
|
|
CommonList<Author> res = new CommonList<>(); |
|
|
|
|
|
res.setTotal((int) total); |
|
|
|
|
|
res.setList(authors); |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Integer save(Author a) { |
|
|
|
|
|
if (a.getId() != null) { |
|
|
|
|
|
int poemCnt = manualMapper.getPoemCntByAuthor(a.getId()); |
|
|
|
|
|
a.setPoemCnt(poemCnt); |
|
|
|
|
|
authorMapper.updateByPrimaryKeySelective(a); |
|
|
|
|
|
} else { |
|
|
|
|
|
authorMapper.insertSelective(a); |
|
|
|
|
|
} |
|
|
|
|
|
return a.getId(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public Map<Integer, Author> getByIds(List<Integer> ids) { |
|
|
public Map<Integer, Author> getByIds(List<Integer> ids) { |
|
|
AuthorExample example = new AuthorExample(); |
|
|
AuthorExample example = new AuthorExample(); |
|
|
example.createCriteria().andIdIn(ids); |
|
|
example.createCriteria().andIdIn(ids); |
|
@ -39,4 +75,27 @@ public class AuthorService { |
|
|
res.setList(authors); |
|
|
res.setList(authors); |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setQuery(PaginationQuery query, AuthorExample.Criteria criteria) { |
|
|
|
|
|
criteria.andStatusGreaterThanOrEqualTo(0); |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(query.getQuery())) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
query.getQuery().forEach(x -> { |
|
|
|
|
|
switch (x.getKey()) { |
|
|
|
|
|
case "status": |
|
|
|
|
|
criteria.andStatusEqualTo(Integer.valueOf(x.getVal())); |
|
|
|
|
|
break; |
|
|
|
|
|
case "id": |
|
|
|
|
|
criteria.andIdEqualTo(Integer.valueOf(x.getVal())); |
|
|
|
|
|
break; |
|
|
|
|
|
case "name": |
|
|
|
|
|
criteria.andNameLike(x.getVal() + "%"); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BizException(ExceptionCode.PARAM_ILLEGAL_WARN, "参数非法"); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|