package com.ruoyi.system.service.impl;

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

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RecordInfoMapper;
import com.ruoyi.system.domain.RecordInfo;
import com.ruoyi.system.service.IRecordInfoService;

/**
 * 记录信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-02-07
 */
@Service
public class RecordInfoServiceImpl implements IRecordInfoService 
{
    @Autowired
    private RecordInfoMapper recordInfoMapper;

    /**
     * 查询记录信息
     * 
     * @param id 记录信息主键
     * @return 记录信息
     */
    @Override
    public RecordInfo selectRecordInfoById(Long id)
    {
        return recordInfoMapper.selectRecordInfoById(id);
    }

    /**
     * 查询记录信息列表
     * 
     * @param recordInfo 记录信息
     * @return 记录信息
     */
    @Override
    public List<RecordInfo> selectRecordInfoList(RecordInfo recordInfo)
    {
        return recordInfoMapper.selectRecordInfoList(recordInfo);
    }

    /**
     * 新增记录信息
     * 
     * @param recordInfo 记录信息
     * @return 结果
     */
    @Override
    public int insertRecordInfo(RecordInfo recordInfo)
    {
        recordInfo.setCreateTime(DateUtils.getNowDate());
        return recordInfoMapper.insertRecordInfo(recordInfo);
    }

    /**
     * 修改记录信息
     * 
     * @param recordInfo 记录信息
     * @return 结果
     */
    @Override
    public int updateRecordInfo(RecordInfo recordInfo)
    {
        recordInfo.setUpdateTime(DateUtils.getNowDate());
        return recordInfoMapper.updateRecordInfo(recordInfo);
    }

    /**
     * 批量删除记录信息
     * 
     * @param ids 需要删除的记录信息主键
     * @return 结果
     */
    @Override
    public int deleteRecordInfoByIds(Long[] ids)
    {
        return recordInfoMapper.deleteRecordInfoByIds(ids);
    }

    /**
     * 删除记录信息信息
     * 
     * @param id 记录信息主键
     * @return 结果
     */
    @Override
    public int deleteRecordInfoById(Long id)
    {
        return recordInfoMapper.deleteRecordInfoById(id);
    }

    @Override
    public AjaxResult numberInfo() {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        RecordInfo recordInfo = new RecordInfo();
        recordInfo.setAddresseeId(String.valueOf(user.getUserId()));
        recordInfo.setIsRead("0");
        List<RecordInfo> list = recordInfoMapper.selectRecordInfoList(recordInfo);
        Map<String,Object> map = new HashMap<>();
        map.put("total",list.size());
        map.put("recordInfoList",list);
        return AjaxResult.success("成功",map);
    }

    @Override
    public int isChange(Long[] ids) {
        return recordInfoMapper.updateRecordInfoIsChange(ids);
    }
}
