package com.prolog.rdc.tms.controller;

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.product.core.tools.util.JsonMapper;
import com.prolog.rdc.tms.model.dto.ShipBillDTO;
import com.prolog.rdc.tms.model.dto.ShipBillFeeListDTO;
import com.prolog.rdc.tms.model.vo.SettlementOrderVO;
import com.prolog.rdc.tms.model.vo.ShipBillQueryVO;
import com.prolog.rdc.tms.service.SettlementManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@Api(tags = "费用结算")
@RestController
@RequestMapping("/settlementManagement")
public class FeeSettlementManagementController {

    private final Logger logger = LoggerFactory.getLogger(FeeSettlementManagementController.class);

    @Autowired
    private SettlementManagementService settlementManagementService;

    @UserLog("费用结算-列表查询")
    @ApiOperation(value = "费用结算-列表查询", notes = "费用结算-列表查询")
    @PostMapping("/findList")
    public RestMessage<Page<ShipBillFeeListDTO>> findList(@RequestBody @Valid ShipBillQueryVO vo) {
        logger.info("- > findList vo={}", JsonMapper.toJsonString(vo));
        Page<ShipBillFeeListDTO> page = settlementManagementService.findList(vo);
        return RestMessage.newInstance(true, "操作成功", page);
    }

    @UserLog("费用结算-结算单信息")
    @ApiOperation(value = "费用结算-结算单信息", notes = "费用结算-结算单信息")
    @PostMapping("/settlementSave")
    public RestMessage<Object> settlementSave(@RequestBody @Valid SettlementOrderVO vo) {
        logger.info("- > settlementSave vo={}", JsonMapper.toJsonString(vo));
        settlementManagementService.settlementSave(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("运单管理-详情")
    @ApiOperation(value = "运单管理-详情", notes = "运单管理-详情")
    @PostMapping("/detail")
    public RestMessage<ShipBillDTO> detail(@RequestParam("shipbillNo") String shipbillNo) {
        logger.info("- > detail vo={}", JsonMapper.toJsonString(shipbillNo));
        ShipBillDTO detail = settlementManagementService.detail(shipbillNo);
        return RestMessage.newInstance(true, "操作成功", detail);
    }
}