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.BaseStudentBehaviorManage;
import com.xjrsoft.module.student.entity.BaseStudentBehaviorProject;
import com.xjrsoft.module.student.mapper.BaseStudentBehaviorManageMapper;
import com.xjrsoft.module.student.mapper.BaseStudentBehaviorProjectMapper;
import com.xjrsoft.module.student.service.IBaseStudentBehaviorProjectService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @title: 学生操行分考核项目
* @Author fanxp
* @Date: 2023-11-15
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class BaseStudentBehaviorProjectServiceImpl extends MPJBaseServiceImpl<BaseStudentBehaviorProjectMapper, BaseStudentBehaviorProject> implements IBaseStudentBehaviorProjectService {
    private final BaseStudentBehaviorProjectMapper baseStudentBehaviorProjectMapper;
    private final BaseStudentBehaviorManageMapper baseStudentBehaviorManageMapper;
    @Override
    public Boolean deleteDeepByIds(List<Long> ids) {
        //查询是否有操行记录
        QueryWrapper<BaseStudentBehaviorManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("base_student_behavior_project_id", ids);
        Long count = baseStudentBehaviorManageMapper.selectCount(queryWrapper);
        if(ObjectUtil.isNotNull(count) && count > 0){
            throw new MyException("该考核项目下已有操行记录，无法删除");
        }

        //删除操行记录下面的学生
        //删除操行记录下面的班级
        baseStudentBehaviorProjectMapper.deleteBatchIds(ids);
        return true;
    }
}
