Browse Source

pms功能优化 设备运行数据收集 中间表

zhangcl 3 months ago
parent
commit
f61c817df2
11 changed files with 586 additions and 0 deletions
  1. 1 0
      yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java
  2. 93 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/IotDeviceRunLogController.java
  3. 70 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogPageReqVO.java
  4. 80 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogRespVO.java
  5. 58 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogSaveReqVO.java
  6. 9 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java
  7. 89 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotdevicerunlog/IotDeviceRunLogDO.java
  8. 38 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java
  9. 55 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogService.java
  10. 71 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogServiceImpl.java
  11. 22 0
      yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceMapper.xml

+ 1 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -48,4 +48,5 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_MAIN_WORK_ORDER_BOM_MATERIAL_NOT_EXISTS = new ErrorCode(139,"保养bom物料不存在");
     ErrorCode IOT_MAIN_WORK_ORDER_BOM_MATERIAL_NOT_EXISTS = new ErrorCode(139,"保养bom物料不存在");
     ErrorCode IOT_MAINTENANCE_PLAN_NO_EXISTS = new ErrorCode(140,"维修计划不存在");
     ErrorCode IOT_MAINTENANCE_PLAN_NO_EXISTS = new ErrorCode(140,"维修计划不存在");
     ErrorCode IOT_MAIN_WORK_ORDER_NOT_EXISTS = new ErrorCode(141,"保养工单不存在");
     ErrorCode IOT_MAIN_WORK_ORDER_NOT_EXISTS = new ErrorCode(141,"保养工单不存在");
+    ErrorCode IOT_DEVICE_RUN_LOG_NOT_EXISTS = new ErrorCode(142, "设备运行数据记录 中间表不存在");
 }
 }

+ 93 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/IotDeviceRunLogController.java

