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.easyexcel.util.ExcelUtils;
import com.prolog.rdc.tms.model.dto.income.ArReconciliationLoadingDTO;
import com.prolog.rdc.tms.model.dto.income.BmsBillIncomeFeeDetailDTO;
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.vo.BmsFeeAdjustImportVO;
import com.prolog.rdc.tms.model.vo.income.ArReconciliationLoadingVO;
import com.prolog.rdc.tms.service.ArReconciliationMngService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * @author lhb
 * @date 2023/5/9
 */
@RestController
@Api(tags = "BMS-应收管理 对账管理")
@RequestMapping("/arReconciliationMng")
public class ArReconciliationMngController {

    @Autowired
    private ArReconciliationMngService service;

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

    @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("/getLog")
    public RestMessage<List<BmsLogOperationDTO>> getLog(@RequestParam("id") Long id) {
        return RestMessage.newInstance(true, "操作成功", service.getLog(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("/confirm")
    public RestMessage<Object> confirm(@RequestBody List<String> ids) {
        service.confirm(ids);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("调整费用-导入模版下载")
    @ApiOperation(value = "调整费用-导入模版下载", notes = "调整费用-导入模版下载")
    @PostMapping("/download_template")
    public RestMessage<String> feeImport(HttpServletResponse response) throws IOException {
        ExcelUtils.export(response, BmsFeeAdjustImportVO.class, "派车单费用模板", null, null, null, true);
        return null;
    }

    @UserLog("调整费用-导入")
    @ApiOperation(value = "调整费用-导入", notes = "调整费用-导入")
    @PostMapping("/import")
    public RestMessage<String> feeAdjustImport(@RequestParam("file") MultipartFile file, HttpServletRequest httpServletRequest) throws Exception{
        service.importFeeAdjustData(file);
        return RestMessage.newInstance(true, "导入成功", null);
    }

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

}