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.PatrolInspectionSite;
import com.usky.fire.service.PatrolInspectionPlanSonService;
import com.usky.fire.service.vo.PatrolInspectionPlanSonVo;
import com.usky.fire.service.vo.PatrolInspectionRecordVo;
import com.usky.fire.service.vo.PatrolInspectionSiteVo;
import com.usky.fire.service.vo.PlanRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * APP-巡检
 *
 * @author JCB
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/appPatrolInspection")
public class AppPatrolInspectionController {

    @Autowired
    private PatrolInspectionPlanSonService patrolInspectionPlanSonService;

    /**
     * App-巡检自查-/首页/巡检计划-统计
     *
     * @param currentDate 时间 格式：yyyy-MM-dd
     * @return
     */
    @GetMapping("appPlanStatistics")
    public ApiResult<Map<String, Object>> appPlanStatistics(@RequestParam(value = "currentDate", required = false) String currentDate) {
        return ApiResult.success(patrolInspectionPlanSonService.appPlanStatistics(currentDate));
    }

    /**
     * App-巡检自查-巡检计划
     *
     * @param currentDate 日期 格式：yyyy-MM-dd
     * @param sort        排序 （正序：ASC 倒序：DESC）
     * @return
     */
    @GetMapping("patrolInspectionPlan")
    public ApiResult<List<PatrolInspectionPlanSonVo>> patrolInspectionPlan(@RequestParam(value = "currentDate", required = false) String currentDate,
                                                                           @RequestParam(value = "sort", required = false, defaultValue = "DESC") String sort) {
        return ApiResult.success(patrolInspectionPlanSonService.patrolInspectionPlan(currentDate, sort));
    }

    /**
     * 手机端-巡检自检-巡检计划-扫码查询计划
     *
     * @param siteNubmber 地点号码
     * @return
     */
    @GetMapping("planList")
    public ApiResult<List<PatrolInspectionPlanSonVo>> planList(@RequestParam(value = "siteNubmber") String siteNubmber) {
        return ApiResult.success(patrolInspectionPlanSonService.planList(siteNubmber));
    }


    /**
     * 手机端-巡检自检-巡检扫码地点详情
     *
     * @param siteId      地点ID
     * @param siteNubmber 地点号码
     * @param planSonId   子计划Id
     * @return
     */
    @GetMapping("siteDetails")
    public ApiResult<Map<String, Object>> siteDetails(@RequestParam(value = "siteId", required = false, defaultValue = "0") Integer siteId,
                                                      @RequestParam(value = "siteNubmber", required = false) String siteNubmber,
                                                      @RequestParam(value = "planSonId", required = false) Integer planSonId) {
        return ApiResult.success(patrolInspectionPlanSonService.siteDetails(siteId, siteNubmber, planSonId));
    }

    /**
     * 手机端-巡检自检-巡检上报-提交
     *
     * @param planRecordVo
     * @return
     */
    @Log(title = "移动端-巡检上报", businessType = BusinessType.UPDATE)
    @PostMapping("updatePlan")
    public ApiResult<Void> updatePlan(@RequestBody PlanRecordVo planRecordVo) {
        patrolInspectionPlanSonService.updatePlan(planRecordVo);
        return ApiResult.success();
    }


    /**
     * 手机端-巡检自检-巡检扫码地点详情
     *
     * @param planSonId 子计划ID
     * @return
     */
    @GetMapping("planSonSiteDetails")
    public ApiResult<List<PatrolInspectionSiteVo>> planSonSiteDetails(@RequestParam(value = "planSonId") Integer planSonId) {
        return ApiResult.success(patrolInspectionPlanSonService.planSonSiteDetails(planSonId));
    }


    /**
     * 手机端-巡检自检-点位采集-提交
     *
     * @param patrolInspectionSite
     * @return
     */
    @Log(title = "移动端-点位采集", businessType = BusinessType.INSERT)
    @PostMapping("addSite")
    public ApiResult<Void> addSite(@RequestBody PatrolInspectionSite patrolInspectionSite) {
        patrolInspectionPlanSonService.addSite(patrolInspectionSite);
        return ApiResult.success();
    }


    /**
     * 手机端-巡检自检-点位采集-采集记录
     *
     * @param startTime 开始时间 格式：yyyy-MM-dd HH:mm:ss
     * @param endTime   结束时间 格式：yyyy-MM-dd HH:mm:ss
     * @return
     */
    @GetMapping("siteList")
    public ApiResult<List<PatrolInspectionSite>> siteList(@RequestParam(value = "startTime", required = false) String startTime,
                                                          @RequestParam(value = "endTime", required = false) String endTime) {
        return ApiResult.success(patrolInspectionPlanSonService.siteList(startTime, endTime));
    }

    /**
     * 手机端-巡检自检-巡检记录
     *
     * @param currentDate 时间 格式：yyyy-MM-dd
     * @param sort        排序 （正序：ASC 倒序：DESC）
     * @param id          记录ID
     * @return
     */
    @GetMapping("recordList")
    public ApiResult<List<PatrolInspectionRecordVo>> recordList(@RequestParam(value = "currentDate", required = false) String currentDate,
                                                                @RequestParam(value = "sort", required = false, defaultValue = "DESC") String sort,
                                                                @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                                                                @RequestParam(value = "planSonId", required = false, defaultValue = "0") Integer planSonId,
                                                                @RequestParam(value = "siteId", required = false, defaultValue = "0") Integer siteId) {
        return ApiResult.success(patrolInspectionPlanSonService.recordList(currentDate, sort, id, planSonId, siteId));
    }


    /**
     * 手机端-巡检自检-巡检记录-查看巡检项
     *
     * @param recordId 记录ID
     * @param siteId   地点ID
     * @return
     */
    @GetMapping("recordOption")
    public ApiResult<Map<String, Object>> recordOption(@RequestParam(value = "recordId") Integer recordId,
                                                       @RequestParam(value = "siteId") Integer siteId) {
        return ApiResult.success(patrolInspectionPlanSonService.recordOption(recordId, siteId));
    }

    /**
     * 巡检系统漏检数据到巡检异常记录表中
     *
     * @return
     */
    @PostMapping("addPatrolInspectionAbnormalData")
    public ApiResult<Void> addPatrolInspectionAbnormalData(){
        patrolInspectionPlanSonService.addPatrolInspectionAbnormalData();
        return ApiResult.success();
    }

}