package com.aidex.web.controller.app;


import com.aidex.common.app.domain.vo.LocationVO;
import com.aidex.common.app.domain.vo.SysWharfVO;
import com.aidex.common.app.server.IAppService;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.gps.domain.LocationEntity;
import com.aidex.system.domain.SysConfig;
import com.aidex.system.domain.SysDictData;
import com.aidex.system.domain.SysNotice;
import com.aidex.system.domain.SysWharf;
import com.aidex.system.domain.vo.SysRouteVo;
import com.aidex.system.service.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/app")
@Tag(name = "小程序相关接口", description = "小程序管调用接口")
public class AppController {


    @Autowired
    private IAppService iAppService;

    @Autowired
    private SysWharfService sysWharfService;

    @Autowired
    private SysDictDataService sysDictDataService;

    @Autowired
    private SysNoticeService noticeService;

    @GetMapping("/carousel")
    @ApiOperation(value = "获取轮播信息", notes = "获取轮播信息", produces = "application/json")
    public R<List<SysNotice>> carousel()
    {
        return R.data(iAppService.getCarouselList());
    }

    @GetMapping("/notice")
    @ApiOperation(value = "获取通知公告", notes = "获取通知公告", produces = "application/json")
    public R<List<SysNotice>> notice()
    {
        return R.data(iAppService.getNoticeList());
    }

    @GetMapping("/noticeAndCarouseldetails/{id}")
    @ApiOperation(value = "获取轮播或公告详情", notes = "获取轮播或公告详情", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "数据主键ID", required = true, dataType = "String", paramType = "query")})
    public R<SysNotice> noticeAndCarouseldetails(@PathVariable("id") String id)
    {
        return R.data(iAppService.findCarouselAndNoticeDetails(id));
    }

    @GetMapping("/wharf")
    @ApiOperation(value = "获取全部站点列表", notes = "获取全部站点列表", produces = "application/json")
    public R<List<SysWharf>> findSysWharfList()
    {
        return R.data(iAppService.findSysWharfList());
    }

    @GetMapping("/location")
    @ApiOperation(value = "获取离我最近的船只位置", notes = "获取离我最近的船只位置", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "direction", value = "正向（TRUE）/反向（FALSE）、默认正向", required = true, dataType = "Boolean"),
            @ApiImplicitParam(name = "lat", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(name = "lon", value = "经度", required = true, dataType = "String")})
    public R<LocationVO> getLocation(@RequestParam(defaultValue = "true", name = "direction") Boolean direction,@RequestParam(defaultValue = "",name = "lat") String lat, @RequestParam(defaultValue = "",name = "lon") String lon )
    {
        return R.data(iAppService.findAllLocationByNext(direction,lat,lon));
    }


    @GetMapping("/location/all")
    @ApiOperation(value = "获取全部船只位置", notes = "获取全部船只位置", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "direction", value = "正向（TRUE）/反向（FALSE）、默认正向", required = true, dataType = "Boolean")})
    public R<List<LocationEntity>> getLocationAll(@RequestParam(defaultValue = "true", name = "direction") Boolean direction)
    {
        return R.data(iAppService.findAllLocation(direction));
    }

    @GetMapping("/wharf/my")
    @ApiOperation(value = "获取离我最近的站点及距离", notes = "获取离我最近的站点及距离", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lat", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(name = "lon", value = "经度", required = true, dataType = "String")})
    public R<SysWharfVO> getWharfMy(@RequestParam(defaultValue = "",name = "lat") String lat, @RequestParam(defaultValue = "",name = "lon") String lon )
    {
        return R.data(iAppService.findNearestStation(lat,lon));
    }

    @GetMapping("/route")
    @ApiOperation(value = "获取航线信息", notes = "获取航线信息", produces = "application/json")
    public R<List<SysRouteVo>> getRoute()
    {
        return R.data(sysWharfService.getRouteList());
    }

    @GetMapping("/notice/type")
    @ApiOperation(value = "获取信息类型", notes = "获取信息类型", produces = "application/json")
    public R<List<SysDictData>> getNoticeType()
    {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType("sys_notice_type");
        List<SysDictData> list = sysDictDataService.findList(sysDictData);
        return R.data(list);
    }

    @GetMapping("/notice/data")
    @ApiOperation(value = "按信息类型获取信息数据", notes = "按信息类型获取信息数据", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictValue", value = "信息类型", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true, dataType = "int")})
    public R<PageInfo> getNoticeData(@RequestParam(defaultValue = "1",name = "dictValue") String dictValue,
                                     @RequestParam(defaultValue = "1" ,name = "pageNum") Integer pageNum,
                                     @RequestParam(defaultValue = "10" ,name = "pageSize") Integer pageSize)
    {
        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeType(dictValue);
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(pageNum);
        pageDomain.setPageSize(pageSize);
        sysNotice.setPage(pageDomain);
        return R.data(noticeService.findPage(sysNotice));
    }

}
