package com.iailab.module.model.mcs.pre.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.module.model.mcs.pre.dao.DmModuleItemDao;
import com.iailab.module.model.mcs.pre.dao.MmPredictMergeItemDao;
import com.iailab.module.model.mcs.pre.entity.MmPredictMergeItemEntity;
import com.iailab.module.model.mcs.pre.service.MmPredictMergeItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.UUID;

/**
 * @author PanZhibao
 * @date 2021年04月27日 9:27
 */
@Service
public class MmPredictMergeItemServiceImpl extends ServiceImpl<MmPredictMergeItemDao, MmPredictMergeItemEntity> implements MmPredictMergeItemService {

    @Autowired
    private MmPredictMergeItemDao mmPredictMergeItemDao;
    
    @Override
    public void savePredictMergeItem(MmPredictMergeItemEntity predictMergeItem) {
        predictMergeItem.setId(UUID.randomUUID().toString());
        mmPredictMergeItemDao.insert(predictMergeItem);
    }

    @Override
    public void update(MmPredictMergeItemEntity predictMergeItem) {
        this.updateById(predictMergeItem);
    }

    public void deleteBatch(String[] itemIds) {
        QueryWrapper queryWrapper = new QueryWrapper<MmPredictMergeItemEntity>();
        queryWrapper.in("itemid", itemIds);
        mmPredictMergeItemDao.delete(queryWrapper);
    }

    public MmPredictMergeItemEntity getByItemid(String itemid) {
        QueryWrapper queryWrapper = new QueryWrapper<MmPredictMergeItemEntity>();
        queryWrapper.eq("itemid", itemid);
        List<MmPredictMergeItemEntity> list = mmPredictMergeItemDao.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return new MmPredictMergeItemEntity();
        }
        return list.get(0);
    }
}