package com.vetti.web.controller.hotake;

import com.vetti.common.annotation.Log;
import com.vetti.common.core.controller.BaseController;
import com.vetti.common.core.domain.AjaxResult;
import com.vetti.common.core.page.TableDataInfo;
import com.vetti.common.enums.BusinessType;
import com.vetti.common.utils.SecurityUtils;
import com.vetti.common.utils.poi.ExcelUtil;
import com.vetti.hotake.domain.HotakeCandidateCompliance;
import com.vetti.hotake.domain.dto.CandidateComplianceDto;
import com.vetti.hotake.service.IHotakeCandidateComplianceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags ="候选者合规")
@RestController
@RequestMapping("/hotake/candidateCompliance")
public class HotakeCandidateComplianceController extends BaseController
{
    @Autowired
    private IHotakeCandidateComplianceService hotakeCandidateComplianceService;

    @ApiOperation("查询候选者合规列表")
    @PreAuthorize("@ss.hasPermi('hotake:candidateCompliance:list')")
    @GetMapping("/list")
    public TableDataInfo list(HotakeCandidateCompliance hotakeCandidateCompliance)
    {
        startPage();
        List<CandidateComplianceDto> list = hotakeCandidateComplianceService.selectHotakeCandidateComplianceList(hotakeCandidateCompliance);
        return getDataTable(list);
    }

    @ApiOperation("获取当前登录人候选者合规列表")
    @GetMapping("/listByLoginUser")
    public AjaxResult listByLoginUser()
    {
        HotakeCandidateCompliance query = new HotakeCandidateCompliance();
        query.setUserId(SecurityUtils.getUserId());
        List<CandidateComplianceDto> list = hotakeCandidateComplianceService.selectHotakeCandidateComplianceList(query);
        return AjaxResult.success(list);
    }

//    @ApiOperation("导出候选者合规列表")
//    @PreAuthorize("@ss.hasPermi('hotake:candidateCompliance:export')")
//    @Log(title = "候选者合规", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(HotakeCandidateCompliance hotakeCandidateCompliance)
//    {
//        List<HotakeCandidateCompliance> list = hotakeCandidateComplianceService.selectHotakeCandidateComplianceList(hotakeCandidateCompliance);
//        ExcelUtil<HotakeCandidateCompliance> util = new ExcelUtil<HotakeCandidateCompliance>(HotakeCandidateCompliance.class);
//        return util.exportExcel(list, "候选者合规数据");
//    }

    @ApiOperation("获取候选者合规详细信息")
    @PreAuthorize("@ss.hasPermi('hotake:candidateCompliance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hotakeCandidateComplianceService.selectHotakeCandidateComplianceById(id));
    }

    @ApiOperation("新增候选者合规")
    @PreAuthorize("@ss.hasPermi('hotake:candidateCompliance:add')")
    @Log(title = "候选者合规", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestPart("file") MultipartFile file, HotakeCandidateCompliance hotakeCandidateCompliance)
    {
        return toAjax(hotakeCandidateComplianceService.insertHotakeCandidateCompliance(file, hotakeCandidateCompliance));
    }

    @ApiOperation("修改候选者合规")
    @PreAuthorize("@ss.hasPermi('hotake:candidateCompliance:edit')")
    @Log(title = "候选者合规", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestPart(name = "file", required = false) MultipartFile file, HotakeCandidateCompliance hotakeCandidateCompliance)
    {
        return toAjax(hotakeCandidateComplianceService.updateHotakeCandidateCompliance(file, hotakeCandidateCompliance));
    }

    @ApiOperation("删除候选者合规")
    @PreAuthorize("@ss.hasPermi('hotake:candidateCompliance:remove')")
    @Log(title = "候选者合规", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hotakeCandidateComplianceService.deleteHotakeCandidateComplianceByIds(ids));
    }
}
