|
| 1 | +package org.spring.springboot.service.impl; |
| 2 | + |
| 3 | +import org.slf4j.Logger; |
| 4 | +import org.slf4j.LoggerFactory; |
| 5 | +import org.spring.springboot.domain.City; |
| 6 | +import org.spring.springboot.repository.CityRepository; |
| 7 | +import org.spring.springboot.service.CityService; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.data.domain.Page; |
| 10 | +import org.springframework.data.domain.PageRequest; |
| 11 | +import org.springframework.data.domain.Pageable; |
| 12 | +import org.springframework.stereotype.Service; |
| 13 | + |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +/** |
| 17 | + * 城市 ES 业务逻辑实现类 |
| 18 | + * <p> |
| 19 | + * Created by bysocket on 07/02/2017. |
| 20 | + */ |
| 21 | +@Service |
| 22 | +public class CityESServiceImpl implements CityService { |
| 23 | + |
| 24 | + private static final Logger LOGGER = LoggerFactory.getLogger(CityESServiceImpl.class); |
| 25 | + |
| 26 | + // 分页参数 -> TODO 代码可迁移到具体项目的公共 common 模块 |
| 27 | + private static final Integer pageNumber = 0; |
| 28 | + private static final Integer pageSize = 10; |
| 29 | + Pageable pageable = new PageRequest(pageNumber, pageSize); |
| 30 | + |
| 31 | + // ES 操作类 |
| 32 | + @Autowired |
| 33 | + CityRepository cityRepository; |
| 34 | + |
| 35 | + public Long saveCity(City city) { |
| 36 | + City cityResult = cityRepository.save(city); |
| 37 | + return cityResult.getId(); |
| 38 | + } |
| 39 | + |
| 40 | + public List<City> findByDescriptionAndScore(String description, Integer score) { |
| 41 | + return cityRepository.findByDescriptionAndScore(description, score); |
| 42 | + } |
| 43 | + |
| 44 | + public List<City> findByDescriptionOrScore(String description, Integer score) { |
| 45 | + return cityRepository.findByDescriptionOrScore(description, score); |
| 46 | + } |
| 47 | + |
| 48 | + public List<City> findByDescription(String description) { |
| 49 | + return cityRepository.findByDescription(description, pageable).getContent(); |
| 50 | + } |
| 51 | + |
| 52 | + public List<City> findByDescriptionNot(String description) { |
| 53 | + return cityRepository.findByDescriptionNot(description, pageable).getContent(); |
| 54 | + } |
| 55 | + |
| 56 | + public List<City> findByDescriptionLike(String description) { |
| 57 | + return cityRepository.findByDescriptionLike(description, pageable).getContent(); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments