package com.xunmei.core.resumption.controller;

import cn.hutool.core.date.DateTime;
import com.xunmei.common.core.web.controller.BaseController;
import com.xunmei.common.core.web.domain.AjaxResult;
import com.xunmei.common.core.web.page.TableDataInfo;
import com.xunmei.core.resumption.domain.Protection;
import com.xunmei.core.resumption.dto.appRule.AppRuleEditDto;
import com.xunmei.core.resumption.dto.protection.ProtectionEditDto;
import com.xunmei.core.resumption.dto.protection.ProtectionLogPageDto;
import com.xunmei.core.resumption.dto.protection.ProtectionPageDto;
import com.xunmei.core.resumption.service.IProtectionService;
import com.xunmei.core.resumption.vo.protection.ProtectionPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 */
@Slf4j
@Api(description = "中台", tags = "布防")
@RestController
@RequestMapping("/resumption/protection/")
class ProtectionController extends BaseController {
    @Resource
    IProtectionService protectionService;

    @ApiOperation(value = "分页")
    @GetMapping(value = "page")
//    @WebMethodLogDesc("防区状态app")
    TableDataInfo page(final ProtectionPageDto request) {
        TableDataInfo data = this.protectionService.pageList(request);
        return data;
    }

    @ApiOperation(value = "分页")
    @GetMapping(value = "log/page")
    TableDataInfo LogpageList(final ProtectionLogPageDto request) {
        final TableDataInfo page = this.protectionService.history(request);
        return page;
    }

    @ApiOperation(value = "新增/编辑")
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ProtectionEditDto editDto) {
        return success(protectionService.edit(editDto));
    }

    @ApiOperation(value = "删除规范")
    @GetMapping("{id}")
    public AjaxResult get(@PathVariable Long id) {
        Protection r = protectionService.get(id);
        return success(r);
    }

    @ApiOperation(value = "删除规范")
    @DeleteMapping("{id}")
    public AjaxResult del(@PathVariable Long id) {
        boolean r = protectionService.del(id);
        return success(r);
    }

    @ApiOperation(value = "布撤防")
    @PostMapping("updatestatus/{protectionId}/{status}")
    public AjaxResult edit(@PathVariable Long protectionId,@PathVariable String status) {
        return success(protectionService.updateStatus(protectionId,status));
    }
}