Просмотр исходного кода

一键呼叫功能-查询设备列表

wwh 1 месяц назад
Родитель
Сommit
065845df28

BIN
app-admin/libs/artemis-http-client-1.1.15.RELEASE.jar


+ 2 - 0
app-admin/pom.xml

@@ -33,6 +33,8 @@
             <groupId>com.hikvision.ga</groupId>
             <artifactId>artemis-http-client</artifactId>
             <version>1.1.15.RELEASE</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/libs/artemis-http-client-1.1.15.RELEASE.jar</systemPath>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>

+ 19 - 3
app-admin/src/main/java/com/ruoyi/web/controller/chenyanlogin/controller/GetHuiCunController.java

@@ -3,13 +3,13 @@ package com.ruoyi.web.controller.chenyanlogin.controller;
 import com.ruoyi.common.core.domain.AjaxResult;
 
 import com.ruoyi.web.controller.chenyanlogin.service.HuiCunService;
+import com.ruoyi.web.controller.chenyanlogin.service.impl.ZhwlCaller;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.*;
 
 @Api(tags ="慧村接口 同步")
 @RestController
@@ -47,6 +47,22 @@ public class GetHuiCunController {
         return huiCunService.getZhwlDeviceData();
     }
 
+    @ApiOperation("一键呼叫数据查询接口(新)")
+    @GetMapping("/getZhwlDeviceData/list")
+    public  AjaxResult getZhwlDeviceData2(@RequestParam String deviceModelName,
+                                          @RequestParam Integer state,
+                                          @RequestParam Integer fullFlag,
+                                          @RequestParam Integer pageNum,
+                                          @RequestParam Integer pageSize) {
+        ZhwlCaller.DeviceListQueryVO request = new ZhwlCaller.DeviceListQueryVO();
+        request.setDeviceModelName(deviceModelName);
+        request.setState(state);
+        request.setFullFlag(ObjectUtils.isEmpty(fullFlag) ? 0 : fullFlag);
+        request.setPageNum(ObjectUtils.isEmpty(pageNum) ? 1 : pageNum);
+        request.setPageSize(ObjectUtils.isEmpty(pageSize) ? 1 : pageSize);
+        return huiCunService.getZhwlDeviceData(request);
+    }
+
     //积分排行数据查询接口
     @ApiOperation("积分排行数据查询接口")
     @GetMapping("/getPointRankData")

+ 2 - 0
app-admin/src/main/java/com/ruoyi/web/controller/chenyanlogin/service/HuiCunService.java

