From 1277b4070523eb810b059736fb8ea58eabb410e4 Mon Sep 17 00:00:00 2001 From: "Mr.j" <2221464500@qq.com> Date: Mon, 11 Aug 2025 17:12:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E7=8A=B6=E6=80=81=E5=9B=BE=E6=97=A0=E6=B3=95=E9=A1=BA?= =?UTF-8?q?=E5=88=A9=E4=BE=9D=E6=8D=AE=E6=B5=81=E7=A8=8B=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../znpt/domain/entity/EquipmentEntity.java | 3 + .../dite/znpt/domain/vo/EquipmentResp.java | 3 + .../service/EquipmentStatusUpdateService.java | 51 ++++ .../impl/EquipmentApprovalServiceImpl.java | 140 ++++++++++- .../service/impl/EquipmentServiceImpl.java | 8 + .../EquipmentStatusUpdateServiceImpl.java | 232 ++++++++++++++++++ 6 files changed, 435 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/com/dite/znpt/service/EquipmentStatusUpdateService.java create mode 100644 core/src/main/java/com/dite/znpt/service/impl/EquipmentStatusUpdateServiceImpl.java diff --git a/core/src/main/java/com/dite/znpt/domain/entity/EquipmentEntity.java b/core/src/main/java/com/dite/znpt/domain/entity/EquipmentEntity.java index e6d836b..642ee6e 100644 --- a/core/src/main/java/com/dite/znpt/domain/entity/EquipmentEntity.java +++ b/core/src/main/java/com/dite/znpt/domain/entity/EquipmentEntity.java @@ -177,6 +177,9 @@ public class EquipmentEntity extends AuditableEntity implements Serializable { @ApiModelProperty("发票状态") private String invoiceStatus; + @ApiModelProperty("采购状态,NOT_STARTED-未开始,PENDING_APPROVAL-待审批,APPROVED-已通过,REJECTED-已拒绝,COMPLETED-已完成") + private String procurementStatus; + @ApiModelProperty("附件") private String attachments; diff --git a/core/src/main/java/com/dite/znpt/domain/vo/EquipmentResp.java b/core/src/main/java/com/dite/znpt/domain/vo/EquipmentResp.java index d936b01..04642f2 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/EquipmentResp.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/EquipmentResp.java @@ -154,6 +154,9 @@ public class EquipmentResp implements Serializable { @ApiModelProperty("总价") private BigDecimal totalPrice; + @ApiModelProperty("采购状态,NOT_STARTED-未开始,PENDING_APPROVAL-待审批,APPROVED-已通过,REJECTED-已拒绝,COMPLETED-已完成") + private String procurementStatus; + // 移除备用状态字段,使用现有的 location_status 字段 // @ApiModelProperty("备用状态") // private String spareStatus; diff --git a/core/src/main/java/com/dite/znpt/service/EquipmentStatusUpdateService.java b/core/src/main/java/com/dite/znpt/service/EquipmentStatusUpdateService.java new file mode 100644 index 0000000..2963dde --- /dev/null +++ b/core/src/main/java/com/dite/znpt/service/EquipmentStatusUpdateService.java @@ -0,0 +1,51 @@ +package com.dite.znpt.service; + +/** + * 设备状态更新服务接口 + * 用于处理设备审批后的状态更新,避免循环依赖 + * + * @author Bear.G + * @date 2025/1/8/周三 17:50 + */ +public interface EquipmentStatusUpdateService { + + /** + * 更新设备采购状态 + * + * @param equipmentId 设备ID + * @param status 新状态 + */ + void updateProcurementStatus(String equipmentId, String status); + + /** + * 更新设备借用状态 + * + * @param equipmentId 设备ID + * @param status 新状态 + */ + void updateBorrowStatus(String equipmentId, String status); + + /** + * 更新设备归还状态 + * + * @param equipmentId 设备ID + * @param status 新状态 + */ + void updateReturnStatus(String equipmentId, String status); + + /** + * 更新设备位置状态 + * + * @param equipmentId 设备ID + * @param locationStatus 新位置状态 + */ + void updateLocationStatus(String equipmentId, String locationStatus); + + /** + * 更新设备使用状态 + * + * @param equipmentId 设备ID + * @param useStatus 新使用状态 + */ + void updateUseStatus(String equipmentId, String useStatus); +} diff --git a/core/src/main/java/com/dite/znpt/service/impl/EquipmentApprovalServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/EquipmentApprovalServiceImpl.java index f311a84..480734d 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/EquipmentApprovalServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/EquipmentApprovalServiceImpl.java @@ -10,6 +10,7 @@ import com.dite.znpt.domain.vo.EquipmentApprovalReq; import com.dite.znpt.domain.vo.EquipmentApprovalResp; import com.dite.znpt.domain.vo.EquipmentProcurementApplyReq; import com.dite.znpt.service.EquipmentApprovalService; +import com.dite.znpt.service.EquipmentStatusUpdateService; import com.dite.znpt.websocket.SimpleWebSocketHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -34,6 +35,9 @@ public class EquipmentApprovalServiceImpl implements EquipmentApprovalService { @Resource private EquipmentApprovalMapper equipmentApprovalMapper; + + @Resource + private EquipmentStatusUpdateService equipmentStatusUpdateService; @Override public IPage getPendingApprovals(EquipmentApprovalListReq req) { @@ -85,6 +89,21 @@ public class EquipmentApprovalServiceImpl implements EquipmentApprovalService { entity.setApprovalComment(req.getApprovalComment()); equipmentApprovalMapper.updateById(entity); + + // 审批通过后,更新设备状态 + try { + if ("PROCUREMENT".equals(entity.getBusinessType())) { + equipmentStatusUpdateService.updateProcurementStatus(entity.getEquipmentId(), "APPROVED"); + } else if ("BORROW".equals(entity.getBusinessType())) { + equipmentStatusUpdateService.updateBorrowStatus(entity.getEquipmentId(), "APPROVED"); + } else if ("RETURN".equals(entity.getBusinessType())) { + equipmentStatusUpdateService.updateReturnStatus(entity.getEquipmentId(), "APPROVED"); + } + log.info("设备状态更新成功,设备ID: {}, 审批ID: {}", entity.getEquipmentId(), approvalId); + } catch (Exception e) { + log.error("设备状态更新失败,设备ID: {}, 审批ID: {}", entity.getEquipmentId(), approvalId, e); + // 不抛出异常,避免影响审批流程 + } } @Override @@ -101,6 +120,21 @@ public class EquipmentApprovalServiceImpl implements EquipmentApprovalService { entity.setApprovalComment(req.getApprovalComment()); equipmentApprovalMapper.updateById(entity); + + // 审批拒绝后,更新设备状态 + try { + if ("PROCUREMENT".equals(entity.getBusinessType())) { + equipmentStatusUpdateService.updateProcurementStatus(entity.getEquipmentId(), "REJECTED"); + } else if ("BORROW".equals(entity.getBusinessType())) { + equipmentStatusUpdateService.updateBorrowStatus(entity.getEquipmentId(), "REJECTED"); + } else if ("RETURN".equals(entity.getBusinessType())) { + equipmentStatusUpdateService.updateReturnStatus(entity.getEquipmentId(), "REJECTED"); + } + log.info("设备状态更新成功,设备ID: {}, 审批ID: {}", entity.getEquipmentId(), approvalId); + } catch (Exception e) { + log.error("设备状态更新失败,设备ID: {}, 审批ID: {}", entity.getEquipmentId(), approvalId, e); + // 不抛出异常,避免影响审批流程 + } } @Override @@ -264,7 +298,7 @@ public class EquipmentApprovalServiceImpl implements EquipmentApprovalService { // 更新设备采购状态 - 新增逻辑 try { - updateEquipmentProcurementStatus(req.getEquipmentId(), "PENDING_APPROVAL"); + equipmentStatusUpdateService.updateProcurementStatus(req.getEquipmentId(), "PENDING_APPROVAL"); log.info("设备采购状态更新成功,设备ID: {}", req.getEquipmentId()); } catch (Exception e) { log.error("设备采购状态更新失败,设备ID: {}", req.getEquipmentId(), e); @@ -297,7 +331,7 @@ public class EquipmentApprovalServiceImpl implements EquipmentApprovalService { log.warn("设备ID为空,跳过状态更新"); return; } - + try { log.info("准备更新设备采购状态,设备ID: {}, 新状态: {}", equipmentId, status); @@ -316,6 +350,108 @@ public class EquipmentApprovalServiceImpl implements EquipmentApprovalService { } } + + + /** + * 审批通过后更新设备状态 + */ + private void updateEquipmentStatusAfterApproval(EquipmentApprovalEntity entity) { + if (entity == null || entity.getEquipmentId() == null) { + log.warn("审批实体或设备ID为空,跳过状态更新"); + return; + } + + try { + log.info("审批通过后更新设备状态,设备ID: {}, 业务类型: {}", entity.getEquipmentId(), entity.getBusinessType()); + + // 根据业务类型更新不同的设备状态 + if ("PROCUREMENT".equals(entity.getBusinessType())) { + // 采购审批通过,更新设备状态为已采购 + updateEquipmentProcurementStatus(entity.getEquipmentId(), "APPROVED"); + } else if ("BORROW".equals(entity.getBusinessType())) { + // 借用审批通过,更新设备状态为已借用 + updateEquipmentBorrowStatus(entity.getEquipmentId(), "APPROVED"); + } else if ("RETURN".equals(entity.getBusinessType())) { + // 归还审批通过,更新设备状态为已归还 + updateEquipmentReturnStatus(entity.getEquipmentId(), "APPROVED"); + } + + log.info("设备状态更新成功,设备ID: {}", entity.getEquipmentId()); + } catch (Exception e) { + log.error("审批通过后更新设备状态失败,设备ID: {}", entity.getEquipmentId(), e); + throw e; + } + } + + /** + * 审批拒绝后更新设备状态 + */ + private void updateEquipmentStatusAfterRejection(EquipmentApprovalEntity entity) { + if (entity == null || entity.getEquipmentId() == null) { + log.warn("审批实体或设备ID为空,跳过状态更新"); + return; + } + + try { + log.info("审批拒绝后更新设备状态,设备ID: {}, 业务类型: {}", entity.getEquipmentId(), entity.getBusinessType()); + + // 根据业务类型更新不同的设备状态 + if ("PROCUREMENT".equals(entity.getBusinessType())) { + // 采购审批拒绝,更新设备状态为审批拒绝 + updateEquipmentProcurementStatus(entity.getEquipmentId(), "REJECTED"); + } else if ("BORROW".equals(entity.getBusinessType())) { + // 借用审批拒绝,更新设备状态为借用拒绝 + updateEquipmentBorrowStatus(entity.getEquipmentId(), "REJECTED"); + } else if ("RETURN".equals(entity.getBusinessType())) { + // 归还审批拒绝,更新设备状态为归还拒绝 + updateEquipmentReturnStatus(entity.getEquipmentId(), "REJECTED"); + } + + log.info("设备状态更新成功,设备ID: {}", entity.getEquipmentId()); + } catch (Exception e) { + log.error("审批拒绝后更新设备状态失败,设备ID: {}", entity.getEquipmentId(), e); + throw e; + } + } + + /** + * 更新设备借用状态 + */ + private void updateEquipmentBorrowStatus(String equipmentId, String status) { + if (equipmentId == null || equipmentId.trim().isEmpty()) { + log.warn("设备ID为空,跳过借用状态更新"); + return; + } + + try { + log.info("准备更新设备借用状态,设备ID: {}, 新状态: {}", equipmentId, status); + // 这里可以添加具体的更新逻辑 + // 例如:equipmentMapper.updateBorrowStatus(equipmentId, status); + } catch (Exception e) { + log.error("更新设备借用状态失败,设备ID: {}, 状态: {}", equipmentId, status, e); + throw e; + } + } + + /** + * 更新设备归还状态 + */ + private void updateEquipmentReturnStatus(String equipmentId, String status) { + if (equipmentId == null || equipmentId.trim().isEmpty()) { + log.warn("设备ID为空,跳过归还状态更新"); + return; + } + + try { + log.info("准备更新设备归还状态,设备ID: {}, 新状态: {}", equipmentId, status); + // 这里可以添加具体的更新逻辑 + // 例如:equipmentMapper.updateReturnStatus(equipmentId, status); + } catch (Exception e) { + log.error("更新设备归还状态失败,设备ID: {}, 状态: {}", equipmentId, status, e); + throw e; + } + } + @Override public IPage getMyProcurementApplications(EquipmentApprovalListReq req) { log.info("开始获取我的采购申请,请求参数: {}", req); diff --git a/core/src/main/java/com/dite/znpt/service/impl/EquipmentServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/EquipmentServiceImpl.java index 8f15c6e..ebaac5c 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/EquipmentServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/EquipmentServiceImpl.java @@ -562,6 +562,9 @@ public class EquipmentServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(EquipmentEntity::getEquipmentId, equipmentId); + + // 根据状态设置相应的字段 + if ("APPROVED".equals(status)) { + // 审批通过:设置采购状态为已通过,位置状态为库存中,使用状态为空闲中 + updateWrapper.set(EquipmentEntity::getProcurementStatus, "APPROVED"); + updateWrapper.set(EquipmentEntity::getLocationStatus, "in_stock"); + updateWrapper.set(EquipmentEntity::getUseStatus, "0"); + updateWrapper.set(EquipmentEntity::getInStockTime, LocalDateTime.now()); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备采购审批通过,设置状态为已通过"); + } else if ("REJECTED".equals(status)) { + // 审批拒绝:设置采购状态为已拒绝,位置状态为未入库,使用状态为空闲中 + updateWrapper.set(EquipmentEntity::getProcurementStatus, "REJECTED"); + updateWrapper.set(EquipmentEntity::getLocationStatus, "not_in_stock"); + updateWrapper.set(EquipmentEntity::getUseStatus, "0"); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备采购审批拒绝,设置状态为已拒绝"); + } else if ("PENDING_APPROVAL".equals(status) || "PENDING".equals(status)) { + // 待审批:设置采购状态为待审批,位置状态为待审批,使用状态为空闲中 + updateWrapper.set(EquipmentEntity::getProcurementStatus, "PENDING_APPROVAL"); + updateWrapper.set(EquipmentEntity::getLocationStatus, "pending_approval"); + updateWrapper.set(EquipmentEntity::getUseStatus, "0"); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备采购申请提交,设置状态为待审批"); + } else if ("COMPLETED".equals(status)) { + // 采购完成:设置采购状态为已完成,位置状态为库存中,使用状态为空闲中 + updateWrapper.set(EquipmentEntity::getProcurementStatus, "COMPLETED"); + updateWrapper.set(EquipmentEntity::getLocationStatus, "in_stock"); + updateWrapper.set(EquipmentEntity::getUseStatus, "0"); + updateWrapper.set(EquipmentEntity::getInStockTime, LocalDateTime.now()); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备采购完成,设置状态为已完成"); + } + + // 执行更新 + int updateCount = equipmentMapper.update(null, updateWrapper); + if (updateCount > 0) { + log.info("设备采购状态更新成功,设备ID: {}, 新状态: {}, 影响行数: {}", equipmentId, status, updateCount); + } else { + log.warn("设备采购状态更新失败,设备ID: {}, 新状态: {}, 可能设备不存在", equipmentId, status); + } + + } catch (Exception e) { + log.error("更新设备采购状态失败,设备ID: {}, 状态: {}", equipmentId, status, e); + throw e; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateBorrowStatus(String equipmentId, String status) { + if (equipmentId == null || equipmentId.trim().isEmpty()) { + log.warn("设备ID为空,跳过借用状态更新"); + return; + } + + try { + log.info("开始更新设备借用状态,设备ID: {}, 新状态: {}", equipmentId, status); + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(EquipmentEntity::getEquipmentId, equipmentId); + + if ("APPROVED".equals(status)) { + // 借用审批通过:设置位置状态为外借中,使用状态为使用中 + updateWrapper.set(EquipmentEntity::getLocationStatus, "borrowed"); + updateWrapper.set(EquipmentEntity::getUseStatus, "1"); + updateWrapper.set(EquipmentEntity::getBorrowingTime, LocalDateTime.now()); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备借用审批通过,设置状态为外借中"); + } else if ("REJECTED".equals(status)) { + // 借用审批拒绝:保持原有状态 + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备借用审批拒绝,保持原有状态"); + } + + // 执行更新 + int updateCount = equipmentMapper.update(null, updateWrapper); + if (updateCount > 0) { + log.info("设备借用状态更新成功,设备ID: {}, 新状态: {}, 影响行数: {}", equipmentId, status, updateCount); + } else { + log.warn("设备借用状态更新失败,设备ID: {}, 新状态: {}, 可能设备不存在", equipmentId, status); + } + + } catch (Exception e) { + log.error("更新设备借用状态失败,设备ID: {}, 状态: {}", equipmentId, status, e); + throw e; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateReturnStatus(String equipmentId, String status) { + if (equipmentId == null || equipmentId.trim().isEmpty()) { + log.warn("设备ID为空,跳过归还状态更新"); + return; + } + + try { + log.info("开始更新设备归还状态,设备ID: {}, 新状态: {}", equipmentId, status); + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(EquipmentEntity::getEquipmentId, equipmentId); + + if ("APPROVED".equals(status)) { + // 归还审批通过:设置位置状态为库存中,使用状态为空闲中 + updateWrapper.set(EquipmentEntity::getLocationStatus, "in_stock"); + updateWrapper.set(EquipmentEntity::getUseStatus, "0"); + updateWrapper.set(EquipmentEntity::getReturnTime, LocalDateTime.now()); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备归还审批通过,设置状态为库存中"); + } else if ("REJECTED".equals(status)) { + // 归还审批拒绝:保持原有状态 + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + log.info("设备归还审批拒绝,保持原有状态"); + } + + // 执行更新 + int updateCount = equipmentMapper.update(null, updateWrapper); + if (updateCount > 0) { + log.info("设备归还状态更新成功,设备ID: {}, 新状态: {}, 影响行数: {}", equipmentId, status, updateCount); + } else { + log.warn("设备归还状态更新失败,设备ID: {}, 新状态: {}, 可能设备不存在", equipmentId, status); + } + + } catch (Exception e) { + log.error("更新设备归还状态失败,设备ID: {}, 状态: {}", equipmentId, status, e); + throw e; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateLocationStatus(String equipmentId, String locationStatus) { + if (equipmentId == null || equipmentId.trim().isEmpty()) { + log.warn("设备ID为空,跳过位置状态更新"); + return; + } + + try { + log.info("开始更新设备位置状态,设备ID: {}, 新位置状态: {}", equipmentId, locationStatus); + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(EquipmentEntity::getEquipmentId, equipmentId); + updateWrapper.set(EquipmentEntity::getLocationStatus, locationStatus); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + + // 执行更新 + int updateCount = equipmentMapper.update(null, updateWrapper); + if (updateCount > 0) { + log.info("设备位置状态更新成功,设备ID: {}, 新位置状态: {}, 影响行数: {}", equipmentId, locationStatus, updateCount); + } else { + log.warn("设备位置状态更新失败,设备ID: {}, 新位置状态: {}, 可能设备不存在", equipmentId, locationStatus); + } + + } catch (Exception e) { + log.error("更新设备位置状态失败,设备ID: {}, 位置状态: {}", equipmentId, locationStatus, e); + throw e; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateUseStatus(String equipmentId, String useStatus) { + if (equipmentId == null || equipmentId.trim().isEmpty()) { + log.warn("设备ID为空,跳过使用状态更新"); + return; + } + + try { + log.info("开始更新设备使用状态,设备ID: {}, 新使用状态: {}", equipmentId, useStatus); + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(EquipmentEntity::getEquipmentId, equipmentId); + updateWrapper.set(EquipmentEntity::getUseStatus, useStatus); + updateWrapper.set(EquipmentEntity::getStatusChangeTime, LocalDateTime.now()); + + // 执行更新 + int updateCount = equipmentMapper.update(null, updateWrapper); + if (updateCount > 0) { + log.info("设备使用状态更新成功,设备ID: {}, 新使用状态: {}, 影响行数: {}", equipmentId, useStatus, updateCount); + } else { + log.warn("设备使用状态更新失败,设备ID: {}, 新使用状态: {}, 可能设备不存在", equipmentId, useStatus); + } + + } catch (Exception e) { + log.error("更新设备使用状态失败,设备ID: {}, 使用状态: {}", equipmentId, useStatus, e); + throw e; + } + } +}