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.DmsPlanRepairDetail;
import com.aucma.dms.service.IDmsPlanRepairDetailService;
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 Open Platform
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/dms/dmsRepairDetail")
public class DmsPlanRepairDetailController extends BaseController
{

    @Autowired
    private IDmsPlanRepairDetailService dmsPlanRepairDetailService;

    /**
     * 查询检修计划明细列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRepairDetail:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsPlanRepairDetail dmsPlanRepairDetail)
    {
        startPage();
        List<DmsPlanRepairDetail> list = dmsPlanRepairDetailService.selectDmsPlanRepairDetailList(dmsPlanRepairDetail);
        return getDataTable(list);
    }

    /** 根据计划id查询计划明细列表*/
    @GetMapping("/selectPlanRepairDetailByPlanRepairId/{planRepairId}")
    public TableDataInfo selectPlanRepairDetailByPlanRepairId(@PathVariable("planRepairId") Long planRepairId){
        List<DmsPlanRepairDetail> dmsPlanRepairDetails = dmsPlanRepairDetailService.selectPlanRepairDetailByPlanRepairId(planRepairId);
        return getDataTable(dmsPlanRepairDetails);

    }

    /**
     * 导出检修计划明细列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRepairDetail:export')" )
    ////@Log(title = "检修计划明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsPlanRepairDetail dmsPlanRepairDetail)
    {
        List<DmsPlanRepairDetail> list = dmsPlanRepairDetailService.selectDmsPlanRepairDetailList(dmsPlanRepairDetail);
        ExcelUtil<DmsPlanRepairDetail> util = new ExcelUtil<DmsPlanRepairDetail>(DmsPlanRepairDetail.class);
        util.exportExcel(response, list, "检修计划明细数据");
    }

    /**
     * 获取检修计划明细详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRepairDetail:query')" )
    @GetMapping(value = "/{planRepairDetailId}")
    public AjaxResult getInfo(@PathVariable("planRepairDetailId") Long planRepairDetailId)
    {
        return success(dmsPlanRepairDetailService.selectDmsPlanRepairDetailByPlanRepairDetailId(planRepairDetailId));
    }

    /**
     * 新增检修计划明细
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRepairDetail:add')" )
    ////@Log(title = "检修计划明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsPlanRepairDetail dmsPlanRepairDetail)
    {
        return toAjax(dmsPlanRepairDetailService.insertDmsPlanRepairDetail(dmsPlanRepairDetail));
    }

    /**
     * 修改检修计划明细
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRepairDetail:edit')" )
    ////@Log(title = "检修计划明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsPlanRepairDetail dmsPlanRepairDetail)
    {
        return toAjax(dmsPlanRepairDetailService.updateDmsPlanRepairDetail(dmsPlanRepairDetail));
    }

    /**
     * 删除检修计划明细
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRepairDetail:remove')" )
    ////@Log(title = "检修计划明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planRepairDetailIds}")
    public AjaxResult remove(@PathVariable Long[] planRepairDetailIds)
    {
        return toAjax(dmsPlanRepairDetailService.deleteDmsPlanRepairDetailByPlanRepairDetailIds(planRepairDetailIds));
    }
}
