package com.xjrsoft.module.teacher.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.common.utils.TreeUtil;
import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.module.teacher.dto.TeacherAwardStatisticsPageDto;
import com.xjrsoft.module.teacher.entity.TeacherAwardItem;
import com.xjrsoft.module.teacher.mapper.TeacherAwardItemMapper;
import com.xjrsoft.module.teacher.service.ITeacherAwardItemService;
import com.xjrsoft.module.teacher.vo.TeacherAwardItemPageVo;
import com.xjrsoft.module.teacher.vo.TeacherAwardItemVo;
import com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsPageVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @title: 教师奖项
* @Author dzx
* @Date: 2024-06-04
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class TeacherAwardItemServiceImpl extends MPJBaseServiceImpl<TeacherAwardItemMapper, TeacherAwardItem> implements ITeacherAwardItemService {


    @Override
    public Page<TeacherAwardStatisticsPageVo> getStatisticsPage(Page<TeacherAwardStatisticsPageVo> page, TeacherAwardStatisticsPageDto dto) {

        return this.baseMapper.getStatisticsPage(page, dto);
    }

    @Override
    public List<TeacherAwardItemVo> getTeacherAwardItemTree(Integer isThesis) {
        LambdaQueryWrapper<TeacherAwardItem> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper
                .orderByDesc(TeacherAwardItem::getId)
                .eq(isThesis != null, TeacherAwardItem::getIsThesis, isThesis)
                .select(TeacherAwardItem.class,x -> VoToColumnUtil.fieldsToColumns(TeacherAwardItemPageVo.class).contains(x.getProperty()));
        List<TeacherAwardItem> list = this.list(queryWrapper);
        List<TeacherAwardItemVo> itemVos = BeanUtil.copyToList(list, TeacherAwardItemVo.class);
        return TreeUtil.build(itemVos);
    }

}
