|
@@ -0,0 +1,88 @@
|
|
|
+package cn.com.qmth.examcloud.service.core.service;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.service.core.dao.LearnCenterRepo;
|
|
|
+import cn.com.qmth.examcloud.service.core.entity.LearnCenter;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.data.domain.ExampleMatcher;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by songyue on 17/1/14.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class LearnCenterService {
|
|
|
+ @Autowired
|
|
|
+ LearnCenterRepo learnCenterRepo;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有学习中心(分页)
|
|
|
+ * @param learnCenterCriteria
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity getAllLearnCenter(LearnCenter learnCenterCriteria, Pageable pageable){
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
+ .withMatcher("code",startsWith())
|
|
|
+ .withMatcher("name",startsWith());
|
|
|
+ Example<LearnCenter> learnCenterExample = Example.of(learnCenterCriteria, exampleMatcher);
|
|
|
+ return new ResponseEntity(learnCenterRepo.findAll(learnCenterExample,pageable), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有学习中心
|
|
|
+ * @param learnCenterCriteria
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity getAllLearnCenter(LearnCenter learnCenterCriteria){
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
+ .withMatcher("code",startsWith())
|
|
|
+ .withMatcher("name",startsWith());
|
|
|
+ Example<LearnCenter> learnCenterExample = Example.of(learnCenterCriteria, exampleMatcher);
|
|
|
+ return new ResponseEntity(learnCenterRepo.findAll(learnCenterExample), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按ID获取学习中心
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity<LearnCenter> getLearnCenterById(Long id){
|
|
|
+ return new ResponseEntity<LearnCenter>(learnCenterRepo.findOne(id),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存学习中心
|
|
|
+ * @param learnCenter
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity saveLearnCenter(LearnCenter learnCenter){
|
|
|
+ return new ResponseEntity(learnCenterRepo.save(learnCenter),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除学习中心
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity deleteLearnCenter(Long id){
|
|
|
+ learnCenterRepo.delete(id);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除所有学习中心
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity deleteAllLearnCenter(){
|
|
|
+ learnCenterRepo.deleteAll();
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|