package com.prolog.rdc.tms.controller.basicData;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.basicData.StartingStationViewDTO;
import com.prolog.rdc.tms.model.dto.basicData.StationDistanceDTO;
import com.prolog.rdc.tms.model.dto.basicData.StationPageDTO;
import com.prolog.rdc.tms.model.dto.basicData.StationViewDTO;
import com.prolog.rdc.tms.model.vo.basicData.*;
import com.prolog.rdc.tms.service.basicData.StationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

import javax.validation.Valid;
import java.util.List;

/**
* 站点资料 Controller
* <p>
* Copyright: Copyright (C) 2023 prolog-int, Inc. All rights reserved.
* <p>
* Company: 湖北普罗格科技股份有限公司
*
*
* @author rdc
* @since 2023-03-24 16:03:25
*/
@RestController
@Api(tags = "站点资料控制器")
@RequestMapping("/station")
public class StationController {

    @Autowired
    private StationService service;

    @UserLog("站点资料分页查询")
    @ApiOperation(value = "站点资料分页查询", notes = "站点资料分页查询")
    @PostMapping("/page")
    public RestMessage<Page<StationPageDTO>> pageStationExecute(@RequestBody StationQueryVO vo) {
        try {
            Page<StationPageDTO> itemPagingQueryDTOs = service.pageStationData(vo);
            return RestMessage.newInstance(true, "查询成功", itemPagingQueryDTOs);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("站点资料弹窗")
    @ApiOperation(value = "站点资料弹窗", notes = "站点资料弹窗")
    @PostMapping("/popup")
    public RestMessage<Page<StationPageDTO>> popupStationExecute(@RequestBody StationQueryVO vo) {
        try {
            Page<StationPageDTO> itemPopupQueryDTOs = service.popupStationData(vo);
            return RestMessage.newInstance(true, "查询成功", itemPopupQueryDTOs);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("根据行政区查询站点资料")
    @ApiOperation(value = "根据行政区查询站点资料", notes = "根据行政区查询站点资料")
    @PostMapping("/query_by_administrative")
    public RestMessage<StationPageDTO> queryStationByAdministrativeExecute(@RequestBody StationQueryByAreasVO vo) {
        try {
            StationPageDTO queryDTO = service.queryStationByAdministrativeData(vo);
            return RestMessage.newInstance(true, "查询成功", queryDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("站点资料查看")
    @ApiOperation(value = "站点资料查看", notes = "站点资料查看")
    @PostMapping("/view")
    public RestMessage<StationViewDTO> viewStationExecute(@RequestBody StationQueryVO vo) {
        try {
            StationViewDTO dto = service.viewStationData(vo);
            return RestMessage.newInstance(true, "查看成功", dto);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("站点资料查看")
    @ApiOperation(value = "站点资料查看", notes = "站点资料查看")
    @PostMapping("/view_by_name")
    public RestMessage<StationViewDTO> viewStationByNameExecute(@RequestBody StationQueryVO vo) {
        try {
            StationViewDTO dto = service.viewStationByNameData(vo);
            return RestMessage.newInstance(true, "查看成功", dto);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("始发站点资料查询")
    @ApiOperation(value = "始发站点资料查询", notes = "始发站点资料查询")
    @PostMapping("/starting_station_query")
    public RestMessage<List<StartingStationViewDTO>> queryStartingStationExecute(@RequestBody StationQueryVO vo) {
        try {
            List<StartingStationViewDTO> list = service.queryStartingStationData(vo);
            return RestMessage.newInstance(true, "查看成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("站点资料新增")
    @ApiOperation(value = "站点资料新增", notes = "站点资料新增")
    @PostMapping("/add")
    public RestMessage<String> addStationExecute(@RequestBody @Valid StationAddVO vo) {
        try {
            service.addStationData(vo);
            return RestMessage.newInstance(true, "新增成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("站点资料修改")
    @ApiOperation(value = "站点资料修改", notes = "站点资料修改")
    @PostMapping("/update")
    public RestMessage<String> updateStationExecute(@RequestBody @Valid StationUpdateVO vo) {
        try {
            service.updateStationData(vo);
            return RestMessage.newInstance(true, "修改成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("停用")
    @ApiOperation(value = "停用", notes = "停用")
    @PostMapping("/disable")
    public RestMessage<Object> disableExecute(@RequestBody List<Long> ids){
        service.disableData(ids);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("启用")
    @ApiOperation(value = "启用", notes = "启用")
    @PostMapping("/active")
    public RestMessage<Object> activeExecute(@RequestBody List<Long> ids){
        service.activeData(ids);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("站点距离查询")
    @ApiOperation(value = "站点距离查询", notes = "站点距离查询")
    @PostMapping("/query_distance")
    public RestMessage<List<StationDistanceDTO>> queryStationDistanceExecute(@RequestBody List<StationDistanceVO> vos) {
        try {
            List<StationDistanceDTO> list = service.queryStationDistanceData(vos);
            return RestMessage.newInstance(true, "查看成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

}
