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

/**
 * 应急资源明细Controller
 *
 * @author xintong
 * @date 2021-10-27
 */
@Validated
@Api(value = "应急资源明细控制器", tags = {"应急资源明细管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/zhdd/resourceDetail")
public class ResourceDetailController extends BaseController {

    private final IResourceDetailService iResourceDetailService;

    /**
     * 查询应急资源明细列表
     */
    @ApiOperation("查询应急资源明细列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:list')")
    @GetMapping("/list")
    public TableDataInfo<ResourceDetailVo> list(@Validated(QueryGroup.class) ResourceDetailBo bo) {
        return iResourceDetailService.queryPageList(bo);
    }

    /**
     * 导出应急资源明细列表
     */
    @ApiOperation("导出应急资源明细列表")
//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:export')")
    @Log(title = "应急资源明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated ResourceDetailBo bo, HttpServletResponse response) {
        List<ResourceDetailVo> list = iResourceDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "应急资源明细", ResourceDetailVo.class, response);
    }

    /**
     * 获取应急资源明细详细信息
     */
    @ApiOperation("获取应急资源明细详细信息")
//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:query')")
    @GetMapping("/{id}")
    public AjaxResult<ResourceDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return AjaxResult.success(iResourceDetailService.queryById(id));
    }

    /**
     * 新增应急资源明细
     */
    @ApiOperation("新增应急资源明细")
//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:add')")
    @Log(title = "应急资源明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ResourceDetailBo bo) {
        return toAjax(iResourceDetailService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改应急资源明细
     */
    @ApiOperation("修改应急资源明细")
//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:edit')")
    @Log(title = "应急资源明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ResourceDetailBo bo) {
        return toAjax(iResourceDetailService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除应急资源明细
     */
    @ApiOperation("删除应急资源明细")
//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:remove')")
    @Log(title = "应急资源明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iResourceDetailService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
