package cn.iocoder.yudao.module.mes.dal.mysql.subjectplan;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.subjectplan.SubjectPlanDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.subjectplan.vo.*;

/**
 * 项目方案关联 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface SubjectPlanMapper extends BaseMapperX<SubjectPlanDO> {

    default PageResult<SubjectPlanDO> selectPage(SubjectPlanPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SubjectPlanDO>()
                .eqIfPresent(SubjectPlanDO::getSubjectId, reqVO.getSubjectId())
                .eqIfPresent(SubjectPlanDO::getPlanId, reqVO.getPlanId())
                .betweenIfPresent(SubjectPlanDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SubjectPlanDO::getId));
    }

    /**
     * 物理删除指定计划的关联
     *
     * @param planId 计划ID
     */
    @Delete("DELETE FROM besure.mes_subject_plan WHERE plan_id = #{planId}")
    void deleteByPlanId(Long planId);

}