Browse Source

iot server 服务代码提交

jingyuanchao 1 năm trước cách đây
mục cha
commit
85e919a4f9

+ 15 - 12
project_data/sql/0.1.1/soc/soc.sql

@@ -265,18 +265,19 @@ CREATE TABLE `iot_air_conditioner_log` (
 
 drop table if exists iot_server_info;
 CREATE TABLE if not exists `iot_server_info` (
-                                                 `id` bigint DEFAULT NULL COMMENT '主键',
-                                                 `iot_name` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
-                                                 `iot_code` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '服务编码(全局唯一)',
-                                                 `org_id` bigint DEFAULT NULL COMMENT '组织机构id',
-                                                 `org_name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '组织机构名称',
-                                                 `org_path` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '组织机构路径',
-                                                 `iot_status` bit(1) DEFAULT NULL COMMENT '链接状态:0:未知(未启用),1:在线,2:离线',
-                                                 `last_connect_time` datetime DEFAULT NULL COMMENT '最近一次链接时间',
-                                                 `create_by` varchar(125) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
-                                                 `create_time` datetime DEFAULT NULL COMMENT '创建时间',
-                                                 `update_by` varchar(125) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
-                                                 `update_time` datetime DEFAULT NULL COMMENT '修改时间'
+       `id` bigint DEFAULT NULL COMMENT '主键',
+       `iot_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
+       `iot_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '服务编码(全局唯一)',
+       `org_id` bigint DEFAULT NULL COMMENT '组织机构id',
+       `org_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '组织机构名称',
+       `org_path` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '组织机构路径',
+       `iot_status` bit(1) DEFAULT NULL COMMENT '链接状态:0:未知(未启用),1:在线,2:离线',
+       `last_connect_time` datetime DEFAULT NULL COMMENT '最近一次链接时间',
+       `ip` varchar(125) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'ip地址',
+       `create_by` varchar(125) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
+       `create_time` datetime DEFAULT NULL COMMENT '创建时间',
+       `update_by` varchar(125) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
+       `update_time` datetime DEFAULT NULL COMMENT '修改时间'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='iot客户端信息';
 
 
@@ -285,6 +286,8 @@ CREATE TABLE if not exists `iot_server_info` (
 
 
 
+
+
 -- ----------------------------
 -- 部署中心新增表及视图脚本
 -- ----------------------------

+ 3 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/iot/domain/IotServerInfo.java

@@ -2,6 +2,8 @@ package com.xunmei.common.core.domain.iot.domain;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xunmei.common.core.constant.Constants;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -54,6 +56,7 @@ public class IotServerInfo implements Serializable {
     @TableField("iot_status")
     private int iotStatus;
 
+    @JsonFormat(pattern = Constants.HMS_FORMAT)
     @ApiModelProperty(value = "最近一次链接时间")
     @TableField("last_connect_time")
     private LocalDateTime lastConnectTime;

+ 8 - 4
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/IotServerInfoController.java

@@ -1,12 +1,15 @@
 package com.xunmei.iot.controller;
 
 
+import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.iot.dto.serverInfo.IotServerInfoAddDto;
 import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.service.IotServerInfoService;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -30,14 +33,15 @@ public class IotServerInfoController {
 
     @ApiOperation("iot服务列表")
     @PostMapping({"/page"})
-    TableDataInfo<IotServerInfoPageVo> webPage(@RequestBody final IotServerInfoPageDto request) {
-        return serverInfoService.serverPage(request);
+    TableDataInfo<IotServerInfoPageVo> webPage(@RequestBody final IotServerInfoPageDto req) {
+        return serverInfoService.serverPage(req);
     }
 
     @ApiOperation("新增")
     @PostMapping({"/add"})
-    TableDataInfo<IotServerInfoPageVo> add(@RequestBody final IotServerInfoPageDto request) {
-        return serverInfoService.serverPage(request);
+    AjaxResult add(@RequestBody @Validated final IotServerInfoAddDto req) {
+        serverInfoService.addIotServer(req);
+        return AjaxResult.success();
     }
 
 }

+ 19 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/serverInfo/IotServerInfoAddDto.java

@@ -0,0 +1,19 @@
+package com.xunmei.iot.dto.serverInfo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+public class IotServerInfoAddDto {
+
+    @NotNull(message = "请选择所属机构")
+    @ApiModelProperty(value = "机构id")
+    private Long orgId;
+
+    @NotNull(message = "请输入名称")
+    @ApiModelProperty(value = "名称")
+    private String iotName;
+
+}

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotServerInfoService.java

@@ -3,6 +3,7 @@ package com.xunmei.iot.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.iot.dto.serverInfo.IotServerInfoAddDto;
 import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 
@@ -17,4 +18,6 @@ import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 public interface IotServerInfoService extends IService<IotServerInfo> {
 
     TableDataInfo<IotServerInfoPageVo> serverPage(IotServerInfoPageDto request);
+
+    int addIotServer(IotServerInfoAddDto req);
 }

+ 38 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotServerInfoServiceImpl.java

@@ -1,14 +1,26 @@
 package com.xunmei.iot.service.impl;
 
+import cn.hutool.core.lang.UUID;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.common.security.utils.SecurityUtils;
+import com.xunmei.iot.dto.serverInfo.IotServerInfoAddDto;
 import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.mapper.IotServerInfoMapper;
 import com.xunmei.iot.service.IotServerInfoService;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
+import com.xunmei.system.api.RemoteOrgService;
+import com.xunmei.system.api.domain.SysOrg;
+import lombok.val;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
 
 /**
  * <p>
@@ -21,10 +33,36 @@ import org.springframework.stereotype.Service;
 @Service
 public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, IotServerInfo> implements IotServerInfoService {
 
+    @Autowired
+    RemoteOrgService orgService;
 
     @Override
     public TableDataInfo<IotServerInfoPageVo> serverPage(IotServerInfoPageDto request) {
+        if (request.getCheckSub()){
+            SysOrg sysOrg = orgService.selectOrgById(request.getOrgId(), SecurityConstants.INNER);
+            request.setOrgPath(sysOrg.getPath());
+        }
         Page<IotServerInfoPageVo> page = baseMapper.selectServerPage(request.getPageRequest(),request);
         return TableDataInfo.build(page);
     }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int addIotServer(IotServerInfoAddDto req) {
+        SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
+        val serverInfo = new IotServerInfo();
+        serverInfo.setIotCode(UUID.fastUUID().toString());
+        serverInfo.setIotName(req.getIotName());
+        serverInfo.setIotStatus(0);
+        serverInfo.setOrgPath(sysOrg.getPath());
+        serverInfo.setOrgName(sysOrg.getShortName());
+        serverInfo.setOrgId(sysOrg.getId());
+        serverInfo.setId(IdWorker.getId());
+        serverInfo.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
+        serverInfo.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
+        serverInfo.setCreateTime(LocalDateTime.now());
+        serverInfo.setUpdateTime(LocalDateTime.now());
+        return baseMapper.insert(serverInfo);
+    }
 }

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/serverInfo/IotServerInfoPageVo.java

@@ -9,5 +9,10 @@ import lombok.EqualsAndHashCode;
 public class IotServerInfoPageVo extends IotServerInfo {
 
 
+    private String ip;
+    private String firstOrgName;
+    private String secondOrgName;
+
+
 
 }

+ 10 - 2
soc-modules/soc-modules-iot/src/main/resources/mapper/IotServerInfoMapper.xml

@@ -2,17 +2,25 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.xunmei.iot.mapper.IotServerInfoMapper">
     <select id="selectServerPage" resultType="com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo">
-        select i.* from iot_server_info i
+        select o.affiliated_area as firstOrgName,o.affiliated_bank as secondOrgName, i.* from iot_server_info i inner join sys_org o on o.id=i.org_id
         <where>
             <if test="req.iotStatus!=null">
                 and i.iot_status=#{req.iotStatus}
             </if>
             <if test="req.iotName!=null and req.iotName!=''">
-                and i.iot_name like concat('%',#{req.iotStatus},'%')
+                and i.iot_name like concat('%',#{req.iotName},'%')
             </if>
             <if test="req.iotCode!=null and req.iotCode!=''">
                 and i.iot_code like concat('%',#{req.iotCode},'%')
             </if>
+            <choose>
+                <when test="req.checkSub == false">
+                    and i.org_id=#{req.orgId}
+                </when>
+                <otherwise>
+                    and i.org_path like concat(#{req.orgPath},'%')
+                </otherwise>
+            </choose>
         </where>
     </select>
 </mapper>