package com.hw.dms.controller;

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

import com.hw.common.core.utils.DateUtils;
import com.hw.common.security.annotation.InnerAuth;
import com.hw.dms.domain.DmsPlanMaint;
import com.hw.dms.service.IDmsPlanMaintService;
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.DmsBillsMaintInstance;
import com.hw.dms.service.IDmsBillsMaintInstanceService;
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-29
 */
@RestController
@RequestMapping("/dmsBillsMaintInstance")
public class DmsBillsMaintInstanceController extends BaseController
{
    @Autowired
    private IDmsBillsMaintInstanceService dmsBillsMaintInstanceService;
    @Autowired
    private IDmsPlanMaintService dmsPlanMaintService;

    /**
     * 查询保养工单列表
     */
    @RequiresPermissions("dms:dmsBillsMaintInstance:list")
    @GetMapping("/list")
    public TableDataInfo list(DmsBillsMaintInstance dmsBillsMaintInstance)
    {
        startPage();
        List<DmsBillsMaintInstance> list = dmsBillsMaintInstanceService.selectDmsBillsMaintInstanceList(dmsBillsMaintInstance);
        return getDataTable(list);
    }

    /**
     * 导出保养工单列表
     */
    @RequiresPermissions("dms:dmsBillsMaintInstance:export")
    @Log(title = "保养工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBillsMaintInstance dmsBillsMaintInstance)
    {
        List<DmsBillsMaintInstance> list = dmsBillsMaintInstanceService.selectDmsBillsMaintInstanceList(dmsBillsMaintInstance);
        ExcelUtil<DmsBillsMaintInstance> util = new ExcelUtil<DmsBillsMaintInstance>(DmsBillsMaintInstance.class);
        util.exportExcel(response, list, "保养工单数据");
    }

    /**
     * 获取保养工单详细信息
     */
    @RequiresPermissions("dms:dmsBillsMaintInstance:query")
    @GetMapping(value = "/{maintInstanceId}")
    public AjaxResult getInfo(@PathVariable("maintInstanceId") Long maintInstanceId)
    {
        return success(dmsBillsMaintInstanceService.selectDmsBillsMaintInstanceByMaintInstanceId(maintInstanceId));
    }

    /**
     * 新增保养工单
     */
    @RequiresPermissions("dms:dmsBillsMaintInstance:add")
    @Log(title = "保养工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsBillsMaintInstance dmsBillsMaintInstance)
    {
        return null;
//        return toAjax(dmsBillsMaintInstanceService.insertDmsBillsMaintInstance(dmsBillsMaintInstance));
    }

//    @InnerAuth
    @PostMapping("/autoAdd")
    public AjaxResult autoAdd(@RequestBody String planMaintCode)
    {
        return toAjax(dmsBillsMaintInstanceService.insertDmsBillsMaintInstance(planMaintCode));
    }

    /**
     * 修改保养工单
     */
    @RequiresPermissions("dms:dmsBillsMaintInstance:edit")
    @Log(title = "保养工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBillsMaintInstance dmsBillsMaintInstance)
    {
        return toAjax(dmsBillsMaintInstanceService.updateDmsBillsMaintInstance(dmsBillsMaintInstance));
    }

    /**
     * 删除保养工单
     */
    @RequiresPermissions("dms:dmsBillsMaintInstance:remove")
    @Log(title = "保养工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintInstanceIds}")
    public AjaxResult remove(@PathVariable Long[] maintInstanceIds)
    {
        return toAjax(dmsBillsMaintInstanceService.deleteDmsBillsMaintInstanceByMaintInstanceIds(maintInstanceIds));
    }
}
