| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.basic.entity.Supply; |
| | | import com.ruoyi.basic.mapper.CoalInfoMapper; |
| | | import com.ruoyi.business.dto.EquipmentManagementDto; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.business.dto.EquipmentUsageRecordDto; |
| | | import com.ruoyi.business.entity.EquipmentManagement; |
| | | import com.ruoyi.business.entity.EquipmentUsageDetail; |
| | |
| | | import com.ruoyi.business.mapper.EquipmentUsageDetailMapper; |
| | | import com.ruoyi.business.mapper.EquipmentUsageRecordMapper; |
| | | import com.ruoyi.business.service.EquipmentUsageRecordService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDate; |
| | |
| | | } |
| | | |
| | | // 处理归还逻辑 |
| | | if (equipmentUsageRecordDto.getEquipmentStatus() == 2) { |
| | | if (equipmentUsageRecordDto.getEquipmentStatus() != 1) { |
| | | result = handleReturnOperation(equipmentUsageRecordDto, equipment, originalRecord, userId, username); |
| | | } else { |
| | | // 处理普通编辑逻辑(非归还状态) |
| | |
| | | |
| | | private int handleReturnOperation(EquipmentUsageRecordDto dto, EquipmentManagement equipment, |
| | | EquipmentUsageRecord originalRecord, Long userId, String username) { |
| | | // 获取本次归还数量 |
| | | // 校验归还数量 |
| | | Integer returnQuantity = dto.getReturnQuantity(); |
| | | if (returnQuantity == null || returnQuantity <= 0) { |
| | | throw new RuntimeException("归还数量必须大于0"); |
| | |
| | | throw new RuntimeException("归还数量不能超过未归还数量,剩余未归还数量:" + remainingQuantity); |
| | | } |
| | | |
| | | // 更新主记录 |
| | | // 准备更新记录 |
| | | EquipmentUsageRecord updateRecord = new EquipmentUsageRecord(); |
| | | updateRecord.setId(originalRecord.getId()); |
| | | updateRecord.setReturnQuantity(originalRecord.getReturnQuantity() + returnQuantity); |
| | | updateRecord.setEquipmentStatus(2); // 已归还状态 |
| | | updateRecord.setUsageEndTime(LocalDate.now()); |
| | | // 如果全部归还,更新状态和时间 |
| | | // if (updateRecord.getReturnQuantity().equals(originalRecord.getUsageQuantity())) { |
| | | // |
| | | // } |
| | | int newReturnQuantity = originalRecord.getReturnQuantity() + returnQuantity; |
| | | updateRecord.setReturnQuantity(newReturnQuantity); |
| | | |
| | | // 恢复库存 |
| | | // 判断是否全部归还 |
| | | boolean isFullReturn = newReturnQuantity == originalRecord.getUsageQuantity(); |
| | | int newStatus = isFullReturn ? 3 : 2; // 3表示全部归还,2表示部分归还 |
| | | updateRecord.setEquipmentStatus(newStatus); |
| | | updateRecord.setUsageEndTime(LocalDate.now()); |
| | | |
| | | // 恢复库存数量 |
| | | equipment.setQuantity(equipment.getQuantity() + returnQuantity); |
| | | equipmentManagementMapper.updateById(equipment); |
| | | |
| | |
| | | |
| | | // 保存归还明细记录 |
| | | if (result > 0) { |
| | | String remark = "设备归还" + (updateRecord.getEquipmentStatus() == 2 ? "(全部归还)" : "(部分归还)"); |
| | | saveUsageDetail(originalRecord.getId(), originalRecord.getEquipmentId(), 2, returnQuantity, userId, username, remark); |
| | | String remark = isFullReturn ? "设备归还(全部归还)" : "设备归还(部分归还)"; |
| | | int operationType = isFullReturn ? 3 : 2; // 与主记录状态保持一致 |
| | | saveUsageDetail(originalRecord.getId(), originalRecord.getEquipmentId(), |
| | | operationType, returnQuantity, userId, username, remark); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |