|
|
@@ -0,0 +1,126 @@
|
|
|
+package com.mooctest.crowd.domain.repository;
|
|
|
+
|
|
|
+import com.mooctest.crowd.domain.dao.*;
|
|
|
+import com.mooctest.crowd.domain.domainobject.*;
|
|
|
+import com.mooctest.crowd.domain.exception.ApplicationTypeNoExistException;
|
|
|
+import com.mooctest.crowd.domain.exception.FieldNoExistException;
|
|
|
+import com.mooctest.crowd.domain.exception.TestTypeNoExistException;
|
|
|
+import com.mooctest.crowd.domain.model.*;
|
|
|
+import com.mooctest.crowd.domain.util.Converter;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author guochao
|
|
|
+ * @date 2020-06-22 17:23
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class CommonRepo {
|
|
|
+ @Autowired
|
|
|
+ private TestTypeDao testTypeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationTypeDao applicationTypeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationTypeToTestTypeDao applicationTypeToTestTypeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FieldDao fieldDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ResourceDao resourceDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompetitionDao competitionDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ResidentAgencyDao residentAgencyDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PartnerDao partnerDao;
|
|
|
+
|
|
|
+ public List<TestType> getAllTestType(){
|
|
|
+ return testTypeDao.findAll().stream().map(testTypePO -> Converter.convert(TestType.class, testTypePO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ApplicationType> getAllApplicationType(){
|
|
|
+ return applicationTypeDao.findAll().stream().map(applicationTypePO -> Converter.convert(ApplicationType.class, applicationTypePO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Field> getAllFieldType(){
|
|
|
+ return fieldDao.findAll().stream().map(fieldPO -> Converter.convert(Field.class, fieldPO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Resource> getAllResource(){
|
|
|
+ return resourceDao.findAll().stream().map(resourcePO -> Converter.convert(Resource.class, resourcePO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Competition> getAllCompetitionTop3(Pageable pageable){
|
|
|
+ List<CompetitionPO> competitionPOS = competitionDao.findAll(pageable);
|
|
|
+ return competitionPOS.stream().map(competitionPO -> Converter.convert(Competition.class, competitionPO))
|
|
|
+ .filter(competition -> competition.getIsDeleted() == DeletedStatus.isNotDeleted).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Competition> getAllCompetition(){
|
|
|
+ return competitionDao.findAll().stream()
|
|
|
+ .map(competitionPO -> Converter.convert(Competition.class, competitionPO))
|
|
|
+ .filter(competition -> competition.getIsDeleted() == DeletedStatus.isNotDeleted).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Partner> getAllPartner(){
|
|
|
+ return partnerDao.findAll().stream().map(partnerPO -> Converter.convert(Partner.class, partnerPO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ResidentAgency> getAllResidentAgency(){
|
|
|
+ return residentAgencyDao.findAll().stream().map(residentAgencyPO -> Converter.convert(ResidentAgency.class, residentAgencyPO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplicationType getApplicationTypeByAppCode(String appCode){
|
|
|
+ Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByCode(appCode);
|
|
|
+ if(!applicationTypePO.isPresent()){
|
|
|
+ throw new ApplicationTypeNoExistException();
|
|
|
+ }else {
|
|
|
+ return Converter.convert(ApplicationType.class, applicationTypePO.get());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public TestType getTestTypeByAppCode(String typeCode){
|
|
|
+ Optional<TestTypePO> testTypePO = testTypeDao.findByCode(typeCode);
|
|
|
+ if(!testTypePO.isPresent()){
|
|
|
+ throw new TestTypeNoExistException();
|
|
|
+ }else {
|
|
|
+ return Converter.convert(TestType.class, testTypePO.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Field getFieldByAppCode(String code){
|
|
|
+ Optional<FieldPO> fieldPO = fieldDao.findByCode(code);
|
|
|
+ if(!fieldPO.isPresent()){
|
|
|
+ throw new FieldNoExistException();
|
|
|
+ }else {
|
|
|
+ return Converter.convert(Field.class, fieldPO.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ApplicationTypeToTestType> getAppToTypeByAppCode(String appCode){
|
|
|
+ List<ApplicationTypeToTestTypePO> appToTypeList = applicationTypeToTestTypeDao.findByApplicationTypeCode(appCode);
|
|
|
+ return appToTypeList.stream().map(applicationTypeToTestTypePO -> Converter.convert(ApplicationTypeToTestType.class, applicationTypeToTestTypePO)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<TestType> getTestTypeListByAppCode(String appTypeCode){
|
|
|
+ List<ApplicationTypeToTestType> appToTypeList = getAppToTypeByAppCode(appTypeCode);
|
|
|
+ List<TestType> testTypeList = appToTypeList.stream().map(applicationTypeToTestType -> {
|
|
|
+ TestType testTypeByAppCode = getTestTypeByAppCode(applicationTypeToTestType.getTestTypeCode());
|
|
|
+ return testTypeByAppCode;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return testTypeList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|