package org.ta.pddserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.ta.pdd.entity.LogsMailScanEntity;
import org.ta.pdd.entity.StorageEntity;
import org.ta.pddserver.mapper.LogsMailScanMapper;
import org.ta.pddserver.model.api.request.LogsMailScanListVORequest;
import org.ta.pddserver.model.api.request.StorageListVORequest;
import org.ta.pddserver.service.LogsMailScanService;

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

@Service
public class LogsMailScanImpl extends ServiceImpl<LogsMailScanMapper, LogsMailScanEntity> implements LogsMailScanService {

    public void makeLog(String mailNo, String action) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = authentication.getName();
        LogsMailScanEntity entity = new LogsMailScanEntity();
        entity.setMailNo(mailNo);
        entity.setAction(action);
        entity.setAuthor(username);
        this.save(entity);
    }

    public List<LogsMailScanEntity> getByMail(String mailNo) {
        return this.baseMapper.selectByMailNo(mailNo);
    }

    public Map<String, Object> logsMailScanList(LogsMailScanListVORequest param) {
        List<LogsMailScanEntity> list = baseMapper.logsMailScanList(param);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        return map;
    }
}