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.ShipBillFeeDTO;
import com.prolog.rdc.tms.model.dto.ShipBillFeeListDTO;
import com.prolog.rdc.tms.model.vo.ShipBillQueryVO;
import com.prolog.rdc.tms.service.ReconciliationManagementService;
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;
import java.util.List;

@Api(tags = "对账单管理")
@RestController
@RequestMapping("/reconciliation")
public class ReconciliationManagementController {

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

    @Autowired
    private ReconciliationManagementService reconciliationManagementService;

    @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 = reconciliationManagementService.findList(vo);
        return RestMessage.newInstance(true, "操作成功", page);
    }

    @UserLog("对账单管理-提交")
    @ApiOperation(value = "对账单管理-提交", notes = "对账单管理-提交")
    @PostMapping("/submit")
    public RestMessage<Object> submit(@RequestBody List<String> ids) {
        logger.info("- > submit vo={}", JsonMapper.toJsonString(ids));
        reconciliationManagementService.submit(ids);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("对账单管理-确认")
    @ApiOperation(value = "对账单管理-确认", notes = "对账单管理-确认")
    @PostMapping("/confirm")
    public RestMessage<Object> confirm(@RequestBody List<String> ids) {
        logger.info("- > confirm vo={}", JsonMapper.toJsonString(ids));
        reconciliationManagementService.confirm(ids);
        return RestMessage.newInstance(true, "操作成功", null);
    }

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