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.StorageHalfwayExportDTO;
import com.prolog.rdc.tms.model.dto.StorageHalfwayGetShipbillDTO;
import com.prolog.rdc.tms.model.dto.StorageHalfwayItemDetailDTO;
import com.prolog.rdc.tms.model.dto.StorageHalfwayPackageDetailDTO;
import com.prolog.rdc.tms.model.dto.StorageHalfwayQueryByLoadbillDTO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayAbnormalRegisterByShipbillVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayAbnormalRegisterVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayAdvancedQueryVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayDeliveredConfirmByShipbillVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayDeliveredConfirmVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayExportAllVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayExportPageVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayFeedBackByShipbillVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayFeedBackVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayGetShipbillVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayItemDetailVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayPackageDetailVO;
import com.prolog.rdc.tms.model.vo.StorageHalfwayQueryByLoadbillVO;
import com.prolog.rdc.tms.service.StorageHalfwayService;
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/17 11:05
 */
@RestController
@Api(tags = "运输管理-入库在途")
@RequestMapping("storageHalfway")
public class StorageHalfwayController {

    @Autowired
    private StorageHalfwayService storageHalfwayService;

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

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

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

    }

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

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

    @UserLog("运单-送达确认")
    @ApiOperation(value = "运单-送达确认", notes = "运单-送达确认")
    @PostMapping("/shipbill_delivered_confirm")
    public RestMessage<Object> shipbillDeliveredConfirmExecute(@RequestBody StorageHalfwayDeliveredConfirmByShipbillVO storageHalfwayDeliveredConfirmByShipbillVO){
        storageHalfwayService.shipbillDeliveredConfirmData(storageHalfwayDeliveredConfirmByShipbillVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

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

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

    @UserLog("派车单送达确认")
    @ApiOperation(value = "派车单送达确认", notes = "派车单送达确认")
    @PostMapping("/delivered_confirm")
    public RestMessage<Object> deliveredConfirmExecute(@RequestBody StorageHalfwayDeliveredConfirmVO storageHalfwayDeliveredConfirmVO){
        storageHalfwayService.deliveredConfirmData(storageHalfwayDeliveredConfirmVO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

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

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

    @UserLog("导出所有数据")
    @ApiOperation(value = "导出所有数据", notes = "导出所有数据")
    @PostMapping("/export_all")
    public RestMessage<Object> exportAllExecute(@RequestBody StorageHalfwayExportAllVO storageHalfwayExportAllVO, HttpServletResponse response) {
        try {
            List<StorageHalfwayExportDTO> list = storageHalfwayService.exportAllData(storageHalfwayExportAllVO);
            ExcelUtils.export(response, StorageHalfwayExportDTO.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 StorageHalfwayExportPageVO storageHalfwayExportPageVO, HttpServletResponse response) {
        try {
            List<StorageHalfwayExportDTO> list = storageHalfwayService.exportPageData(storageHalfwayExportPageVO);
            ExcelUtils.export(response, StorageHalfwayExportDTO.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<StorageHalfwayExportDTO> list = storageHalfwayService.exportSelectLineData(loadbillIds);
            ExcelUtils.export(response, StorageHalfwayExportDTO.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>> printStorageHalfwayExecute(@RequestBody List<String> loadbillIds) {
            Map<String, Object> map = storageHalfwayService.printStorageHalfwayData(loadbillIds);
            return RestMessage.newInstance(true, "打印成功！", map);
    }
}
