Browse Source

已采集设备型号列表(已去重)

guozhaoshun 6 years ago
parent
commit
1a27c3e4a5

+ 3 - 5
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserDeviceController.java

@@ -3,16 +3,14 @@ package cn.rankin.cmsweb.controller.user;
 
 import cn.rankin.cmsweb.service.user.UserDeviceService;
 import cn.rankin.common.utils.api.model.APIResult;
-import cn.rankin.data.api.user.entity.DownloadInfo;
 import cn.rankin.data.api.user.entity.UserDevice;
-import com.alibaba.fastjson.JSON;
+import cn.rankin.data.api.user.vo.DeviceModelVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
-
 /**
  * The controller of user device
  */
@@ -33,8 +31,8 @@ public class UserDeviceController
     }
 
     @RequestMapping(value = "/model/list", method = RequestMethod.GET)
-    public APIResult<UserDevice> searchDeviceModel(@RequestParam("deviceModel") String deviceModel) {
-        APIResult<UserDevice> apiResult = userDeviceService.searchDeviceModel(deviceModel);
+    public APIResult<List<DeviceModelVo>> searchDeviceModel(@RequestParam("deviceModel") String deviceModel) {
+        APIResult<List<DeviceModelVo>> apiResult = userDeviceService.searchDeviceModel(deviceModel);
         return apiResult;
     }
 }

+ 2 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/UserDeviceService.java

@@ -2,6 +2,7 @@ package cn.rankin.cmsweb.service.user;
 
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.data.api.user.entity.UserDevice;
+import cn.rankin.data.api.user.vo.DeviceModelVo;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 
@@ -14,5 +15,5 @@ public interface UserDeviceService
     List<UserDevice> findByCondition(@PathVariable("uid") String uid);
 
     @RequestMapping(value = "/userDevice/model/list", method = RequestMethod.GET)
-    APIResult<UserDevice> searchDeviceModel(@RequestParam("deviceModel") String deviceModel);
+    APIResult<List<DeviceModelVo>> searchDeviceModel(@RequestParam("deviceModel") String deviceModel);
 }

+ 3 - 9
rankin-user-service/src/main/java/cn/rankin/userservice/controller/UserDeviceController.java

@@ -1,21 +1,15 @@
 package cn.rankin.userservice.controller;
 
 import cn.rankin.common.utils.api.model.APIResult;
-import cn.rankin.common.utils.api.page.Page;
-import cn.rankin.common.utils.enums.BaseOrderEnum;
-import cn.rankin.data.api.user.dto.CampusSearchDTO;
 import cn.rankin.data.api.user.dto.UserDeviceDTO;
-import cn.rankin.data.api.user.dto.UserDeviceSearchDTO;
-import cn.rankin.data.api.user.entity.Campus;
 import cn.rankin.data.api.user.entity.UserDevice;
+import cn.rankin.data.api.user.vo.DeviceModelVo;
 import cn.rankin.userservice.helper.RaStringHelper;
 import cn.rankin.userservice.service.UserDeviceService;
-import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-import java.util.LinkedHashMap;
 import java.util.List;
 
 
@@ -59,8 +53,8 @@ public class UserDeviceController
     }
 
     @RequestMapping(value = "/model/list", method = RequestMethod.GET)
-    public APIResult<UserDevice> searchDeviceModel(@RequestParam("deviceModel") String deviceModel) {
-        APIResult<UserDevice> apiResult = userDeviceService.searchDeviceModel(deviceModel);
+    public APIResult<List<DeviceModelVo>> searchDeviceModel(@RequestParam("deviceModel") String deviceModel) {
+        APIResult<List<DeviceModelVo>> apiResult = userDeviceService.searchDeviceModel(deviceModel);
         return apiResult;
     }
 

+ 1 - 1
rankin-user-service/src/main/java/cn/rankin/userservice/repository/UserDeviceRepository.java

@@ -35,5 +35,5 @@ public interface UserDeviceRepository extends BasicJpaRepository<UserDevice, Str
      * @return
      */
     @Query(value = "select distinct(u.deviceModel) from  UserDevice  u where u.deviceModel LIKE CONCAT('%',?1,'%') order by u.gmtModified desc")
-    List<UserDevice> queryDeviceModel(String deviceModel);
+    List<String> queryDeviceModel(String deviceModel);
 }

+ 11 - 5
rankin-user-service/src/main/java/cn/rankin/userservice/service/UserDeviceService.java

@@ -6,13 +6,12 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.util.JpaSortUtil;
 import cn.rankin.data.api.user.dto.UserDeviceDTO;
 import cn.rankin.data.api.user.entity.UserDevice;
+import cn.rankin.data.api.user.vo.DeviceModelVo;
 import cn.rankin.userservice.repository.UserDeviceRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class UserDeviceService
@@ -97,8 +96,15 @@ public class UserDeviceService
 
     }
 
-    public APIResult<UserDevice> searchDeviceModel(String deviceModel) {
-        List<UserDevice> deviceModels = userDeviceRepository.queryDeviceModel(deviceModel);
+    public APIResult<List<DeviceModelVo>> searchDeviceModel(String deviceModel) {
+        List<String> models = userDeviceRepository.queryDeviceModel(deviceModel);
+        List<DeviceModelVo> deviceModels = new ArrayList<>();
+        models.forEach(model -> {
+            DeviceModelVo vo = new DeviceModelVo();
+            vo.setDeviceModel(model);
+            deviceModels.add(vo);
+        });
+
         return APIResult.ok(deviceModels);
     }
 }