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.DmsBillsLubeInstance;
import com.aucma.dms.service.IDmsBillsLubeInstanceService;
import com.aucma.dms.service.IDmsPlanLubeService;
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-02-26
 */
@RestController
@RequestMapping("/dms/dmsBillsLubeInstance")
public class DmsBillsLubeInstanceController extends BaseController
{
    @Autowired
    private IDmsBillsLubeInstanceService dmsBillsLubeInstanceService;
    @Autowired
    private IDmsPlanLubeService dmsPlanLubeService;

    /**
     * 查询润滑工单列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBillsLubeInstance:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsBillsLubeInstance dmsBillsLubeInstance)
    {
        startPage();
        List<DmsBillsLubeInstance> list = dmsBillsLubeInstanceService.selectDmsBillsLubeInstanceList(dmsBillsLubeInstance);
        return getDataTable(list);
    }

    /**
     * 导出润滑工单列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBillsLubeInstance:export')" )
    ////@Log(title = "润滑工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBillsLubeInstance dmsBillsLubeInstance)
    {
        List<DmsBillsLubeInstance> list = dmsBillsLubeInstanceService.selectDmsBillsLubeInstanceList(dmsBillsLubeInstance);
        ExcelUtil<DmsBillsLubeInstance> util = new ExcelUtil<DmsBillsLubeInstance>(DmsBillsLubeInstance.class);
        util.exportExcel(response, list, "润滑工单数据");
    }

    /**
     * 获取润滑工单详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBillsLubeInstance:query')" )
    @GetMapping(value = "/{lubeInstanceId}")
    public AjaxResult getInfo(@PathVariable("lubeInstanceId") Long lubeInstanceId)
    {
        return success(dmsBillsLubeInstanceService.selectDmsBillsLubeInstanceByLubeInstanceId(lubeInstanceId));
    }

    /**
     * 新增润滑工单
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBillsLubeInstance:add')" )
    ////@Log(title = "润滑工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsBillsLubeInstance dmsBillsLubeInstance)
    {
        return toAjax(dmsBillsLubeInstanceService.insertDmsBillsLubeInstance(dmsBillsLubeInstance));
    }
    /**
     * 自动创建
     * */
    @PostMapping("/autoAdd")
    public AjaxResult autoAdd(@RequestBody String lubeInstanceCode)
    {
        return toAjax(dmsBillsLubeInstanceService.insertDmsBillsLubeInstance(lubeInstanceCode));
    }


    /**
     * 修改润滑工单
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBillsLubeInstance:edit')" )
    ////@Log(title = "润滑工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBillsLubeInstance dmsBillsLubeInstance)
    {
        return toAjax(dmsBillsLubeInstanceService.updateDmsBillsLubeInstance(dmsBillsLubeInstance));
    }

    /**
     * 删除润滑工单
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBillsLubeInstance:remove')" )
    ////@Log(title = "润滑工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lubeInstanceIds}")
    public AjaxResult remove(@PathVariable Long[] lubeInstanceIds)
    {
        return toAjax(dmsBillsLubeInstanceService.deleteDmsBillsLubeInstanceByLubeInstanceIds(lubeInstanceIds));
    }
}
