chenxiaofei пре 3 месеци
родитељ
комит
ca3436fc51

+ 0 - 25
iot-platform-common/src/main/java/com/platform/Main.java

@@ -1,25 +0,0 @@
-package com.platform;
-
-/**
- * @Author: 马超伟
- * @CreateTime: 2025-09-30
- * @Description: ${description}
- * @Version: 1.0
- */
-
-
-//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
-// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
-public class Main {
-    public static void main(String[] args) {
-        //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
-        // to see how IntelliJ IDEA suggests fixing it.
-        System.out.printf("Hello and welcome!");
-
-        for (int i = 1; i <= 5; i++) {
-            //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
-            // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
-            System.out.println("i = " + i);
-        }
-    }
-}

+ 31 - 0
iot-platform-common/src/main/java/com/platform/exception/BusinessException.java

@@ -0,0 +1,31 @@
+package com.platform.exception;
+
+import lombok.Getter;
+
+/**
+ * 业务异常类
+ */
+@Getter
+public class BusinessException extends RuntimeException {
+    
+    private final Integer code;
+    private final String message;
+    
+    public BusinessException(String message) {
+        super(message);
+        this.code = 500;
+        this.message = message;
+    }
+    
+    public BusinessException(Integer code, String message) {
+        super(message);
+        this.code = code;
+        this.message = message;
+    }
+    
+    public BusinessException(ErrorCode errorCode) {
+        super(errorCode.getMessage());
+        this.code = errorCode.getCode();
+        this.message = errorCode.getMessage();
+    }
+}

+ 42 - 0
iot-platform-common/src/main/java/com/platform/exception/CommonErrorCode.java

