浏览代码

iot server 服务代码提交

jingyuanchao 1 年之前
父节点
当前提交
560a3fb660

+ 25 - 6
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/IotServerInfoController.java

@@ -3,17 +3,16 @@ 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.IotServerInfoEditDto;
 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;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * <p>
@@ -39,10 +38,30 @@ public class IotServerInfoController {
 
     @ApiOperation("新增")
     @PostMapping({"/add"})
-    AjaxResult add(@RequestBody @Validated final IotServerInfoAddDto req) {
+    AjaxResult add(@RequestBody @Validated final IotServerInfoEditDto req) {
         serverInfoService.addIotServer(req);
         return AjaxResult.success();
     }
 
+    @ApiOperation("编辑")
+    @PostMapping({"/edit"})
+    AjaxResult edit(@RequestBody @Validated final IotServerInfoEditDto req) {
+        serverInfoService.editIot(req);
+        return AjaxResult.success();
+    }
+
+
+    @ApiOperation("详情")
+    @GetMapping({"/{id}"})
+    AjaxResult add(@PathVariable Long id) {
+        return AjaxResult.success(serverInfoService.getById(id));
+    }
+
+    @ApiOperation("导出")
+    @PostMapping({"/export"})
+    void export( IotServerInfoPageDto req, HttpServletResponse response) {
+        serverInfoService.export(req,response);
+    }
+
 }
 

+ 3 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/serverInfo/IotServerInfoAddDto.java → soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/serverInfo/IotServerInfoEditDto.java

@@ -6,7 +6,9 @@ import lombok.Data;
 import javax.validation.constraints.NotNull;
 
 @Data
-public class IotServerInfoAddDto {
+public class IotServerInfoEditDto {
+
+    private Long id;
 
     @NotNull(message = "请选择所属机构")
     @ApiModelProperty(value = "机构id")

+ 8 - 2
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotServerInfoService.java

@@ -3,10 +3,12 @@ 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.IotServerInfoEditDto;
 import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.vo.serverInfo.IotServerInfoPageVo;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * <p>
  * iot客户端信息 服务类
@@ -19,5 +21,9 @@ public interface IotServerInfoService extends IService<IotServerInfo> {
 
     TableDataInfo<IotServerInfoPageVo> serverPage(IotServerInfoPageDto request);
 
-    int addIotServer(IotServerInfoAddDto req);
+    int addIotServer(IotServerInfoEditDto req);
+
+    void editIot(IotServerInfoEditDto req);
+
+    void export(IotServerInfoPageDto req, HttpServletResponse response);
 }

+ 49 - 3
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotServerInfoServiceImpl.java

@@ -1,14 +1,18 @@
 package com.xunmei.iot.service.impl;
 
 import cn.hutool.core.lang.UUID;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 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.exception.SystemException;
 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.IotServerInfoEditDto;
 import com.xunmei.iot.dto.serverInfo.IotServerInfoPageDto;
 import com.xunmei.iot.mapper.IotServerInfoMapper;
 import com.xunmei.iot.service.IotServerInfoService;
@@ -20,7 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.http.HttpServletResponse;
+import java.net.URLEncoder;
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * <p>
@@ -49,10 +56,10 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int addIotServer(IotServerInfoAddDto req) {
+    public int addIotServer(IotServerInfoEditDto req) {
         SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
         val serverInfo = new IotServerInfo();
-        serverInfo.setIotCode(UUID.fastUUID().toString());
+        serverInfo.setIotCode(UUID.fastUUID().toString());//分配后不可变更
         serverInfo.setIotName(req.getIotName());
         serverInfo.setIotStatus(0);
         serverInfo.setOrgPath(sysOrg.getPath());
@@ -65,4 +72,43 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
         serverInfo.setUpdateTime(LocalDateTime.now());
         return baseMapper.insert(serverInfo);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void editIot(IotServerInfoEditDto req) {
+        if (ObjectUtil.isEmpty(req.getId())){
+            throw new RuntimeException("请选择具体iot服务进行查看!");
+        }
+        IotServerInfo info = getById(req.getId());
+        if (ObjectUtil.isEmpty(info)){
+            throw new RuntimeException("未找到具体iot服务!");
+        }
+        info.setIotName(req.getIotName());
+        updateById(info);
+    }
+
+    @Override
+    public void export(IotServerInfoPageDto req, HttpServletResponse response) {
+        req.setPageSize(Integer.MAX_VALUE);
+        TableDataInfo<IotServerInfoPageVo> tableDataInfo = this.serverPage(req);
+        List<IotServerInfoPageVo> list = tableDataInfo.getRows();
+        if (ObjectUtil.isEmpty(list)) {
+            throw new SystemException("暂无可用数据导出!");
+        }
+        try {
+            // 设置响应头
+            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("Iot服务", "utf-8"));
+            response.setContentType("application/octet-stream;charset=UTF-8");
+            response.setCharacterEncoding("utf-8");
+            // 数据导出
+            EasyExcel.write(response.getOutputStream(), IotServerInfoPageVo.class)
+                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("Iot服务").doWrite(list);
+        } catch (Exception e) {
+            e.printStackTrace();
+            // 重置response
+            response.reset();
+            response.setContentType("application/json");
+            response.setCharacterEncoding("utf-8");
+        }
+    }
 }

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

@@ -1,18 +1,64 @@
 package com.xunmei.iot.vo.serverInfo;
 
-import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xunmei.common.core.constant.Constants;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
 
-@EqualsAndHashCode(callSuper = true)
+import java.io.Serializable;
+import java.util.Date;
+
 @Data
-public class IotServerInfoPageVo extends IotServerInfo {
+@ColumnWidth(15) //列宽,最大值为255
+@HeadRowHeight(16) //表头行高
+@ContentRowHeight(16) //数据行高
+public class IotServerInfoPageVo implements Serializable {
 
+    private static final long serialVersionUID = 1L;
 
-    private String ip;
+    @ExcelProperty(value = "地区")
+    @ApiModelProperty(value = "地区")
     private String firstOrgName;
+
+    @ExcelProperty(value = "行社名称")
+    @ApiModelProperty(value = "行社名称")
     private String secondOrgName;
 
+    @ExcelProperty(value = "所属机构")
+    @ApiModelProperty(value = "所属机构")
+    private String orgName;
+
+    @ExcelProperty(value = "Iot名称")
+    @ApiModelProperty(value = "Iot名称")
+    private String iotName;
+
+    @ExcelProperty(value = "Iot编码")
+    @ApiModelProperty(value = "Iot编码(全局唯一)")
+    private String iotCode;
+
+    @ExcelProperty(value = "Iot服务IP")
+    @ApiModelProperty(value = "Iot服务IP")
+    private String iotIp;
+
+    @ExcelProperty(value = "状态",converter = IotServerStatusConverter.class)
+    @ApiModelProperty(value = "链接状态:0:未知(未启用),1:在线,2:离线")
+    private int iotStatus;
+
+    @ExcelProperty(value = "状态更新时间")
+    @JsonFormat(pattern = Constants.HMS_FORMAT)
+    @ApiModelProperty(value = "最近一次链接时间")
+    private Date lastConnectTime;
 
+    @ExcelIgnore
+    @ApiModelProperty(value = "组织机构id")
+    private Long orgId;
 
+    @ExcelIgnore
+    @ApiModelProperty(value = "主键")
+    private Long id;
 }

+ 40 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/serverInfo/IotServerStatusConverter.java

@@ -0,0 +1,40 @@
+package com.xunmei.iot.vo.serverInfo;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.CellData;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+
+public class IotServerStatusConverter implements Converter<Integer> {
+
+
+
+    @Override
+    public Class supportJavaTypeKey() {
+        return null;
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return null;
+    }
+
+    @Override
+    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+        return null;
+    }
+
+    @Override
+    public CellData convertToExcelData(Integer status, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+        if (ObjectUtil.equal(0,status)) {
+            return new CellData("未启用");
+        }
+        if (ObjectUtil.equal(1,status)) {
+            return new CellData("在线");
+        }
+        return new CellData("离线");
+
+    }
+}