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.*;
import com.prolog.rdc.tms.model.dto.shipbill.BmsLogOperationDTO;
import com.prolog.rdc.tms.model.vo.ArFeeSettlementPageVO;
import com.prolog.rdc.tms.model.vo.ArSettlementOrderUpdateVO;
import com.prolog.rdc.tms.model.vo.SettlementFeeQueryVO;
import com.prolog.rdc.tms.model.vo.ArSettlementQueryVO;
import com.prolog.rdc.tms.service.ArCloseAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author lhb
 * @date 2023/5/9
 */
@RestController
@Api(tags = "BMS-应收管理 结算管理")
@RequestMapping("/ar_closeAccount")
@Slf4j
public class ArCloseAccountController {

    @Autowired
    private ArCloseAccountService closeAccountService;

    @UserLog("结算管理-列表查询")
    @ApiOperation(value = "费用结算-列表查询", notes = "费用结算-列表查询")
    @PostMapping("/findList")
    public RestMessage<Page<ArSettlementOrderDTO>> findList(@RequestBody @Valid ArSettlementQueryVO vo) throws ParseException {
        log.info("- > findList vo={}", JsonMapper.toJsonString(vo));
        Page<ArSettlementOrderDTO> page = closeAccountService.findList(vo);
        return RestMessage.newInstance(true, "操作成功", page);
    }

    @UserLog("盘点派车单查询")
    @ApiOperation(value = "盘点派车单查询", notes = "盘点派车单查询")
    @PostMapping("/find_loading")
    public RestMessage<Page<ArCloseAccountBillDTO>> findLoading(@RequestBody ArFeeSettlementPageVO vo) {
        return RestMessage.newInstance(true, "查询成功", closeAccountService.findLoading(vo));
    }

    @UserLog("结算管理-详情")
    @ApiOperation(value = "费用结算-详情", notes = "费用结算-详情")
    @PostMapping("/detail")
    public RestMessage<ArSettlementOrderDetailDTO> detail(@RequestParam("id") Long id) {
        log.info("- > detail vo={}", JsonMapper.toJsonString(id));
        ArSettlementOrderDetailDTO dto = closeAccountService.detail(id);
        return RestMessage.newInstance(true, "操作成功", dto);
    }

    @UserLog("结算管理-修改")
    @ApiOperation(value = "费用结算-修改", notes = "费用结算-修改")
    @PostMapping("/update")
    public RestMessage<Object> update(@RequestBody @Valid ArSettlementOrderUpdateVO vo) {
        log.info("- > update vo={}", JsonMapper.toJsonString(vo));
        closeAccountService.update(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("结算管理-审核")
    @ApiOperation(value = "费用结算-审核", notes = "费用结算-审核")
    @PostMapping("/audit")
    public RestMessage<Object> audit(@RequestBody List<Long> ids) {
        log.info("- > audit vo={}", JsonMapper.toJsonString(ids));
        closeAccountService.audit(ids);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("结算管理-费用信息")
    @ApiOperation(value = "费用结算-费用信息", notes = "费用结算-费用信息")
    @PostMapping("/feeList")
    public RestMessage<Page<BmsIncomeFeeDetailDTO>> feeList(@RequestBody SettlementFeeQueryVO vo) {
        log.info("- > feeList vo={}", JsonMapper.toJsonString(vo));
        Page<BmsIncomeFeeDetailDTO> page = closeAccountService.feeList(vo);
        return RestMessage.newInstance(true, "操作成功", page);
    }

    @UserLog("结算管理-日志")
    @ApiOperation(value = "费用结算-日志", notes = "费用结算-日志")
    @PostMapping("/findListForLog")
    public RestMessage<List<BmsLogOperationDTO>> findListForLog(@RequestParam("id") Long id) {
        log.info("- > findListForLog vo={}", JsonMapper.toJsonString(id));
        List<BmsLogOperationDTO> page = closeAccountService.findListForLog(id);
        return RestMessage.newInstance(true, "操作成功", page);
    }

    @UserLog("结算管理-作废")
    @ApiOperation(value = "费用结算-作废", notes = "费用结算-作废")
    @PostMapping("/invalid")
    public RestMessage<Object> invalid(@RequestParam("id") Long id) {
        log.info("- > invalid vo={}", JsonMapper.toJsonString(id));
        closeAccountService.invalid(id);
        return RestMessage.newInstance(true, "操作成功", null);
    }

}