package com.goomood.phm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.goomood.common.annotation.Log;
import com.goomood.common.core.controller.BaseController;
import com.goomood.common.core.domain.AjaxResult;
import com.goomood.common.enums.BusinessType;
import com.goomood.phm.domain.TechData;
import com.goomood.phm.service.ITechDataService;
import com.goomood.common.utils.poi.ExcelUtil;
import com.goomood.common.core.page.TableDataInfo;

/**
 * 技术资料Controller
 * 
 * @author goomood
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/tech/techData")
public class TechDataController extends BaseController
{
    @Autowired
    private ITechDataService techDataService;

    /**
     * 查询技术资料列表
     */
    @PreAuthorize("@ss.hasPermi('tech:techData:list')")
    @GetMapping("/list")
    public TableDataInfo list(TechData techData)
    {
        startPage();
        List<TechData> list = techDataService.selectTechDataList(techData);
        return getDataTable(list);
    }

    /**
     * 导出技术资料列表
     */
    @PreAuthorize("@ss.hasPermi('tech:techData:export')")
    @Log(title = "技术资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TechData techData)
    {
        List<TechData> list = techDataService.selectTechDataList(techData);
        ExcelUtil<TechData> util = new ExcelUtil<TechData>(TechData.class);
        util.exportExcel(response, list, "技术资料数据");
    }

    /**
     * 获取技术资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('tech:techData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(techDataService.selectTechDataById(id));
    }

    /**
     * 新增技术资料
     */
    @PreAuthorize("@ss.hasPermi('tech:techData:add')")
    @Log(title = "技术资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechData techData)
    {
        return toAjax(techDataService.insertTechData(techData));
    }

    /**
     * 修改技术资料
     */
    @PreAuthorize("@ss.hasPermi('tech:techData:edit')")
    @Log(title = "技术资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechData techData)
    {
        return toAjax(techDataService.updateTechData(techData));
    }

    /**
     * 删除技术资料
     */
    @PreAuthorize("@ss.hasPermi('tech:techData:remove')")
    @Log(title = "技术资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(techDataService.deleteTechDataByIds(ids));
    }

    @Log(title = "下载文件", businessType = BusinessType.OTHER)
    @PostMapping("/download/{oosId}")
    public AjaxResult downloadFile(@PathVariable("oosId") Long oosId,HttpServletResponse response)
    {
        return toAjax(techDataService.downloadFile(oosId,response));
    }
}
