package com.ruoyi.web.controller.zhdd;

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

import com.ruoyi.zhdd.domain.bo.PlanFileBo;
import com.ruoyi.zhdd.service.IPlanFileService;
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.PlanVo;
import com.ruoyi.zhdd.domain.bo.PlanBo;
import com.ruoyi.zhdd.service.IPlanService;
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/plan")
public class PlanController extends BaseController {

    private final IPlanService iPlanService;
    private final IPlanFileService planFileService;

    /**
     * 查询预案管理列表
     */
    @ApiOperation("查询预案管理列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:plan:list')")
    @GetMapping("/list")
    public TableDataInfo<PlanVo> list(@Validated(QueryGroup.class) PlanBo bo) {
        return iPlanService.queryPageList(bo);
    }

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

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

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

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

    @ApiOperation("新增预案文件")
    @Log(title = "新增预案文件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/file")
    public AjaxResult<Void> addFile(PlanFileBo planFileBo) {
        return toAjax(planFileService.insertByBo(planFileBo) ? 1 : 0);
    }
}
