package com.hw.dms.controller;

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

import com.hw.common.core.utils.DateUtils;
import com.hw.dms.domain.DmsBillsInspectInstance;
import com.hw.dms.domain.DmsPlanInspect;
import com.hw.dms.domain.DmsPlanLube;
import com.hw.dms.service.IDmsPlanLubeService;
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.DmsBillsLubeInstance;
import com.hw.dms.service.IDmsBillsLubeInstanceService;
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-02-26
 */
@RestController
@RequestMapping("/dmsBillsLubeInstance")
public class DmsBillsLubeInstanceController extends BaseController
{
    @Autowired
    private IDmsBillsLubeInstanceService dmsBillsLubeInstanceService;
    @Autowired
    private IDmsPlanLubeService dmsPlanLubeService;

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

    /**
     * 导出润滑工单列表
     */
    @RequiresPermissions("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, "润滑工单数据");
    }

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

    /**
     * 新增润滑工单
     */
    @RequiresPermissions("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));
    }


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

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