package com.prolog.rdc.tms.controller;

import java.util.List;
import java.util.Map;

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.RestController;

import javax.servlet.http.HttpServletResponse;

import com.prolog.common.util.DateUtils;
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.DeliveryConfirmExportDTO;
import com.prolog.rdc.tms.model.dto.DeliveryConfirmGetShipbillDTO;
import com.prolog.rdc.tms.model.dto.DeliveryConfirmItemDetailDTO;
import com.prolog.rdc.tms.model.dto.DeliveryConfirmPackageDetailDTO;
import com.prolog.rdc.tms.model.dto.DeliveryConfirmQueryByLoadbillDTO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmAbnormalRegisterByShipbillVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmAbnormalRegisterVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmAdvancedQueryVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmDeleteDetailVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmExportAllVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmExportPageVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmFeedBackByShipbillVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmFeedBackVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmGetShipbillVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmItemDetailVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmPackageDetailVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmQueryByLoadbillVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmStartShipmentByShipbillVO;
import com.prolog.rdc.tms.model.vo.DeliveryConfirmStartShipmentVO;
import com.prolog.rdc.tms.service.DeliveryConfirmService;
import com.prolog.rdc.tms.util.PublicMethods;
import com.prolog.wms.base.util.ExcelUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 提货确认控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/6/23 10:00
 */
@RestController
@Api(tags = "运输管理-提货确认")
@RequestMapping("deliveryConfirm")
public class DeliveryConfirmController {

    @Autowired
    private DeliveryConfirmService deliveryConfirmService;

