package com.skr.mdm.api.track.controller;

import com.skr.mdm.api.track.service.TrackService;
import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author nfq
 * @date 2020/9/22 16:33
 */
@RestController
@RequestMapping("track")
@Api(tags = "轨迹")
public class TrackController {

    @Autowired
    private TrackService trackService;

    @PostMapping("terminal")
    @ApiOperation(value = "获取终端")
    @PreAuthorize("hasAnyAuthority(new String[] {'sys:equipment:security:position', 'sys:equipment:security:track'})")
    public ResponseResult listEquipmentByDepartmentId(@RequestParam(required = false) Integer departmentId,
                                                      @RequestParam(required = false) String userName,
                                                      @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return trackService.listEquipmentByDepartmentId(departmentId, userName, loginAdminDTO);
    }

    @PostMapping("location")
    @ApiOperation(value = "获取终端位置")
    @PreAuthorize("hasAnyAuthority('sys:equipment:security:position')")
    public ResponseResult getLocation(Integer sid, Integer tid, Integer trid) {
        return trackService.getLocation(sid, tid, trid);
    }

    @PostMapping("search")
    @ApiOperation(value = "获取终端轨迹")
    @PreAuthorize("hasAnyAuthority('sys:equipment:security:track')")
    public ResponseResult getTrack(Integer sid, Integer tid, Integer trid, Long startTime, Long endTime) {
        return trackService.getTrack(sid, tid, trid, startTime, endTime);
    }
}
