package com.rongwei.sfcommon.sys.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rongwe.scentity.domian.AspSafetyMeeting;
import com.rongwei.safecommon.utils.JSCommonUtils;
import com.rongwei.sfcommon.sys.dao.AspSafetyMeetingDao;
import com.rongwei.sfcommon.sys.service.AspSafetyMeetingService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class AspSafetyMeetingImpl extends ServiceImpl<AspSafetyMeetingDao, AspSafetyMeeting> implements AspSafetyMeetingService {

    @Override
    public void reportMessage() {
        //查询今天和明天需要提醒的会议
        List<AspSafetyMeeting> list = this.baseMapper.selectNeedReportMessage();

        //遍历list处理发送消息
        list.forEach(item -> {
            //处理需要接收消息的人
            List<String> userIdList = Arrays.asList(item.getMeetingparticipationid().split(","));
            String meetingHeader = ObjectUtil.isNotEmpty(item.getMeetingheader()) ? item.getMeetingheader() : "";
            String meetingTitle = ObjectUtil.isNotEmpty(item.getMeetingtitle()) ? item.getMeetingtitle() : "";
            String meetingDate = ObjectUtil.isNotEmpty(item.getMeetingdate()) ? DateUtil.format(item.getMeetingdate(), "yyyy-MM-dd HH:mm:ss") : "";
            String meetingAddress = ObjectUtil.isNotEmpty(item.getMeetingaddress()) ? item.getMeetingaddress() : "";
            String meetingRemark = ObjectUtil.isNotEmpty(item.getMeetingremark()) ? item.getMeetingremark() : "";

            //发送消息
            JSCommonUtils.sendNotify("会议提醒",
                    "由【" + meetingHeader + "】主持的【"
                            + meetingTitle + "】，将于【"
                            + meetingDate + "】在【"
                            + meetingAddress + "】召开会议、会议说明：【"
                            + meetingRemark + "】，请届时参加！",
                    null,
                    userIdList,
                    item.getId(),
                    "safetymeeting");
        });
    }
}
