package com.shanghaichengdi.ghjgitem.controller;

import com.alibaba.fastjson.JSONObject;
import com.shanghaichengdi.ghjgitem.constant.HttpStatus;
import com.shanghaichengdi.ghjgitem.service.CommonService;
import com.shanghaichengdi.ghjgitem.vo.CargoInfoForShipLockVo;
import com.shanghaichengdi.ghjgitem.vo.ObjectBodyVo;
import com.shanghaichengdi.ghjgitem.vo.ShipInfoForShipLockVo;
import com.shanghaichengdi.ghjgitem.vo.request.ShipDataRequest;
import com.shanghaichengdi.ghjgitem.vo.response.ReturnMsg;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping("/cargoDeclare")
public class CargoDeclareController extends CommonController  {
    @Resource
    private CommonService commonService;

    @PostMapping("getCargoInfoByShipId")
    public ReturnMsg getCargoInfoByShipId(@RequestBody @Validated ObjectBodyVo vo) {
        if (!checkDbKey(vo.getKey())) {
            return ReturnMsg.error(HttpStatus.BAD_REQUEST, "key值有误,请确认您输入的key值正确!");
        }
        String paramJsonData = getParamJsonData(vo.getData());
        ShipDataRequest req = JSONObject.parseObject(paramJsonData, ShipDataRequest.class);
        CargoInfoForShipLockVo voList = commonService.selectCargoDeclareInfoByShipId(req.getShipId());
        String jsonString = JSONObject.toJSONString(voList);
        String encodedData = resultEncode(jsonString);
        return ReturnMsg.success("获取成功", encodedData);
    }
}
