package org.jeecg.modules.regular.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.jeecg.modules.regular.entity.RegularMaterial;
import org.jeecg.modules.regular.entity.RegularTools;
import org.jeecg.modules.regular.mapper.RegularMaterialMapper;
import org.jeecg.modules.regular.service.IRegularMaterialService;
import org.jeecg.modules.workOrder.entity.WorkOrder;
import org.jeecg.modules.workOrder.mapper.WorkOrderMapper;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 检修物料
 * @Author: jeecg-boot
 * @Date:   2025-01-16
 * @Version: V1.0
 */
@Service
@RequiredArgsConstructor
public class RegularMaterialServiceImpl extends ServiceImpl<RegularMaterialMapper, RegularMaterial> implements IRegularMaterialService {
    private final WorkOrderMapper workOrderMapper;

    @Override
    public List<RegularMaterial> queryByWorkOrder(String id) throws Exception {
        WorkOrder order = workOrderMapper.selectById(id);
        if(order == null){
            throw new Exception("工单不存在");
        }
//        if(order.getStatus() != 2){
//            throw new Exception("当前工单无法进行工器具申请操作");
//        }

        return baseMapper.selectList(new LambdaQueryWrapper<RegularMaterial>()
                .eq(RegularMaterial::getRegular, order.getRegularId()));
    }
}
