package com.yuchen.saas.park.service.controller.alarm;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatWarningLevel;
import com.yuchen.saas.park.service.service.IWarningLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.secure.utils.AuthUtil;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 吕海泉
 * @create 2020/12/7 16:53
 */
@RestController
@AllArgsConstructor
@RequestMapping("/level")
@Api(value = "报警等级管理接口", tags = "报警等级管理接口")
public class WarningLevelController {


    @Autowired
    private IWarningLevelService iWarningLevelService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "报警登记详情", notes = "报警登记详情")
    public R<PmgBatWarningLevel> detail(PmgBatWarningLevel pmgBatWarningLevel) {
        PmgBatWarningLevel detail = iWarningLevelService.getOne(Condition.getQueryWrapper(pmgBatWarningLevel));
        return R.data(detail);
    }

    /**
     * 获取所有报警等级
     */
    @GetMapping("/getAllLevel")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取所有报警等级", notes = "获取所有报警等级")
    public R<List<PmgBatWarningLevel>> getAllLevel() {
        List<PmgBatWarningLevel> detail = iWarningLevelService.getAllLevel();
        return R.data(detail);
    }

    /**
     * 根据园区获取报警等级
     */
    @GetMapping("/getLevelByParkId")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "根据园区获取报警等级", notes = "根据园区获取报警等级")
    public R<List<PmgBatWarningLevel>> getLevelByParkId(@RequestParam(required = false) Long parkId) {
        if(parkId==null){
            parkId= Long.parseLong(AuthUtil.getUser().getParkId());
        }
        List<PmgBatWarningLevel> list = iWarningLevelService.getLevelByParkId(parkId);
        return R.data(list);
    }

    /**
     * 获取所有报警等级 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取所有报警等级 分页", notes = "获取所有报警等级 分页")
    public R<IPage<PmgBatWarningLevel>> list(PmgBatWarningLevel pmgBatWarningLevel, Query query) {
        IPage<PmgBatWarningLevel> pages = iWarningLevelService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgBatWarningLevel));
        return  R.data(pages);
    }

    /**
     * 报警等级 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "报警等级 新增", notes = "报警等级 新增")
    public R save(@Valid @RequestBody PmgBatWarningLevel pmgBatWarningLevel) {
        return R.status(iWarningLevelService.save(pmgBatWarningLevel));
    }

    /**
     * 报警等级 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "报警等级 修改", notes = "报警等级 修改")
    public R update(@Valid @RequestBody PmgBatWarningLevel pmgBatWarningLevel) {
        return R.status(iWarningLevelService.updateById(pmgBatWarningLevel));
    }

    /**
     * 报警等级 删除
     * @param ids
     * @return
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "报警等级 删除", notes = "报警等级 删除")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(iWarningLevelService.deleteLogic(Func.toLongList(ids)));
    }
}

