|
|
@@ -0,0 +1,67 @@
|
|
|
+package cn.iselab.mooctest.site.service.fromKibug.impl;
|
|
|
+
|
|
|
+import cn.iselab.mooctest.site.common.enums.AppPlatform;
|
|
|
+import cn.iselab.mooctest.site.dao.fromKibug.MobileClientDao;
|
|
|
+import cn.iselab.mooctest.site.models.fromKibug.MobileClient;
|
|
|
+import cn.iselab.mooctest.site.service.fromKibug.MobileClientService;
|
|
|
+import cn.iselab.mooctest.site.web.data.fromKibug.CreateMobileClientVO;
|
|
|
+import cn.iselab.mooctest.site.web.exception.IllegalOperationException;
|
|
|
+import cn.iselab.mooctest.site.web.util.Converter;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by NJUta on 2017/6/1.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MobileClientServiceImpl implements MobileClientService {
|
|
|
+ @Autowired
|
|
|
+ private MobileClientDao mobileClientDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MobileClient> getLastestMobileClients(AppPlatform platform) throws Exception {
|
|
|
+ List<MobileClient> mobileClients = new ArrayList<>();
|
|
|
+ MobileClient temp;
|
|
|
+ if (platform != null) {
|
|
|
+ temp = getLastestMobileClient(platform);
|
|
|
+ if (temp != null) mobileClients.add(temp);
|
|
|
+ } else {
|
|
|
+ temp = getLastestMobileClient(AppPlatform.ANDROID);
|
|
|
+ if (temp != null) mobileClients.add(temp);
|
|
|
+ temp = getLastestMobileClient(AppPlatform.IOS);
|
|
|
+ if (temp != null) mobileClients.add(temp);
|
|
|
+ }
|
|
|
+ return mobileClients;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int create(CreateMobileClientVO mobileClient) throws Exception {
|
|
|
+ List<MobileClient> lastestMobileList = getLastestMobileClients(mobileClient.getParsedPlatform());
|
|
|
+ MobileClient lastestMobile = null;
|
|
|
+ if (lastestMobileList != null && lastestMobileList.size() > 0) {
|
|
|
+ lastestMobile = lastestMobileList.get(0);
|
|
|
+ }
|
|
|
+ if (lastestMobile != null && mobileClient.getVersion() <= lastestMobile.getVersion()) {
|
|
|
+ throw new IllegalOperationException();
|
|
|
+ }
|
|
|
+ MobileClient client = Converter.convert(MobileClient.class, mobileClient);
|
|
|
+ client.setPlatform(mobileClient.getParsedPlatform().getPlatformId());
|
|
|
+ mobileClientDao.save(client);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private MobileClient getLastestMobileClient(AppPlatform platform) throws Exception {
|
|
|
+ Pageable pageable=new PageRequest(0,1);
|
|
|
+ List<MobileClient> mobileClients = mobileClientDao.getLastestMobileClient(platform.getPlatformId(),pageable).getContent();
|
|
|
+ if (mobileClients.size() > 0) {
|
|
|
+ return mobileClients.get(0);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|