package com.itheima.file.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.file.pojo.Org;
import com.itheima.file.pojo.Person;
import com.itheima.file.service.OrgService;
import com.itheima.file.service.PersonService;
import com.itheima.file.util.ExcelUtils;
import com.itheima.file.util.HTTPHelper;
import com.itheima.file.util.SslUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private OrgService orgService;
    @Autowired
    private PersonService personService;

    @GetMapping("/org")
    public void getOrgList(HttpServletResponse response){
        QueryWrapper<Org> queryWrapper = new QueryWrapper<>();
        queryWrapper.last(" limit 500");
        List<Org> list = orgService.list(queryWrapper);
        try {
            ExcelUtils.exportExcel(list, "组织信息", "组织信息", Org.class, "组织信息", response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GetMapping("/person")
    public void getPersonList(HttpServletResponse response){
        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        // queryWrapper.last(" limit 500");
        List<Person> list = personService.list(queryWrapper);
        try {
            ExcelUtils.exportExcel(list, "人员信息", "人员信息", Person.class, "人员信息", response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
