package com.ningdatech.pmapi.projectlib.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.pmapi.common.constant.BizConst;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.model.entity.ProjectStatusChange;
import com.ningdatech.pmapi.projectlib.mapper.NdProjectStatusChangeMapper;
import com.ningdatech.pmapi.projectlib.service.INdProjectStatusChangeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author CMM
 * @since 2023-02-27
 */
@Service
public class NdProjectStatusChangeServiceImpl extends ServiceImpl<NdProjectStatusChangeMapper, ProjectStatusChange> implements INdProjectStatusChangeService {

    @Override
    public ProjectStatusChange getByProjectStatus(ProjectStatusChangeEvent event, Long projectId) {
        LambdaQueryWrapper<ProjectStatusChange> query = Wrappers.lambdaQuery(ProjectStatusChange.class)
                .eq(ProjectStatusChange::getEvent, event)
                .eq(ProjectStatusChange::getProjectId, projectId)
                .orderByDesc(ProjectStatusChange::getCreateOn)
                .last(BizConst.LIMIT_1);
        return getOne(query);
    }

}
