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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.jeecg.modules.regular.entity.RegularTools;
import org.jeecg.modules.regular.mapper.RegularToolsMapper;
import org.jeecg.modules.regular.service.IRegularToolsService;
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 RegularToolsServiceImpl extends ServiceImpl<RegularToolsMapper, RegularTools> implements IRegularToolsService {
    private final WorkOrderMapper workOrderMapper;
    private final RegularToolsMapper regularToolsMapper;

    @Override
    public List<RegularTools> 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<RegularTools>()
                .eq(RegularTools::getRegular, order.getRegularId()));
    }

    @Override
    public List<RegularTools> listAll(String detailId) {
        return regularToolsMapper.queryListByDetailId(detailId);
    }
}
