Browse Source

pms 保养工单 上传附件

zhangcl 2 days ago
parent
commit
fd7086687b

+ 2 - 1
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/AttachmentTypeEnum.java

@@ -9,7 +9,8 @@ public enum AttachmentTypeEnum {
     EXTERNAL_RENTAL("EXTERNAL_RENTAL", "外租设备", 1),
     CONSTRUCTION_DESIGN("CONSTRUCTION_DESIGN", "工程设计", 2),
     GEOLOGICAL_DESIGN("GEOLOGICAL_DESIGN", "地质设计", 3),
-    COMPLETION_REPORT("COMPLETION_REPORT", "完井报告", 4);
+    COMPLETION_REPORT("COMPLETION_REPORT", "完井报告", 4),
+    MAINTENANCE_STANDARD("MAINTENANCE_STANDARD", "保养标准", 5);
 
     private String code;
     private String msg;

+ 38 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorder/IotMainWorkOrderController.java

@@ -14,12 +14,17 @@ 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.iotattachment.vo.IotAttachmentPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.*;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceExportRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotattachment.IotAttachmentDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorder.IotMainWorkOrderDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
+import cn.iocoder.yudao.module.pms.enums.AttachmentCategoryEnum;
+import cn.iocoder.yudao.module.pms.enums.AttachmentTypeEnum;
+import cn.iocoder.yudao.module.pms.service.iotattachment.IotAttachmentService;
 import cn.iocoder.yudao.module.pms.service.iotdeviceperson.IotDevicePersonService;
 import cn.iocoder.yudao.module.pms.service.iotmainworkorder.IotMainWorkOrderService;
 import cn.iocoder.yudao.module.pms.service.iotmainworkorderbom.IotMainWorkOrderBomService;
@@ -70,6 +75,8 @@ public class IotMainWorkOrderController {
     private IotDevicePersonService iotDevicePersonService;
     @Resource
     private DictDataService dictDataService;
+    @Resource
+    private IotAttachmentService iotAttachmentService;
 
     @PostMapping("/create")
     @Operation(summary = "创建保养工单")
@@ -94,6 +101,14 @@ public class IotMainWorkOrderController {
         return success(true);
     }
 
+    @PutMapping("/hiWorkOrderAttachment")
+    @Operation(summary = "历史保养工单 上传附件")
+    @PreAuthorize("@ss.hasPermission('pms:iot-main-work-order:update')")
+    public CommonResult<Boolean> hiWorkOrderAttachment(@Valid @RequestBody IotMainWorkOrderSaveReqVO orderReqVO) {
+        iotMainWorkOrderService.hiWorkOrderAttachment(orderReqVO);
+        return success(true);
+    }
+
     @PutMapping("/modifyWorkOrder")
     @Operation(summary = "修改退回的保养工单")
     @PreAuthorize("@ss.hasPermission('pms:iot-main-work-order:update')")
@@ -133,7 +148,29 @@ public class IotMainWorkOrderController {
     @PreAuthorize("@ss.hasPermission('pms:iot-main-work-order:query')")
     public CommonResult<IotMainWorkOrderRespVO> getIotMainWorkOrder(@RequestParam("id") Long id) {
         IotMainWorkOrderDO iotMainWorkOrder = iotMainWorkOrderService.getIotMainWorkOrder(id);
-        return success(BeanUtils.toBean(iotMainWorkOrder, IotMainWorkOrderRespVO.class));
+        return success(buildWorkOrder(iotMainWorkOrder));
+    }
+
+    /**
+     * 查询保养工单详情
+     * @param iotMainWorkOrder
+     * @return
+     */
+    private IotMainWorkOrderRespVO buildWorkOrder(IotMainWorkOrderDO iotMainWorkOrder) {
+        if (ObjUtil.isEmpty(iotMainWorkOrder)) {
+            return new IotMainWorkOrderRespVO();
+        }
+        IotMainWorkOrderRespVO workOrderVO = BeanUtils.toBean(iotMainWorkOrder, IotMainWorkOrderRespVO.class);
+        // 查询当前工单关联的附件信息
+        IotAttachmentPageReqVO reqVO = new IotAttachmentPageReqVO();
+        reqVO.setBizId(workOrderVO.getId());
+        reqVO.setCategory(AttachmentCategoryEnum.MAINTENANCE.getCode());
+        reqVO.setType(AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode());
+        List<IotAttachmentDO> attachments = iotAttachmentService.getIotAttachments(reqVO);
+        if (CollUtil.isNotEmpty(attachments)) {
+            workOrderVO.setAttachments(attachments);
+        }
+        return workOrderVO;
     }
 
     @GetMapping("/deviceWorkOrder")

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorder/vo/IotMainWorkOrderRespVO.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo;
 
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomRespVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotattachment.IotAttachmentDO;
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -126,4 +127,7 @@ public class IotMainWorkOrderRespVO {
 
     @Schema(description = "筛选了指定设备的保养工单bom")
     private List<IotMainWorkOrderBomRespVO> workOrderBomS;
+
+    @Schema(description = "附件列表")
+    private List<IotAttachmentDO> attachments;
 }

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmainworkorder/vo/IotMainWorkOrderSaveReqVO.java

@@ -1,10 +1,12 @@
 package cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo;
 
+import cn.iocoder.yudao.module.pms.controller.admin.iotattachment.vo.IotAttachmentSaveReqVO;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.List;
 
 @Schema(description = "管理后台 - 保养工单新增/修改 Request VO")
 @Data
@@ -81,4 +83,7 @@ public class IotMainWorkOrderSaveReqVO {
      */
     @Schema(description = "退回保养工单标识", example = "1")
     private String backFlag;
+
+    @Schema(description = "附件列表")
+    private List<IotAttachmentSaveReqVO> attachments;
 }

+ 7 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderService.java

@@ -209,4 +209,11 @@ public interface IotMainWorkOrderService {
      * @return
      */
     void modifyWorkOrder(IotMainWorkOrderSaveVO saveVO);
+
+    /**
+     * 上传 历史保养工单 的附件
+     *
+     * @return
+     */
+    void hiWorkOrderAttachment(IotMainWorkOrderSaveReqVO orderReqVO);
 }

+ 108 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java

@@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
+import cn.iocoder.yudao.module.pms.controller.admin.iotattachment.vo.IotAttachmentSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotlockstock.vo.IotLockStockPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomPageReqVO;
@@ -25,6 +26,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbommaterial.
 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.IotDeviceDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotattachment.IotAttachmentDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotlockstock.IotLockStockDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorder.IotMainWorkOrderDO;
@@ -32,6 +34,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWor
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotoutbound.IotOutboundDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotattachment.IotAttachmentMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotlockstock.IotLockStockMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBomMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorder.IotMainWorkOrderMapper;
@@ -39,6 +42,8 @@ import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbom.IotMainWorkOrde
 import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorderbommaterial.IotMainWorkOrderBomMaterialMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotoutbound.IotOutboundMapper;
 import cn.iocoder.yudao.module.pms.dal.redis.BizNoRedisDAO;
+import cn.iocoder.yudao.module.pms.enums.AttachmentCategoryEnum;
+import cn.iocoder.yudao.module.pms.enums.AttachmentTypeEnum;
 import cn.iocoder.yudao.module.pms.service.IotDeviceService;
 import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
 import cn.iocoder.yudao.module.pms.service.iotmaintenancebom.IotMaintenanceBomService;
@@ -47,6 +52,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.common.collect.ImmutableMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -68,7 +74,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAIN_WORK_ORDER_EXECUTED;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAIN_WORK_ORDER_NOT_EXISTS;
-import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.DEPT_NOT_FOUND;
 
 /**
  * 保养工单 Service 实现类
@@ -105,6 +110,8 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
     private IotOutboundMapper iotOutboundMapper;
     @Resource
     private DeptMapper deptMapper;
+    @Resource
+    private IotAttachmentMapper iotAttachmentMapper;
 
     @Override
     public Long createIotMainWorkOrder(IotMainWorkOrderSaveReqVO createReqVO) {
@@ -2049,6 +2056,34 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             updateObj.setResult(2);
         }
         iotMainWorkOrderMapper.updateById(updateObj);
+
+        // 更新工单的附件记录 rq_iot_attachment
+        List<IotAttachmentSaveReqVO> attachmentReqVO = mainWorkOrder.getAttachments();
+        List<IotAttachmentDO> tobeAddedAttachments = new ArrayList<>();
+        if (CollUtil.isNotEmpty(attachmentReqVO)) {
+            attachmentReqVO.forEach(att -> {
+                IotAttachmentDO attachment = new IotAttachmentDO();
+                attachment.setBizId(updateObj.getId());
+                attachment.setCategory(AttachmentCategoryEnum.MAINTENANCE.getCode());
+                attachment.setType(AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode());
+                attachment.setFilePath(att.getFilePath());
+                attachment.setFileSize(att.getFileSize());
+                attachment.setFilename(att.getFilename());
+                attachment.setFileType(att.getFileType());
+                attachment.setRemark(att.getRemark());
+                tobeAddedAttachments.add(attachment);
+            });
+        }
+        // 先删除附件再新增附件
+        int count = iotAttachmentMapper.deleteByMap(ImmutableMap.of(
+                "category", AttachmentCategoryEnum.MAINTENANCE.getCode(),
+                "biz_id", updateObj.getId(),
+                "type", AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode()
+        ));
+        if (CollUtil.isNotEmpty(tobeAddedAttachments)) {
+            iotAttachmentMapper.insertBatch(tobeAddedAttachments);
+        }
+
         // 如果有保养项已经保养完成,根据保养项规则 实时更新 关联 的 保养计划 明细 保养项的 ‘上次保养运行时间、上次保养自然日期、上次保养公里数’
         // 查询明细中所有设备的累计运行里程、累计运行时间
         // 全部按照多个累计属性 来统计
@@ -2326,6 +2361,35 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             }
         }
         iotMainWorkOrderMapper.insert(order);
+
+        // 添加附件 先删除再新增
+        // 更新工单的附件记录 rq_iot_attachment
+        List<IotAttachmentSaveReqVO> attachmentReqVO = mainWorkOrder.getAttachments();
+        List<IotAttachmentDO> tobeAddedAttachments = new ArrayList<>();
+        if (CollUtil.isNotEmpty(attachmentReqVO)) {
+            attachmentReqVO.forEach(att -> {
+                IotAttachmentDO attachment = new IotAttachmentDO();
+                attachment.setBizId(order.getId());
+                attachment.setCategory(AttachmentCategoryEnum.MAINTENANCE.getCode());
+                attachment.setType(AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode());
+                attachment.setFilePath(att.getFilePath());
+                attachment.setFileSize(att.getFileSize());
+                attachment.setFilename(att.getFilename());
+                attachment.setFileType(att.getFileType());
+                attachment.setRemark(att.getRemark());
+                tobeAddedAttachments.add(attachment);
+            });
+        }
+        // 先删除附件再新增附件
+        int count = iotAttachmentMapper.deleteByMap(ImmutableMap.of(
+                "category", AttachmentCategoryEnum.MAINTENANCE.getCode(),
+                "biz_id", order.getId(),
+                "type", AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode()
+        ));
+        if (CollUtil.isNotEmpty(tobeAddedAttachments)) {
+            iotAttachmentMapper.insertBatch(tobeAddedAttachments);
+        }
+
         // 保养工单明细
         Set<Long> bomNodeIds = new HashSet<>();
         Set<Long> deviceIds = new HashSet<>();
@@ -2910,6 +2974,49 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         }
     }
 
+    @Override
+    public void hiWorkOrderAttachment(IotMainWorkOrderSaveReqVO orderReqVO) {
+        if (ObjectUtil.isEmpty(orderReqVO)) {
+            throw exception(IOT_MAIN_WORK_ORDER_NOT_EXISTS);
+        }
+        Long mainWorkOrderId = orderReqVO.getId();
+        if (ObjectUtil.isEmpty(mainWorkOrderId)) {
+            throw exception(IOT_MAIN_WORK_ORDER_NOT_EXISTS);
+        }
+        // 查询保养工单是否存在
+        IotMainWorkOrderDO workOrder = iotMainWorkOrderMapper.selectById(mainWorkOrderId);
+        if (ObjectUtil.isEmpty(workOrder)) {
+            throw exception(IOT_MAIN_WORK_ORDER_NOT_EXISTS);
+        }
+
+        // 更新工单的附件记录 rq_iot_attachment
+        List<IotAttachmentSaveReqVO> attachmentReqVO = orderReqVO.getAttachments();
+        List<IotAttachmentDO> tobeAddedAttachments = new ArrayList<>();
+        if (CollUtil.isNotEmpty(attachmentReqVO)) {
+            attachmentReqVO.forEach(att -> {
+                IotAttachmentDO attachment = new IotAttachmentDO();
+                attachment.setBizId(mainWorkOrderId);
+                attachment.setCategory(AttachmentCategoryEnum.MAINTENANCE.getCode());
+                attachment.setType(AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode());
+                attachment.setFilePath(att.getFilePath());
+                attachment.setFileSize(att.getFileSize());
+                attachment.setFilename(att.getFilename());
+                attachment.setFileType(att.getFileType());
+                attachment.setRemark(att.getRemark());
+                tobeAddedAttachments.add(attachment);
+            });
+        }
+        // 先删除附件再新增附件
+        int count = iotAttachmentMapper.deleteByMap(ImmutableMap.of(
+                "category", AttachmentCategoryEnum.MAINTENANCE.getCode(),
+                "biz_id", mainWorkOrderId,
+                "type", AttachmentTypeEnum.MAINTENANCE_STANDARD.getCode()
+        ));
+        if (CollUtil.isNotEmpty(tobeAddedAttachments)) {
+            iotAttachmentMapper.insertBatch(tobeAddedAttachments);
+        }
+    }
+
     private static class Triple<A, B, C> {
         private final A first;
         private final B second;