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

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.task.vo.assignee.TaskAssigneeLogPageReqVO;
import com.njcn.rdms.module.project.dal.dataobject.project.task.TaskAssigneeLogDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface TaskAssigneeLogMapper extends BaseMapperX<TaskAssigneeLogDO> {

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

}
