zhangcl 3 дней назад
Родитель
Сommit
cc22b6836e

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

@@ -1,6 +1,9 @@
 package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.LocalDateTimeUtil;
+import cn.hutool.core.util.ObjUtil;
 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;
@@ -12,6 +15,7 @@ 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.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
 import cn.iocoder.yudao.module.pms.service.IotDeviceService;
@@ -104,10 +108,35 @@ public class IotDeviceAllotLogController {
     public void exportIotDeviceAllotLogExcel(@Valid IotDeviceAllotLogPageReqVO pageReqVO,
               HttpServletResponse response) throws IOException {
         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        // 先查询符合条件的设备id集合 再根据deviceIds集合查询对应的调拨记录
+        IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
+        BeanUtils.copyProperties(pageReqVO, deviceReqVO);
+        deviceReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<IotDeviceRespVO> relationDevices = iotDeviceService.allotRelationDevices(deviceReqVO).getList();
+        List<Long> deviceIds = new ArrayList<>();
+
+        if (CollUtil.isNotEmpty(relationDevices)) {
+            relationDevices.forEach(device -> {
+                deviceIds.add(device.getId());
+            });
+        }
+        if (CollUtil.isEmpty(deviceIds)) {
+            deviceIds.add(Long.MAX_VALUE);
+        }
+        pageReqVO.setDeviceIds(deviceIds);
         List<IotDeviceAllotLogDO> list = iotDeviceAllotLogService.getIotDeviceAllotLogPage(pageReqVO).getList();
+        List<IotDeviceAllotLogRespVO> deviceAllotLogs = buildDeviceAllotList(list);
+        if (CollUtil.isNotEmpty(deviceAllotLogs)) {
+            deviceAllotLogs.forEach(log -> {
+                // 创建时间 格式化 yyyy-MM-dd
+                if (ObjUtil.isNotEmpty(log.getCreateTime())) {
+                    log.setCreateTimeStr(LocalDateTimeUtil.format(log.getCreateTime(), DatePattern.NORM_DATETIME_PATTERN));
+                }
+            });
+        }
         // 导出 Excel
-        ExcelUtils.write(response, "设备调拨日志.xls", "数据", IotDeviceAllotLogRespVO.class,
-                        BeanUtils.toBean(list, IotDeviceAllotLogRespVO.class));
+        ExcelUtils.write(response, "设备调拨日志.xls", "设备调拨日志", IotDeviceAllotLogRespVO.class,
+                deviceAllotLogs);
     }
 
     private List<IotDeviceAllotLogRespVO> buildDeviceAllotList(List<IotDeviceAllotLogDO> deviceAllots) {

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

@@ -8,6 +8,7 @@ import lombok.ToString;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.time.LocalDateTime;
+import java.util.Collection;
 
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
@@ -36,4 +37,27 @@ public class IotDeviceAllotLogPageReqVO extends PageParam {
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
 
+    /**
+     * 扩展属性
+     */
+    @Schema(description = "设备id集合", example = "12,13")
+    private Collection<Long> deviceIds;
+
+    @Schema(description = "设备编码", example = "YF321")
+    private String deviceCode;
+
+    @Schema(description = "设备名称", example = "增压机")
+    private String deviceName;
+
+    @Schema(description = "设备品牌", example = "寿力")
+    private String brand;
+
+    @Schema(description = "设备状态", example = "sg")
+    private String deviceStatus;
+
+    @Schema(description = "资产性质")
+    private String assetProperty;
+
+    @Schema(description = "是否设置过设备责任人/调整过状态/调拨 Y设置过 N未设置 A全部")
+    private String setFlag;
 }

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

@@ -12,52 +12,56 @@ import java.time.LocalDateTime;
 @ExcelIgnoreUnannotated
 public class IotDeviceAllotLogRespVO {
 
+    @Schema(description = "设备编码", example = "YF001")
+    @ExcelProperty("设备编码")
+    private String deviceCode;
+
+    @Schema(description = "设备名称", example = "钻机")
+    @ExcelProperty("设备名称")
+    private String deviceName;
+
+    @Schema(description = "调拨前部门", example = "YF001")
+    @ExcelProperty("调整前部门")
+    private String oldDeptName;
+
+    @Schema(description = "调拨后部门", example = "钻机")
+    @ExcelProperty("调整后部门")
+    private String newDeptName;
+
     @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("设备调拨原因")
+    @ExcelProperty("调整原因")
     private String reason;
 
     @Schema(description = "备注", example = "随便")
-    @ExcelProperty("备注")
     private String remark;
 
+    @Schema(description = "创建人姓名", example = "张三")
+    @ExcelProperty("调整人")
+    private String creatorName;
+
     @Schema(description = "创建时间")
-    @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
+    @Schema(description = "创建时间")
+    @ExcelProperty("调整时间")
+    private String createTimeStr;
+
     /**
      * 扩展字段
      */
-    @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;
 }

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

@@ -18,12 +18,13 @@ public interface IotDeviceAllotLogMapper extends BaseMapperX<IotDeviceAllotLogDO
     default PageResult<IotDeviceAllotLogDO> selectPage(IotDeviceAllotLogPageReqVO reqVO) {
         return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceAllotLogDO>()
                 .eqIfPresent(IotDeviceAllotLogDO::getDeviceId, reqVO.getDeviceId())
+                .inIfPresent(IotDeviceAllotLogDO::getDeviceId, reqVO.getDeviceIds())
                 .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));
+                .orderByDesc(IotDeviceAllotLogDO::getDeviceId));
     }
 
 }