package com.cn.fdapfe.biz.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.cn.fdapfe.common.utils.file.FileCopyUtils;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cn.fdapfe.common.annotation.Log;
import com.cn.fdapfe.common.core.controller.BaseController;
import com.cn.fdapfe.common.core.domain.AjaxResult;
import com.cn.fdapfe.common.enums.BusinessType;
import com.cn.fdapfe.biz.domain.FdAlgorithm;
import com.cn.fdapfe.biz.service.IFdAlgorithmService;
import com.cn.fdapfe.common.utils.poi.ExcelUtil;
import com.cn.fdapfe.common.core.page.TableDataInfo;

/**
 * 故障诊断算法功能验证Controller
 * 
 * @author Allen
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/test/ddAlgorithm")
public class FdAlgorithmController extends BaseController
{
    @Resource
    private IFdAlgorithmService fdAlgorithmService;

    /**
     * 查询故障诊断算法功能验证列表
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:list')")
    @GetMapping("/list")
    public TableDataInfo list(FdAlgorithm fdAlgorithm)
    {
        startPage();
        List<FdAlgorithm> list = fdAlgorithmService.selectFdAlgorithmList(fdAlgorithm);
        return getDataTable(list);
    }

    /**
     * 导出故障诊断算法功能验证列表
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:export')")
    @Log(title = "故障诊断算法功能验证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FdAlgorithm fdAlgorithm)
    {
        List<FdAlgorithm> list = fdAlgorithmService.selectFdAlgorithmList(fdAlgorithm);
        ExcelUtil<FdAlgorithm> util = new ExcelUtil<FdAlgorithm>(FdAlgorithm.class);
        util.exportExcel(response, list, "故障诊断算法功能验证数据");
    }

    /**
     * 获取故障诊断算法功能验证详细信息
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(fdAlgorithmService.selectFdAlgorithmById(id));
    }

    /**
     * 新增故障诊断算法功能验证
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:add')")
    @Log(title = "故障诊断算法功能验证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FdAlgorithm fdAlgorithm) throws IOException, InterruptedException {
        return toAjax(fdAlgorithmService.insertFdAlgorithm(fdAlgorithm));
    }

    /**
     * 修改故障诊断算法功能验证
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:edit')")
    @Log(title = "故障诊断算法功能验证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FdAlgorithm fdAlgorithm) throws IOException, InterruptedException {
        return toAjax(fdAlgorithmService.updateFdAlgorithm(fdAlgorithm));
    }

    /**
     * 删除故障诊断算法功能验证
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:remove')")
    @Log(title = "故障诊断算法功能验证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(fdAlgorithmService.deleteFdAlgorithmByIds(ids));
    }

    /**
     * 验证
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:edit')")
    @Log(title = "验证", businessType = BusinessType.UPDATE)
    @PutMapping("/handleVerify")
    public Map handleVerify(@RequestBody FdAlgorithm po) throws IOException, InterruptedException {
        return fdAlgorithmService.handleVerify(po);
    }

    /**
     * 查询故障诊断算法功能验证Options
     */
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:list')")
    @GetMapping("/getOptions")
    public AjaxResult getOptions()
    {
        return success(fdAlgorithmService.getOptions());
    }
    @PreAuthorize("@ss.hasPermi('test:ddAlgorithm:edit')")
    @PostMapping("/fileCopys")
    public AjaxResult fileCopys(@RequestBody Map<String, Object> params) throws IOException {
        // 直接从Map中获取参数
        String fileName = (String) params.get("fileName");
        String filelocalPath = (String) params.get("filelocalPath");
        String modelPath = (String) params.get("modelPath");
        return AjaxResult.success(FileCopyUtils.copyFile(filelocalPath,modelPath+ File.separator + "input",fileName));
    }

}
