Quellcode durchsuchen

pms功能优化 设备调拨

zhangcl vor 3 Monaten
Ursprung
Commit
589a90d989
15 geänderte Dateien mit 605 neuen und 4 gelöschten Zeilen
  1. 1 0
      yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java
  2. 14 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java
  3. 149 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/IotDeviceAllotLogController.java
  4. 39 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotLogPageReqVO.java
  5. 63 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotLogRespVO.java
  6. 28 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotLogSaveReqVO.java
  7. 28 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotSaveReqVO.java
  8. 0 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicestatuslog/IotDeviceStatusLogController.java
  9. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceSimpleRespVO.java
  10. 50 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotdeviceallotlog/IotDeviceAllotLogDO.java
  11. 1 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java
  12. 29 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdeviceallotlog/IotDeviceAllotLogMapper.java
  13. 64 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdeviceallotlog/IotDeviceAllotLogService.java
  14. 120 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdeviceallotlog/IotDeviceAllotLogServiceImpl.java
  15. 13 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/util/IotDeviceConvert.java

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

@@ -60,4 +60,5 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_SAP_PICKING_LIST_NOT_EXISTS = new ErrorCode(147, "PMS SAP 领料单不存在");
     ErrorCode IOT_DEVICE_PERSON_NOT_EXISTS = new ErrorCode(148, "设备负责人分配不存在");
     ErrorCode IOT_DEVICE_STATUS_LOG_NOT_EXISTS = new ErrorCode(149, "设备状态调整日志不存在");
+    ErrorCode IOT_DEVICE_ALLOT_LOG_NOT_EXISTS = new ErrorCode(150, "设备调拨日志不存在");
 }

+ 14 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -7,6 +7,7 @@ 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.iotdeviceallotlog.vo.IotDeviceAllotSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceperson.vo.IotDevicePersonRelationSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.*;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
@@ -18,6 +19,7 @@ import cn.iocoder.yudao.module.pms.service.DeviceServiceImpl;
 import cn.iocoder.yudao.module.pms.service.IotDeviceService;
 import cn.iocoder.yudao.module.pms.service.IotProductClassifyService;
 import cn.iocoder.yudao.module.pms.service.iotbom.IotBomService;
+import cn.iocoder.yudao.module.pms.service.iotdeviceallotlog.IotDeviceAllotLogService;
 import cn.iocoder.yudao.module.pms.service.iotdeviceperson.IotDevicePersonService;
 import cn.iocoder.yudao.module.pms.service.iotmodel.IotModelService;
 import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
