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.BmsShipBillFeeDetailDTO;
import com.prolog.rdc.tms.model.dto.SettlementOrderDTO;
import com.prolog.rdc.tms.model.entity.BmsLogOperationModel;
import com.prolog.rdc.tms.model.vo.SettlementOrderUpdateVO;
import com.prolog.rdc.tms.model.vo.ArSettlementQueryVO;
import com.prolog.rdc.tms.service.CloseAccountService;
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.text.ParseException;
import java.util.List;


@Api(tags = "结算管理")
@RestController
@RequestMapping("/closeAccount")
public class CloseAccountController {

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

    @Autowired
    private CloseAccountService closeAccountService;

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

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

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

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

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

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

}