package com.usky.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.iot.domain.BaseBuildEngineering;
import com.usky.iot.domain.BaseBuildUnit;
import com.usky.iot.mapper.BaseBuildEngineeringMapper;
import com.usky.iot.service.BaseBuildEngineeringService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fu
 * @since 2026-02-03
 */
@Service
public class BaseBuildEngineeringServiceImpl extends AbstractCrudService<BaseBuildEngineeringMapper, BaseBuildEngineering> implements BaseBuildEngineeringService {
    @Override
    public void add(BaseBuildEngineering baseBuildEngineering){
        baseBuildEngineering.setCreateBy(SecurityUtils.getUsername());
        baseBuildEngineering.setCreateTime(LocalDateTime.now());
        baseBuildEngineering.setTenantId(SecurityUtils.getTenantId());
        this.save(baseBuildEngineering);
    }

    @Override
    public void update(BaseBuildEngineering baseBuildEngineering){
        baseBuildEngineering.setUpdateBy(SecurityUtils.getUsername());
        baseBuildEngineering.setUpdateTime(LocalDateTime.now());
        this.updateById(baseBuildEngineering);
    }

    @Override
    public void remove(Integer id){

        this.removeById(id);

    }

    @Override
    public List<BaseBuildEngineering> baseBuildEngineeringList(Integer id, Integer buildId){
        LambdaQueryWrapper<BaseBuildEngineering> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(!ObjectUtils.isEmpty(id),BaseBuildEngineering::getId,id)
                .eq(BaseBuildEngineering::getBuildId,buildId)
                .eq(BaseBuildEngineering::getTenantId,SecurityUtils.getTenantId())
                .orderByDesc(BaseBuildEngineering::getId);
        List<BaseBuildEngineering> list = this.list(queryWrapper);
        return list;
    }
}
