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.BmsBillIncomeFeeInfoDTO;
import com.prolog.rdc.tms.model.dto.income.BmsLoadingBillIncomeFeeInfoDTO;
import com.prolog.rdc.tms.model.dto.income.BmsLoadingBillIncomeFeeDTO;
import com.prolog.rdc.tms.model.dto.income.BmsShipBillIncomeFeeInfoDTO;
import com.prolog.rdc.tms.model.dto.income.BmsShipBillIncomeFeeDTO;
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.vo.income.BmsIncomeFeeAddVO;
import com.prolog.rdc.tms.model.vo.income.BmsIncomeQueryVO;
import com.prolog.rdc.tms.service.BmsBillIncomeFeeService;
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/4/13
 */
@RestController
@Api(tags = "BMS-收入台账管理")
@RequestMapping("/bmsIncomeFee")
public class BmsBillIncomeFeeController {

    @Autowired
    private BmsBillIncomeFeeService service;

    @UserLog("台账运单列表查询")
    @ApiOperation(value = "台账运单列表查询", notes = "台账运单列表查询")
    @PostMapping("/findShipBillFee")
    public RestMessage<Page<BmsShipBillIncomeFeeDTO>> findShipBillFee(@RequestBody @Valid BmsIncomeQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功", service.findShipBillFee(vo));
    }

    @UserLog("台账派车单列表查询")
    @ApiOperation(value = "台账派车单列表查询", notes = "台账派车单列表查询")
    @PostMapping("/findLoadingBillFee")
    public RestMessage<Page<BmsLoadingBillIncomeFeeDTO>> findLoadingBillFee(@RequestBody @Valid BmsIncomeQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功", service.findLoadingBillFee(vo));
    }

    @UserLog("台账详情")
    @ApiOperation(value = "台账详情", notes = "台账详情")
    @PostMapping("/detailById")
    public RestMessage<BmsBillIncomeFeeInfoDTO> detailById(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.detailById(id));
    }

    @UserLog("运单台账详情")
    @ApiOperation(value = "运单台账详情", notes = "运单台账详情")
    @PostMapping("/detailShipBillById")
    public RestMessage<BmsShipBillIncomeFeeInfoDTO> detailShipBillById(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.detailShipBillById(id));
    }

    @UserLog("派车单台账详情")
    @ApiOperation(value = "派车单台账详情", notes = "派车单台账详情")
    @PostMapping("/detailLoadingBillById")
    public RestMessage<BmsLoadingBillIncomeFeeInfoDTO> detailLoadingBillById(@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("/addFee")
    public RestMessage<Object> addFee(@RequestBody @Valid BmsIncomeFeeAddVO vo) {
        service.addFee(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("费用录入查询运单")
    @ApiOperation(value = "费用录入查询运单", notes = "费用录入查询运单")
    @PostMapping("/queryShipBill")
    public RestMessage<List<BmsShipBillIncomeFeeDTO>> queryShipBill(@RequestBody BmsIncomeQueryVO vo) {
        vo.setPageNum(1);
        vo.setPageSize(Integer.MAX_VALUE);
        Page<BmsShipBillIncomeFeeDTO> page = service.findShipBillFee(vo);
        return RestMessage.newInstance(true, "操作成功", page.getList());
    }

    @UserLog("费用录入查询派车单")
    @ApiOperation(value = "费用录入查询派车单", notes = "费用录入查询派车单")
    @PostMapping("/queryLoadingBill")
    public RestMessage<List<BmsLoadingBillIncomeFeeDTO>> queryLoadingBill(@RequestBody BmsIncomeQueryVO vo) {
        vo.setPageNum(1);
        vo.setPageSize(Integer.MAX_VALUE);
        Page<BmsLoadingBillIncomeFeeDTO> page = service.findLoadingBillFee(vo);
        return RestMessage.newInstance(true, "操作成功", page.getList());
    }

    @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("/submit")
    public RestMessage<Object> submit(@RequestBody List<Long> idList) {
        service.submit(idList);
        return RestMessage.newInstance(true, "操作成功", null);
    }

}