package cn.com.taiji.beidou.web.controller.ship;

import cn.com.taiji.beidou.common.core.controller.BaseController;
import cn.com.taiji.beidou.common.core.domain.R;
import cn.com.taiji.beidou.common.core.page.TableDataInfo;
import cn.com.taiji.beidou.common.utils.StringUtils;

import cn.com.taiji.beidou.common.utils.bean.BeanUtils;
import cn.com.taiji.beidou.ship.status.domain.*;
import cn.com.taiji.beidou.ship.status.service.ShipStatusService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author CHEN
 * @Date 2022/11/12 15:29
 */
@Api(tags = "离线、长停船舶")
@RestController
public class ShipStatusController extends BaseController {

    @Resource
    private ShipStatusService shipStatusService;

    @ApiOperation("离线船舶详情")
    @GetMapping("/offLineShipById")
    public R<ShipStatusResult> findOffLineShipById(String devideNo){
        try{
            return R.ok(shipStatusService.selectById(devideNo,"OFFLINE",null));
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
    }

    @ApiOperation("离线船舶列表")
    @PostMapping("/offLineShipList")
    public TableDataInfo offLineShipList(@RequestBody OfflineShipReq req) {
        ShipStatusReq shipStatusReq = new ShipStatusReq();
        String sortType = req.getSortType();
        if ("descending".equals(sortType)){
            req.setSortType("DESC");
        }else if("ascending".equals(sortType)){
            req.setSortType("ASC");
        }
        BeanUtils.copyProperties(req,shipStatusReq);
        shipStatusReq.setDevideNo(req.getShipId());
        shipStatusReq.setIsOnline("OFFLINE");
        startPage(shipStatusReq.getPageNum(),shipStatusReq.getPageSize());
        List<ShipStatusResult> shipStatusResults = shipStatusService.selectShipStatusList(shipStatusReq);
        return getDataTable(shipStatusResults);
    }

    @ApiOperation("离线船舶统计")
    @GetMapping("/offlineShipStatistic")
    public R<OfflineShipStatistics> offlineShipStatistic(String shipId, String deptId){
        return shipStatusService.offlineShipTotal(shipId,deptId);
    }

    @ApiOperation("长停船舶详情")
    @GetMapping("/stasisShipById")
    public R<ShipStatusResult> stasisShipById(String devideNo){
        try{
            return R.ok(shipStatusService.selectById(devideNo,null,"TRUE"));
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
    }

    @ApiOperation("长停船舶列表")
    @PostMapping("/stasisShipList")
    public TableDataInfo stasisShipList(@RequestBody stasisShipReq req) {
        ShipStatusReq shipStatusReq = new ShipStatusReq();
        BeanUtils.copyProperties(req,shipStatusReq);
        shipStatusReq.setDevideNo(req.getShipId());
        shipStatusReq.setIsStasis("TRUE");
        startPage(req.getPageNum(),req.getPageSize());
        List<ShipStatusResult> shipStatusResults = shipStatusService.selectShipStatusList(shipStatusReq);
        return getDataTable(shipStatusResults);
    }


    @ApiOperation("长停船舶统计")
    @GetMapping("/stasisShipStatistic")
    public R<StasisShipStatistics> stasisShipStatistic(String shipId,String deptId){
        return shipStatusService.stasisShipTotal(shipId,deptId);
    }
}
