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.rdc.tms.model.dto.income.BmsBillIncomeFeeDetailDTO;
import com.prolog.rdc.tms.model.dto.income.BmsLoadingBillIncomeFeeDTO;
import com.prolog.rdc.tms.model.dto.income.BmsLoadingBillIncomeFeeInfoDTO;
import com.prolog.rdc.tms.model.dto.shipbill.BmsLogOperationDTO;
import com.prolog.rdc.tms.model.dto.shipbill.BmsShipBillDTO;
import com.prolog.rdc.tms.model.dto.shipbill.BmsShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.shipbill.BmsShipBillPackageDTO;
import com.prolog.rdc.tms.model.entity.BmsIncomeSettlementModel;
import com.prolog.rdc.tms.model.vo.settlement.income.BmsIncomeFeeSettlementVO;
import com.prolog.rdc.tms.model.vo.settlement.income.IncomeFeeSettlementPageVO;
import com.prolog.rdc.tms.service.BmsBillIncomeFeeService;
import com.prolog.rdc.tms.service.BmsIncomeFeeSettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author hongbo.pan
 * @date 2023/5/4
 */
@RestController
@Api(tags = "结算管理-应收管理-费用结算")
@RequestMapping("/incomeFeeSettlement")
public class BmsIncomeFeeSettlementController {

    @Autowired
    private BmsBillIncomeFeeService service;

    @Autowired
    private BmsIncomeFeeSettlementService settlementService;

    @UserLog("派车单台账")
    @ApiOperation(value = "派车单台账", notes = "派车单台账")
    @PostMapping("/page")
    public RestMessage<Page<BmsLoadingBillIncomeFeeDTO>> page(@RequestBody IncomeFeeSettlementPageVO vo) {
        return RestMessage.newInstance(true, "查询成功", settlementService.findLoadingBillIncomeFeeForSettlement(vo));
    }

    @UserLog("查看派车单")
    @ApiOperation(value = "查看派车单", notes = "查看派车单")
    @PostMapping("/view")
    public RestMessage<BmsLoadingBillIncomeFeeInfoDTO> view(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "查询成功", service.detailLoadingBillById(id));
    }

    @UserLog("费用明细")
    @ApiOperation(value = "费用明细", notes = "费用明细")
    @PostMapping("/getDetail")
    public RestMessage<List<BmsBillIncomeFeeDetailDTO>> getDetail(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getDetail(id));
    }

    @UserLog("操作日志")
    @ApiOperation(value = "操作日志", notes = "操作日志")
    @PostMapping("/getLog")
    public RestMessage<List<BmsLogOperationDTO>> getLog(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getLog(id));
    }

    @UserLog("运单查询")
    @ApiOperation(value = "运单查询", notes = "运单查询")
    @PostMapping("/getShipBill")
    public RestMessage<List<BmsShipBillDTO>> getShipBill(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getShipBill(id));
    }

    @UserLog("商品明细查询")
    @ApiOperation(value = "商品明细查询", notes = "商品明细查询")
    @PostMapping("/getItem")
    public RestMessage<List<BmsShipBillDetailDTO>> getItem(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getItem(id));
    }

    @UserLog("包裹明细查询")
    @ApiOperation(value = "包裹明细查询", notes = "包裹明细查询")
    @PostMapping("/getPackage")
    public RestMessage<List<BmsShipBillPackageDTO>> getPackage(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getPackage(id));
    }

    @UserLog("审核日志")
    @ApiOperation(value = "审核日志", notes = "审核日志")
    @PostMapping("/getAudit")
    public RestMessage<List<Object>> getAudit(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getAudit(id));
    }

    @UserLog("费用结算")
    @ApiOperation(value = "费用结算", notes = "费用结算")
    @PostMapping("/feeSettlement")
    public RestMessage<Object> feeSettlement(@RequestBody @Valid BmsIncomeFeeSettlementVO vo) {
        settlementService.feeSettlement(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("结算单初始化")
    @ApiOperation(value = "结算单初始化", notes = "结算单初始化")
    @PostMapping("/initIncomeSettlement")
    public RestMessage<BmsIncomeSettlementModel> initIncomeSettlement(@RequestBody List<Long> feeIdList) {
        return RestMessage.newInstance(true, "操作成功", settlementService.initIncomeSettlement(feeIdList));
    }

}