@@ -0,0 +1,93 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
+import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+import java.io.IOException;
+import java.util.List;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@Tag(name = "管理后台 - 设备运行数据记录 中间表")
+@RestController
+@RequestMapping("/pms/iot-device-run-log")
+@Validated
+public class IotDeviceRunLogController {
+
+    @Resource
+    private IotDeviceRunLogService iotDeviceRunLogService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建设备运行数据记录 中间表")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-run-log:create')")
+    public CommonResult<Long> createIotDeviceRunLog(@Valid @RequestBody IotDeviceRunLogSaveReqVO createReqVO) {
+        return success(iotDeviceRunLogService.createIotDeviceRunLog(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新设备运行数据记录 中间表")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-run-log:update')")
+    public CommonResult<Boolean> updateIotDeviceRunLog(@Valid @RequestBody IotDeviceRunLogSaveReqVO updateReqVO) {
+        iotDeviceRunLogService.updateIotDeviceRunLog(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除设备运行数据记录 中间表")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-run-log:delete')")
+    public CommonResult<Boolean> deleteIotDeviceRunLog(@RequestParam("id") Long id) {
+        iotDeviceRunLogService.deleteIotDeviceRunLog(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得设备运行数据记录 中间表")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-run-log:query')")
+    public CommonResult<IotDeviceRunLogRespVO> getIotDeviceRunLog(@RequestParam("id") Long id) {
+        IotDeviceRunLogDO iotDeviceRunLog = iotDeviceRunLogService.getIotDeviceRunLog(id);
+        return success(BeanUtils.toBean(iotDeviceRunLog, IotDeviceRunLogRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得设备运行数据记录 中间表分页")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-run-log:query')")
+    public CommonResult<PageResult<IotDeviceRunLogRespVO>> getIotDeviceRunLogPage(@Valid IotDeviceRunLogPageReqVO pageReqVO) {
+        PageResult<IotDeviceRunLogDO> pageResult = iotDeviceRunLogService.getIotDeviceRunLogPage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, IotDeviceRunLogRespVO.class));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出设备运行数据记录 中间表 Excel")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-run-log:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportIotDeviceRunLogExcel(@Valid IotDeviceRunLogPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<IotDeviceRunLogDO> list = iotDeviceRunLogService.getIotDeviceRunLogPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "设备运行数据记录 中间表.xls", "数据", IotDeviceRunLogRespVO.class,
+                        BeanUtils.toBean(list, IotDeviceRunLogRespVO.class));
+    }
+
+}

+ 70 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogPageReqVO.java

@@ -0,0 +1,70 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo;
+
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 设备运行数据记录 中间表分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class IotDeviceRunLogPageReqVO extends PageParam {
+
+    @Schema(description = "部门id 所属小队", example = "4540")
+    private Long deptId;
+
+    @Schema(description = "设备id", example = "9192")
+    private Long deviceId;
+
+    @Schema(description = "设备编码")
+    private String deviceCode;
+
+    @Schema(description = "设备部件")
+    private String deviceComp;
+
+    @Schema(description = "采集点位 信息 code")
+    private String pointCode;
+
+    @Schema(description = "采集点位信息 名称", example = "李四")
+    private String pointName;
+
+    @Schema(description = "数据类型 1手动填报 2自动采集", example = "1")
+    private Integer type;
+
+    @Schema(description = "设备运行记录值 运行公里数km 运行公里数H")
+    private BigDecimal value;
+
+    @Schema(description = "填报时间 or 采集时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] time;
+
+    @Schema(description = "当日运行时间 H")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private BigDecimal[] dailyRunTime;
+
+    @Schema(description = "累计运行时间 H")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private BigDecimal[] totalRunTime;
+
+    @Schema(description = "当日运行里程 H")
+    private BigDecimal dailyMileage;
+
+    @Schema(description = "累计运行里程 H")
+    private BigDecimal totalMileage;
+
+    @Schema(description = "备注", example = "你猜")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 80 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogRespVO.java

@@ -0,0 +1,80 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 设备运行数据记录 中间表 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class IotDeviceRunLogRespVO {
+
+    @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12620")
+    @ExcelProperty("主键id")
+    private Long id;
+
+    @Schema(description = "部门id 所属小队", example = "4540")
+    @ExcelProperty("部门id 所属小队")
+    private Long deptId;
+
+    @Schema(description = "设备id", example = "9192")
+    @ExcelProperty("设备id")
+    private Long deviceId;
+
+    @Schema(description = "设备编码")
+    @ExcelProperty("设备编码")
+    private String deviceCode;
+
+    @Schema(description = "设备部件")
+    @ExcelProperty("设备部件")
+    private String deviceComp;
+
+    @Schema(description = "采集点位 信息 code")
+    @ExcelProperty("采集点位 信息 code")
+    private String pointCode;
+
+    @Schema(description = "采集点位信息 名称", example = "李四")
+    @ExcelProperty("采集点位信息 名称")
+    private String pointName;
+
+    @Schema(description = "数据类型 1手动填报 2自动采集", example = "1")
+    @ExcelProperty("数据类型 1手动填报 2自动采集")
+    private Integer type;
+
+    @Schema(description = "设备运行记录值 运行公里数km 运行公里数H")
+    @ExcelProperty("设备运行记录值 运行公里数km 运行公里数H")
+    private BigDecimal value;
+
+    @Schema(description = "填报时间 or 采集时间")
+    @ExcelProperty("填报时间 or 采集时间")
+    private LocalDateTime time;
+
+    @Schema(description = "当日运行时间 H")
+    @ExcelProperty("当日运行时间 H")
+    private BigDecimal dailyRunTime;
+
+    @Schema(description = "累计运行时间 H")
+    @ExcelProperty("累计运行时间 H")
+    private BigDecimal totalRunTime;
+
+    @Schema(description = "当日运行里程 H")
+    @ExcelProperty("当日运行里程 H")
+    private BigDecimal dailyMileage;
+
+    @Schema(description = "累计运行里程 H")
+    @ExcelProperty("累计运行里程 H")
+    private BigDecimal totalMileage;
+
+    @Schema(description = "备注", example = "你猜")
+    @ExcelProperty("备注")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+}

+ 58 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogSaveReqVO.java

@@ -0,0 +1,58 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 设备运行数据记录 中间表新增/修改 Request VO")
+@Data
+public class IotDeviceRunLogSaveReqVO {
+
+    @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "12620")
+    private Long id;
+
+    @Schema(description = "部门id 所属小队", example = "4540")
+    private Long deptId;
+
+    @Schema(description = "设备id", example = "9192")
+    private Long deviceId;
+
+    @Schema(description = "设备编码")
+    private String deviceCode;
+
+    @Schema(description = "设备部件")
+    private String deviceComp;
+
+    @Schema(description = "采集点位 信息 code")
+    private String pointCode;
+
+    @Schema(description = "采集点位信息 名称", example = "李四")
+    private String pointName;
+
+    @Schema(description = "数据类型 1手动填报 2自动采集", example = "1")
+    private Integer type;
+
+    @Schema(description = "设备运行记录值 运行公里数km 运行公里数H")
+    private BigDecimal value;
+
+    @Schema(description = "填报时间 or 采集时间")
+    private LocalDateTime time;
+
+    @Schema(description = "当日运行时间 H")
+    private BigDecimal dailyRunTime;
+
+    @Schema(description = "累计运行时间 H")
+    private BigDecimal totalRunTime;
+
+    @Schema(description = "当日运行里程 H")
+    private BigDecimal dailyMileage;
+
+    @Schema(description = "累计运行里程 H")
+    private BigDecimal totalMileage;
+
+    @Schema(description = "备注", example = "你猜")
+    private String remark;
+
+}

+ 9 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java

@@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.Data;
 
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 
 
 @Schema(description = "管理后台 - 设备台账 Response VO")
 @Schema(description = "管理后台 - 设备台账 Response VO")
@@ -153,4 +154,12 @@ public class IotDeviceRespVO {
     private String name;
     private String name;
     @Schema(description = "bom节点编码")
     @Schema(description = "bom节点编码")
     private String code;
     private String code;
+
+    /**
+     * 计算字段
+     */
+    @Schema(description = "设备累计运行里程")
+    private BigDecimal totalMileage;
+    @Schema(description = "设备累计运行时间")
+    private BigDecimal totalRunTime;
 }
 }

+ 89 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotdevicerunlog/IotDeviceRunLogDO.java

@@ -0,0 +1,89 @@
+package cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog;
+
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * 设备运行数据记录 中间表 DO
+ *
+ * @author ruiqi
+ */
+@TableName("rq_iot_device_run_log")
+@KeySequence("rq_iot_device_run_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class IotDeviceRunLogDO extends BaseDO {
+
+    /**
+     * 主键id
+     */
+    @TableId
+    private Long id;
+    /**
+     * 部门id 所属小队
+     */
+    private Long deptId;
+    /**
+     * 设备id
+     */
+    private Long deviceId;
+    /**
+     * 设备编码
+     */
+    private String deviceCode;
+    /**
+     * 设备部件
+     */
+    private String deviceComp;
+    /**
+     * 采集点位 信息 code
+     */
+    private String pointCode;
+    /**
+     * 采集点位信息 名称
+     */
+    private String pointName;
+    /**
+     * 数据类型 1手动填报 2自动采集
+     */
+    private Integer type;
+    /**
+     * 设备运行记录值 运行公里数km 运行公里数H
+     */
+    private BigDecimal value;
+    /**
+     * 填报时间 or 采集时间
+     */
+    private LocalDateTime time;
+    /**
+     * 当日运行时间 H
+     */
+    private BigDecimal dailyRunTime;
+    /**
+     * 累计运行时间 H
+     */
+    private BigDecimal totalRunTime;
+    /**
+     * 当日运行里程 H
+     */
+    private BigDecimal dailyMileage;
+    /**
+     * 累计运行里程 H
+     */
+    private BigDecimal totalMileage;
+    /**
+     * 备注
+     */
+    private String remark;
+
+}

+ 38 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java

@@ -0,0 +1,38 @@
+package cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 设备运行数据记录 中间表 Mapper
+ *
+ * @author ruiqi
+ */
+@Mapper
+public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
+
+    default PageResult<IotDeviceRunLogDO> selectPage(IotDeviceRunLogPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceRunLogDO>()
+                .eqIfPresent(IotDeviceRunLogDO::getDeptId, reqVO.getDeptId())
+                .eqIfPresent(IotDeviceRunLogDO::getDeviceId, reqVO.getDeviceId())
+                .eqIfPresent(IotDeviceRunLogDO::getDeviceCode, reqVO.getDeviceCode())
+                .eqIfPresent(IotDeviceRunLogDO::getDeviceComp, reqVO.getDeviceComp())
+                .eqIfPresent(IotDeviceRunLogDO::getPointCode, reqVO.getPointCode())
+                .likeIfPresent(IotDeviceRunLogDO::getPointName, reqVO.getPointName())
+                .eqIfPresent(IotDeviceRunLogDO::getType, reqVO.getType())
+                .eqIfPresent(IotDeviceRunLogDO::getValue, reqVO.getValue())
+                .betweenIfPresent(IotDeviceRunLogDO::getTime, reqVO.getTime())
+                .betweenIfPresent(IotDeviceRunLogDO::getDailyRunTime, reqVO.getDailyRunTime())
+                .betweenIfPresent(IotDeviceRunLogDO::getTotalRunTime, reqVO.getTotalRunTime())
+                .eqIfPresent(IotDeviceRunLogDO::getDailyMileage, reqVO.getDailyMileage())
+                .eqIfPresent(IotDeviceRunLogDO::getTotalMileage, reqVO.getTotalMileage())
+                .eqIfPresent(IotDeviceRunLogDO::getRemark, reqVO.getRemark())
+                .betweenIfPresent(IotDeviceRunLogDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(IotDeviceRunLogDO::getId));
+    }
+
+}

+ 55 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogService.java

@@ -0,0 +1,55 @@
+package cn.iocoder.yudao.module.pms.service.iotdevicerunlog;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
+
+import javax.validation.Valid;
+
+/**
+ * 设备运行数据记录 中间表 Service 接口
+ *
+ * @author ruiqi
+ */
+public interface IotDeviceRunLogService {
+
+    /**
+     * 创建设备运行数据记录 中间表
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createIotDeviceRunLog(@Valid IotDeviceRunLogSaveReqVO createReqVO);
+
+    /**
+     * 更新设备运行数据记录 中间表
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateIotDeviceRunLog(@Valid IotDeviceRunLogSaveReqVO updateReqVO);
+
+    /**
+     * 删除设备运行数据记录 中间表
+     *
+     * @param id 编号
+     */
+    void deleteIotDeviceRunLog(Long id);
+
+    /**
+     * 获得设备运行数据记录 中间表
+     *
+     * @param id 编号
+     * @return 设备运行数据记录 中间表
+     */
+    IotDeviceRunLogDO getIotDeviceRunLog(Long id);
+
+    /**
+     * 获得设备运行数据记录 中间表分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 设备运行数据记录 中间表分页
+     */
+    PageResult<IotDeviceRunLogDO> getIotDeviceRunLogPage(IotDeviceRunLogPageReqVO pageReqVO);
+
+}

+ 71 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogServiceImpl.java

@@ -0,0 +1,71 @@
+package cn.iocoder.yudao.module.pms.service.iotdevicerunlog;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog.IotDeviceRunLogMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import javax.annotation.Resource;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_RUN_LOG_NOT_EXISTS;
+
+/**
+ * 设备运行数据记录 中间表 Service 实现类
+ *
+ * @author ruiqi
+ */
+@Service
+@Validated
+public class IotDeviceRunLogServiceImpl implements IotDeviceRunLogService {
+
+    @Resource
+    private IotDeviceRunLogMapper iotDeviceRunLogMapper;
+
+    @Override
+    public Long createIotDeviceRunLog(IotDeviceRunLogSaveReqVO createReqVO) {
+        // 插入
+        IotDeviceRunLogDO iotDeviceRunLog = BeanUtils.toBean(createReqVO, IotDeviceRunLogDO.class);
+        iotDeviceRunLogMapper.insert(iotDeviceRunLog);
+        // 返回
+        return iotDeviceRunLog.getId();
+    }
+
+    @Override
+    public void updateIotDeviceRunLog(IotDeviceRunLogSaveReqVO updateReqVO) {
+        // 校验存在
+        validateIotDeviceRunLogExists(updateReqVO.getId());
+        // 更新
+        IotDeviceRunLogDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceRunLogDO.class);
+        iotDeviceRunLogMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteIotDeviceRunLog(Long id) {
+        // 校验存在
+        validateIotDeviceRunLogExists(id);
+        // 删除
+        iotDeviceRunLogMapper.deleteById(id);
+    }
+
+    private void validateIotDeviceRunLogExists(Long id) {
+        if (iotDeviceRunLogMapper.selectById(id) == null) {
+            throw exception(IOT_DEVICE_RUN_LOG_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public IotDeviceRunLogDO getIotDeviceRunLog(Long id) {
+        return iotDeviceRunLogMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<IotDeviceRunLogDO> getIotDeviceRunLogPage(IotDeviceRunLogPageReqVO pageReqVO) {
+        return iotDeviceRunLogMapper.selectPage(pageReqVO);
+    }
+
+}

+ 22 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceMapper.xml

@@ -49,6 +49,8 @@
 
 
     <select id="deviceAssociateBomList"
     <select id="deviceAssociateBomList"
             resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
             resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO">
+        SELECT *
+        FROM (
         SELECT
         SELECT
         t.id ,
         t.id ,
         t.device_code,
         t.device_code,
@@ -79,5 +81,25 @@
                 #{key}
                 #{key}
             </foreach>
             </foreach>
         </if>
         </if>
+        )t2
+        LEFT JOIN (
+        SELECT
+        l.device_id,
+        l.total_run_time,
+        l.total_mileage,
+        l.time
+        FROM rq_iot_device_run_log l
+        RIGHT JOIN (
+        SELECT
+        device_id,
+        MAX(time) AS latest_time,
+        MAX(id)	AS max_id
+        FROM rq_iot_device_run_log
+        GROUP BY device_id
+        ) AS latest
+        ON l.device_id = latest.device_id
+        AND l.time = latest.latest_time
+        AND l.id = latest.max_id
+        ) tmp ON tmp.device_id = t2.id
     </select>
     </select>
 </mapper>
 </mapper>