package com.fizz.business.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Objects;

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.fizz.business.mapper.PdiSetupMapper;
import com.fizz.business.domain.PdiSetups;
import com.fizz.business.service.IPdiSetupService;

/**
 * 生产计划的参数详情Service业务层处理
 *
 * @author Joshi
 * @date 2025-09-25
 */
@Service
public class PdiSetupServiceImpl extends ServiceImpl<PdiSetupMapper, PdiSetups> implements IPdiSetupService {

    @Override
    public List<PdiSetups> selectPdiSetupList(PdiSetups pdiSetup) {
        return lambdaQuery()
                .eq(StrUtil.isNotBlank(pdiSetup.getCoilid()), PdiSetups::getCoilid, pdiSetup.getCoilid())
                .eq(StrUtil.isNotBlank(pdiSetup.getPlanid()), PdiSetups::getPlanid, pdiSetup.getPlanid())
                .eq(StrUtil.isNotBlank(pdiSetup.getSteelGrade()), PdiSetups::getSteelGrade, pdiSetup.getSteelGrade())
                .eq(Objects.nonNull(pdiSetup.getThick()), PdiSetups::getThick, pdiSetup.getThick())
                .eq(Objects.nonNull(pdiSetup.getYieldStren()), PdiSetups::getYieldStren, pdiSetup.getYieldStren())
                .orderByDesc(PdiSetups::getUpdateTime)
                .list();
    }

    @Override
    public PdiSetups selectPdiSetupById(Long id) {
        return getById(id);
    }

    @Override
    public Boolean insertPdiSetup(PdiSetups pdiSetup) {
        pdiSetup.setCreateTime(ObjectUtil.defaultIfNull(pdiSetup.getCreateTime(), new Date()));
        pdiSetup.setUpdateTime(new Date());
        return save(pdiSetup);
    }

    @Override
    public Boolean updatePdiSetup(PdiSetups pdiSetup) {
        if (pdiSetup.getId() == null) {
            throw new IllegalArgumentException("When updating the tension parameter, the id cannot be empty");
        }
        pdiSetup.setUpdateTime(new Date());
        return updateById(pdiSetup);
    }

    @Override
    public Boolean deletePdiSetupByIds(Long[] ids) {
        return removeByIds(java.util.Arrays.asList(ids));
    }
}