    @UserLog("派车单查询")
    @ApiOperation(value = "派车单查询", notes = "派车单查询")
    @PostMapping("/query_loadbill")
    public RestMessage<Page<DeliveryConfirmQueryByLoadbillDTO>> queryLoadbillPageExecute(@RequestBody DeliveryConfirmQueryByLoadbillVO deliveryConfirmQueryByLoadbillVO){
        Page<DeliveryConfirmQueryByLoadbillDTO> page = deliveryConfirmService.queryLoadbillPageData(deliveryConfirmQueryByLoadbillVO);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("派车单高级查询")
    @ApiOperation(value = "派车单高级查询", notes = "派车单高级查询")
    @PostMapping("/advanced_query_loadbill")
    public RestMessage<Page<DeliveryConfirmQueryByLoadbillDTO>> advancedQueryLoadbillPageExecute(@RequestBody DeliveryConfirmAdvancedQueryVO deliveryConfirmAdvancedQueryVO){
        Page<DeliveryConfirmQueryByLoadbillDTO> page = deliveryConfirmService.advancedQueryLoadbillPageData(deliveryConfirmAdvancedQueryVO);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("配载运单查询")
    @ApiOperation(value = "配载运单查询", notes = "配载运单查询")
    @PostMapping("/get_shipbill")
    public RestMessage<Page<DeliveryConfirmGetShipbillDTO>> getShipbillExecute(@RequestBody DeliveryConfirmGetShipbillVO deliveryConfirmGetShipbillVO){
        Page<DeliveryConfirmGetShipbillDTO> page = deliveryConfirmService.getShipbillData(deliveryConfirmGetShipbillVO);
        return RestMessage.newInstance(true, "查询成功！", page);

    }

    @UserLog("配载商品查询")
    @ApiOperation(value = "配载商品查询", notes = "配载商品查询")
    @PostMapping("/item_detail")
    public RestMessage<Page<DeliveryConfirmItemDetailDTO>> itemDetailExecute(@RequestBody DeliveryConfirmItemDetailVO deliveryConfirmItemDetailVO){
        Page<DeliveryConfirmItemDetailDTO> page = deliveryConfirmService.itemDetailData(deliveryConfirmItemDetailVO);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("配载包裹查询")
    @ApiOperation(value = "配载包裹查询", notes = "配载包裹查询")
    @PostMapping("/package_detail")
    public RestMessage<Page<DeliveryConfirmPackageDetailDTO>> packageDetailExecute(@RequestBody DeliveryConfirmPackageDetailVO deliveryConfirmPackageDetailVO){
        Page<DeliveryConfirmPackageDetailDTO> page = deliveryConfirmService.packageDetailData(deliveryConfirmPackageDetailVO);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("运单启运登记")
    @ApiOperation(value = "运单启运登记", notes = "运单启运登记")
    @PostMapping("/shipbill_start_shipment")
    public RestMessage<Object> shipbillStartShipmentExecute(@RequestBody DeliveryConfirmStartShipmentByShipbillVO deliveryConfirmStartShipmentByShipbillVO){
            deliveryConfirmService.shipbillStartShipmentData(deliveryConfirmStartShipmentByShipbillVO);
            return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("运单客服反馈")
    @ApiOperation(value = "运单客服反馈", notes = "运单客服反馈")
    @PostMapping("/shipbill_feed_back")
    public RestMessage<Object> shipbillFeedBackExecute(@RequestBody DeliveryConfirmFeedBackByShipbillVO deliveryConfirmFeedBackByShipbillVO){
        deliveryConfirmService.shipbillFeedBackData(deliveryConfirmFeedBackByShipbillVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("运单异常登记")
    @ApiOperation(value = "运单异常登记", notes = "运单异常登记")
    @PostMapping("/shipbill_abnormal_register")
    public RestMessage<Object> shipbillAbnormalRegisterExecute(@RequestBody DeliveryConfirmAbnormalRegisterByShipbillVO deliveryConfirmAbnormalRegisterByShipbillVO){
        deliveryConfirmService.shipbillAbnormalRegisterData(deliveryConfirmAbnormalRegisterByShipbillVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("派车单启运登记")
    @ApiOperation(value = "派车单启运登记", notes = "派车单启运登记")
    @PostMapping("/start_shipment")
    public RestMessage<Object> startShipmentExecute(@RequestBody DeliveryConfirmStartShipmentVO deliveryConfirmStartShipmentVO){
        deliveryConfirmService.startShipmentData(deliveryConfirmStartShipmentVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("派车单客服反馈")
    @ApiOperation(value = "派车单客服反馈", notes = "派车单客服反馈")
    @PostMapping("/feed_back")
    public RestMessage<Object> feedBackExecute(@RequestBody DeliveryConfirmFeedBackVO deliveryConfirmFeedBackVO){
        deliveryConfirmService.feedBackData(deliveryConfirmFeedBackVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("派车单异常登记")
    @ApiOperation(value = "派车单异常登记", notes = "派车单异常登记")
    @PostMapping("/abnormal_register")
    public RestMessage<Object> abnormalRegisterExecute(@RequestBody DeliveryConfirmAbnormalRegisterVO deliveryConfirmAbnormalRegisterVO){
        deliveryConfirmService.abnormalRegisterData(deliveryConfirmAbnormalRegisterVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("导出所有数据")
    @ApiOperation(value = "导出所有数据", notes = "导出所有数据")
    @PostMapping("/export_all")
    public RestMessage<Object> exportAllExecute(@RequestBody DeliveryConfirmExportAllVO deliveryConfirmExportAllVO, HttpServletResponse response) {
        try {
            List<DeliveryConfirmExportDTO> list = deliveryConfirmService.exportAllData(deliveryConfirmExportAllVO);
            ExcelUtils.export(response, DeliveryConfirmExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
            return RestMessage.newInstance(true, "导出成功！", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
        }
    }

    @UserLog("导出当前页数据")
    @ApiOperation(value = "导出当前页数据", notes = "导出当前页数据")
    @PostMapping("/export_page")
    public RestMessage<Object> exportPageExecute(@RequestBody DeliveryConfirmExportPageVO deliveryConfirmExportPageVO, HttpServletResponse response) {
        try {
            List<DeliveryConfirmExportDTO> list = deliveryConfirmService.exportPageData(deliveryConfirmExportPageVO);
            ExcelUtils.export(response, DeliveryConfirmExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
            return RestMessage.newInstance(true, "导出成功！", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
        }
    }

    @UserLog("导出选择行数据")
    @ApiOperation(value = "导出选择行数据", notes = "导出选择行数据")
    @PostMapping("/export_select_line")
    public RestMessage<Object> exportSelectLineExecute(@RequestBody List<String> loadbillIds, HttpServletResponse response) {
        try {
            List<DeliveryConfirmExportDTO> list = deliveryConfirmService.exportSelectLineData(loadbillIds);
            ExcelUtils.export(response, DeliveryConfirmExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
            return RestMessage.newInstance(true, "导出成功！", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
        }
    }

    @UserLog("提货确认打印")
    @ApiOperation(value = "提货确认打印", notes = "提货确认打印")
    @PostMapping("/print")
    public RestMessage<Map<String, Object>> printDeliveryConfirmExecute(@RequestBody List<String> loadbillIds) {
        Map<String, Object> map = deliveryConfirmService.printDeliveryConfirmData(loadbillIds);
        return RestMessage.newInstance(true, "打印成功！", map);
    }

    @UserLog("配载运单剔除")
    @ApiOperation(value = "配载运单剔除", notes = "配载运单剔除")
    @PostMapping("/delete_detail")
    public RestMessage<Object> deleteDetailSendCarExecute(@RequestBody DeliveryConfirmDeleteDetailVO deliveryConfirmDeleteDetailVO) {
            deliveryConfirmService.deleteDetailSendCarData(deliveryConfirmDeleteDetailVO);
            return RestMessage.newInstance(true, "剔除成功！", null);
    }
}
