package com.aircraft.modules.article.service.impl;

import com.aircraft.modules.article.domain.CpModule;
import com.aircraft.modules.article.mapper.CpModuleMapper;
import com.aircraft.modules.article.service.CpModuleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 标签模块表 服务实现类
 * </p>
 *
 * @author cli
 * @since 2025-07-10
 */
@Service
public class CpModuleServiceImpl extends ServiceImpl<CpModuleMapper, CpModule> implements CpModuleService {
    @Autowired
    private CpModuleMapper moduleMapper;

    @Override
    public void updateDelFlagById(Integer id, Integer delFlag) {
        baseMapper.updateDelFlagById(id, delFlag);
    }

    @Override
    public boolean existsById(Integer moduleId) {
        if (moduleId == null) {
            return false;
        }

        // 使用LambdaQueryWrapper，类型安全且自动处理参数
        LambdaQueryWrapper<CpModule> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CpModule::getId, moduleId)
                .eq(CpModule::getDelFlag, 0);

        return moduleMapper.selectCount(queryWrapper) > 0;
    }
}