@@ -0,0 +1,42 @@
+package com.platform.exception;
+
+
+
+/**
+ * 常见错误码枚举
+ */
+public enum CommonErrorCode implements ErrorCode {
+    
+    /**
+     * 参数校验异常
+     */
+    PARAM_VALIDATE_FAILED(1001, "参数校验失败"),
+    
+    /**
+     * 数据不存在
+     */
+    DATA_NOT_FOUND(1002, "数据不存在"),
+    
+    /**
+     * 系统异常
+     */
+    SYSTEM_ERROR(9999, "系统异常");
+    
+    private final Integer code;
+    private final String message;
+    
+    CommonErrorCode(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+    
+    @Override
+    public Integer getCode() {
+        return code;
+    }
+    
+    @Override
+    public String getMessage() {
+        return message;
+    }
+}

+ 17 - 0
iot-platform-common/src/main/java/com/platform/exception/ErrorCode.java

@@ -0,0 +1,17 @@
+package com.platform.exception;
+
+/**
+ * 错误码枚举接口
+ */
+public interface ErrorCode {
+    
+    /**
+     * 获取错误码
+     */
+    Integer getCode();
+    
+    /**
+     * 获取错误信息
+     */
+    String getMessage();
+}

+ 120 - 0
iot-platform-common/src/main/java/com/platform/utils/EasyExcelUtil.java

@@ -0,0 +1,120 @@
+package com.platform.utils;
+
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.support.ExcelTypeEnum;
+import com.alibaba.excel.write.metadata.style.WriteCellStyle;
+import com.alibaba.excel.write.metadata.style.WriteFont;
+import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author: 马超伟
+ * @CreateTime: 2025-09-08
+ * @Description:
+ * @Version: 1.0
+ */
+
+
+public class EasyExcelUtil {
+
+    public static <T> List<T> importExcel(InputStream inputStream, Class<T> clazz) {
+        return EasyExcel.read(inputStream).head(clazz).sheet().doReadSync();
+    }
+
+    public static <T> void exportExcel(String fileName, List<T> data, HttpServletResponse response) throws Exception {
+        if (CollectionUtils.isEmpty(data)) {
+            return ;
+        }
+        T t = data.get(0);
+        // 设置响应内容类型
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setCharacterEncoding("utf-8");
+
+        // 设置文件名
+        String name = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
+        response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xlsx");
+        //解决跨域问题
+        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+        // 创建表头样式
+        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
+        // 设置表头居中对齐
+        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+        // 设置表头字体
+        WriteFont headWriteFont = new WriteFont();
+        headWriteFont.setFontHeightInPoints((short) 12);
+        headWriteFont.setBold(true);
+        headWriteCellStyle.setWriteFont(headWriteFont);
+
+        // 创建内容样式
+        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
+        // 设置内容居中对齐
+        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+
+        // 初始化表格样式策略
+        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
+                new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
+
+        // 使用EasyExcel写入数据
+        EasyExcel.write(response.getOutputStream(), t.getClass()).excelType(ExcelTypeEnum.XLSX)
+                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                .sheet()
+                .doWrite(data);
+    }
+
+
+    /**
+     * 下载Excel模板
+     * @param fileName 文件名
+     * @param clazz 模板对应的实体类
+     * @param response HttpServletResponse对象
+     * @param <T> 实体类泛型
+     * @throws Exception 异常
+     */
+    public static <T> void exportTemplate(String fileName, Class<T> clazz, HttpServletResponse response) throws Exception {
+        // 设置响应内容类型
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setCharacterEncoding("utf-8");
+
+        // 设置文件名
+        String name = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
+        response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xlsx");
+        // 解决跨域问题
+        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+
+        // 创建表头样式
+        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
+        // 设置表头居中对齐
+        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+        // 设置表头字体
+        WriteFont headWriteFont = new WriteFont();
+        headWriteFont.setFontHeightInPoints((short) 12);
+        headWriteFont.setBold(true);
+        headWriteCellStyle.setWriteFont(headWriteFont);
+
+        // 创建内容样式
+        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
+        // 设置内容居中对齐
+        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+
+        // 初始化表格样式策略
+        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
+                new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
+
+        // 使用EasyExcel写入空数据生成模板
+        EasyExcel.write(response.getOutputStream(), clazz)
+                .excelType(ExcelTypeEnum.XLSX)
+                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                .registerWriteHandler(horizontalCellStyleStrategy)
+                .sheet("模板")
+                .doWrite(new ArrayList<>()); // 写入空列表,只生成表头
+    }
+
+}

+ 18 - 1
iot-platform-manager/src/main/java/com/platform/controller/IotDeviceController.java

@@ -6,8 +6,10 @@ import com.platform.request.device.IotDeviceRequest;
 import com.platform.response.device.DeviceDetailResp;
 import com.platform.response.device.DevicePageResp;
 import com.platform.result.HttpResult;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 物联网设备管理控制器
@@ -59,5 +61,20 @@ public class IotDeviceController {
         return HttpResult.success(iotDeviceManage.pageDeviceDetail(req));
     }
 
-    //todo cxf 备黑白名单,设备动态
+    /**
+     * 下载设备导入模板
+     */
+    @PostMapping("/exportTemplate")
+    public HttpResult<Void> exportTemplate(HttpServletResponse response) {
+        return HttpResult.success(iotDeviceManage.exportTemplate(response));
+    }
+
+    /**
+     * 批量导入设备
+     */
+    @PostMapping("/importExcel")
+    public HttpResult<Void> importExcel(@RequestParam("file") MultipartFile file) {
+        return HttpResult.success(iotDeviceManage.importExcel(file));
+    }
+    //todo cxf 备黑白名单,设备动态  查询saas_equipment_manage表,还需要查询时序表
 }

+ 31 - 0
iot-platform-manager/src/main/java/com/platform/dto/DeviceExcelTemplateDTO.java

@@ -0,0 +1,31 @@
+package com.platform.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+@Data
+public class DeviceExcelTemplateDTO {
+    
+    @ExcelProperty("物理模型名称")
+    private String modName;
+    
+    @ExcelProperty("设备名称")
+    private String deviceName;
+    
+    @ExcelProperty("设备类别")
+    private String deviceType;
+
+    @ExcelProperty("品牌")
+    private String brand;
+
+    @ExcelProperty("型号")
+    private String model;
+
+    @ExcelProperty("SN号")
+    private String sn;
+
+    @ExcelProperty("备注")
+    private String description;
+    
+    // 可以根据实际需求添加更多字段
+}

+ 26 - 0
iot-platform-manager/src/main/java/com/platform/entity/IotDevice.java

@@ -1,6 +1,7 @@
 package com.platform.entity;
 
 import com.baomidou.mybatisplus.annotation.*;
+import com.platform.request.device.IotDeviceRequest;
 import lombok.Data;
 import java.time.LocalDateTime;
 
