package com.usky.fire.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.fire.domain.PatrolInspectionArea;
import com.usky.fire.service.PatrolInspectionAreaService;
import com.usky.fire.service.vo.PatrolInspectionAreaVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡查自检-巡检区域
 *
 * @author JCB
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/patrolInspectionArea")
public class PatrolInspectionAreaController {

    @Autowired
    private PatrolInspectionAreaService patrolInspectionAreaService;

    /**
     * 巡查自检-巡检区域-新增
     *
     * @param patrolInspectionAreaVo
     * @return
     */
    @Log(title = "巡检区域", businessType = BusinessType.INSERT)
    @PostMapping("addPatrolInspectionArea")
    public ApiResult<Void> addPatrolInspectionArea(@RequestBody PatrolInspectionAreaVo patrolInspectionAreaVo) {
        patrolInspectionAreaService.addPatrolInspectionArea(patrolInspectionAreaVo);
        return ApiResult.success();
    }


    /**
     * 巡查自检-巡检区域-子区域新增
     *
     * @param patrolInspectionArea
     * @return
     */
    @Log(title = "巡检区域-子区域", businessType = BusinessType.INSERT)
    @PostMapping("addPatrolInspectionAreaSon")
    public ApiResult<Void> addPatrolInspectionAreaSon(@RequestBody PatrolInspectionArea patrolInspectionArea) {
        patrolInspectionAreaService.addPatrolInspectionAreaSon(patrolInspectionArea);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检区域-编辑
     *
     * @param patrolInspectionArea
     * @return
     */
    @Log(title = "巡检区域", businessType = BusinessType.UPDATE)
    @PostMapping("updatePatrolInspectionArea")
    public ApiResult<Void> updatePatrolInspectionArea(@RequestBody PatrolInspectionArea patrolInspectionArea) {
        patrolInspectionAreaService.updatePatrolInspectionArea(patrolInspectionArea);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检区域-删除
     *
     * @param id 区域ID
     * @return
     */
    @Log(title = "巡检区域", businessType = BusinessType.DELETE)
    @GetMapping("delPatrolInspectionArea")
    public ApiResult<Void> delPatrolInspectionArea(@RequestParam(value = "id") Integer id) {
        patrolInspectionAreaService.delPatrolInspectionArea(id);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检区域-列表查詢
     *
     * @param areaName 区域名称
     * @param id       区域ID
     * @return
     */
    @GetMapping("patrolInspectionAreaList")
    public ApiResult<List<PatrolInspectionArea>> patrolInspectionAreaList(@RequestParam(value = "areaName", required = false) String areaName,
                                                                          @RequestParam(value = "id", required = false, defaultValue = "0") Integer id) {
        return ApiResult.success(patrolInspectionAreaService.patrolInspectionAreaList(id, areaName));
    }

    /**
     * 巡查自检-巡检区域-一级区域下拉框/巡检人员-二级区域查询
     *
     * @param areaFid 区域父ID
     * @return
     */
    @GetMapping("patrolInspectionAreaSelect")
    public ApiResult<List<PatrolInspectionArea>> patrolInspectionAreaSelect(@RequestParam(value = "areaFid", required = false, defaultValue = "0") Integer areaFid) {
        return ApiResult.success(patrolInspectionAreaService.patrolInspectionAreaSelect(areaFid));
    }


}