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.PickingOutboundExportDTO;
import com.prolog.rdc.tms.model.dto.PickingOutboundGetShipbillDTO;
import com.prolog.rdc.tms.model.dto.PickingOutboundItemDetailDTO;
import com.prolog.rdc.tms.model.dto.PickingOutboundLoadingScanDTO;
import com.prolog.rdc.tms.model.dto.PickingOutboundPackageDetailDTO;
import com.prolog.rdc.tms.model.dto.PickingOutboundQueryByLoadbillDTO;
import com.prolog.rdc.tms.model.vo.PickingOutboundAbnormalRegisterByShipbillVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundAbnormalRegisterVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundAdvancedQueryVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundConfirmVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundDeleteDetailVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundExportAllVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundExportPageVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundFeedBackByShipbillVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundFeedBackVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundGetShipbillVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundItemDetailVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundLoadingScanVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundPackageDetailVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundQueryByLoadbillVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundStartShipmentByShipbillVO;
import com.prolog.rdc.tms.model.vo.PickingOutboundStartShipmentVO;
import com.prolog.rdc.tms.service.PickingOutboundService;
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/27 14:23
 */
@RestController
@Api(tags = "运输管理-拣货出库")
@RequestMapping("pickingOutbound")
public class PickingOutboundController {

    @Autowired
    private PickingOutboundService pickingOutboundService;

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

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

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

    }

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

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

    /*@UserLog("拣货出库-装车扫描-已扫描查询")
    @ApiOperation(value = "拣货出库-装车扫描-已扫描查询", notes = "拣货出库-装车扫描-已扫描查询")
    @PostMapping("/query_scanned")
    public RestMessage<PickingOutboundScannedDTO> queryScannedExecute(@RequestBody PickingOutboundByLoadbillidVO pickingOutboundByLoadbillidVO) {
        PickingOutboundScannedDTO dto = pickingOutboundService.queryScannedData(pickingOutboundByLoadbillidVO);
        return RestMessage.newInstance(true, "查询成功！", dto);
    }

    @UserLog("拣货出库-装车扫描-未扫描查询")
    @ApiOperation(value = "拣货出库-装车扫描-未扫描查询", notes = "拣货出库-装车扫描-未扫描查询")
    @PostMapping("/query_not_scanned")
    public RestMessage<List<PickingOutboundNotScannedDTO>> queryNotScannedExecute(@RequestBody PickingOutboundByLoadbillidVO pickingOutboundByLoadbillidVO) {
        List<PickingOutboundNotScannedDTO> list = pickingOutboundService.queryNotScannedData(pickingOutboundByLoadbillidVO);
        return RestMessage.newInstance(true, "查询成功！", list);
    }*/

    @UserLog("装车扫描")
    @ApiOperation(value = "装车扫描", notes = "装车扫描")
    @PostMapping("/loading_scan")
    public RestMessage<PickingOutboundLoadingScanDTO> loadingScanExecute(@RequestBody PickingOutboundLoadingScanVO pickingOutboundLoadingScanVO) {
        PickingOutboundLoadingScanDTO dto = pickingOutboundService.loadingScanData(pickingOutboundLoadingScanVO);
        return RestMessage.newInstance(true, "操作成功", dto);
    }

    @UserLog("装车确认")
    @ApiOperation(value = "装车确认", notes = "装车确认")
    @PostMapping("/loading_confirm")
    public RestMessage<Object> loadingConfirmExecute(@RequestBody PickingOutboundConfirmVO pickingOutboundConfirmVO) {
        pickingOutboundService.loadingConfirmData(pickingOutboundConfirmVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

//    @UserLog("装车确认-加剔除")
//    @ApiOperation(value = "装车确认-加剔除", notes = "装车确认-加剔除")
//    @PostMapping("/loading_confirm_cull")
//    public RestMessage<Object> loadingConfirmCullExecute(@RequestBody PickingOutboundConfirmVO pickingOutboundConfirmVO) {
//        pickingOutboundService.loadingConfirmCullData(pickingOutboundConfirmVO);
//        return RestMessage.newInstance(true, "操作成功！", null);
//    }

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

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

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

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

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

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

    @UserLog("导出所有数据")
    @ApiOperation(value = "导出所有数据", notes = "导出所有数据")
    @PostMapping("/export_all")
    public RestMessage<Object> exportAllExecute(@RequestBody PickingOutboundExportAllVO pickingOutboundExportAllVO, HttpServletResponse response) {
        try {
            List<PickingOutboundExportDTO> list = pickingOutboundService.exportAllData(pickingOutboundExportAllVO);
            ExcelUtils.export(response, PickingOutboundExportDTO.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 PickingOutboundExportPageVO pickingOutboundExportPageVO, HttpServletResponse response) {
        try {
            List<PickingOutboundExportDTO> list = pickingOutboundService.exportPageData(pickingOutboundExportPageVO);
            ExcelUtils.export(response, PickingOutboundExportDTO.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<PickingOutboundExportDTO> list = pickingOutboundService.exportSelectLineData(loadbillIds);
            ExcelUtils.export(response, PickingOutboundExportDTO.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 = pickingOutboundService.printDeliveryConfirmData(loadbillIds);
        return RestMessage.newInstance(true, "打印成功！", map);
    }

    @UserLog("配载运单剔除")
    @ApiOperation(value = "配载运单剔除", notes = "配载运单剔除")
    @PostMapping("/delete_detail")
    public RestMessage<Object> deleteDetailExecute(@RequestBody PickingOutboundDeleteDetailVO pickingOutboundDeleteDetailVO) {
        pickingOutboundService.deleteDetailData(pickingOutboundDeleteDetailVO);
        return RestMessage.newInstance(true, "剔除成功！", null);
    }
}
