package com.phm.manage.controller;

import com.phm.common.annotation.Log;
import com.phm.common.core.controller.BaseController;
import com.phm.common.core.domain.AjaxResult;
import com.phm.common.core.page.TableDataInfo;
import com.phm.common.enums.BusinessType;
import com.phm.common.utils.poi.ExcelUtil;
import com.phm.manage.domain.PreHandleResult;
import com.phm.manage.service.IPreHandleResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据预处理结果Controller
 *
 * @author phm
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/manage/preHandleResult")
public class PreHandleResultController extends BaseController {
    @Autowired
    private IPreHandleResultService preHandleResultService;

    /**
     * 查询数据预处理结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:preHandleResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(PreHandleResult preHandleResult) {
        startPage();
        List<PreHandleResult> list = preHandleResultService.selectPreHandleResultList(preHandleResult);
        return getDataTable(list);
    }

    /**
     * 导出数据预处理结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:preHandleResult:export')")
    @Log(title = "数据预处理结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PreHandleResult preHandleResult) {
        List<PreHandleResult> list = preHandleResultService.selectPreHandleResultList(preHandleResult);
        ExcelUtil<PreHandleResult> util = new ExcelUtil<PreHandleResult>(PreHandleResult.class);
        util.exportExcel(response, list, "数据预处理结果数据");
    }

    /**
     * 获取数据预处理结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:preHandleResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(preHandleResultService.selectPreHandleResultById(id));
    }

    /**
     * 新增数据预处理结果
     */
    @PreAuthorize("@ss.hasPermi('manage:preHandleResult:add')")
    @Log(title = "数据预处理结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PreHandleResult preHandleResult) {
        return toAjax(preHandleResultService.insertPreHandleResult(preHandleResult));
    }

    /**
     * 修改数据预处理结果
     */
    @PreAuthorize("@ss.hasPermi('manage:preHandleResult:edit')")
    @Log(title = "数据预处理结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PreHandleResult preHandleResult) {
        return toAjax(preHandleResultService.updatePreHandleResult(preHandleResult));
    }

    /**
     * 删除数据预处理结果
     */
    @PreAuthorize("@ss.hasPermi('manage:preHandleResult:remove')")
    @Log(title = "数据预处理结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(preHandleResultService.deletePreHandleResultByIds(ids));
    }
}
