/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2023/11/9
 */
package org.springblade.modules.yjxt.business.check.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.enums.DanagerAreaCehckTypeEnum;
import org.springblade.modules.yjxt.base.servicePerson.dto.YjxtServicePersonDTO;
import org.springblade.modules.yjxt.base.servicePerson.vo.YjxtServicePersonVO;
import org.springblade.modules.yjxt.business.check.dto.DangerAreaCheckInfoDTO;
import org.springblade.modules.yjxt.business.check.entity.DangerAreaCheckInfoEntity;
import org.springblade.modules.yjxt.business.check.service.IDangerAreaCheckService;
import org.springblade.modules.yjxt.business.check.vo.DangerAreaCheckInfoVO;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/***
 * Date:2023/11/9
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("galaxy-business/yj/check")
@AllArgsConstructor
@Api(value = "应急系统巡查巡检管理接口", tags = "增、删、改、查")
public class DangerAreaCheckController extends BladeController {

    private final IDangerAreaCheckService danagerAreaCheckService;

    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "名称", paramType = "query", dataType = "string"),
    })
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页")
    public R<IPage<DangerAreaCheckInfoVO>> page(@ApiIgnore DangerAreaCheckInfoDTO dto, Query query) {
        BladeUser user = AuthUtil.getUser();
        IPage<DangerAreaCheckInfoVO> pages = danagerAreaCheckService.selectPage(Condition.getPage(query), dto);
        return R.data(pages);
    }


    /**
     * 上报
     */
    @PostMapping("/report")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入 User")
    public R report(@RequestBody DangerAreaCheckInfoEntity entity) {
        if (Func.isNull(entity.getCheckType())) {
            return R.fail("参数错误");
        }
        if (DanagerAreaCehckTypeEnum.CHECK_2.getCode().intValue() == entity.getCheckType().intValue()) {
            if (Func.isNull(entity.getWarnId())) {
                return R.fail("参数错误");
            }
        }
        danagerAreaCheckService.save(entity);
        return R.status(true);
    }
}
