package com.yh.saas.plugin.configuration.announcement.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yh.saas.common.support.util.IdGenerator;
import com.yh.saas.common.support.util.query.QueryUtils;
import com.yh.saas.plugin.configuration.announcement.entity.AnnoReadUserInfo;
import com.yh.saas.plugin.configuration.announcement.mapper.AnnoReadUserInfoMapper;
import com.yh.saas.plugin.configuration.announcement.service.IAnnoReadUserInfoService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 公告模块 - 关联联系人 - 业务实现类
 * </p>
 *
 * @Auther ZhangMingYu
 * @since 2019年8月14日16:00:15
 */
@Service
public class AnnoReadUserInfoServiceImpl extends ServiceImpl<AnnoReadUserInfoMapper, AnnoReadUserInfo> implements IAnnoReadUserInfoService {

    @Autowired
    private AnnoReadUserInfoMapper annoReadUserInfoMapper;

    @Override
    public void createAll(List<AnnoReadUserInfo> annoReadUserInfos) {
        if (CollectionUtils.isEmpty(annoReadUserInfos)){
            return;
        }

        annoReadUserInfos.forEach(annoReadUserInfo -> {
            annoReadUserInfo.setId(IdGenerator.generateUUID());
            annoReadUserInfo.setIsRead("0");
        });
        insertBatch(annoReadUserInfos);
    }

    @Override
    public void remove(String announcementId) {
        annoReadUserInfoMapper.remove(announcementId);
    }

    @Override
    public List<AnnoReadUserInfo> queryLoginUser(String loginUserId) {
        return selectList(new EntityWrapper<AnnoReadUserInfo>().eq(AnnoReadUserInfo.QueryFiles.READ_USER_ID, loginUserId));
    }

    @Override
    public void haveSee(AnnoReadUserInfo annoReadUserInfo){
        annoReadUserInfo.setIsRead("1");
        update(annoReadUserInfo, QueryUtils.convertExampleToWrapper(annoReadUserInfo));
    }

}
