package com.ruoyi.ehsNoticeMessage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.ruoyi.ehsNoticeMessage.mapper.EhsNoticeMessageMapper;
import com.ruoyi.ehsNoticeMessage.domain.EhsNoticeMessage;
import com.ruoyi.ehsNoticeMessage.service.IEhsNoticeMessageService;

/**
 * 内部公告Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-06
 */
@Service
public class EhsNoticeMessageServiceImpl extends ServiceImpl<EhsNoticeMessageMapper, EhsNoticeMessage> implements IEhsNoticeMessageService {

	@Autowired
	private EhsNoticeMessageMapper ehsNoticeMessageMapper;

	/**
	 * 查询内部公告
	 *
	 * @param noticeMessageId 内部公告主键
	 * @return 内部公告
	 */
	@Override
	public EhsNoticeMessage selectEhsNoticeMessageByNoticeMessageId(Long noticeMessageId)
	{
		return ehsNoticeMessageMapper.selectEhsNoticeMessageByNoticeMessageId(noticeMessageId);
	}

	/**
	 * 查询内部公告列表
	 *
	 * @param ehsNoticeMessage 内部公告
	 * @return 内部公告
	 */
	@Override
	public List<EhsNoticeMessage> selectEhsNoticeMessageList(EhsNoticeMessage ehsNoticeMessage)
	{
		return ehsNoticeMessageMapper.selectEhsNoticeMessageList(ehsNoticeMessage);
	}
	@Override
	public List<EhsNoticeMessage> selectEhsNoticeMessageListAdmin(EhsNoticeMessage ehsNoticeMessage)
	{
		return ehsNoticeMessageMapper.selectEhsNoticeMessageListAdmin(ehsNoticeMessage);
	}
	@Override
	public int updateReadCompany(EhsNoticeMessage ehsNoticeMessage)
	{
		return ehsNoticeMessageMapper.updateReadCompany(ehsNoticeMessage);
	}

	private LambdaQueryWrapper<EhsNoticeMessage> buildQueryWrapper(EhsNoticeMessage query) {
		Map<String, Object> params = query.getParams();
		LambdaQueryWrapper<EhsNoticeMessage> lqw = Wrappers.lambdaQuery();
					lqw.eq(StringUtils.isNotBlank(query.getTitle()), EhsNoticeMessage::getTitle, query.getTitle());
					lqw.eq(StringUtils.isNotBlank(query.getDisplayContent()), EhsNoticeMessage::getDisplayContent, query.getDisplayContent());
					lqw.like(StringUtils.isNotBlank(query.getFileName()), EhsNoticeMessage::getFileName, query.getFileName());
					lqw.eq(StringUtils.isNotBlank(query.getStatus()), EhsNoticeMessage::getStatus, query.getStatus());
					lqw.eq(StringUtils.isNotBlank(query.getReadDeptId()), EhsNoticeMessage::getReadDeptId, query.getReadDeptId());
					lqw.eq(query.getMesgType() != null, EhsNoticeMessage::getMesgType, query.getMesgType());
					lqw.eq(StringUtils.isNotBlank(query.getDeptList()), EhsNoticeMessage::getDeptList, query.getDeptList());
					lqw.eq(query.getAllDept() != null, EhsNoticeMessage::getAllDept, query.getAllDept());
				lqw.orderByDesc(EhsNoticeMessage::getCreateTime);
					lqw.eq(query.getDeptId() != null, EhsNoticeMessage::getDeptId, query.getDeptId());
					lqw.eq(query.getCreateUserId() != null, EhsNoticeMessage::getCreateUserId, query.getCreateUserId());
					lqw.eq(query.getUpdateUserId() != null, EhsNoticeMessage::getUpdateUserId, query.getUpdateUserId());
		return lqw;
	}

}
