package com.ruoyi.web.controller.zhdd;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhdd.domain.vo.DutyReportVo;
import com.ruoyi.zhdd.domain.bo.DutyReportBo;
import com.ruoyi.zhdd.service.IDutyReportService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 值班报告信息Controller
 *
 * @author xintong
 * @date 2021-10-11
 */
@Validated
@Api(value = "值班报告信息控制器", tags = {"值班报告信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/zhdd/dutyReport")
public class DutyReportController extends BaseController {

    private final IDutyReportService iDutyReportService;

    /**
     * 查询值班报告信息列表
     */
    @ApiOperation("查询值班报告信息列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:list')")
    @GetMapping("/list")
    public TableDataInfo<DutyReportVo> list(@Validated(QueryGroup.class) DutyReportBo bo) {
        return iDutyReportService.queryPageList(bo);
    }

    /**
     * 导出值班报告信息列表
     */
    @ApiOperation("导出值班报告信息列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:export')")
    @Log(title = "值班报告信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated DutyReportBo bo, HttpServletResponse response) {
        List<DutyReportVo> list = iDutyReportService.queryList(bo);
        ExcelUtil.exportExcel(list, "值班报告信息", DutyReportVo.class, response);
    }

    /**
     * 获取值班报告信息详细信息
     */
    @ApiOperation("获取值班报告信息详细信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:query')")
    @GetMapping("/{id}")
    public AjaxResult<DutyReportVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return AjaxResult.success(iDutyReportService.queryById(id));
    }

    /**
     * 新增值班报告信息
     */
    @ApiOperation("新增值班报告信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:add')")
    @Log(title = "值班报告信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody DutyReportBo bo) {
        return toAjax(iDutyReportService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改值班报告信息
     */
    @ApiOperation("修改值班报告信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:edit')")
    @Log(title = "值班报告信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody DutyReportBo bo) {
        return toAjax(iDutyReportService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除值班报告信息
     */
    @ApiOperation("删除值班报告信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:remove')")
    @Log(title = "值班报告信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iDutyReportService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
