package com.sqx.modules.resumes.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.resumes.entity.Company;
import com.sqx.modules.resumes.service.CompanyService;
import com.sqx.modules.utils.excel.ExcelData;
import com.sqx.modules.utils.excel.ExportExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(value = "企业", tags = {"企业"})
@RequestMapping(value = "/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

//    @PostMapping("/insertCompany")
//    @ApiOperation("添加企业")
//    public Result insertCompany(@RequestBody Company company){
//        return companyService.insertCompany(company);
//    }
    @Login
    @PostMapping("/insertCompany")
    @ApiOperation("添加企业")
    public Result insertCompany(@RequestBody Company company,@RequestAttribute("userId")Long userId){

       return companyService.insertCompany(company,userId);
   }
    @PostMapping("/updateCompany")
    @ApiOperation("修改企业")
    public Result updateCompany(@RequestBody Company company){
        company.setStatus(2);
        return companyService.updateCompany(company);
    }

    @PostMapping("/auditCompany")
    @ApiOperation("审核企业")
    public Result auditCompany(String ids,String content,Integer status){
        return companyService.auditContent(ids, content, status);
    }

    @GetMapping("/selectCompanyByUserId")
    @ApiOperation("查询用户的企业")
    public Result selectCompanyByUserId(Long userId){
        return Result.success().put("data",companyService.selectCompanyByUserId(userId));
    }
    @GetMapping("/selectCompanyList")
    @ApiOperation("查询企业列表")
    public Result selectCompanyList(Integer page,Integer limit,String startTime, String endTime,String companyName,String companyPhone,String userName,Integer status){
        return companyService.selectCompanyList(page, limit,startTime,endTime, companyName, companyPhone, userName, status);
    }

    @GetMapping("/selectCompanyByCompanyId")
    @ApiOperation("查询企业详情")
    public Result selectCompanyByCompanyId(Long companyId){
        return Result.success().put("data",companyService.selectCompanyByCompanyId( companyId));
    }

    @PostMapping("/deleteCompany")
    @ApiOperation("删除企业")
    public Result deleteCompany(Long companyId){
        return Result.success().put("data",companyService.removeById(companyId));
    }



    @GetMapping("/exportExcelCompanyList")
    @ApiOperation("导出企业列表")
    public void exportExcelCompanyList(String startTime, String endTime, String companyName, String companyPhone, String userName, Integer status, HttpServletResponse response) throws Exception {
        ExcelData excelData = companyService.exportExcelCompanyList(startTime,endTime,companyName,companyPhone,userName,status);
        ExportExcelUtils.exportExcel(response, "企业列表.xlsx", excelData);
    }


}
