package cn.pluss.platform.schedule.impl;

import cn.pluss.platform.entity.TaskSort;
import cn.pluss.platform.entity.UserTask;
import cn.pluss.platform.mapper.UserTaskMapper;
import cn.pluss.platform.schedule.TaskSortService;
import cn.pluss.platform.schedule.UserTaskService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Djh
 * @since 2022-05-27
 */
@Service
public class UserTaskServiceImpl extends ServiceImpl<UserTaskMapper, UserTask> implements UserTaskService {

    @Autowired
    private TaskSortService taskSortService;

    private <E extends IPage<UserTask>> void wrapper(E result) {
        final List<TaskSort> taskSortList = taskSortService.list();
        for (UserTask record : result.getRecords()) {
            UserTask.wrapper(record, taskSortList);
        }
    }

    @Override
    public <E extends IPage<UserTask>> E page(E page) {
        final E result = super.page(page);
        wrapper(result);

        return result;
    }

    @Override
    public <E extends IPage<UserTask>> E page(E page, Wrapper<UserTask> queryWrapper) {
        final E result = super.page(page, queryWrapper);
        wrapper(result);

        return result;
    }
}
