package com.yida.data.school.secondClass.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassVenueExhibit;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassVenueExhibitGroup;
import com.yida.data.school.secondClass.mapper.EduSecondClassVenueExhibitMapper;
import com.yida.data.school.secondClass.mapper.EduSecondclassVenueExhibitGroupMapper;
import com.yida.data.school.secondClass.service.EduSecondClassVenueExhibitGroupService;
import com.yida.data.school.vo.secondClass.VenueExhibitGroupVO;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * Service实现
 *
 * @author zhanghaijun
 * @date 2022-04-18 09:39:53
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class EduSecondClassVenueExhibitGroupServiceImpl extends ServiceImpl
    <EduSecondclassVenueExhibitGroupMapper, EduSecondClassVenueExhibitGroup> implements EduSecondClassVenueExhibitGroupService {

    private final EduSecondClassVenueExhibitMapper eduSecondClassVenueExhibitMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public List<VenueExhibitGroupVO> listGroup(Long venueId) {
        return baseMapper.listGroup(venueId);
    }

    @Override
    public void saveGroup(EduSecondClassVenueExhibitGroup group) {
        saveOrUpdate(group);
    }

    @Override

    public void delGroup(Long id) {
        EduSecondClassVenueExhibitGroup group = getById(id);
        removeById(id);
        // 清空该分组下展品的分组信息
        if (group != null) {
            eduSecondClassVenueExhibitMapper.update(null, Wrappers.<EduSecondClassVenueExhibit>lambdaUpdate()
                .eq(EduSecondClassVenueExhibit::getGroupId, id)
                .set(EduSecondClassVenueExhibit::getGroupId, 0L));
        }
    }

    @Override
    public VenueExhibitGroupVO getInfo(Long groupId) {
        EduSecondClassVenueExhibitGroup group = getById(groupId);
        VenueExhibitGroupVO vo = new VenueExhibitGroupVO();
        BeanUtils.copyProperties(group,vo);
        return vo;
    }
}
