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

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.common.exception.MyException;
import com.xjrsoft.module.student.entity.BaseStudentCadre;
import com.xjrsoft.module.student.entity.BaseStudentPost;
import com.xjrsoft.module.student.mapper.BaseStudentPostMapper;
import com.xjrsoft.module.student.service.IBaseStudentCadreService;
import com.xjrsoft.module.student.service.IBaseStudentPostService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @title: 学生职务设置
* @Author dzx
* @Date: 2023-11-13
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class BaseStudentPostServiceImpl extends MPJBaseServiceImpl<BaseStudentPostMapper, BaseStudentPost> implements IBaseStudentPostService {


    private final IBaseStudentCadreService baseStudentCadreService;

    /**
     * 删除学生职务设置（逻辑)
     * @author phoenix
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteLogicallyBatchByIds(List<Long> ids){
        QueryWrapper<BaseStudentCadre> queryWrapper = new QueryWrapper<>();

        queryWrapper.in("post_id",ids);
        Long count = baseStudentCadreService.count(queryWrapper);
        if(ObjectUtil.isNotNull(count) && count > 0){
            throw new MyException("有学生任职于选中的职务");
        }
        return removeBatchByIds(ids);
    }
}
