package com.sqx.modules.message.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.message.dao.OrderMessageDao;
import com.sqx.modules.message.entity.MessageInfo;
import com.sqx.modules.message.service.OrderMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderMessageServiceInpl extends ServiceImpl<OrderMessageDao, MessageInfo> implements OrderMessageService {

    @Autowired
    private OrderMessageDao orderMessageDao;

    @Override
    public Result selectReadFlag(Integer page, Integer limit, String[] shopIds) {
        Page<MessageInfo> pages=new Page<>(page,limit);
        PageUtils pageUtils = new PageUtils(orderMessageDao.selectReadFlag(pages, shopIds));
        return Result.success().put("data", pageUtils);
    }

    @Override
    public Result checkOrderMessage(Long id) {
        MessageInfo messageInfo = new MessageInfo();
        messageInfo.setId(id);
        messageInfo.setReadFlag(1);
        baseMapper.updateById(messageInfo);
        return Result.success();
    }

    @Override
    public Result allcheckOrderMessage(String[] shopId,Integer orderType) {

        baseMapper.allcheckOrderMessage(shopId,orderType==null?2:orderType);
        return Result.success();
    }

    @Override
    public Result selectReadFlagCount(String[] shopId,Integer orderType) {
        int i = orderMessageDao.selectReadFlagCountByFlag(shopId,orderType==null?2:orderType);
        return Result.success().put("data", i);
    }
}