@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.chenyanlogin.service;
 
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.web.controller.chenyanlogin.service.impl.ZhwlCaller;
 
 public interface HuiCunService {
     AjaxResult getBasicData();
@@ -12,6 +13,7 @@ public interface HuiCunService {
 
 
     AjaxResult getZhwlDeviceData();
+    AjaxResult getZhwlDeviceData(ZhwlCaller.DeviceListQueryVO queryVO);
 
     AjaxResult getPointRankData();
 

+ 31 - 34
app-admin/src/main/java/com/ruoyi/web/controller/chenyanlogin/service/impl/HuiCunServiceImpl.java

@@ -7,13 +7,7 @@ import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.core.domain.entity.SysUser;
-import com.ruoyi.framework.web.service.SysLoginService;
-import com.ruoyi.system.domain.SysUserRole;
-import com.ruoyi.system.mapper.SysUserRoleMapper;
-import com.ruoyi.system.service.ISysUserService;
 import com.ruoyi.web.controller.chenyanlogin.ChengYanAesUtil;
 import com.ruoyi.web.controller.chenyanlogin.dto.*;
 import com.ruoyi.web.controller.chenyanlogin.dto.HouseVillagerRelation;
@@ -37,9 +31,11 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
+import javax.annotation.Resource;
 import javax.sound.midi.Soundbank;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDateTime;
 import java.util.*;
 
 import static com.ruoyi.common.core.domain.AjaxResult.error;
@@ -75,6 +71,9 @@ public class HuiCunServiceImpl implements HuiCunService {
     @Autowired
     private RestTemplate restTemplate;
 
+    @Resource
+    private ZhwlCaller zhwlCaller;
+
     //基础数据查询接口
     @Override
     public AjaxResult getBasicData() {
@@ -142,6 +141,29 @@ public class HuiCunServiceImpl implements HuiCunService {
         }
 
     }
+
+    @Override
+    public AjaxResult getZhwlDeviceData(ZhwlCaller.DeviceListQueryVO queryVO) {
+        ZhwlCaller.DeviceRespDTO response = zhwlCaller.getDeviceList(queryVO);
+        //todo test start
+//        List<ZhwlCaller.DeviceRespDTO.DeviceItemDTO> list = new ArrayList<>();
+//        ZhwlCaller.DeviceRespDTO.DeviceItemDTO item1 = new ZhwlCaller.DeviceRespDTO.DeviceItemDTO();
+//        item1.setDeviceId(10001L);
+//        item1.setDeviceModelName("test-10001");
+//        item1.setCreateTime(LocalDateTime.now().toString());
+//        item1.setUpdateTime(LocalDateTime.now().toString());
+//        list.add(item1);
+//        ZhwlCaller.DeviceRespDTO.DeviceItemDTO item2 = new ZhwlCaller.DeviceRespDTO.DeviceItemDTO();
+//        item2.setDeviceId(10002L);
+//        item2.setDeviceModelName("test-10002");
+//        item2.setCreateTime(LocalDateTime.now().toString());
+//        item2.setUpdateTime(LocalDateTime.now().toString());
+//        list.add(item2);
+//        response.setData(list);
+        //todo test end
+        return success(response);
+    }
+
     //积分排行数据查询接口
     @Override
     public AjaxResult getPointRankData() {
@@ -217,20 +239,13 @@ public class HuiCunServiceImpl implements HuiCunService {
         }
     }
 
-
-
     @Autowired
     private PersonInfoMapper personInfoMapper;
     @Autowired
     private TagsMapper tagsMapper;
     @Autowired
     private TagsPersonMapper tagsPersonMapper;
-    @Autowired
-    private ISysUserService sysUserService;
-    @Autowired
-    private SysUserRoleMapper sysUserRoleMapper;
-    @Autowired
-    private SysLoginService loginService;
+
     @Transactional
     public void saveVillager(SyncVillagerDataDto villageNewsDataDto) {
 
@@ -244,7 +259,6 @@ public class HuiCunServiceImpl implements HuiCunService {
         List<VillagerList> villagerList = villageNewsDataDto.getVillagerList();
         for (VillagerList list : villagerList) {
             PersonInfo personInfo = personInfoMapper.selectById(list.getId());
-            saveUser(personInfo.getPhone());
             if (ObjectUtil.isEmpty(personInfo)){
                 personInfo =  copyVillagerToPerson(personInfo,list);
                 personInfo.setId(list.getId());
@@ -255,27 +269,10 @@ public class HuiCunServiceImpl implements HuiCunService {
                 personInfoMapper.updateById(personInfo);
             }
         }
-    }
 
-    private void  saveUser(String phone){
-        SysUser phonenumber = sysUserService.selectUserByPhone(phone);
-        if (ObjectUtil.isEmpty(phonenumber)){
-            phonenumber  = new SysUser();
-            phonenumber.setUserName(phone);
-            phonenumber.setPhonenumber(phone);
-            phonenumber.setNickName("测试");
-            phonenumber.setSex("0");
-            phonenumber.setPassword("$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2");
-            sysUserService.registerUser(phonenumber);
-            SysUserRole sysUserRole = new SysUserRole();
-            sysUserRole.setRoleId(4L);
-            SysUser sysUser = sysUserService.selectUserByPhone(phone);
-            sysUserRole.setUserId(sysUser.getUserId());
-            List list = new ArrayList();
-            list.add(sysUserRole);
-            sysUserRoleMapper.batchUserRole(list);
-        }
+
     }
+
     private void saveVillagerTag(List<VillagerTagList> villagerTagList) {
         if (ObjectUtil.isNotEmpty(villagerTagList)){
             for (VillagerTagList list : villagerTagList) {

+ 233 - 0
app-admin/src/main/java/com/ruoyi/web/controller/chenyanlogin/service/impl/ZhwlCaller.java

@@ -0,0 +1,233 @@
+package com.ruoyi.web.controller.chenyanlogin.service.impl;
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.*;
+import org.springframework.stereotype.Component;
+import org.springframework.util.DigestUtils;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ZhwlCaller {
+
+    private static final Logger log = LoggerFactory.getLogger(ZhwlCaller.class);
+
+//    @Value("${cloud.platform.appKey}")
+    private String appKey = "Kg2pE5V0";
+
+//    @Value("${cloud.platform.appSecret}")
+    private String appSecret = "7a3bbfd6656e1bdef7290b714c1d1c73578a4ce2";
+
+//    @Value("${cloud.platform.baseUrl}")
+    private String baseUrl = "https://webapi.nbiotyun.com"; // e.g., http://domain/api/v1
+
+    private final RestTemplate restTemplate = new RestTemplate();
+
+    // 接口路径常量(便于管理)
+    private static final String GET_DEVICE_LIST_PATH = "/api/v1/dev/getList";
+
+    /**
+     * 公共方法:构建带认证信息的请求头
+     *
+     * @param path      原始请求路径(如:/dev/getList),用于签名
+     * @param timestamp 时间戳(毫秒)
+     * @return HttpHeaders
+     */
+    private HttpHeaders buildCommonHeaders(String path, long timestamp) {
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        headers.set("appKey", appKey);
+        headers.set("timestamp", String.valueOf(timestamp));
+
+        // 签名:MD5(path + timestamp + appSecret)
+        String signatureSource = path + timestamp + appSecret;
+        String signature = DigestUtils.md5DigestAsHex(signatureSource.getBytes(StandardCharsets.UTF_8));
+        headers.set("signature", signature);
+        log.debug("signatureSource:{}", signatureSource);
+        log.debug("headers:{}", JSON.toJSONString(headers));
+        return headers;
+    }
+
+    /**
+     * 通用 POST 请求模板方法(可扩展)
+     */
+    private ResponseEntity<String> postForString(String endpointPath, Object requestBody) {
+        String url = baseUrl + endpointPath;
+        long timestamp = System.currentTimeMillis();
+
+        try {
+            // 序列化请求体
+            String jsonBody = JSON.toJSONString(requestBody);
+
+            // 构建请求头
+            HttpHeaders headers = buildCommonHeaders(endpointPath, timestamp);
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            // 明确接受 JSON,但即使返回 text/html 也能拿到字符串
+            headers.setAccept(Collections.singletonList(MediaType.ALL)); // 接受任意类型
+
+            // 构建请求实体
+            HttpEntity<String> entity = new HttpEntity<>(jsonBody, headers);
+
+            // 使用 String.class 接收响应体,不管 Content-Type 是什么
+            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
+            log.debug(response.toString());
+            return response;
+//            return new ResponseEntity<>(null);
+        } catch (Exception e) {
+            throw new RuntimeException("调用接口失败: " + url, e);
+        }
+    }
+    private ResponseEntity<Map<String, Object>> postForMap(String endpointPath, Object requestBody) {
+        String url = baseUrl + endpointPath;
+        long timestamp = System.currentTimeMillis();
+
+        try {
+            String jsonBody = JSON.toJSONString(requestBody);
+            HttpHeaders headers = buildCommonHeaders(endpointPath, timestamp);
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+
+            HttpEntity<String> entity = new HttpEntity<>(jsonBody, headers);
+
+            ParameterizedTypeReference<Map<String, Object>> typeRef =
+                    new ParameterizedTypeReference<Map<String, Object>>() {};
+
+            ResponseEntity<Map<String, Object>> response = restTemplate.exchange(url, HttpMethod.POST, entity, typeRef);
+
+            return response;
+
+        } catch (Exception e) {
+            throw new RuntimeException("调用接口失败: " + url, e);
+        }
+    }
+    // ==================== 接口调用方法区 ====================
+
+    /**
+     * 查询设备列表
+     */
+    public DeviceRespDTO getDeviceList(DeviceListQueryVO queryVO) {
+        ResponseEntity<String> response = postForString(GET_DEVICE_LIST_PATH, queryVO);
+        //1. 检查 HTTP 状态码
+        if (!response.getStatusCode().is2xxSuccessful()) {
+            log.info("HTTP {} - 请求失败,响应内容: {}",response.getStatusCode() ,response.getBody());
+            return new DeviceRespDTO();
+        }
+
+        String body = response.getBody();
+        if (body == null || body.trim().isEmpty()) {
+            log.info("云平台返回空响应体");
+            return new DeviceRespDTO();
+        }
+
+        //2. 打印原始响应(调试用,上线可关闭)
+         log.debug("原始响应: {}", body);
+
+        try {
+            //3. 先解析外层 JSON
+            Map<String, Object> map = JSON.parseObject(body, Map.class);
+
+            //4. 提取 code、success
+            String code = (String) map.get("code");
+            Boolean success = (Boolean) map.get("success");
+
+            Object messageObj = map.get("message");
+            if (!(messageObj instanceof Map)) {
+                throw new RuntimeException("响应中的 message 字段不是对象类型: " + messageObj);
+            }
+
+            Map<String, Object> messageMap = (Map<String, Object>) messageObj;
+
+            //5. 构建返回 DTO
+            DeviceRespDTO respDTO = new DeviceRespDTO();
+            respDTO.setPageSize((Integer) messageMap.get("pageSize"));
+            respDTO.setPageCount((Integer) messageMap.get("pageCount"));
+            respDTO.setCurrentPage((Integer) messageMap.get("currentPage"));
+            respDTO.setTotal((Integer) messageMap.get("total"));
+
+            //6. 解析 data 列表(关键:用 Fastjson 转成 List<DeviceItemDTO>)
+            Object dataList = messageMap.get("data");
+            if (dataList instanceof List) {
+                respDTO.setData(JSON.parseArray(JSON.toJSONString(dataList), DeviceRespDTO.DeviceItemDTO.class));
+            } else {
+                respDTO.setData(new ArrayList<>());
+            }
+
+            return respDTO;
+
+        } catch (Exception e) {
+            throw new RuntimeException("解析响应数据失败,响应内容: " + body, e);
+        }
+    }
+
+
+    @Data
+    public static class DeviceListQueryVO {
+
+        private String deviceModelName;
+
+        private Integer pageNum = 10;
+
+        private Integer pageSize = 1; // 最大值可在业务层校验 1-100
+
+        private String startTime;
+        private String endTime;
+
+        private Integer fullFlag = 0; // 0: 本级, 1: 所有
+
+        private Integer state; // 设备状态
+        private Integer registerSign; // 入网注册标志
+    }
+
+    @Data
+    public static class DeviceRespDTO {
+
+        private List<DeviceItemDTO> data;
+
+        private Integer pageSize;
+        private Integer pageCount;
+        private Integer currentPage;
+        private Integer total;
+
+        @Data
+        public static class DeviceItemDTO implements Serializable {
+            private Long deviceId;
+            private String deviceImei;
+            private String deviceImsi;
+            private String iccid;
+            private String deviceTypeName;
+            private String deviceModelName;
+            private Integer registerSign;
+            private Integer state;
+            private Double latitude;
+            private Double longitude;
+            private String installAddress;
+            private String contact;
+            private String phonenumber;
+            private String companyName;
+            private String floorName;
+            private String buildingName;
+            private String roomName;
+            private String region;
+
+            @JSONField(name = "createTime")
+            private String createTime;
+
+            @JSONField(name = "updateTime")
+            private String updateTime;
+        }
+    }
+
+}

+ 42 - 13
app-admin/src/main/java/com/ruoyi/web/controller/chenyanlogin/timer/GetHuivCunTimer.java

@@ -1,24 +1,23 @@
 package com.ruoyi.web.controller.chenyanlogin.timer;
 
-import cn.hutool.json.JSONUtil;
-import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.web.controller.chenyanlogin.service.HuiCunService;
-import org.apache.commons.collections4.Get;
-import org.checkerframework.checker.units.qual.A;
+import com.ruoyi.web.controller.chenyanlogin.service.impl.ZhwlCaller;
+import com.ruoyi.web.domain.entity.ZhwlDeviceListEntity;
+import com.ruoyi.web.service.impl.ZhwlDeviceListServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cglib.beans.BeanCopier;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.util.ObjectUtils;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 
+@Slf4j
 @Configuration
 @EnableScheduling
 public class GetHuivCunTimer {
@@ -26,6 +25,9 @@ public class GetHuivCunTimer {
     @Autowired
     private HuiCunService huiCunService;
 
+    @Resource
+    private ZhwlDeviceListServiceImpl zhwlDeviceListService;
+
     //基础数据查询接口
     @Scheduled(cron = "0 0 * * * ? ")
     public  void getBasicData(){
@@ -47,7 +49,34 @@ public class GetHuivCunTimer {
     //一键呼叫数据查询接口
     @Scheduled(cron = "0 0 * * * ? ")
     public  void getZhwlDeviceData(){
-        huiCunService.getZhwlDeviceData();
+        //huiCunService.getZhwlDeviceData();
+        ZhwlCaller.DeviceListQueryVO queryVO = new ZhwlCaller.DeviceListQueryVO();
+        //全量查询
+        queryVO.setFullFlag(1);
+        try {
+            AjaxResult result = huiCunService.getZhwlDeviceData(queryVO);
+            if(!ObjectUtils.isEmpty(result) && "200".equals(result.getOrDefault(AjaxResult.CODE_TAG,0).toString())
+                    && !ObjectUtils.isEmpty(result.get(AjaxResult.DATA_TAG))) {
+                ZhwlCaller.DeviceRespDTO response = (ZhwlCaller.DeviceRespDTO) result.get(AjaxResult.DATA_TAG);
+                if(!ObjectUtils.isEmpty(response.getData())) {
+                    BeanCopier copier = BeanCopier.create(ZhwlCaller.DeviceRespDTO.DeviceItemDTO.class, ZhwlDeviceListEntity.class, false);
+                    for(ZhwlCaller.DeviceRespDTO.DeviceItemDTO item : response.getData()) {
+                        ZhwlDeviceListEntity entity = new ZhwlDeviceListEntity();
+                        copier.copy(item,entity,null);
+                        if(!ObjectUtils.isEmpty(item.getCreateTime())) {
+                            entity.setCreateTime(LocalDateTime.parse(item.getCreateTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+                        }
+                        if(!ObjectUtils.isEmpty(item.getUpdateTime())) {
+                            entity.setUpdateTime(LocalDateTime.parse(item.getUpdateTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+                        }
+                        zhwlDeviceListService.insertOrUpdate(entity);
+                    }
+                }
+            }
+        }catch (Exception e) {
+            log.error("定时刷新智慧云平台获取到的设备列表信息处理失败,详细异常信息:{}", e.toString());
+        }
+
     }
 
     //积分排行数据查询接口

+ 68 - 0
app-admin/src/main/java/com/ruoyi/web/domain/entity/ZhwlDeviceListEntity.java

@@ -0,0 +1,68 @@
+package com.ruoyi.web.domain.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+@Data
+@TableName(value = "zhwl_device_list")
+public class ZhwlDeviceListEntity implements Serializable {
+
+    @TableId
+    private Long deviceId;
+
+    private String deviceImei;
+
+    private String deviceImsi;
+
+    private String iccid;
+
+    private String deviceTypeName;
+
+    private String deviceModelName;
+
+    private Integer registerSign;
+
+    private Integer state;
+
+    private Double latitude;
+
+    private Double longitude;
+
+    private String installAddress;
+
+    private String contact;
+
+    private String phonenumber;
+
+    private String companyName;
+
+    private String floorName;
+
+    private String buildingName;
+
+    private String roomName;
+
+    private String region;
+
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField(value = "create_time", fill = FieldFill.INSERT)
+    private LocalDateTime createTime;
+
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField(value = "update_time", fill = FieldFill.UPDATE)
+    private LocalDateTime updateTime;
+
+    /**
+     * 删除标志
+     */
+    @TableLogic
+    private Integer deleted = 0;
+
+}

+ 16 - 0
app-admin/src/main/java/com/ruoyi/web/mapper/ZhwlDeviceListMapper.java

@@ -0,0 +1,16 @@
+package com.ruoyi.web.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.web.domain.entity.ZhwlDeviceListEntity;
+
+
+/**
+ * @Entity
+ */
+public interface ZhwlDeviceListMapper extends BaseMapper<ZhwlDeviceListEntity> {
+
+}
+
+
+
+

+ 21 - 0
app-admin/src/main/java/com/ruoyi/web/service/ZhwlDeviceListService.java

@@ -0,0 +1,21 @@
+package com.ruoyi.web.service;
+
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.web.controller.chenyanlogin.service.impl.ZhwlCaller;
+import com.ruoyi.web.domain.entity.ZhwlDeviceListEntity;
+
+public interface ZhwlDeviceListService {
+
+    AjaxResult add(ZhwlDeviceListEntity request);
+
+    AjaxResult edit(ZhwlDeviceListEntity request);
+
+    AjaxResult delete(String ids);
+
+    AjaxResult page(ZhwlCaller.DeviceListQueryVO request);
+
+    AjaxResult listAll();
+
+    AjaxResult insertOrUpdate(ZhwlDeviceListEntity request);
+
+}

+ 85 - 0
app-admin/src/main/java/com/ruoyi/web/service/impl/ZhwlDeviceListServiceImpl.java

@@ -0,0 +1,85 @@
+package com.ruoyi.web.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.web.controller.chenyanlogin.service.impl.ZhwlCaller;
+import com.ruoyi.web.domain.entity.ZhwlDeviceListEntity;
+import com.ruoyi.web.mapper.ZhwlDeviceListMapper;
+import com.ruoyi.web.service.ZhwlDeviceListService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
+import java.util.Arrays;
+
+import static com.ruoyi.common.core.domain.AjaxResult.error;
+import static com.ruoyi.common.core.domain.AjaxResult.success;
+
+@Slf4j
+@Service
+public class ZhwlDeviceListServiceImpl extends ServiceImpl<ZhwlDeviceListMapper, ZhwlDeviceListEntity>  implements ZhwlDeviceListService {
+
+    @Transactional
+    @Override
+    public AjaxResult add(ZhwlDeviceListEntity request) {
+        //入参检测
+        if(ObjectUtils.isEmpty(request.getDeviceId())) {
+            return error("请传入【设备编号】!");
+        }
+        //防重检测,
+        Integer count = lambdaQuery().eq(ZhwlDeviceListEntity::getDeviceId, request.getDeviceId()).count();
+        if (count != 0) {
+            return error("请勿重复添加!");
+        }
+        return success("添加成功", baseMapper.insert(request));
+    }
+
+    @Transactional
+    @Override
+    public AjaxResult edit(ZhwlDeviceListEntity request) {
+        //数据格式校验
+        if(ObjectUtils.isEmpty(request.getDeviceId())){
+            return error("待更新数据未传入有效ID,请设置数据的唯一标识ID!");
+        }
+        //根据数据的id更新所有不为空的字段
+        return updateById(request) ? success("修改成功!") : error("修改失败,请重试!");
+    }
+
+    @Transactional
+    @Override
+    public AjaxResult delete(String ids) {
+        String[] idList = ids.split(",");
+        return success("删除成功", removeByIds(Arrays.asList(idList)));
+    }
+
+    @Override
+    public AjaxResult page(ZhwlCaller.DeviceListQueryVO request) {
+        //构造查询条件(检索条件未定时,先按不为空的字段进行等值查询)
+        LambdaQueryWrapper<ZhwlDeviceListEntity> wrapper = new LambdaQueryWrapper<>();
+        if(!ObjectUtils.isEmpty(request.getDeviceModelName())) {
+            wrapper.eq(ZhwlDeviceListEntity::getDeviceModelName, request.getDeviceModelName());
+        }
+        if(!ObjectUtils.isEmpty(request.getState())) {
+            wrapper.eq(ZhwlDeviceListEntity::getState, request.getState());
+        }
+        if(!ObjectUtils.isEmpty(request.getRegisterSign())) {
+            wrapper.eq(ZhwlDeviceListEntity::getRegisterSign, request.getRegisterSign());
+        }
+        return success(baseMapper.selectPage(new Page<>(request.getPageNum(),request.getPageSize()), wrapper));
+    }
+
+    @Override
+    public AjaxResult listAll() {
+        return success(lambdaQuery().list());
+    }
+
+    @Transactional
+    @Override
+    public AjaxResult insertOrUpdate(ZhwlDeviceListEntity request) {
+        Boolean result = saveOrUpdate(request);
+        return success(result);
+    }
+}

+ 25 - 1
sql/sql.sql

@@ -636,5 +636,29 @@ create table environment_warning_threshold_role
 )ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 comment '人居环境预警阈值负责人角色表';
 
 
-
+-- 智慧物联云平台.设备列表
+CREATE TABLE `zhwl_device_list` (
+                                    `device_id` BIGINT NOT NULL COMMENT '设备ID',
+                                    `device_imei` VARCHAR(50) COMMENT '设备IMEI',
+                                    `device_imsi` VARCHAR(50) COMMENT '设备IMSI',
+                                    `iccid` VARCHAR(50) COMMENT 'ICCID',
+                                    `device_type_name` VARCHAR(50) COMMENT '设备类型名称',
+                                    `device_model_name` VARCHAR(50) COMMENT '设备型号名称',
+                                    `register_sign` INT COMMENT '注册标志',
+                                    `state` INT COMMENT '状态',
+                                    `latitude` DOUBLE COMMENT '纬度',
+                                    `longitude` DOUBLE COMMENT '经度',
+                                    `install_address` VARCHAR(255) COMMENT '安装地址',
+                                    `contact` VARCHAR(50) COMMENT '联系人',
+                                    `phonenumber` VARCHAR(20) COMMENT '联系电话',
+                                    `company_name` VARCHAR(100) COMMENT '公司名称',
+                                    `floor_name` VARCHAR(50) COMMENT '楼层名称',
+                                    `building_name` VARCHAR(50) COMMENT '楼栋名称',
+                                    `room_name` VARCHAR(50) COMMENT '房间名称',
+                                    `region` VARCHAR(50) COMMENT '区域',
+                                    `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除',
+                                    `create_time` datetime COMMENT '创建时间',
+                                    `update_time` datetime COMMENT '更新时间',
+                                    PRIMARY KEY (`device_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='智慧物联平台.设备信息表';