package com.aucma.dms.controller;

import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.dms.domain.DmsPlanMaint;
import com.aucma.dms.service.IDmsPlanMaintService;
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 xins
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/dms/maint")
public class DmsPlanMaintController extends BaseController
{

    @Autowired
    private IDmsPlanMaintService dmsPlanMaintService;


    /**
     * 查询保养计划信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:maint:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsPlanMaint dmsPlanMaint)
    {
        startPage();
        List<DmsPlanMaint> list = dmsPlanMaintService.selectDmsPlanMaintList(dmsPlanMaint);
        return getDataTable(list);
    }

    /**
     * 导出保养计划信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:maint:export')" )
    ////@Log(title = "保养计划信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsPlanMaint dmsPlanMaint)
    {
        List<DmsPlanMaint> list = dmsPlanMaintService.selectDmsPlanMaintList(dmsPlanMaint);
        ExcelUtil<DmsPlanMaint> util = new ExcelUtil<DmsPlanMaint>(DmsPlanMaint.class);
        util.exportExcel(response, list, "保养计划信息数据");
    }

    /**
     * 获取保养计划信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:maint:query')" )
    @GetMapping(value = "/{planMaintId}")
    public AjaxResult getInfo(@PathVariable("planMaintId") Long planMaintId)
    {
        return success(dmsPlanMaintService.selectDmsPlanMaintByPlanMaintId(planMaintId));
    }

    /**
     * 新增保养计划信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:maint:add')" )
    ////@Log(title = "保养计划信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsPlanMaint dmsPlanMaint)
    {
        int i = dmsPlanMaintService.insertDmsPlanMaint(dmsPlanMaint);
        return toAjax(i);
    }

    /**
     * 修改保养计划信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:maint:edit')" )
    ////@Log(title = "保养计划信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsPlanMaint dmsPlanMaint)
    {
        return toAjax(dmsPlanMaintService.updateDmsPlanMaint(dmsPlanMaint));
    }

    /**
     * 删除保养计划信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:maint:remove')" )
    ////@Log(title = "保养计划信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planMaintIds}")
    public AjaxResult remove(@PathVariable Long[] planMaintIds)
    {
        return toAjax(dmsPlanMaintService.deleteDmsPlanMaintByPlanMaintIds(planMaintIds));
    }
}
