package com.muyu.enterprise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.enterprise.domain.FaultMessage;
import com.muyu.enterprise.mapper.FaultMessageMapper;
import com.muyu.enterprise.service.FaultMessageService;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 站内信业务实现层
 * @Author: chenruijia
 * @Date 2024/9/28 12.19
 * @Description FaultMessageServiceImpl:站内信业务实现层
 */
@Service
public class FaultMessageServiceImpl extends ServiceImpl<FaultMessageMapper, FaultMessage> implements FaultMessageService {

    @Override
    public List<FaultMessage> selectOne() {
        LambdaQueryWrapper<FaultMessage> queryWrapper = new LambdaQueryWrapper<>();
        //查询消息状态为1的未读数据
        queryWrapper.eq(FaultMessage::getFaultMessageState, 1);
        return this.list(queryWrapper);
    }

    @Override
    public List<FaultMessage> selectTwo() {
        LambdaQueryWrapper<FaultMessage> queryWrapper = new LambdaQueryWrapper<>();
        //查询消息状态为2的已读数据
        queryWrapper.eq(FaultMessage::getFaultMessageState, 2);
        return this.list(queryWrapper);
    }

    @Override
    public List<FaultMessage> faultMessageList(FaultMessage faultMessage) {
        String username = SecurityUtils.getUsername();
        LambdaQueryWrapper<FaultMessage> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(faultMessage.getFaultMessageRemoveName())) {
            queryWrapper.eq(FaultMessage::getFaultMessageSendName,username);
        }
        if (StringUtils.isNotEmpty(String.valueOf(faultMessage.getFaultMessageState()))) {
            queryWrapper.eq(FaultMessage::getFaultMessageState,faultMessage.getFaultMessageState());
        }
        if (StringUtils.isNotEmpty(faultMessage.getFaultMessageSendName())) {
            queryWrapper.like(FaultMessage::getFaultMessageSendName,faultMessage.getFaultMessageSendName());
        }
        return this.list(queryWrapper);
    }
}
