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.Maintenance;
import com.phm.manage.service.IMaintenanceService;
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/maintenance")
public class MaintenanceController extends BaseController {
    @Autowired
    private IMaintenanceService maintenanceService;

    /**
     * 查询维护信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Maintenance maintenance) {
        startPage();
        List<Maintenance> list = maintenanceService.selectMaintenanceList(maintenance);
        return getDataTable(list);
    }

    /**
     * 导出维护信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenance:export')")
    @Log(title = "维护信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Maintenance maintenance) {
        List<Maintenance> list = maintenanceService.selectMaintenanceList(maintenance);
        ExcelUtil<Maintenance> util = new ExcelUtil<Maintenance>(Maintenance.class);
        util.exportExcel(response, list, "维护信息数据");
    }

    /**
     * 获取维护信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(maintenanceService.selectMaintenanceById(id));
    }

    /**
     * 新增维护信息
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenance:add')")
    @Log(title = "维护信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Maintenance maintenance) {
        return toAjax(maintenanceService.insertMaintenance(maintenance));
    }

    /**
     * 修改维护信息
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenance:edit')")
    @Log(title = "维护信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Maintenance maintenance) {
        return toAjax(maintenanceService.updateMaintenance(maintenance));
    }

    /**
     * 删除维护信息
     */
    @PreAuthorize("@ss.hasPermi('manage:maintenance:remove')")
    @Log(title = "维护信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(maintenanceService.deleteMaintenanceByIds(ids));
    }
}