@@ -77,6 +79,8 @@ public class IotDeviceController {
     private DeviceServiceImpl deviceServiceImpl;
     @Autowired
     private IotDevicePersonService iotDevicePersonService;
+    @Autowired
+    private IotDeviceAllotLogService iotDeviceAllotLogService;
 
     @PostMapping("/create")
     @Operation(summary = "创建设备台账")
@@ -87,11 +91,18 @@ public class IotDeviceController {
 
     @PostMapping("/saveDeviceStatuses")
     @Operation(summary = "批量调整设备状态")
-    @PreAuthorize("@ss.hasPermission('pms:iot-device-person:create')")
+    @PreAuthorize("@ss.hasPermission('rq:iot-device:create')")
     public CommonResult<Long> saveDeviceStatuses(@Valid @RequestBody List<IotDevicePersonRelationSaveReqVO> reqVOS) {
         return success(iotDevicePersonService.saveDeviceStatuses(reqVOS));
     }
 
+    @PostMapping("/saveDeviceAllot")
+    @Operation(summary = "设备调拨")
+    @PreAuthorize("@ss.hasPermission('rq:iot-device:create')")
+    public CommonResult<Long> saveDeviceAllot(@Valid @RequestBody List<IotDeviceAllotSaveReqVO> reqVOS) {
+        return success(iotDeviceAllotLogService.saveDeviceAllot(reqVOS));
+    }
+
     @PutMapping("/update")
     @Operation(summary = "更新设备台账")
     @PreAuthorize("@ss.hasPermission('rq:iot-device:update')")
@@ -169,7 +180,8 @@ public class IotDeviceController {
     @Operation(summary = "获取设备精简信息列表", description = "只包含被开启的设备,主要用于前端的下拉选项")
     public CommonResult<List<IotDeviceSimpleRespVO>> getSimpleDeviceList(@Valid IotDevicePageReqVO reqVO) {
         List<IotDeviceDO> list = iotDeviceService.getSimpleDeviceList(reqVO);
-        return success(BeanUtils.toBean(list, IotDeviceSimpleRespVO.class));
+        Map<Long, DeptDO> deptMap = deptService.getDeptMap(convertList(list, IotDeviceDO::getDeptId));
+        return success(new ArrayList<>(IotDeviceConvert.INSTANCE.convertSimpleLists(list, deptMap)));
     }
 
     @GetMapping("/responsiblePage")

+ 149 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/IotDeviceAllotLogController.java

@@ -0,0 +1,149 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog;
+
+import cn.hutool.core.collection.CollUtil;
+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.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+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.iotdeviceallotlog.vo.IotDeviceAllotLogPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogRespVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogSaveReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
+import cn.iocoder.yudao.module.pms.service.IotDeviceService;
+import cn.iocoder.yudao.module.pms.service.iotdeviceallotlog.IotDeviceAllotLogService;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
+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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
+
+@Tag(name = "管理后台 - 设备调拨日志")
+@RestController
+@RequestMapping("/pms/iot-device-allot-log")
+@Validated
+public class IotDeviceAllotLogController {
+
+    @Resource
+    private IotDeviceAllotLogService iotDeviceAllotLogService;
+    @Resource
+    private AdminUserApi adminUserApi;
+    @Resource
+    private IotDeviceService iotDeviceService;
+    @Resource
+    private DeptService deptService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建设备调拨日志")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:create')")
+    public CommonResult<Long> createIotDeviceAllotLog(@Valid @RequestBody IotDeviceAllotLogSaveReqVO createReqVO) {
+        return success(iotDeviceAllotLogService.createIotDeviceAllotLog(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新设备调拨日志")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:update')")
+    public CommonResult<Boolean> updateIotDeviceAllotLog(@Valid @RequestBody IotDeviceAllotLogSaveReqVO updateReqVO) {
+        iotDeviceAllotLogService.updateIotDeviceAllotLog(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除设备调拨日志")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:delete')")
+    public CommonResult<Boolean> deleteIotDeviceAllotLog(@RequestParam("id") Long id) {
+        iotDeviceAllotLogService.deleteIotDeviceAllotLog(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得设备调拨日志")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:query')")
+    public CommonResult<IotDeviceAllotLogRespVO> getIotDeviceAllotLog(@RequestParam("id") Long id) {
+        IotDeviceAllotLogDO iotDeviceAllotLog = iotDeviceAllotLogService.getIotDeviceAllotLog(id);
+        return success(BeanUtils.toBean(iotDeviceAllotLog, IotDeviceAllotLogRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得设备调拨日志分页")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:query')")
+    public CommonResult<PageResult<IotDeviceAllotLogRespVO>> getIotDeviceAllotLogPage(@Valid IotDeviceAllotLogPageReqVO pageReqVO) {
+        PageResult<IotDeviceAllotLogDO> pageResult = iotDeviceAllotLogService.getIotDeviceAllotLogPage(pageReqVO);
+        return success(new PageResult<>(buildDeviceAllotList(pageResult.getList()), pageResult.getTotal()));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出设备调拨日志 Excel")
+    @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportIotDeviceAllotLogExcel(@Valid IotDeviceAllotLogPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<IotDeviceAllotLogDO> list = iotDeviceAllotLogService.getIotDeviceAllotLogPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "设备调拨日志.xls", "数据", IotDeviceAllotLogRespVO.class,
+                        BeanUtils.toBean(list, IotDeviceAllotLogRespVO.class));
+    }
+
+    private List<IotDeviceAllotLogRespVO> buildDeviceAllotList(List<IotDeviceAllotLogDO> deviceAllots) {
+        if (CollUtil.isEmpty(deviceAllots)) {
+            return Collections.emptyList();
+        }
+        // 将调拨前部门、调拨后部门id设置到相同的集合
+        List<Long> deptIds = new ArrayList<>();
+        deviceAllots.forEach(deviceAllot -> {
+            deptIds.add(deviceAllot.getOldDeptId());
+            deptIds.add(deviceAllot.getNewDeptId());
+        });
+        // 调拨前部门集合
+        Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
+        // 操作人集合
+        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(deviceAllots,
+                allot -> Stream.of(NumberUtils.parseLong(allot.getCreator()))));
+        // 组装设备信息
+        Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(deviceAllots,
+                allot -> Stream.of(allot.getDeviceId())));
+        // 2. 转换成 VO
+        return BeanUtils.toBean(deviceAllots, IotDeviceAllotLogRespVO.class, allotVO -> {
+            // 设置设备相关信息
+            MapUtils.findAndThen(deviceMap, allotVO.getDeviceId(),
+                    device -> allotVO.setDeviceName(device.getDeviceName()));
+            MapUtils.findAndThen(deviceMap, allotVO.getDeviceId(),
+                    device -> allotVO.setDeviceCode(device.getDeviceCode()));
+            // 设置 调拨前部门 调拨后部门信息
+            MapUtils.findAndThen(deptMap, allotVO.getOldDeptId(), dept -> allotVO.setOldDeptName(dept.getName()));
+            MapUtils.findAndThen(deptMap, allotVO.getNewDeptId(), dept -> allotVO.setNewDeptName(dept.getName()));
+            // 设置操作人信息
+            MapUtils.findAndThen(userMap, NumberUtils.parseLong(allotVO.getCreator()),
+                    user -> allotVO.setCreatorName(user.getNickname()));
+        });
+    }
+
+}

+ 39 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotLogPageReqVO.java

@@ -0,0 +1,39 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.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.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 IotDeviceAllotLogPageReqVO extends PageParam {
+
+    @Schema(description = "设备id", example = "10930")
+    private Long deviceId;
+
+    @Schema(description = "设备调拨前部门", example = "30278")
+    private Long oldDeptId;
+
+    @Schema(description = "设备调拨后部门", example = "27763")
+    private Long newDeptId;
+
+    @Schema(description = "设备调拨原因", example = "不好")
+    private String reason;
+
+    @Schema(description = "备注", example = "随便")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 63 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotLogRespVO.java

@@ -0,0 +1,63 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.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.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 设备调拨日志 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class IotDeviceAllotLogRespVO {
+
+    @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13465")
+    @ExcelProperty("主键id")
+    private Long id;
+
+    @Schema(description = "设备id", example = "10930")
+    @ExcelProperty("设备id")
+    private Long deviceId;
+
+    @Schema(description = "设备调拨前部门", example = "30278")
+    @ExcelProperty("设备调拨前部门")
+    private Long oldDeptId;
+
+    @Schema(description = "设备调拨后部门", example = "27763")
+    @ExcelProperty("设备调拨后部门")
+    private Long newDeptId;
+
+    @Schema(description = "设备调拨原因", example = "不好")
+    @ExcelProperty("设备调拨原因")
+    private String reason;
+
+    @Schema(description = "备注", example = "随便")
+    @ExcelProperty("备注")
+    private String remark;
+
+    @Schema(description = "创建时间")
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+    /**
+     * 扩展字段
+     */
+    @Schema(description = "设备编码", example = "YF001")
+    private String deviceCode;
+
+    @Schema(description = "设备名称", example = "钻机")
+    private String deviceName;
+
+    @Schema(description = "创建人姓名", example = "张三")
+    private String creatorName;
+
+    @Schema(description = "创建人id", example = "101")
+    private String creator;
+
+    @Schema(description = "调拨前部门名称", example = "YF001")
+    private String oldDeptName;
+
+    @Schema(description = "调拨后部门名称", example = "钻机")
+    private String newDeptName;
+}

+ 28 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotLogSaveReqVO.java

@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Schema(description = "管理后台 - 设备调拨日志新增/修改 Request VO")
+@Data
+public class IotDeviceAllotLogSaveReqVO {
+
+    @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13465")
+    private Long id;
+
+    @Schema(description = "设备id", example = "10930")
+    private Long deviceId;
+
+    @Schema(description = "设备调拨前部门", example = "30278")
+    private Long oldDeptId;
+
+    @Schema(description = "设备调拨后部门", example = "27763")
+    private Long newDeptId;
+
+    @Schema(description = "设备调拨原因", example = "不好")
+    private String reason;
+
+    @Schema(description = "备注", example = "随便")
+    private String remark;
+
+}

+ 28 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdeviceallotlog/vo/IotDeviceAllotSaveReqVO.java

@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Schema(description = "管理后台 - 设备调拨 Request VO")
+@Data
+public class IotDeviceAllotSaveReqVO {
+
+    @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "13572")
+    private Long id;
+
+    @Schema(description = "设备id", requiredMode = Schema.RequiredMode.REQUIRED, example = "30175")
+    @NotNull(message = "设备id不能为空")
+    private Long deviceId;
+
+    @Schema(description = "设备调拨前部门", example = "4801")
+    private Long deptId;
+
+    @Schema(description = "调拨原因", example = "项目要求")
+    private String reason;
+
+    @Schema(description = "备注", example = "项目要求")
+    private String remark;
+
+}

+ 0 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicestatuslog/IotDeviceStatusLogController.java

@@ -37,7 +37,6 @@ import java.util.stream.Stream;
 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
 
 @Tag(name = "管理后台 - 设备状态调整日志")
 @RestController

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

@@ -45,4 +45,10 @@ public class IotDeviceSimpleRespVO {
     @Schema(description = "图片", example = "https://www.iocoder.cn")
     @ExcelProperty("图片")
     private String picUrl;
+
+    /**
+     * 扩展字段
+     */
+    @Schema(description = "设备所属部门名称", example = "HY-1")
+    private String deptName;
 }

+ 50 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotdeviceallotlog/IotDeviceAllotLogDO.java

@@ -0,0 +1,50 @@
+package cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog;
+
+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.*;
+
+/**
+ * 设备调拨日志 DO
+ *
+ * @author ruiqi
+ */
+@TableName("rq_iot_device_allot_log")
+@KeySequence("rq_iot_device_allot_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class IotDeviceAllotLogDO extends BaseDO {
+
+    /**
+     * 主键id
+     */
+    @TableId
+    private Long id;
+    /**
+     * 设备id
+     */
+    private Long deviceId;
+    /**
+     * 设备调拨前部门
+     */
+    private Long oldDeptId;
+    /**
+     * 设备调拨后部门
+     */
+    private Long newDeptId;
+    /**
+     * 设备调拨原因
+     */
+    private String reason;
+    /**
+     * 备注
+     */
+    private String remark;
+
+}

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java

@@ -22,7 +22,7 @@ import java.util.List;
 public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
     default PageResult<IotDeviceDO> selectPage(IotDevicePageReqVO reqVO, Collection<Long> deptIds) {
         return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceDO>()
-                .eqIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
+                .likeIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
                 .likeIfPresent(IotDeviceDO::getDeviceName, reqVO.getDeviceName())
                 .eqIfPresent(IotDeviceDO::getBrand, reqVO.getBrand())
                 .eqIfPresent(IotDeviceDO::getModel, reqVO.getModel())

+ 29 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdeviceallotlog/IotDeviceAllotLogMapper.java

@@ -0,0 +1,29 @@
+package cn.iocoder.yudao.module.pms.dal.mysql.iotdeviceallotlog;
+
+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.iotdeviceallotlog.vo.IotDeviceAllotLogPageReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 设备调拨日志 Mapper
+ *
+ * @author ruiqi
+ */
+@Mapper
+public interface IotDeviceAllotLogMapper extends BaseMapperX<IotDeviceAllotLogDO> {
+
+    default PageResult<IotDeviceAllotLogDO> selectPage(IotDeviceAllotLogPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceAllotLogDO>()
+                .eqIfPresent(IotDeviceAllotLogDO::getDeviceId, reqVO.getDeviceId())
+                .eqIfPresent(IotDeviceAllotLogDO::getOldDeptId, reqVO.getOldDeptId())
+                .eqIfPresent(IotDeviceAllotLogDO::getNewDeptId, reqVO.getNewDeptId())
+                .eqIfPresent(IotDeviceAllotLogDO::getReason, reqVO.getReason())
+                .eqIfPresent(IotDeviceAllotLogDO::getRemark, reqVO.getRemark())
+                .betweenIfPresent(IotDeviceAllotLogDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(IotDeviceAllotLogDO::getId));
+    }
+
+}

+ 64 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdeviceallotlog/IotDeviceAllotLogService.java

@@ -0,0 +1,64 @@
+package cn.iocoder.yudao.module.pms.service.iotdeviceallotlog;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogSaveReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
+
+import javax.validation.Valid;
+import java.util.List;
+
+/**
+ * 设备调拨日志 Service 接口
+ *
+ * @author ruiqi
+ */
+public interface IotDeviceAllotLogService {
+
+    /**
+     * 创建设备调拨日志
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createIotDeviceAllotLog(@Valid IotDeviceAllotLogSaveReqVO createReqVO);
+
+    /**
+     * 更新设备调拨日志
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateIotDeviceAllotLog(@Valid IotDeviceAllotLogSaveReqVO updateReqVO);
+
+    /**
+     * 删除设备调拨日志
+     *
+     * @param id 编号
+     */
+    void deleteIotDeviceAllotLog(Long id);
+
+    /**
+     * 获得设备调拨日志
+     *
+     * @param id 编号
+     * @return 设备调拨日志
+     */
+    IotDeviceAllotLogDO getIotDeviceAllotLog(Long id);
+
+    /**
+     * 获得设备调拨日志分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 设备调拨日志分页
+     */
+    PageResult<IotDeviceAllotLogDO> getIotDeviceAllotLogPage(IotDeviceAllotLogPageReqVO pageReqVO);
+
+    /**
+     * 保存设备调拨记录
+     *
+     * @param reqVOS 设备调拨 关联 集合
+     * @return
+     */
+    Long saveDeviceAllot(List<IotDeviceAllotSaveReqVO> reqVOS);
+}

+ 120 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdeviceallotlog/IotDeviceAllotLogServiceImpl.java

@@ -0,0 +1,120 @@
+package cn.iocoder.yudao.module.pms.service.iotdeviceallotlog;
+
+import cn.hutool.core.collection.CollUtil;
+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.iotdeviceallotlog.vo.IotDeviceAllotLogPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogSaveReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotdeviceallotlog.IotDeviceAllotLogMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_ALLOT_LOG_NOT_EXISTS;
+
+/**
+ * 设备调拨日志 Service 实现类
+ *
+ * @author ruiqi
+ */
+@Service
+@Validated
+public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
+
+    @Resource
+    private IotDeviceAllotLogMapper iotDeviceAllotLogMapper;
+    @Resource
+    private IotDeviceMapper iotDeviceMapper;
+
+    @Override
+    public Long createIotDeviceAllotLog(IotDeviceAllotLogSaveReqVO createReqVO) {
+        // 插入
+        IotDeviceAllotLogDO iotDeviceAllotLog = BeanUtils.toBean(createReqVO, IotDeviceAllotLogDO.class);
+        iotDeviceAllotLogMapper.insert(iotDeviceAllotLog);
+        // 返回
+        return iotDeviceAllotLog.getId();
+    }
+
+    @Override
+    public void updateIotDeviceAllotLog(IotDeviceAllotLogSaveReqVO updateReqVO) {
+        // 校验存在
+        validateIotDeviceAllotLogExists(updateReqVO.getId());
+        // 更新
+        IotDeviceAllotLogDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceAllotLogDO.class);
+        iotDeviceAllotLogMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteIotDeviceAllotLog(Long id) {
+        // 校验存在
+        validateIotDeviceAllotLogExists(id);
+        // 删除
+        iotDeviceAllotLogMapper.deleteById(id);
+    }
+
+    private void validateIotDeviceAllotLogExists(Long id) {
+        if (iotDeviceAllotLogMapper.selectById(id) == null) {
+            throw exception(IOT_DEVICE_ALLOT_LOG_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public IotDeviceAllotLogDO getIotDeviceAllotLog(Long id) {
+        return iotDeviceAllotLogMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<IotDeviceAllotLogDO> getIotDeviceAllotLogPage(IotDeviceAllotLogPageReqVO pageReqVO) {
+        return iotDeviceAllotLogMapper.selectPage(pageReqVO);
+    }
+
+    @Override
+    public Long saveDeviceAllot(List<IotDeviceAllotSaveReqVO> reqVOS) {
+        // 批量保存设备的状态
+        if (CollUtil.isEmpty(reqVOS)) {
+            throw exception(IOT_DEVICE_ALLOT_LOG_NOT_EXISTS);
+        }
+        // 查询出所有要保存设备的id
+        List<Long> deviceIds = new ArrayList<>();
+        reqVOS.forEach(req -> {
+            deviceIds.add(req.getDeviceId());
+        });
+        List<IotDeviceDO> devices = iotDeviceMapper.selectList("id", deviceIds);
+        Map<Long, IotDeviceDO> deviceMap = devices.stream()
+                .collect(Collectors.toMap(IotDeviceDO::getId, device -> device));
+        List<IotDeviceAllotLogDO> deviceAllotLogs = new ArrayList<>();
+        List<IotDeviceDO> tobeUpdatedDevices = new ArrayList<>();
+        reqVOS.forEach(req -> {
+            if (deviceMap.containsKey(req.getDeviceId()) && !req.getDeptId().equals(deviceMap.get(req.getDeviceId()).getDeptId())) {
+                IotDeviceAllotLogDO tempDeviceAllot = new IotDeviceAllotLogDO();
+                tempDeviceAllot.setDeviceId(req.getDeviceId());
+                tempDeviceAllot.setOldDeptId(deviceMap.get(req.getDeviceId()).getDeptId());
+                tempDeviceAllot.setNewDeptId(req.getDeptId());
+                tempDeviceAllot.setReason(req.getReason());
+                deviceAllotLogs.add(tempDeviceAllot);
+                IotDeviceDO device = deviceMap.get(req.getDeviceId());
+                device.setDeptId(req.getDeptId());
+                tobeUpdatedDevices.add(device);
+            }
+        });
+        if (CollUtil.isNotEmpty(deviceAllotLogs)) {
+            iotDeviceAllotLogMapper.insertBatch(deviceAllotLogs);
+        }
+        // 批量修改 设备的状态
+        if (CollUtil.isNotEmpty(tobeUpdatedDevices)) {
+            iotDeviceMapper.updateBatch(tobeUpdatedDevices);
+        }
+        return 0l;
+    }
+
+}

+ 13 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/util/IotDeviceConvert.java

@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSimpleRespVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSimpleRespVO;
@@ -30,6 +31,18 @@ public interface IotDeviceConvert {
         return CollectionUtils.convertList(list, de -> convert(de, deptMap.get(de.getDeptId())));
     }
 
+    default List<IotDeviceSimpleRespVO> convertSimpleLists(List<IotDeviceDO> list, Map<Long, DeptDO> deptMap) {
+        return CollectionUtils.convertList(list, de -> convert2(de, deptMap.get(de.getDeptId())));
+    }
+
+    default IotDeviceSimpleRespVO convert2(IotDeviceDO device, DeptDO dept) {
+        IotDeviceSimpleRespVO deviceVO = BeanUtils.toBean(device, IotDeviceSimpleRespVO.class);
+        if (dept != null) {
+            deviceVO.setDeptName(dept.getName());
+        }
+        return deviceVO;
+    }
+
     default List<IotDeviceRespVO> convertList1(List<IotDeviceRespVO> list, Map<Long, DeptDO> deptMap) {
         return CollectionUtils.convertList(list, de -> convert1(de, deptMap.get(de.getDeptId())));
     }