package com.yida.data.server.controller.out;

import cn.hutool.core.util.NumberUtil;
import com.yida.data.server.dto._810ADeviceStaticDTO;
import com.yida.data.server.dto._810ALocationDTO;
import com.yida.data.server.dto._810ALowBatDTO;
import com.yida.data.server.dto._810ARiskAreaDTO;
import com.yida.data.server.dto._810AStepDTO;
import com.yida.data.server.vo._810AResVO;
import io.swagger.annotations.ApiOperation;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiOperation("810A学生证对接")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/out/810a")
public class Out810AController {

    private final com.yida.data.server.service._810ADataService _810ADataService;

    @ApiOperation("推送设备最新位置")
    @RequestMapping("PushDeviceCurpos")
    public _810AResVO pushDeviceCurpos(@RequestBody _810ALocationDTO dto) {
        _810ADataService.dealLocation(dto);
        return _810AResVO.success();
    }

    @ApiOperation("围栏告警")
    @RequestMapping("/PushDeviceFence")
    public _810AResVO pushDeviceFence(@RequestBody LinkedHashMap<String, String> dto) {
        _810ARiskAreaDTO dto1 = new _810ARiskAreaDTO();
        log.info("接收告警数据:[{}]", dto);
        dto1.setDEVICENUM(dto.get("DEVICENUM"));
        dto1.setFENCETYPE(NumberUtil.parseInt(dto.get("FENCETYPE")));
        dto1.setBAT(NumberUtil.parseInt(dto.get("BAT")));
        dto1.setGPS(NumberUtil.parseInt(dto.get("GPS")));
        dto1.setGSM(NumberUtil.parseInt(dto.get("GSM")));
        dto1.setISONLINE(NumberUtil.parseInt(dto.get("ISONLINE")));
        dto1.setLA(NumberUtil.parseDouble(dto.get("LA")));
        dto1.setLO(NumberUtil.parseDouble(dto.get("LO")));
        dto1.setLOCTIME(LocalDateTime.parse(dto.get("LOCTIME"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        dto1.setPOSDESC(dto.get("POSDESC"));
        dto1.setREMARK(dto.get("REMARK"));
        dto1.setSPEED(NumberUtil.parseInt(dto.get("SPEED")));
        dto1.setTYPE(NumberUtil.parseInt(dto.get("TYPE")));
        _810ADataService.riskArea(dto1);
        return _810AResVO.success();
    }

    @ApiOperation("学生步数")
    @RequestMapping("/PushDeviceStep")
    public _810AResVO pushDeviceStep(@RequestBody _810AStepDTO dto) {
        _810ADataService.stepPush(dto);
        return _810AResVO.success();
    }

    @ApiOperation("低电量")
    @RequestMapping("/PushDeviceLowbat")
    public _810AResVO pushDeviceLowbat(@RequestBody _810ALowBatDTO dto) {
        _810ADataService.lowBat(dto);
        return _810AResVO.success();
    }

    @ApiOperation("设备脱落")
    @RequestMapping("PushDeviceStatic")
    public _810AResVO pushDeviceStatic(@RequestBody _810ADeviceStaticDTO dto) {
        _810ADataService.deviceStatic(dto);
        return _810AResVO.success();
    }
}
