package com.fjhx.oa.service.daily.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.oa.entity.daily.po.DailyReportDetails;
import com.fjhx.oa.entity.daily.vo.DailyReportDetailsVo;
import com.fjhx.oa.mapper.daily.DailyReportDetailsMapper;
import com.fjhx.oa.service.daily.DailyReportDetailsService;
//import com.fjhx.socket.service.WebSocketServer;
import com.ruoyi.system.utils.UserUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 日报明细 服务实现类
 * </p>
 *
 * @author
 * @since 2023-04-04
 */
//@DS(SourceConstant.OA)
@Service
public class DailyReportDetailsServiceImpl extends ServiceImpl<DailyReportDetailsMapper, DailyReportDetails> implements DailyReportDetailsService {

    @Override
    public List<DailyReportDetailsVo> list(Long id) {
        List<DailyReportDetails> list = list(q -> q.eq(DailyReportDetails::getDailyReportId, id));
        List<DailyReportDetailsVo> dailyReportDetailsVos = BeanUtil.copyToList(list, DailyReportDetailsVo.class);
        UserUtil.assignmentNickName(dailyReportDetailsVos, DailyReportDetails::getCreateUser, DailyReportDetailsVo::setRecipientName);
        return dailyReportDetailsVos;
    }

    @Override
    public void remind(Long id) {
        List<DailyReportDetails> list = list(q -> q.eq(DailyReportDetails::getDailyReportId, id).eq(DailyReportDetails::getIsRead, 0));
        Map<String, Object> msgMap = new HashMap<>();
        msgMap.put("businessId", id);
        msgMap.put("msg", "您有未读的日报");
        for (DailyReportDetails dailyReportDetails : list) {
//            WebSocketServer.sendInfo(dailyReportDetails.getRecipientId(), 1, msgMap);
        }
    }
}
