Commit 3ee4a80277fee0f6fcc59621edc5178ff0d22455
1 parent
3753e07b
添加按批量线路查询方法
Showing
4 changed files
with
35 additions
and
1 deletions
src/main/java/com/bsth/controller/LineInformationController.java
| 1 | package com.bsth.controller; | 1 | package com.bsth.controller; |
| 2 | 2 | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 3 | import org.springframework.web.bind.annotation.RequestMapping; | 6 | import org.springframework.web.bind.annotation.RequestMapping; |
| 7 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 4 | import org.springframework.web.bind.annotation.RestController; | 8 | import org.springframework.web.bind.annotation.RestController; |
| 5 | 9 | ||
| 6 | import com.bsth.entity.LineInformation; | 10 | import com.bsth.entity.LineInformation; |
| 11 | +import com.bsth.service.LineInformationService; | ||
| 7 | 12 | ||
| 8 | /** | 13 | /** |
| 9 | * | 14 | * |
| @@ -25,4 +30,11 @@ import com.bsth.entity.LineInformation; | @@ -25,4 +30,11 @@ import com.bsth.entity.LineInformation; | ||
| 25 | @RequestMapping("lineInformation") | 30 | @RequestMapping("lineInformation") |
| 26 | public class LineInformationController extends BaseController<LineInformation, Integer> { | 31 | public class LineInformationController extends BaseController<LineInformation, Integer> { |
| 27 | 32 | ||
| 33 | + @Autowired | ||
| 34 | + LineInformationService lineInformationService; | ||
| 35 | + | ||
| 36 | + @RequestMapping("/line/multi") | ||
| 37 | + public List<LineInformation> findByLine(@RequestParam String lineCodes){ | ||
| 38 | + return lineInformationService.findByLine(lineCodes); | ||
| 39 | + } | ||
| 28 | } | 40 | } |
src/main/java/com/bsth/repository/LineInformationRepository.java
| 1 | package com.bsth.repository; | 1 | package com.bsth.repository; |
| 2 | 2 | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.springframework.data.jpa.repository.Query; | ||
| 3 | import org.springframework.stereotype.Repository; | 6 | import org.springframework.stereotype.Repository; |
| 4 | 7 | ||
| 5 | import com.bsth.entity.LineInformation; | 8 | import com.bsth.entity.LineInformation; |
| 6 | -import com.bsth.entity.Section; | ||
| 7 | 9 | ||
| 8 | /** | 10 | /** |
| 9 | * | 11 | * |
| @@ -24,4 +26,6 @@ import com.bsth.entity.Section; | @@ -24,4 +26,6 @@ import com.bsth.entity.Section; | ||
| 24 | @Repository | 26 | @Repository |
| 25 | public interface LineInformationRepository extends BaseRepository<LineInformation, Integer> { | 27 | public interface LineInformationRepository extends BaseRepository<LineInformation, Integer> { |
| 26 | 28 | ||
| 29 | + @Query("select i from LineInformation i where i.line.lineCode in ?1") | ||
| 30 | + List<LineInformation> findByLine(List<String> lineCodes); | ||
| 27 | } | 31 | } |
src/main/java/com/bsth/service/LineInformationService.java
| 1 | package com.bsth.service; | 1 | package com.bsth.service; |
| 2 | 2 | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 3 | import com.bsth.entity.LineInformation; | 5 | import com.bsth.entity.LineInformation; |
| 4 | 6 | ||
| 5 | 7 | ||
| @@ -20,4 +22,5 @@ import com.bsth.entity.LineInformation; | @@ -20,4 +22,5 @@ import com.bsth.entity.LineInformation; | ||
| 20 | */ | 22 | */ |
| 21 | public interface LineInformationService extends BaseService<LineInformation, Integer> { | 23 | public interface LineInformationService extends BaseService<LineInformation, Integer> { |
| 22 | 24 | ||
| 25 | + List<LineInformation> findByLine(String lineCodes); | ||
| 23 | } | 26 | } |
src/main/java/com/bsth/service/impl/LineInformationServiceImpl.java
| 1 | package com.bsth.service.impl; | 1 | package com.bsth.service.impl; |
| 2 | 2 | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 3 | import org.springframework.stereotype.Service; | 6 | import org.springframework.stereotype.Service; |
| 4 | 7 | ||
| 5 | import com.bsth.entity.LineInformation; | 8 | import com.bsth.entity.LineInformation; |
| 9 | +import com.bsth.repository.LineInformationRepository; | ||
| 6 | import com.bsth.service.LineInformationService; | 10 | import com.bsth.service.LineInformationService; |
| 11 | +import com.google.common.base.Splitter; | ||
| 7 | 12 | ||
| 8 | /** | 13 | /** |
| 9 | * | 14 | * |
| @@ -24,4 +29,14 @@ import com.bsth.service.LineInformationService; | @@ -24,4 +29,14 @@ import com.bsth.service.LineInformationService; | ||
| 24 | @Service | 29 | @Service |
| 25 | public class LineInformationServiceImpl extends BaseServiceImpl<LineInformation, Integer> implements LineInformationService{ | 30 | public class LineInformationServiceImpl extends BaseServiceImpl<LineInformation, Integer> implements LineInformationService{ |
| 26 | 31 | ||
| 32 | + @Autowired | ||
| 33 | + LineInformationRepository lineInformationRepository; | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<LineInformation> findByLine(String lineCodes) { | ||
| 37 | + List<String> list = Splitter.on(",").omitEmptyStrings().splitToList(lineCodes); | ||
| 38 | + if(list.size() == 0) | ||
| 39 | + return null; | ||
| 40 | + return lineInformationRepository.findByLine(list); | ||
| 41 | + } | ||
| 27 | } | 42 | } |