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.DmsRepairInstanceActivity;
import com.aucma.dms.service.IDmsRepairInstanceActivityService;
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-01-23
 */
@RestController
@RequestMapping("/dms/repairInstanceActivity")
public class DmsRepairInstanceActivityController extends BaseController
{

    @Autowired
    private IDmsRepairInstanceActivityService dmsRepairInstanceActivityService;

    /**
     * 查询检修工单实例节点;最后一步作为检修记录列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:repairInstanceActivity:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsRepairInstanceActivity dmsRepairInstanceActivity)
    {
        startPage();
        List<DmsRepairInstanceActivity> list = dmsRepairInstanceActivityService.selectDmsRepairInstanceActivityList(dmsRepairInstanceActivity);
        return getDataTable(list);
    }

    /**
     * 导出检修工单实例节点;最后一步作为检修记录列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:repairInstanceActivity:export')" )
    ////@Log(title = "检修工单实例节点;最后一步作为检修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsRepairInstanceActivity dmsRepairInstanceActivity)
    {
        List<DmsRepairInstanceActivity> list = dmsRepairInstanceActivityService.selectDmsRepairInstanceActivityList(dmsRepairInstanceActivity);
        ExcelUtil<DmsRepairInstanceActivity> util = new ExcelUtil<DmsRepairInstanceActivity>(DmsRepairInstanceActivity.class);
        util.exportExcel(response, list, "检修工单实例节点;最后一步作为检修记录数据");
    }

    /**
     * 获取检修工单实例节点;最后一步作为检修记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:repairInstanceActivity:query')" )
    @GetMapping(value = "/{instanceActivityId}")
    public AjaxResult getInfo(@PathVariable("instanceActivityId") Long instanceActivityId)
    {
        return success(dmsRepairInstanceActivityService.selectDmsRepairInstanceActivityByInstanceActivityId(instanceActivityId));
    }

    /**
     * 新增检修工单实例节点;最后一步作为检修记录
     */
    //@PreAuthorize("@ss.hasPermi('dms:repairInstanceActivity:add')" )
    ////@Log(title = "检修工单实例节点;最后一步作为检修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsRepairInstanceActivity dmsRepairInstanceActivity)
    {
        return toAjax(dmsRepairInstanceActivityService.insertDmsRepairInstanceActivity(dmsRepairInstanceActivity));
    }

    /**
     * 修改检修工单实例节点;最后一步作为检修记录
     */
    //@PreAuthorize("@ss.hasPermi('dms:repairInstanceActivity:edit')" )
    ////@Log(title = "检修工单实例节点;最后一步作为检修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsRepairInstanceActivity dmsRepairInstanceActivity)
    {
        return toAjax(dmsRepairInstanceActivityService.updateDmsRepairInstanceActivity(dmsRepairInstanceActivity));
    }

    /**
     * 删除检修工单实例节点;最后一步作为检修记录
     */
    //@PreAuthorize("@ss.hasPermi('dms:repairInstanceActivity:remove')" )
    ////@Log(title = "检修工单实例节点;最后一步作为检修记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceActivityIds}")
    public AjaxResult remove(@PathVariable Long[] instanceActivityIds)
    {
        return toAjax(dmsRepairInstanceActivityService.deleteDmsRepairInstanceActivityByInstanceActivityIds(instanceActivityIds));
    }

    /**
     * 通过维修工单实例id查询用户id
     * */
    @GetMapping("/selectUserIdByRepairInstanceId/{repairInstanceId}/userId/{userId}")
    public boolean selectUserIdByRepairInstanceId(@PathVariable("repairInstanceId") Long repairInstanceId,@PathVariable("userId") Long userId){
        return dmsRepairInstanceActivityService.selectUserIdByRepairInstanceId(repairInstanceId,userId);
    }
}
