| | |
| | | import com.ruoyi.business.service.EquipmentManagementService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.business.vo.EquipmentManagementVo; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.transaction.annotation.Isolation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.beans.Transient; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(isolation = Isolation.REPEATABLE_READ) |
| | | public int delByIds(Long[] ids) { |
| | | return equipmentManagementMapper.deleteByIds(Arrays.asList(ids)); |
| | | // 1. 检查设备是否正在使用(添加行锁 for update) |
| | | List<EquipmentUsageRecord> records = equipmentUsageRecordMapper.selectList( |
| | | new LambdaQueryWrapper<EquipmentUsageRecord>() |
| | | .in(EquipmentUsageRecord::getEquipmentId, Arrays.asList(ids)) |
| | | .last("FOR UPDATE") // 添加行锁,锁定查询结果 |
| | | ); |
| | | if (!records.isEmpty()) { |
| | | throw new BaseException("设备正在使用中,请核对!"); |
| | | } else { |
| | | return equipmentManagementMapper.deleteByIds(Arrays.asList(ids)); |
| | | } |
| | | } |
| | | } |