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.PlanTaskVo;
import com.ruoyi.zhdd.domain.bo.PlanTaskBo;
import com.ruoyi.zhdd.service.IPlanTaskService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 预案任务管理Controller
 *
 * @author xitong
 * @date 2021-09-28
 */
@Validated
@Api(value = "预案任务管理控制器", tags = {"预案任务管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/zhdd/planTask")
public class PlanTaskController extends BaseController {

    private final IPlanTaskService iPlanTaskService;

    /**
     * 查询预案任务管理列表
     */
    @ApiOperation("查询预案任务管理列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:list')")
    @GetMapping("/list")
    public AjaxResult<List<PlanTaskVo>> list(@Validated(QueryGroup.class) PlanTaskBo bo) {
        return AjaxResult.success(iPlanTaskService.queryList(bo));
    }

    /**
     * 导出预案任务管理列表
     */
    @ApiOperation("导出预案任务管理列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:export')")
    @Log(title = "预案任务管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated PlanTaskBo bo, HttpServletResponse response) {
        List<PlanTaskVo> list = iPlanTaskService.queryList(bo);
        ExcelUtil.exportExcel(list, "预案任务管理", PlanTaskVo.class, response);
    }

    /**
     * 获取预案任务管理详细信息
     */
    @ApiOperation("获取预案任务管理详细信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:query')")
    @GetMapping("/{id}")
    public AjaxResult<PlanTaskVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return AjaxResult.success(iPlanTaskService.queryById(id));
    }

    /**
     * 新增预案任务管理
     */
    @ApiOperation("新增预案任务管理")
//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:add')")
    @Log(title = "预案任务管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PlanTaskBo bo) {
        return toAjax(iPlanTaskService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改预案任务管理
     */
    @ApiOperation("修改预案任务管理")
//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:edit')")
    @Log(title = "预案任务管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PlanTaskBo bo) {
        return toAjax(iPlanTaskService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除预案任务管理
     */
    @ApiOperation("删除预案任务管理")
//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:remove')")
    @Log(title = "预案任务管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iPlanTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
