package com.kingtom.shengtai.app.message.service.impl;

import java.util.Date;
import java.util.List;

import com.kingtom.kirin.app.system.utils.SystemUtils;
import com.kingtom.kirin.core.common.base.service.impl.BaseServiceImpl;
import com.kingtom.kirin.core.common.exception.AppException;
import com.kingtom.kirin.core.common.utils.CollectionUtils;
import com.kingtom.kirin.core.common.utils.IDUtils;
import com.kingtom.shengtai.app.message.dao.IMsgSummaryDao;
import com.kingtom.shengtai.app.message.model.MsgSummary;
import com.kingtom.shengtai.app.message.service.IMsgReceiveService;
import com.kingtom.shengtai.app.message.service.IMsgSummaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 消息内容表 服务层实现。
 *
 * @author wany
 * @since 2023-12-27
 */
@Service
public class MsgSummaryServiceImpl extends BaseServiceImpl<IMsgSummaryDao, MsgSummary> implements IMsgSummaryService{

    @Autowired
    private IMsgReceiveService msgReceiveService;

    @Override
    public void createMsg(MsgSummary summary, List<String> receiver){
        if(summary == null){
            throw new AppException("消息摘要不能为空！");
        }
        if(StringUtils.isBlank(summary.getType())){
            throw new AppException("消息类型不能为空！");
        }
        if(StringUtils.isBlank(summary.getTitle())){
            throw new AppException("消息标题不能为空！");
        }
        if(StringUtils.isBlank(summary.getContent())){
            throw new AppException("消息内容不能为空！");
        }
        if(CollectionUtils.isEmpty(receiver)){
            throw new AppException("消息接受者不能为空！");
        }
        summary.setId(IDUtils.newUUID());
        summary.setGmtCreate(new Date());
        summary.setGmtModified(summary.getGmtCreate());
        summary.setSysId(SystemUtils.getCurrentSystemId());
        mapper.insert(summary);
        msgReceiveService.create(summary.getId(), receiver);
    }

}
