package com.yida.data.user.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.school.EduSchoolTips;
import com.yida.data.user.mapper.EduSchoolTipsMapper;
import com.yida.data.user.service.EduSchoolTipsService;
import com.yida.data.user.vo.SchoolTipsVo;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 校智慧迎新-须知service层
 *
 * @author ZYJ
 * @date 2021/8/19
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class EduSchoolTipsServiceImpl extends ServiceImpl<EduSchoolTipsMapper, EduSchoolTips> implements EduSchoolTipsService {

    /**
     * 根据学校id获取须知信息
     *
     * @param schoolId 学校id
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.school.vo.SchoolTipsVo>
     * @author ZYJ
     * @date 2021/8/19 17:50
     */
    @Override
    @Transactional(readOnly = true, rollbackFor = Exception.class)
    public SchoolTipsVo getSchoolTips(Long schoolId) {
        // 查询学校须知数据
        EduSchoolTips eduSchoolTips = this.getOne(Wrappers.lambdaQuery(new EduSchoolTips())
                .eq(EduSchoolTips::getSchoolId, schoolId));
        if (!Optional.ofNullable(eduSchoolTips).isPresent()) {
            return null;
        }
        return SchoolTipsVo.builder()
                .content(eduSchoolTips.getContent())
                .title(eduSchoolTips.getTitle())
                .build();
    }
}
