package com.srs.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.srs.dormitory.domain.DmsRepairStatus;
import com.srs.dormitory.mapper.DmsRepairStatusMapper;
import com.srs.dormitory.service.IDmsRepairStatusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.srs.common.utils.PageUtils.startPage;

/**
 * <p>
 * 维修状态追踪表 服务实现类
 * </p>
 *
 * @author 猪油骨
 * @since 2023-08-04
 */
@Service
public class IDmsRepairStatusServiceImpl extends ServiceImpl<DmsRepairStatusMapper, DmsRepairStatus> implements IDmsRepairStatusService {

    @Override
    public List<DmsRepairStatus> repairStatus(Long repairId) {
        startPage();
        List<DmsRepairStatus> list = lambdaQuery()
                .eq(DmsRepairStatus::getRepairRecordId, repairId)
                .orderByDesc(DmsRepairStatus::getId).list();
        if (list.isEmpty()) throw new RuntimeException("该订单不存在，请检查订单是否正确");
        return list;
    }

    @Override
    @Transactional
    public void deleteStatus(List<Long> ids) {
        boolean remove = remove(new LambdaQueryWrapper<DmsRepairStatus>()
                .in(DmsRepairStatus::getRepairRecordId, ids));
        if (!remove) throw new RuntimeException("删除失败");
    }
}
