package cd.casic.ci.process.process.service.machine.impl;


import cd.casic.ci.process.dto.req.machine.MachineInfoReq;
import cd.casic.ci.process.dto.resp.machine.MachineInfoResp;
import cd.casic.ci.process.process.converter.MachineConverter;
import cd.casic.ci.process.process.dao.machine.MachineInfoDao;
import cd.casic.ci.process.process.dataObject.machine.MachineInfo;
import cd.casic.ci.process.process.service.machine.MachineInfoService;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 机器信息表service接口实现类
 * @author herenbin
 * @date 2022-09-27 10:25:29
 */
@Slf4j
@Service
public class MachineInfoServiceImpl extends ServiceImpl<MachineInfoDao, MachineInfo> implements MachineInfoService {
    @Resource
    private MachineInfoDao machineInfoDao;

    @Override
    public List<MachineInfoResp> list(MachineInfoReq req) {
        LambdaQueryWrapper<MachineInfo> wrapper = new LambdaQueryWrapper<>();
// 根据机器名称 查询
        if (ObjectUtil.isNotEmpty(req.getMachineName())) {
            wrapper.like(MachineInfo::getMachineName, req.getMachineName());
        }
        // 根据机器状态 1有效 2无效 查询
        if (ObjectUtil.isNotEmpty(req.getMachineStatus())) {
            wrapper.eq(MachineInfo::getMachineStatus, req.getMachineStatus());
        }
        List<MachineInfo> machineInfos = machineInfoDao.selectList(wrapper);
        return MachineConverter.INSTANCE.toRespList(machineInfos);
    }
}
