修复设备采购状态图无法顺利依据流程变化的问题

This commit is contained in:
Mr.j 2025-08-11 17:12:09 +08:00
parent de2439e65d
commit 1277b40705
6 changed files with 435 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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<EquipmentApprovalResp> 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<EquipmentApprovalResp> getMyProcurementApplications(EquipmentApprovalListReq req) {
log.info("开始获取我的采购申请,请求参数: {}", req);

View File

@ -562,6 +562,9 @@ public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment
resp.setInventoryBasis(entity.getInventoryBasis());
resp.setDynamicRecord(entity.getDynamicRecord());
// 设置采购状态字段
resp.setProcurementStatus(entity.getProcurementStatus());
// 新增字段转换
resp.setUsingDepartment(entity.getUsingDepartment());
resp.setBorrowingTime(entity.getBorrowingTime());
@ -699,6 +702,11 @@ public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment
conditionCount++;
}
// 添加采购状态查询条件 - 确保查询有采购状态的设备
queryWrapper.isNotNull(EquipmentEntity::getProcurementStatus);
log.info("添加采购状态查询条件: 不为空");
conditionCount++;
log.info("总共添加了 {} 个查询条件", conditionCount);
// 按采购时间倒序排列

View File

@ -0,0 +1,232 @@
package com.dite.znpt.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dite.znpt.domain.entity.EquipmentEntity;
import com.dite.znpt.mapper.EquipmentMapper;
import com.dite.znpt.service.EquipmentStatusUpdateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
/**
* 设备状态更新服务实现类
* 使用MyBatis Plus来更新设备状态避免循环依赖
*
* @author Bear.G
* @date 2025/1/8/周三 17:50
*/
@Slf4j
@Service
public class EquipmentStatusUpdateServiceImpl implements EquipmentStatusUpdateService {
@Resource
private EquipmentMapper equipmentMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProcurementStatus(String equipmentId, String status) {
if (equipmentId == null || equipmentId.trim().isEmpty()) {
log.warn("设备ID为空跳过采购状态更新");
return;
}
try {
log.info("开始更新设备采购状态设备ID: {}, 新状态: {}", equipmentId, status);
// 使用MyBatis Plus的LambdaUpdateWrapper来更新设备状态
LambdaUpdateWrapper<EquipmentEntity> 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<EquipmentEntity> 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<EquipmentEntity> 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<EquipmentEntity> 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<EquipmentEntity> 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;
}
}
}