package org.nl.hand.rest;

import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.logging.annotation.Log;
import org.nl.hand.dto.HeadDto;
import org.nl.hand.dto.HeadInstDto;
import org.nl.hand.dto.HeadTaskDto;
import org.nl.hand.dto.RegionDto;
import org.nl.hand.service.HandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author : TuQiang
 * @create 2024/4/2 10:18
 */

@RestController
@RequiredArgsConstructor
@Api(tags = "手持接口")
@RequestMapping("/api/hand")
@Slf4j
public class HandController {
    @Autowired
    private HandService handService;

    @PostMapping("/queryArea")
    @Log("查询区域")
    @ApiOperation("查询区域")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> queryArea() {
        return new ResponseEntity<>(handService.queryArea(), HttpStatus.OK);
    }

    @PostMapping("/queryPointByArea")
    @Log("根据区域编码查点位")
    @ApiOperation("根据区域编码查点位")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> queryPointByArea(@RequestBody RegionDto dto) {
        String region_code = dto.getRegion_code();
        return new ResponseEntity<>(handService.queryPointByArea(region_code), HttpStatus.OK);
    }

    @PostMapping("/callTask")
    @Log("手持创建任务")
    @ApiOperation("手持创建任务")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> callTask(@RequestBody HeadDto dto) {
        return new ResponseEntity<>(handService.callTask(dto), HttpStatus.OK);
    }

    @PostMapping("/insts")
    @Log("查询未完成指令")
    @ApiOperation("查询未完成指令")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> queryInst(@RequestBody HeadInstDto dto) {
        return new ResponseEntity<>(handService.queryInst(dto), HttpStatus.OK);
    }

    @PostMapping("/inst")
    @Log("指令操作")
    @ApiOperation("指令操作")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> instOpt(@RequestBody HeadInstDto dto) throws Exception {
        return new ResponseEntity<>(handService.instOpt(dto), HttpStatus.OK);
    }

    @PostMapping("/tasks")
    @Log("查询未完成指令")
    @ApiOperation("查询未完成指令")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> querytasks(@RequestBody HeadTaskDto dto) {
        return new ResponseEntity<>(handService.querytasks(dto), HttpStatus.OK);
    }

    @PostMapping("/taskoperation")
    @Log("指令操作")
    @ApiOperation("指令操作")
    @SaIgnore
    //@PreAuthorize("@el.check('sect:list')")
    public ResponseEntity<Object> taskOperation(@RequestBody HeadTaskDto dto) throws Exception {
        return new ResponseEntity<>(handService.taskOperation(dto), HttpStatus.OK);
    }

}