@@ -143,4 +144,29 @@ public class IotDevice {
      */
     @TableField("eg_id")
     private Long egId;
+
+    public static IotDevice getInstance(){
+        return new IotDevice();
+    }
+    public static IotDevice toIotDevice(IotDeviceRequest request) {
+        IotDevice iotDevice = IotDevice.getInstance();
+        iotDevice.setId(request.getId());
+        iotDevice.setTenantId(request.getTenantId());
+        iotDevice.setCompanyId(request.getCompanyId());
+        iotDevice.setGuid(request.getGuid());
+        iotDevice.setDeviceCode(request.getDeviceCode());
+        iotDevice.setSn(request.getSn());
+        iotDevice.setModCode(request.getModCode());
+        iotDevice.setDeviceName(request.getDeviceName());
+        iotDevice.setBrand(request.getBrand());
+        iotDevice.setModelCode(request.getModelCode());
+        iotDevice.setDescription(request.getDescription());
+        iotDevice.setRemarks(request.getRemarks());
+        iotDevice.setStatus(request.getStatus());
+        iotDevice.setLongitude(request.getLongitude());
+        iotDevice.setLatitude(request.getLatitude());
+        iotDevice.setHigh(request.getHigh());
+        iotDevice.setEgId(request.getEgId());
+        return iotDevice;
+    }
 }

+ 80 - 0
iot-platform-manager/src/main/java/com/platform/entity/SaasEquipmentManage.java

@@ -0,0 +1,80 @@
+package com.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * 设备基础管理表(关联物联网ID) 实体类
+ */
+@Data
+@TableName("saas_equipment_manage")
+public class SaasEquipmentManage {
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 设备名称
+     */
+    @TableField("device_name")
+    private String deviceName;
+
+    /**
+     * 设备类型
+     */
+    @TableField("equipment_type")
+    private String equipmentType;
+
+    /**
+     * 能源形式
+     */
+    @TableField("energy_type")
+    private Integer energyType;
+
+    /**
+     * 设备GUID
+     */
+    @TableField("equipment_guid")
+    private String equipmentGuid;
+
+    /**
+     * 物联网模型GUID
+     */
+    @TableField("mod_guid")
+    private String modGuid;
+
+    /**
+     * 购买时间
+     */
+    @TableField("pay_time")
+    private LocalDateTime payTime;
+
+    /**
+     * 折旧年限
+     */
+    @TableField("depreciation_period")
+    private Integer depreciationPeriod;
+
+    /**
+     * 折旧总值
+     */
+    @TableField("total_depreciation_value")
+    private BigDecimal totalDepreciationValue;
+
+    /**
+     * 创建时间
+     */
+    @TableField(value = "create_time")
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    @TableField(value = "update_time")
+    private LocalDateTime updateTime;
+}

+ 49 - 2
iot-platform-manager/src/main/java/com/platform/manage/IotDeviceManage.java

@@ -1,24 +1,47 @@
 package com.platform.manage;
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.platform.dto.DeviceExcelTemplateDTO;
+import com.platform.entity.IotDevice;
+import com.platform.exception.BusinessException;
 import com.platform.request.device.DeviceDetailReq;
 import com.platform.request.device.IotDeviceRequest;
 import com.platform.response.device.DeviceDetailResp;
 import com.platform.response.device.DevicePageResp;
+import com.platform.service.IotDeviceService;
+import com.platform.utils.EasyExcelUtil;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
 
 
 /**
  * @author PC
  */
 @Service
