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.DmsMaintInstanceActivity;
import com.hw.dms.service.IDmsMaintInstanceActivityService;
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("/dmsMaintInstanceActivity")
public class DmsMaintInstanceActivityController extends BaseController
{
    @Autowired
    private IDmsMaintInstanceActivityService dmsMaintInstanceActivityService;

    /**
     * 查询保养工单实例节点列表
     */
    @RequiresPermissions("dms:dmsMaintInstanceActivity:list")
    @GetMapping("/list")
    public TableDataInfo list(DmsMaintInstanceActivity dmsMaintInstanceActivity)
    {
        startPage();
        List<DmsMaintInstanceActivity> list = dmsMaintInstanceActivityService.selectDmsMaintInstanceActivityList(dmsMaintInstanceActivity);
        return getDataTable(list);
    }

    /**
     * 导出保养工单实例节点列表
     */
    @RequiresPermissions("dms:dmsMaintInstanceActivity:export")
    @Log(title = "保养工单实例节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsMaintInstanceActivity dmsMaintInstanceActivity)
    {
        List<DmsMaintInstanceActivity> list = dmsMaintInstanceActivityService.selectDmsMaintInstanceActivityList(dmsMaintInstanceActivity);
        ExcelUtil<DmsMaintInstanceActivity> util = new ExcelUtil<DmsMaintInstanceActivity>(DmsMaintInstanceActivity.class);
        util.exportExcel(response, list, "保养工单实例节点数据");
    }

    /**
     * 获取保养工单实例节点详细信息
     */
    @RequiresPermissions("dms:dmsMaintInstanceActivity:query")
    @GetMapping(value = "/{instanceActivityId}")
    public AjaxResult getInfo(@PathVariable("instanceActivityId") Long instanceActivityId)
    {
        return success(dmsMaintInstanceActivityService.selectDmsMaintInstanceActivityByInstanceActivityId(instanceActivityId));
    }

    /**
     * 新增保养工单实例节点
     */
    @RequiresPermissions("dms:dmsMaintInstanceActivity:add")
    @Log(title = "保养工单实例节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsMaintInstanceActivity dmsMaintInstanceActivity)
    {
        return toAjax(dmsMaintInstanceActivityService.insertDmsMaintInstanceActivity(dmsMaintInstanceActivity));
    }

    /**
     * 修改保养工单实例节点
     */
    @RequiresPermissions("dms:dmsMaintInstanceActivity:edit")
    @Log(title = "保养工单实例节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsMaintInstanceActivity dmsMaintInstanceActivity)
    {
        return toAjax(dmsMaintInstanceActivityService.updateDmsMaintInstanceActivity(dmsMaintInstanceActivity));
    }

    /**
     * 删除保养工单实例节点
     */
    @RequiresPermissions("dms:dmsMaintInstanceActivity:remove")
    @Log(title = "保养工单实例节点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceActivityIds}")
    public AjaxResult remove(@PathVariable Long[] instanceActivityIds)
    {
        return toAjax(dmsMaintInstanceActivityService.deleteDmsMaintInstanceActivityByInstanceActivityIds(instanceActivityIds));
    }

    @GetMapping("/selectUserIdByDmsMaintInstanceActivityId/{maintInstanceId}/userId/{userId}")
    public boolean selectUserIdByDmsMaintInstanceActivityId(@PathVariable("maintInstanceId") Long maintInstanceId,@PathVariable("userId") Long userId){
        return dmsMaintInstanceActivityService.selectUserIdByDmsMaintInstanceActivityId(maintInstanceId,userId);
    }
}
