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.AnalyzeResult;
import com.phm.manage.service.IAnalyzeResultService;
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/analyzeResult")
public class AnalyzeResultController extends BaseController {
    @Autowired
    private IAnalyzeResultService analyzeResultService;

    /**
     * 查询数据解析结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(AnalyzeResult analyzeResult) {
        startPage();
        List<AnalyzeResult> list = analyzeResultService.selectAnalyzeResultList(analyzeResult);
        return getDataTable(list);
    }

    /**
     * 导出数据解析结果列表
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeResult:export')")
    @Log(title = "数据解析结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnalyzeResult analyzeResult) {
        List<AnalyzeResult> list = analyzeResultService.selectAnalyzeResultList(analyzeResult);
        ExcelUtil<AnalyzeResult> util = new ExcelUtil<AnalyzeResult>(AnalyzeResult.class);
        util.exportExcel(response, list, "数据解析结果数据");
    }

    /**
     * 获取数据解析结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(analyzeResultService.selectAnalyzeResultById(id));
    }

    /**
     * 新增数据解析结果
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeResult:add')")
    @Log(title = "数据解析结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AnalyzeResult analyzeResult) {
        return toAjax(analyzeResultService.insertAnalyzeResult(analyzeResult));
    }

    /**
     * 修改数据解析结果
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeResult:edit')")
    @Log(title = "数据解析结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AnalyzeResult analyzeResult) {
        return toAjax(analyzeResultService.updateAnalyzeResult(analyzeResult));
    }

    /**
     * 删除数据解析结果
     */
    @PreAuthorize("@ss.hasPermi('manage:analyzeResult:remove')")
    @Log(title = "数据解析结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(analyzeResultService.deleteAnalyzeResultByIds(ids));
    }
}