+@RequiredArgsConstructor
 public class IotDeviceManage {
+    private final IotDeviceService iotDeviceService;
     public Boolean addDevice(IotDeviceRequest request) {
-        return true;
+        IotDevice iotDevice = IotDevice.toIotDevice(request);
+        return iotDeviceService.save(iotDevice);
     }
 
     public Boolean updateDevice(IotDeviceRequest request) {
-        return true;
+        IotDevice iotDevice = IotDevice.toIotDevice(request);
+        if (StringUtils.isBlank(iotDevice.getDeviceCode())){
+            throw new BusinessException("设备编号不能为空");
+        }
+        LambdaUpdateWrapper<IotDevice> updateWrapper = Wrappers.<IotDevice>lambdaUpdate()
+                .eq(IotDevice::getDeviceCode, iotDevice.getDeviceCode());
+        return iotDeviceService.update(iotDevice,updateWrapper);
     }
 
     public Boolean deleteDevice(String guid) {
@@ -32,4 +55,28 @@ public class IotDeviceManage {
     public DevicePageResp pageDeviceDetail(DeviceDetailReq req) {
         return null;
     }
+
+    public Void exportTemplate(HttpServletResponse response) {
+        try {
+            EasyExcelUtil.exportTemplate("设备导入模板", DeviceExcelTemplateDTO.class, response);
+        } catch (Exception e) {
+            throw new BusinessException("设备导入模板异常");
+        }
+        return null;
+    }
+
+
+    public Void importExcel(MultipartFile file) {
+        if (file.isEmpty()) {
+            throw new BusinessException("文件不能为空");
+        }
+        try {
+            InputStream inputStream = file.getInputStream();
+            List<DeviceDetailReq> deviceDetailReqs = EasyExcelUtil.importExcel(inputStream, DeviceDetailReq.class);
+            //todo cxf 导入设备
+        } catch (Exception e) {
+            throw new BusinessException("设备导入异常");
+        }
+        return null;
+    }
 }

+ 15 - 0
iot-platform-manager/src/main/java/com/platform/mapper/SaasEquipmentManageMapper.java

@@ -0,0 +1,15 @@
+package com.platform.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.platform.entity.SaasEquipmentManage;
+
+/**
+ * @Author: 马超伟
+ * @CreateTime: 2025-10-09
+ * @Description:
+ * @Version: 1.0
+ */
+
+@mapper
+public interface SaasEquipmentManageMapper extends BaseMapper<SaasEquipmentManage> {
+}

+ 15 - 0
iot-platform-manager/src/main/java/com/platform/service/SaasEquipmentManageService.java

@@ -0,0 +1,15 @@
+package com.platform.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.platform.entity.SaasEquipmentManage;
+
+/**
+ * @Author: 马超伟
+ * @CreateTime: 2025-10-09
+ * @Description:
+ * @Version: 1.0
+ */
+
+
+public interface SaasEquipmentManageService extends IService<SaasEquipmentManage> {
+}

+ 20 - 0
iot-platform-manager/src/main/java/com/platform/service/impl/SaasEquipmentManageServiceImpl.java

@@ -0,0 +1,20 @@
+package com.platform.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * @Author: 马超伟
+ * @CreateTime: 2025-10-09
+ * @Description:
+ * @Version: 1.0
+ */
+
+
+import com.platform.mapper.SaasEquipmentManageMapper;
+import com.platform.entity.SaasEquipmentManage;
+import com.platform.service.SaasEquipmentManageService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SaasEquipmentManageServiceImpl extends ServiceImpl<SaasEquipmentManageMapper, SaasEquipmentManage> implements SaasEquipmentManageService {
+}

+ 16 - 1
pom.xml

@@ -94,7 +94,22 @@
             <artifactId>taos-jdbcdriver</artifactId>
             <version>3.2.7</version> <!-- 版本根据 TDengine 服务器版本选择 -->
         </dependency>
-
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>provided</scope>
+            <version>1.18.30</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>3.3.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.12.0</version>
+        </dependency>
 
     </dependencies>
 	<dependencyManagement>

+ 30 - 0
sql/2025/11/create_cxf.sql

@@ -115,6 +115,36 @@ create table time_Series_database_mapping
     update_time              datetime                       not null default current_timestamp on update CURRENT_TIMESTAMP comment '更新时间'
 )comment '时序数据库和关系型数据库映射表';
 
+
+
+create table saas_equipment_manage
+(
+    id                       int unsigned auto_increment
+        primary key,
+    device_name              varchar(60)              not null default '' comment '设备名称',
+    equipment_type           varchar(100)             not null default '' comment '设备类型',
+    energy_type              tinyint(1)               not null default 1  comment '能源形式',
+    equipment_guid           varchar(40)              not null default '' comment '设备GUID',
+    mod_guid                 varchar(40)              not null default '' comment '物联网模型GUID',
+    pay_time                 datetime                 not null default '1000-01-01 00:00:00' comment '购买时间',
+    depreciation_period      int                      not null default -1 comment '折旧年限',
+    total_depreciation_value decimal(15, 2)           not null default 0.00 comment '折旧总值',
+    create_time              datetime                 not null default current_timestamp comment '创建时间',
+    update_time              datetime                 not null default current_timestamp on update current_timestamp comment '更新时间'
+
+)
+    comment '设备基础管理表(关联物联网ID)';
+
+create index energy_type
+    on saas_equipment_manage (energy_type);
+
+create index guid
+    on saas_equipment_manage (mod_guid);
+
+create index type
+    on saas_equipment_manage (equipment_type);
+
+
 --    create table iot_device_history
 --    (
 --        id          int unsigned auto_increment