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.domain.PatrolInspectionPersonnel;
import com.usky.fire.service.PatrolInspectionPersonnelService;
import com.usky.fire.service.vo.PatrolInspectionAreaVo;
import com.usky.fire.service.vo.PatrolInspectionPersonnelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡查自检-巡检人员
 *
 * @author JCB
 * @since 2022-07-26
 */
@RestController
@RequestMapping("/patrolInspectionPersonnel")
public class PatrolInspectionPersonnelController {

    @Autowired
    private PatrolInspectionPersonnelService patrolInspectionPersonnelService;

    /**
     * 巡查自检-巡检人员-新增
     *
     * @param patrolInspectionPersonnel
     * @return
     */
    @Log(title = "巡检人员", businessType = BusinessType.INSERT)
    @PostMapping("addPatrolInspectionPersonnel")
    public ApiResult<Void> addPatrolInspectionPersonnel(@RequestBody PatrolInspectionPersonnel patrolInspectionPersonnel) {
        patrolInspectionPersonnelService.addPatrolInspectionPersonnel(patrolInspectionPersonnel);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检人员-修改
     *
     * @param patrolInspectionPersonnel
     * @return
     */
    @Log(title = "巡检人员", businessType = BusinessType.UPDATE)
    @PostMapping("updatePatrolInspectionPersonnel")
    public ApiResult<Void> updatePatrolInspectionPersonnel(@RequestBody PatrolInspectionPersonnel patrolInspectionPersonnel) {
        patrolInspectionPersonnelService.updatePatrolInspectionPersonnel(patrolInspectionPersonnel);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检人员-删除
     *
     * @param id 人员记录表ID
     * @return
     */
    @Log(title = "巡检人员", businessType = BusinessType.DELETE)
    @GetMapping("delPatrolInspectionPersonnel")
    public ApiResult<Void> delPatrolInspectionPersonnel(@RequestParam(value = "id") Integer id) {
        patrolInspectionPersonnelService.delPatrolInspectionPersonnel(id);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检人员-列表查询
     *
     * @param areaId   区域ID
     * @param pageNum  当前页
     * @param pageSize 每页条数
     * @param id       人员记录表ID
     * @return
     */
    @GetMapping("patrolInspectionPersonnelList")
    public ApiResult<CommonPage<PatrolInspectionPersonnelVo>> patrolInspectionPersonnelList(@RequestParam(value = "areaId", required = false) 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(patrolInspectionPersonnelService.patrolInspectionPersonnelList(areaId, pageNum, pageSize, id));
    }

    /**
     * 巡查自检-巡检人员-左侧树形数据
     *
     * @return
     */
    @GetMapping("personnelLeftList")
    public ApiResult<List<PatrolInspectionAreaVo>> personnelLeftList() {
        return ApiResult.success(patrolInspectionPersonnelService.personnelLeftList());
    }

    /**
     * 巡查自检-巡检计划-责任人下拉
     * @param areaId 区域ID
     * @return
     */
    @GetMapping("patrolInspectionPersonnelSelect")
    public ApiResult<List<PatrolInspectionPersonnelVo>> patrolInspectionPersonnelSelect(@RequestParam(value = "areaId", required = false) Integer areaId) {
        return ApiResult.success(patrolInspectionPersonnelService.patrolInspectionPersonnelSelect(areaId));
    }

    /**
     * 人员状态查询（0：签到，1：签退）
     */
    @GetMapping("getStatus")
    public ApiResult<PatrolInspectionPersonnel> getStatus(){
        return ApiResult.success(patrolInspectionPersonnelService.getStatus());
    }
}

