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

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.module.student.dto.BaseStudentCadrePageDto;
import com.xjrsoft.module.student.dto.UpdateBaseStudentCadreDto;
import com.xjrsoft.module.student.entity.BaseStudentCadre;
import com.xjrsoft.module.student.mapper.BaseStudentCadreMapper;
import com.xjrsoft.module.student.service.IBaseStudentCadreService;
import com.xjrsoft.module.student.vo.BaseStudentCadrePageVo;
import com.xjrsoft.module.student.vo.BaseStudentCadreVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @title: 学生干部管理
* @Author dzx
* @Date: 2023-11-14
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class BaseStudentCadreServiceImpl extends MPJBaseServiceImpl<BaseStudentCadreMapper, BaseStudentCadre> implements IBaseStudentCadreService {

    private final BaseStudentCadreMapper baseStudentCadreMapper;

    @Override
    public IPage<BaseStudentCadrePageVo> getListPage(BaseStudentCadrePageDto dto) {
        return baseStudentCadreMapper.getListPage(ConventPage.getPage(dto),dto);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addAll(List<BaseStudentCadre> baseStudentCadreList) {
        for (BaseStudentCadre baseStudentCadre : baseStudentCadreList) {
            baseStudentCadreMapper.insert(baseStudentCadre);
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addOne(BaseStudentCadre baseStudentCadre) {
        baseStudentCadreMapper.insert(baseStudentCadre);
        return true;
    }

    /**
     * 修改学生干部状态（离职、复职）移动端
     * @param dto
     * @return
     */
    @Override
    public Boolean editMobileStatus(UpdateBaseStudentCadreDto dto) {
        BaseStudentCadre baseStudentCadre = BeanUtil.toBean(dto, BaseStudentCadre.class);
        return updateById(baseStudentCadre);
    }

    @Override
    public BaseStudentCadreVo getOneById(Long id) {
        return baseStudentCadreMapper.getOneById(id);
    }
}
