package com.hw.dms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hw.dms.domain.DmsBaseDeviceLedger;
import com.hw.dms.domain.DmsBaseLubeStandard;
import com.hw.dms.domain.DmsBaseLubeStation;
import com.hw.dms.service.IDmsBaseDeviceLedgerService;
import com.hw.dms.service.IDmsBaseLubeStandardService;
import com.hw.dms.service.IDmsBaseLubeStationService;
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.DmsPlanLubeDetail;
import com.hw.dms.service.IDmsPlanLubeDetailService;
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 xins
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/dmsPlanLubeDetail")
public class DmsPlanLubeDetailController extends BaseController
{
    @Autowired
    private IDmsPlanLubeDetailService dmsPlanLubeDetailService;

    @Autowired
    private IDmsBaseLubeStandardService dmsBaseLubeStandardService;

    @Autowired
    private IDmsBaseLubeStationService dmsBaseLubeStationService;

    @Autowired
    private IDmsBaseDeviceLedgerService dmsBaseDeviceLedgerService;

    /**
     * 查询润滑计划明细列表
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:list")
    @GetMapping("/list")
    public TableDataInfo list(DmsPlanLubeDetail dmsPlanLubeDetail)
    {
        startPage();
        List<DmsPlanLubeDetail> list = dmsPlanLubeDetailService.selectDmsPlanLubeDetailList(dmsPlanLubeDetail);
        return getDataTable(list);
    }

    /**
     * 导出润滑计划明细列表
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:export")
    @Log(title = "润滑计划明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsPlanLubeDetail dmsPlanLubeDetail)
    {
        List<DmsPlanLubeDetail> list = dmsPlanLubeDetailService.selectDmsPlanLubeDetailList(dmsPlanLubeDetail);
        ExcelUtil<DmsPlanLubeDetail> util = new ExcelUtil<DmsPlanLubeDetail>(DmsPlanLubeDetail.class);
        util.exportExcel(response, list, "润滑计划明细数据");
    }

    /**
     * 获取润滑计划明细详细信息
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:query")
    @GetMapping(value = "/{planLubeDetailId}")
    public AjaxResult getInfo(@PathVariable("planLubeDetailId") Long planLubeDetailId)
    {
        return success(dmsPlanLubeDetailService.selectDmsPlanLubeDetailByPlanLubeDetailId(planLubeDetailId));
    }
    /**
     * 根据计划id查询明细
     * */
    @GetMapping("/getDmsPlanDetailByPlanLubeId/{planLubeId}")
    public TableDataInfo selectPlanLubeDetailByPlanLubeId(@PathVariable("planLubeId") Long planLubeId){

        List<DmsPlanLubeDetail> dmsPlanLubeDetails = dmsPlanLubeDetailService.selectPlanLubeDetailByPlanLubeId(planLubeId);
        return getDataTable(dmsPlanLubeDetails);
    }

    /**
     * 新增润滑计划明细
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:add")
    @Log(title = "润滑计划明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsPlanLubeDetail dmsPlanLubeDetail)
    {
        return toAjax(dmsPlanLubeDetailService.insertDmsPlanLubeDetail(dmsPlanLubeDetail));
    }

    /**
     * 修改润滑计划明细
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:edit")
    @Log(title = "润滑计划明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsPlanLubeDetail dmsPlanLubeDetail)
    {
        return toAjax(dmsPlanLubeDetailService.updateDmsPlanLubeDetail(dmsPlanLubeDetail));
    }

    /**
     * 删除润滑计划明细
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:remove")
    @Log(title = "润滑计划明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planLubeDetailIds}")
    public AjaxResult remove(@PathVariable Long[] planLubeDetailIds)
    {
        return toAjax(dmsPlanLubeDetailService.deleteDmsPlanLubeDetailByPlanLubeDetailIds(planLubeDetailIds));
    }





    /**
     * 获取润滑标准列表
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:query")
    @GetMapping(value = "/getLubeStations")
    public AjaxResult getLubeStations(DmsBaseLubeStation dmsBaseLubeStation)
    {
        return success(dmsBaseLubeStationService.selectDmsBaseLubeStationList(dmsBaseLubeStation));
    }


    /**
     * 获取润滑部位列表
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:query")
    @GetMapping(value = "/getLubeStandards")
    public AjaxResult getLubeStandards(DmsBaseLubeStandard dmsBaseLubeStandard)
    {
        return success(dmsBaseLubeStandardService.selectDmsBaseLubeStandardList(dmsBaseLubeStandard));
    }


    /**
     * 获取设备列表
     */
    @RequiresPermissions("dms:dmsPlanLubeDetail:query")
    @GetMapping(value = "/getBaseDeviceLedgers")
    public AjaxResult getBaseDeviceLedgers(DmsBaseDeviceLedger dmsBaseDeviceLedger)
    {
        System.out.println(dmsBaseDeviceLedgerService.selectDmsBaseDeviceLedgerList(dmsBaseDeviceLedger));
        return success(dmsBaseDeviceLedgerService.selectDmsBaseDeviceLedgerList(dmsBaseDeviceLedger));
    }



}
