package com.xinda.itsm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.xinda.common.annotation.Log;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.BusinessType;
import com.xinda.itsm.domain.Duty;
import com.xinda.itsm.service.IDutyService;
import com.xinda.common.utils.poi.ExcelUtil;
import com.xinda.common.core.page.TableDataInfo;

/**
 * 值班管理Controller
 *
 * @author kerwincui
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/itsm/duty")
@Api(tags = "值班管理")
public class DutyController extends BaseController
{
    @Autowired
    private IDutyService dutyService;

    /**
     * 查询值班管理列表
     */
    @PreAuthorize("@ss.hasPermi('itsm:duty:list')")
    @GetMapping("/list")
    @ApiOperation("查询值班管理列表")
    public TableDataInfo list(Duty duty)
    {
        startPage();
        List<Duty> list = dutyService.selectDutyList(duty);
        return getDataTable(list);
    }

    /**
     * 导出值班管理列表
     */
    @ApiOperation("导出值班管理列表")
    @PreAuthorize("@ss.hasPermi('itsm:duty:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Duty duty)
    {
        List<Duty> list = dutyService.selectDutyList(duty);
        ExcelUtil<Duty> util = new ExcelUtil<Duty>(Duty.class);
        util.exportExcel(response, list, "值班管理数据");
    }

    /**
     * 获取值班管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('itsm:duty:query')")
    @GetMapping(value = "/{dutyId}")
    @ApiOperation("获取值班管理详细信息")
    public AjaxResult getInfo(@PathVariable("dutyId") Long dutyId)
    {
        return success(dutyService.selectDutyByDutyId(dutyId));
    }

    /**
     * 新增值班管理
     */
    @PreAuthorize("@ss.hasPermi('itsm:duty:add')")
    @PostMapping
    @ApiOperation("新增值班管理")
    public AjaxResult add(@RequestBody Duty duty)
    {
        return toAjax(dutyService.insertDuty(duty));
    }

    /**
     * 修改值班管理
     */
    @PreAuthorize("@ss.hasPermi('itsm:duty:edit')")
    @PutMapping
    @ApiOperation("修改值班管理")
    public AjaxResult edit(@RequestBody Duty duty)
    {
        return toAjax(dutyService.updateDuty(duty));
    }

    /**
     * 删除值班管理
     */
    @PreAuthorize("@ss.hasPermi('itsm:duty:remove')")
    @DeleteMapping("/{dutyIds}")
    @ApiOperation("删除值班管理")
    public AjaxResult remove(@PathVariable Long[] dutyIds)
    {
        return toAjax(dutyService.deleteDutyByDutyIds(dutyIds));
    }
}
