package com.fjhx.mail.controller.message;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.fjhx.mail.config.MailServiceConfig;
import com.fjhx.mail.service.message.InfoService;
import com.ruoyi.common.annotation.NonInterception;
import com.ruoyi.common.core.domain.BaseSelectDto;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/mailInfo")
public class InfoController {

    @Autowired
    private InfoService infoService;

    /**
     * 获取员工邮箱
     */
    @PostMapping("/getUserList")
    public List<SysUser> getUserList() {
        return infoService.getExistMailUserList();
    }

    /**
     * 获取用户邮箱列表
     */
    @NonInterception
    @PostMapping("/getUserEmailList")
    public Object getUserEmailList(@RequestBody BaseSelectDto dto) {
        Long id = dto.getId();
        if (id == null) {
            throw new ServiceException("用户id不能为空");
        }

        String get = HttpUtil.get(MailServiceConfig.urlPrefix + "getUserEmailList/" + id);
        return JSON.parseObject(get);
    }

}
