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.MaintenanceTestControl;
import com.phm.manage.service.IMaintenanceTestControlService;
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/maintenanceTestControl")
public class MaintenanceTestControlController extends BaseController {
    @Autowired
    private IMaintenanceTestControlService maintenanceTestControlService;

    /**
     * 查询维修测试控制列表
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenanceTestControl:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaintenanceTestControl maintenanceTestControl) {
        startPage();
        List<MaintenanceTestControl> list = maintenanceTestControlService.selectMaintenanceTestControlList(maintenanceTestControl);
        return getDataTable(list);
    }

    /**
     * 导出维修测试控制列表
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenanceTestControl:export')")
    @Log(title = "维修测试控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintenanceTestControl maintenanceTestControl) {
        List<MaintenanceTestControl> list = maintenanceTestControlService.selectMaintenanceTestControlList(maintenanceTestControl);
        ExcelUtil<MaintenanceTestControl> util = new ExcelUtil<MaintenanceTestControl>(MaintenanceTestControl.class);
        util.exportExcel(response, list, "维修测试控制数据");
    }

    /**
     * 获取维修测试控制详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenanceTestControl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(maintenanceTestControlService.selectMaintenanceTestControlById(id));
    }

    /**
     * 新增维修测试控制
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenanceTestControl:add')")
    @Log(title = "维修测试控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintenanceTestControl maintenanceTestControl) {
        return toAjax(maintenanceTestControlService.insertMaintenanceTestControl(maintenanceTestControl));
    }

    /**
     * 修改维修测试控制
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenanceTestControl:edit')")
    @Log(title = "维修测试控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaintenanceTestControl maintenanceTestControl) {
        return toAjax(maintenanceTestControlService.updateMaintenanceTestControl(maintenanceTestControl));
    }

    /**
     * 删除维修测试控制
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenanceTestControl:remove')")
    @Log(title = "维修测试控制", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(maintenanceTestControlService.deleteMaintenanceTestControlByIds(ids));
    }
}
