package com.sky.ioc.service.notice.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.ioc.entity.domain.notice.Notice;
import com.sky.ioc.entity.params.notice.NoticeParam;
import com.sky.ioc.enums.NoticeTypeEnums;
import com.sky.ioc.mapper.notice.NoticeMapper;
import com.sky.ioc.service.notice.NoticeService;
import com.sky.ioc.tool.ReturnMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    NoticeMapper noticeMapper;

    @Override
    public ReturnMsg listPage(NoticeParam noticeParam) {
        long count = noticeMapper.countPage(noticeParam);
        JSONObject jsonObject = new JSONObject();
        List<Map<String,Object>> lists = noticeMapper.listPage(noticeParam);
        for(Map<String,Object> map:lists){
            Integer type = Integer.parseInt(String.valueOf( map.get("type")));
            map.put("type",NoticeTypeEnums.getValue(type));
        }
        jsonObject.put("total",count);
        jsonObject.put("data",lists);
        return ReturnMsg.ok(jsonObject);
    }

    @Override
    public ReturnMsg readNotice(List<Integer> ids) {
        if(ids.size()==0||ids==null){
            return ReturnMsg.fail("参数错误");
        }else{
            noticeMapper.updateStatusByIds(ids);
            return ReturnMsg.ok();
        }
    }

    @Override
    public ReturnMsg delNotice(List<Integer> ids) {
        if(ids.size()==0||ids==null){
            return ReturnMsg.fail("参数错误");
        }else{
            noticeMapper.delByIds(ids);
            return ReturnMsg.ok();
        }
    }

    @Override
    public ReturnMsg getNotice(Integer id) {
        Notice notice = noticeMapper.selectById(id);

        return ReturnMsg.ok(notice);
    }

    @Override
    public List<Map<String, Object>> exportData(NoticeParam noticeParam) {
        List<Map<String,Object>> lists = noticeMapper.listPage(noticeParam);
        for(Map<String,Object> map:lists){
            Integer type = Integer.parseInt(String.valueOf( map.get("type")));
            map.put("type",NoticeTypeEnums.getValue(type));
        }
        return  lists;
    }
}
