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.DmsMaintInstanceActivity;
import com.aucma.dms.service.IDmsBaseMaintStationService;
import com.aucma.dms.service.IDmsMaintInstanceActivityService;
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-02-29
 */
@RestController
@RequestMapping("/dms/dmsMaintInstanceActivity")
public class DmsMaintInstanceActivityController extends BaseController
{

    @Autowired
    private IDmsMaintInstanceActivityService dmsMaintInstanceActivityService;

    @Autowired
    private IDmsBaseMaintStationService dmsBaseMaintStationService;

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

    /**
     * 导出保养工单实例节点列表
     */
    //@PreAuthorize("@ss.hasPermi('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, "保养工单实例节点数据");
    }

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

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

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

    /**
     * 删除保养工单实例节点
     */
    //@PreAuthorize("@ss.hasPermi('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);
    }
}
