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.DmsFaultInstanceActivity;
import com.hw.dms.service.IDmsFaultInstanceActivityService;
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-27
 */
@RestController
@RequestMapping("/activity")
public class DmsFaultInstanceActivityController extends BaseController
{
    @Autowired
    private IDmsFaultInstanceActivityService dmsFaultInstanceActivityService;

    /**
     * 查询故障报修工单实例节点列表
     */
    @RequiresPermissions("dms:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(DmsFaultInstanceActivity dmsFaultInstanceActivity)
    {
        startPage();
        List<DmsFaultInstanceActivity> list = dmsFaultInstanceActivityService.selectDmsFaultInstanceActivityList(dmsFaultInstanceActivity);
        return getDataTable(list);
    }

    /**
     * 导出故障报修工单实例节点列表
     */
    @RequiresPermissions("dms:activity:export")
    @Log(title = "故障报修工单实例节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsFaultInstanceActivity dmsFaultInstanceActivity)
    {
        List<DmsFaultInstanceActivity> list = dmsFaultInstanceActivityService.selectDmsFaultInstanceActivityList(dmsFaultInstanceActivity);
        ExcelUtil<DmsFaultInstanceActivity> util = new ExcelUtil<DmsFaultInstanceActivity>(DmsFaultInstanceActivity.class);
        util.exportExcel(response, list, "故障报修工单实例节点数据");
    }

    /**
     * 获取故障报修工单实例节点详细信息
     */
    @RequiresPermissions("dms:activity:query")
    @GetMapping(value = "/{instanceActivityId}")
    public AjaxResult getInfo(@PathVariable("instanceActivityId") Long instanceActivityId)
    {
        return success(dmsFaultInstanceActivityService.selectDmsFaultInstanceActivityByInstanceActivityId(instanceActivityId));
    }

    /**
     * 新增故障报修工单实例节点
     */
    @RequiresPermissions("dms:activity:add")
    @Log(title = "故障报修工单实例节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsFaultInstanceActivity dmsFaultInstanceActivity)
    {
        return toAjax(dmsFaultInstanceActivityService.insertDmsFaultInstanceActivity(dmsFaultInstanceActivity));
    }

    /**
     * 修改故障报修工单实例节点
     */
    @RequiresPermissions("dms:activity:edit")
    @Log(title = "故障报修工单实例节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsFaultInstanceActivity dmsFaultInstanceActivity)
    {
        return toAjax(dmsFaultInstanceActivityService.updateDmsFaultInstanceActivity(dmsFaultInstanceActivity));
    }

    /**
     * 删除故障报修工单实例节点
     */
    @RequiresPermissions("dms:activity:remove")
    @Log(title = "故障报修工单实例节点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceActivityIds}")
    public AjaxResult remove(@PathVariable Long[] instanceActivityIds)
    {
        return toAjax(dmsFaultInstanceActivityService.deleteDmsFaultInstanceActivityByInstanceActivityIds(instanceActivityIds));
    }
    @GetMapping("/selectUserIdByDmsFaultInstanceActivity/{repairInstanceId}/userId/{userId}")
    public boolean selectUserIdByDmsBillsLubeInstanceActivityId(@PathVariable("repairInstanceId") Long inspectInstanceId,@PathVariable("userId") Long userId){
        return   dmsFaultInstanceActivityService.selectUserIdByDmsFaultInstanceActivity(inspectInstanceId,userId);
    }
}
