package com.rf.psychological.group.service.impl;

import com.rf.psychological.group.dao.model.GroupEntity;
import com.rf.psychological.group.dao.repository.GroupInfoRepository;
import com.rf.psychological.group.service.GroupInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lpf
 * @description:
 * @date 26/10/2021下午4:35
 */

@Service
public class GroupInfoServiceImpl implements GroupInfoService {

    @Autowired
    private GroupInfoRepository groupInfoRepository;

    @Override
    public List<GroupEntity> findAllByInstitutionNo(String institutionNo) {
        return this.groupInfoRepository.findAllByInstitutionNo(institutionNo);
    }

    @Override
    public GroupEntity addGroup(GroupEntity groupEntity) {
        return this.groupInfoRepository.saveAndFlush(groupEntity);
    }

    @Override
    public void delGroup(List<String> ids) {
        ids.forEach(id -> {
            this.groupInfoRepository.deleteById(id);
        });
    }

    @Override
    public void updateGroup(String groupName, String id) {
        groupInfoRepository.updateGroup(groupName, id);
    }

    @Override
    public GroupEntity findGroupByInstitutionNoAndName(String institutionNo, String groupName) {
        return this.groupInfoRepository.findByInstitutionNoAndGroupName(institutionNo,groupName);
    }

    @Override
    public GroupEntity findById(String id) {
        return this.groupInfoRepository.findById(id).orElse(null);
    }

}
