package org.springblade.business.service.impl;

import org.springblade.business.entity.ImageClassificationShow;
import org.springblade.business.mapper.ImageClassificationShowMapper;
import org.springblade.business.service.ImageClassificationShowService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImageClassificationShowServiceImpl extends BaseServiceImpl<ImageClassificationShowMapper, ImageClassificationShow> implements ImageClassificationShowService {

    @Override
    public boolean saveOrUpdateClassifyShowConfig(List<ImageClassificationShow> saveShows, List<ImageClassificationShow> updateShows) {
        try{
            //处理新增
            if(saveShows.size() != 0){
                saveShows.forEach(saveShow -> this.baseMapper.insert(saveShow));
            }
            //处理修改
            if(updateShows.size() != 0){
                updateShows.forEach(show -> {
                    //查询原本数据
                    ImageClassificationShow oldShow = this.baseMapper.selectById(show);
                    //修改is_show
                    oldShow.setIsShow(show.getIsShow());
                    this.baseMapper.updateById(oldShow);
                });
            }
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

        return true;
    }

    public List<ImageClassificationShow> queryShowClassify(String projectId, String contractId, String allQuery){
        return this.baseMapper.queryShowClassify(projectId, contractId, allQuery);
    }

}
