package com.njcn.rdms.module.project.dal.mysql.project.execution;

import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.njcn.rdms.module.project.controller.admin.project.execution.vo.assignee.ExecutionAssigneeLogPageReqVO;
import com.njcn.rdms.module.project.dal.dataobject.project.execution.ExecutionAssigneeLogDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface ExecutionAssigneeLogMapper extends BaseMapperX<ExecutionAssigneeLogDO> {

    /**
     * 分页查询执行协办人变更历史，按 actionTime DESC, id DESC 排序。
     * 支持按 actionType[] / userId / 时间范围筛选。
     */
    default PageResult<ExecutionAssigneeLogDO> selectPageByExecutionId(Long executionId,
                                                                       ExecutionAssigneeLogPageReqVO reqVO) {
        LambdaQueryWrapperX<ExecutionAssigneeLogDO> queryWrapper = new LambdaQueryWrapperX<ExecutionAssigneeLogDO>()
                .eq(ExecutionAssigneeLogDO::getExecutionId, executionId)
                .inIfPresent(ExecutionAssigneeLogDO::getActionType, reqVO.getActionTypes())
                .eqIfPresent(ExecutionAssigneeLogDO::getUserId, reqVO.getUserId())
                .geIfPresent(ExecutionAssigneeLogDO::getActionTime, reqVO.getStartTime())
                .leIfPresent(ExecutionAssigneeLogDO::getActionTime, reqVO.getEndTime())
                .orderByDesc(ExecutionAssigneeLogDO::getActionTime)
                .orderByDesc(ExecutionAssigneeLogDO::getId);
        return selectPage(reqVO, queryWrapper);
    }

}
