ソースを参照

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

guozhaoshun 6 年 前
コミット
c291aa219b

+ 6 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserDeviceController.java

@@ -31,5 +31,11 @@ public class UserDeviceController
 
         return APIResult.ok(list);
     }
+
+    @RequestMapping(value = "/model/list", method = RequestMethod.GET)
+    public APIResult<UserDevice> searchDeviceModel(@RequestParam("deviceModel") String deviceModel) {
+        APIResult<UserDevice> apiResult = userDeviceService.searchDeviceModel(deviceModel);
+        return apiResult;
+    }
 }
 

+ 3 - 4
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/UserDeviceService.java

@@ -1,19 +1,18 @@
 package cn.rankin.cmsweb.service.user;
 
 import cn.rankin.common.utils.api.model.APIResult;
-import cn.rankin.common.utils.api.page.Page;
-import cn.rankin.data.api.user.dto.CampusDTO;
 import cn.rankin.data.api.user.entity.UserDevice;
-import cn.rankin.data.api.user.vo.CampusVo;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
-import java.util.Map;
 
 @FeignClient(name = "${service.user.name}")
 public interface UserDeviceService
 {
     @RequestMapping(value = "/userDevice/list/{uid}", method = RequestMethod.GET)
     List<UserDevice> findByCondition(@PathVariable("uid") String uid);
+
+    @RequestMapping(value = "/userDevice/model/list", method = RequestMethod.GET)
+    APIResult<UserDevice> searchDeviceModel(@RequestParam("deviceModel") String deviceModel);
 }

+ 27 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/dto/UserDeviceSearchDTO.java

@@ -0,0 +1,27 @@
+package cn.rankin.data.api.user.dto;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+@Data
+@ToString
+public class UserDeviceSearchDTO  implements Serializable
+{
+    private String userId;
+
+    private String deviceCode;
+
+    private String deviceModel;
+
+    private String deviceMfrs;
+
+    private String deviceName;
+
+    private String deviceType;
+
+    private Integer pageNo = 1;
+
+    private Integer pageSize = 10;
+
+}

+ 14 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/controller/UserDeviceController.java

@@ -1,13 +1,21 @@
 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.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;
 
 
@@ -50,4 +58,10 @@ public class UserDeviceController
         return userDeviceService.findByUserId(uid);
     }
 
+    @RequestMapping(value = "/model/list", method = RequestMethod.GET)
+    public APIResult<UserDevice> searchDeviceModel(@RequestParam("deviceModel") String deviceModel) {
+        APIResult<UserDevice> apiResult = userDeviceService.searchDeviceModel(deviceModel);
+        return apiResult;
+    }
+
 }

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

@@ -29,4 +29,11 @@ public interface UserDeviceRepository extends BasicJpaRepository<UserDevice, Str
      */
     @Query(value = "select u from  UserDevice  u where u.userId = ?1 order by u.gmtModified desc")
     List<UserDevice> findByUserId(String userId);
+
+    /**
+     * 查询所有已采集到的设备类型(去除重复)
+     * @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);
 }

+ 24 - 3
rankin-user-service/src/main/java/cn/rankin/userservice/service/UserDeviceService.java

@@ -1,14 +1,17 @@
 package cn.rankin.userservice.service;
 
+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.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.UserDeviceVo;
-import cn.rankin.userservice.helper.RaStringHelper;
 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;
 
 @Service
@@ -20,7 +23,6 @@ public class UserDeviceService
     /**
      * Find
      *
-     * @param userDeviceVo
      * @return
      */
     public int opUserDevice(UserDeviceDTO uerDeviceDTO)
@@ -80,4 +82,23 @@ public class UserDeviceService
         return list;
     }
 
+    public APIResult<Page<UserDevice>> search(UserDevice simple, Integer pageNo, Integer pageSize, LinkedHashMap<String,BaseOrderEnum> sort) {
+        Long count = userDeviceRepository.count(simple);
+        Page<UserDevice> page = new Page<>(count, pageNo, pageSize);
+        if (count == 0) {
+            return APIResult.ok(page);
+        }
+
+
+        List<UserDevice> result = userDeviceRepository.find(simple, page.getStart(), page.getPageSize(), JpaSortUtil.sort(sort));
+        page.setList(result);
+
+        return APIResult.ok(page);
+
+    }
+
+    public APIResult<UserDevice> searchDeviceModel(String deviceModel) {
+        List<UserDevice> deviceModels = userDeviceRepository.queryDeviceModel(deviceModel);
+        return APIResult.ok(deviceModels);
+    }
 }