package com.hw.dms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.dms.domain.DmsPlanRepairDetail;
import com.hw.dms.service.IDmsPlanRepairDetailService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 检修计划明细Controller
 *
 * @author Open Platform
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/dmsRepairDetail")
public class DmsPlanRepairDetailController extends BaseController
{
    @Autowired
    private IDmsPlanRepairDetailService dmsPlanRepairDetailService;

    /**
     * 查询检修计划明细列表
     */
    @RequiresPermissions("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);

    }

    /**
     * 导出检修计划明细列表
     */
    @RequiresPermissions("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, "检修计划明细数据");
    }

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

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

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

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