package com.songhua.web.controller.ship;

import java.time.Instant;
import java.util.*;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.songhua.system.domain.GPSEquipment;
import com.songhua.system.domain.dto.ShipSaveDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.songhua.common.annotation.Log;
import com.songhua.common.core.controller.BaseController;
import com.songhua.common.core.domain.AjaxResult;
import com.songhua.common.enums.BusinessType;
import com.songhua.system.domain.CruiseShipMapping;
import com.songhua.system.service.ICruiseShipMappingService;
import com.songhua.common.core.page.TableDataInfo;

/**
 * Controller
 */
@RestController
@RequestMapping("/shipMapping")
public class CruiseShipMappingController extends BaseController
{
    @Autowired
    private ICruiseShipMappingService cruiseShipMappingService;


    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('ship:shipMapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(CruiseShipMapping cruiseShipMapping)
    {
        startPage();
        List<CruiseShipMapping> list = cruiseShipMappingService.selectCruiseShipMappingList(cruiseShipMapping);
        return getDataTable(list);
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('ship:shipMapping:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(cruiseShipMappingService.selectCruiseShipMappingById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('ship:shipMapping:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CruiseShipMapping cruiseShipMapping)
    {
        return toAjax(cruiseShipMappingService.insertCruiseShipMapping(cruiseShipMapping));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('ship:shipMapping:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CruiseShipMapping cruiseShipMapping)
    {
        return toAjax(cruiseShipMappingService.updateCruiseShipMapping(cruiseShipMapping));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('ship:shipMapping:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cruiseShipMappingService.deleteCruiseShipMappingByIds(ids));
    }

    @GetMapping("/shipRoute")
    public AjaxResult getCombinedCruiseData() {
        return success(cruiseShipMappingService.getShipRouteData());
    }

    @GetMapping("/getGpsByDid/{did}")
    public AjaxResult getGpsByDid(@PathVariable Long did) {
        return success(cruiseShipMappingService.getGpsByDid(did));
    }


    @PostMapping("/remote/saveCruiseShipMapping")
    public AjaxResult saveCruiseShipMapping(@RequestBody JSONObject json) {
        List<ShipSaveDTO> saveList = JSON.parseArray(json.getString("list"), ShipSaveDTO.class);
        return toAjax(cruiseShipMappingService.saveCruiseShipMapping(saveList));
    }

}
