package com.usky.fire.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.fire.service.PatrolInspectionPlanService;
import com.usky.fire.service.vo.PatrolInspectionAreaVo;
import com.usky.fire.service.vo.PatrolInspectionPlanDataVo;
import com.usky.fire.service.vo.PatrolInspectionPlanVo;
import com.usky.fire.service.vo.PatrolInspectionSiteVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡查自检-巡检计划
 *
 * @author JCB
 * @since 2022-07-18
 */
@RestController
@RequestMapping("/patrolInspectionPlan")
public class PatrolInspectionPlanController {

    @Autowired
    private PatrolInspectionPlanService patrolInspectionPlanService;

    /**
     * 巡查自检-巡检计划-新增
     *
     * @param patrolInspectionPlanVo
     * @return
     */
    @Log(title = "新增巡检计划", businessType = BusinessType.INSERT)
    @PostMapping("addPatrolInspectionPlan")
    public ApiResult<Void> addPatrolInspectionPlan(@RequestBody PatrolInspectionPlanVo patrolInspectionPlanVo) {
        patrolInspectionPlanService.addPatrolInspectionPlan(patrolInspectionPlanVo);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检计划-修改
     *
     * @param patrolInspectionPlanVo
     * @return
     */
    @Log(title = "修改巡检计划", businessType = BusinessType.UPDATE)
    @PostMapping("updatePatrolInspectionPlan")
    public ApiResult<Void> updatePatrolInspectionPlan(@RequestBody PatrolInspectionPlanVo patrolInspectionPlanVo) {
        patrolInspectionPlanService.updatePatrolInspectionPlan(patrolInspectionPlanVo);
        return ApiResult.success();
    }

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

    /**
     * 巡查自检-巡检计划-列表查询
     *
     * @param planName 计划名称
     * @param planType 计划类型（1 普通计划，2 按次计划）
     * @param areaId   区域ID
     * @param pageNum  当前页
     * @param pageSize 每页条数
     * @param id       计划ID
     * @return
     */
    @GetMapping("patrolInspectionPlanList")
    public ApiResult<CommonPage<PatrolInspectionPlanDataVo>> patrolInspectionPlanList(@RequestParam(value = "planName", required = false) String planName,
                                                                                      @RequestParam(value = "planType", required = false, defaultValue = "0") Integer planType,
                                                                                      @RequestParam(value = "areaId", required = false, defaultValue = "0") Integer areaId,
                                                                                      @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                                      @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                                      @RequestParam(value = "id", required = false, defaultValue = "0") Integer id) {
        return ApiResult.success(patrolInspectionPlanService.patrolInspectionPlanList(planName, planType, areaId, pageNum, pageSize, id));
    }

    /**
     * 巡查自检-巡检计划-左侧区域树形
     *
     * @return
     */
    @GetMapping("planLeftList")
    public ApiResult<List<PatrolInspectionAreaVo>> planLeftList() {
        return ApiResult.success(patrolInspectionPlanService.planLeftList());
    }


    /**
     * 巡查自检-巡检计划-新增/修改弹窗的地点数据查询
     *
     * @param planId 计划ID
     * @param areaId 区域ID
     * @return
     */
    @GetMapping("patrolInspectionSiteVoList")
    public ApiResult<List<PatrolInspectionSiteVo>> patrolInspectionSiteVoList(@RequestParam(value = "planId", required = false, defaultValue = "0") Integer planId,
                                                                              @RequestParam(value = "areaId") Integer areaId) {
        return ApiResult.success(patrolInspectionPlanService.patrolInspectionSiteVoList(planId, areaId));
    }

    /**
     * 巡查自检-巡检子计划-手动生成
     *
     * @return
     */
    @GetMapping("addPlanSon")
    public ApiResult<Void> addPlanSon() {
        patrolInspectionPlanService.addPatrolInspectionPlanSon();
        return ApiResult.success();
    }

    /**
     * 巡查自检-近七天子计划缺失补插（已存在则跳过）
     *
     * @return
     */
    @GetMapping("supplementNearSevenDaysPlanSon")
    public ApiResult<Void> supplementNearSevenDaysPlanSon() {
        patrolInspectionPlanService.supplementNearSevenDaysPlanSon();
        return ApiResult.success();
    }

}

